Commit 95700f4c6f

95700f4c6f2323693a22b08930f4bcc80f62c7f5

parent: dba33247c8

Unsigned

Siriusmart <sirius@siri.ws> · 2025-11-08 11:12 UTC

removed outdated cache and stuff?

Layout: unified · split

src/exit.rs +34 −7
@@ -1,13 +1,12 @@
11use home::home_dir;
2use std::{error::Error, fs};
2use std::{collections::HashSet, error::Error, fs};
33use tui_additions::framework::Framework;
44
55use crate::{
6 config::MainConfig,
7 global::{
6 CACHED_BEFORE, config::MainConfig, global::{
87 structs::*,
98 traits::{Collection, CollectionNoId},
10 },
9 }
1110};
1211
1312/// function to run when the app ends
@@ -15,8 +14,8 @@ use crate::{
1514// - move thumbnails of videos in watch history to `~/.local/share/youtube-tui/watch_history/thumbnails`
1615// - remove `~/.cache`
1716pub fn exit(framework: &mut Framework) -> Result<(), Box<dyn Error>> {
18 let limits = framework.data.global.get::<MainConfig>().unwrap().limits;
19 let watchhistory = framework.data.global.get_mut::<WatchHistory>().unwrap();
17 let mut limits = framework.data.global.remove::<MainConfig>().unwrap().limits;
18 let mut watchhistory = framework.data.global.remove::<WatchHistory>().unwrap();
2019 watchhistory.trim(limits.watch_history);
2120 // watchhistory.exit_move();
2221 let _ = watchhistory.save();
@@ -27,9 +26,37 @@ pub fn exit(framework: &mut Framework) -> Result<(), Box<dyn Error>> {
2726 let searchhistory = framework.data.global.get_mut::<SearchHistory>().unwrap();
2827 searchhistory.trim(limits.search_history);
2928 let _ = searchhistory.save();
30 let commandhistory = framework.data.global.get_mut::<CommandHistory>().unwrap();
29 let mut commandhistory = framework.data.global.remove::<CommandHistory>().unwrap();
3130 commandhistory.trim(limits.commands_history);
3231 let _ = commandhistory.save();
32 let library = framework.data.global.get_mut::<Library>().unwrap();
33 let _ = library.save();
34
35 let cached_after: HashSet<String> = HashSet::from_iter(
36 library
37 .items()
38 .iter()
39 .filter_map(|item| item.id())
40 .map(str::to_string)
41 .chain(
42 watchhistory
43 .items()
44 .iter()
45 .filter_map(|item| item.id())
46 .map(str::to_string),
47 ),
48 );
49
50 let cached_before = CACHED_BEFORE.get().unwrap();
51
52 let info_path = home_dir().unwrap().join(".local/share/youtube-tui/info/");
53 let thumbnail_path = home_dir().unwrap().join(".local/share/youtube-tui/info/");
54
55 // remove cache that no longer exists
56 for deleted in cached_before.iter().filter(|id| !cached_after.contains(*id)) {
57 let _ = fs::remove_file(info_path.join(deleted).with_extension("json"));
58 let _ = fs::remove_file(thumbnail_path.join(deleted));
59 }
3360
3461 // let home_dir = home_dir().unwrap();
3562 // let cache_path = home_dir.join(".cache/youtube-tui/");
src/global/functions/run_command.rs −3
@@ -126,7 +126,6 @@ pub fn run_single_command(
126126 Some(item) => {
127127 let library = framework.data.global.get_mut::<Library>().unwrap();
128128 let _ = library.push(item);
129 let _ = library.save();
130129 *framework.data.global.get_mut::<Message>().unwrap() =
131130 Message::Success(String::from("Bookmark added"))
132131 }
@@ -139,7 +138,6 @@ pub fn run_single_command(
139138 let library = framework.data.global.get_mut::<Library>().unwrap();
140139
141140 if library.remove(id) {
142 let _ = library.save();
143141 *framework.data.global.get_mut::<Message>().unwrap() =
144142 Message::Success(String::from("Bookmark removed"))
145143 } else {
@@ -150,7 +148,6 @@ pub fn run_single_command(
150148 ["togglemark", id] => {
151149 let library = framework.data.global.get_mut::<Library>().unwrap();
152150 if library.remove(id) {
153 let _ = library.save();
154151 *framework.data.global.get_mut::<Message>().unwrap() =
155152 Message::Success(String::from("Bookmark removed"))
156153 } else {
src/global/structs/tasks.rs +10 −10
@@ -194,16 +194,16 @@ impl TaskQueue {
194194
195195 Self::render_force_clear(framework, terminal)?;
196196 // reload simply runs `.load()` on all items
197 *framework.data.global.get_mut::<Message>().unwrap() =
198 Message::Message(String::from("Reloading page..."));
199 Self::render_force_clear(framework, terminal)?;
200 *framework.data.global.get_mut::<Message>().unwrap() =
201 if let Err(e) = framework.load() {
202 Message::Error(e.to_string())
203 } else {
204 Message::None
205 };
206 self.render = RenderTask::All;
197 *framework.data.global.get_mut::<Message>().unwrap() =
198 Message::Message(String::from("Reloading page..."));
199 Self::render_force_clear(framework, terminal)?;
200 *framework.data.global.get_mut::<Message>().unwrap() = if let Err(e) = framework.load()
201 {
202 Message::Error(e.to_string())
203 } else {
204 Message::None
205 };
206 self.render = RenderTask::All;
207207
208208 let status = framework.data.global.get_mut::<Status>().unwrap();
209209 status.provider_updated = true;
src/global/traits/collection.rs +5 −2
@@ -58,10 +58,13 @@ where
5858 // removes duplicates and place them on top (if exists)
5959 let id = match item.id() {
6060 Some(t) => t,
61 None => return Ok(()) // TODO make error message
61 None => return Ok(()), // TODO make error message
6262 };
6363
64 let info = home_dir().unwrap().join(".local/share/youtube-tui/info/").join(format!("{id}.json"));
64 let info = home_dir()
65 .unwrap()
66 .join(".local/share/youtube-tui/info/")
67 .join(format!("{id}.json"));
6568
6669 if let Some(index) = self
6770 .items_mut()
src/init.rs +23 −5
@@ -5,6 +5,7 @@ use crate::{
55use home::home_dir;
66use ratatui::{backend::CrosstermBackend, Terminal};
77use std::{
8 collections::HashSet,
89 error::Error,
910 fs::{self},
1011 io::Stdout,
@@ -15,6 +16,7 @@ use tui_additions::framework::{Framework, FrameworkClean};
1516
1617pub static mut MAIN_CONFIG: OnceLock<MainConfig> = OnceLock::new();
1718pub static RUNTIME: OnceLock<Runtime> = OnceLock::new();
19pub static CACHED_BEFORE: OnceLock<HashSet<String>> = OnceLock::new();
1820
1921/// app to run before the app starts
2022// init tasks:
@@ -53,6 +55,25 @@ pub fn init(
5355
5456 load_configs(&mut framework.split_clean().0)?;
5557
58 let library = Library::load();
59 let watchhistory = WatchHistory::load();
60
61 let cached_set: HashSet<String> = HashSet::from_iter(
62 library
63 .items()
64 .iter()
65 .filter_map(|item| item.id())
66 .map(str::to_string)
67 .chain(
68 watchhistory
69 .items()
70 .iter()
71 .filter_map(|item| item.id())
72 .map(str::to_string),
73 ),
74 );
75 CACHED_BEFORE.set(cached_set).unwrap();
76
5677 framework
5778 .data
5879 .global
@@ -61,10 +82,7 @@ pub fn init(
6182 .data
6283 .global
6384 .insert::<SearchHistory>(SearchHistory::load());
64 framework
65 .data
66 .global
67 .insert::<WatchHistory>(WatchHistory::load());
85 framework.data.global.insert::<WatchHistory>(watchhistory);
6886 framework
6987 .data
7088 .global
@@ -73,7 +91,7 @@ pub fn init(
7391 .data
7492 .global
7593 .insert::<Subscriptions>(Subscriptions::load());
76 framework.data.global.insert::<Library>(Library::load());
94 framework.data.global.insert::<Library>(library);
7795 framework.data.global.insert::<Message>(Message::None);
7896
7997 framework.data.global.insert::<Status>(Status {