src/exit.rs
27 lines · 712 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 framework
13 .data
14 .global
15 .get::<WatchHistory>()
16 .unwrap()
17 .exit_move();
18
19 let home_dir = home_dir().unwrap();
20 let cache_path = home_dir.join(".cache/youtube-tui/");
21
22 if cache_path.exists() {
23 fs::remove_dir_all(cache_path)?;
24 }
25
26 Ok(())
27}