src/exit.rs

24 lines · 704 bytes

 1use home::home_dir;
 2use std::{error::Error, fs};
 3use tui_additions::framework::Framework;
 4
 5use crate::global::{structs::WatchHistory, traits::Collection};
 6
 7/// function to run when the app ends
 8// exit tasks:
 9//  - move thumbnails of videos in watch history to `~/.local/share/youtube-tui/watch_history/thumbnails`
10//  - remove `~/.cache`
11pub fn exit(framework: &Framework) -> Result<(), Box<dyn Error>> {
12    if let Some(history) = framework.data.global.get::<WatchHistory>() {
13        history.exit_move()
14    }
15
16    let home_dir = home_dir().unwrap();
17    let cache_path = home_dir.join(".cache/youtube-tui/");
18
19    if cache_path.exists() {
20        fs::remove_dir_all(cache_path)?;
21    }
22
23    Ok(())
24}