From 5d3d893c9ee2d52d7e7b0cea71b96e65d206d8ad Mon Sep 17 00:00:00 2001 From: Sebastiano Giordano <46520354+Krahos@users.noreply.github.com> Date: Thu, 5 Feb 2026 20:13:56 +0100 Subject: [PATCH] feat: add setting to enable/disable the "recents" feature --- i18n/en/cosmic_files.ftl | 1 + src/app.rs | 88 +++++++++++++++++++++++++--------------- src/config.rs | 2 + src/dialog.rs | 14 ++++--- src/lib.rs | 7 +++- 5 files changed, 72 insertions(+), 40 deletions(-) diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 859c4f8..1bb3d5a 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -298,6 +298,7 @@ calculating = Calculating... ## Settings settings = Settings single-click = Single click to open +show-recents = Show recents ### Appearance appearance = Appearance diff --git a/src/app.rs b/src/app.rs index 1c76f35..e78c02c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -424,6 +424,7 @@ pub enum Message { SearchClear, SearchInput(String), SetShowDetails(bool), + SetShowRecents(bool), SetTypeToSearch(TypeToSearch), SystemThemeModeChange, Size(window::Id, Size), @@ -842,12 +843,14 @@ impl App { for path in paths { match open::that_detached(&path) { Ok(()) => { - let _ = recently_used_xbel::update_recently_used( - &path, - Self::APP_ID.to_string(), - "cosmic-files".to_string(), - None, - ); + if self.config.show_recents { + let _ = recently_used_xbel::update_recently_used( + &path, + Self::APP_ID.to_string(), + "cosmic-files".to_string(), + None, + ); + } } Err(err) => { log::warn!("failed to open {}: {}", path.display(), err); @@ -911,13 +914,15 @@ impl App { for (i, mut command) in commands.into_iter().enumerate() { match spawn_detached(&mut command) { Ok(()) => { - for path in paths { - let _ = recently_used_xbel::update_recently_used( - &path.into(), - Self::APP_ID.to_string(), - "cosmic-files".to_string(), - None, - ); + if self.config.show_recents { + for path in paths { + let _ = recently_used_xbel::update_recently_used( + &path.into(), + Self::APP_ID.to_string(), + "cosmic-files".to_string(), + None, + ); + } } return true; @@ -1548,11 +1553,13 @@ impl App { fn update_nav_model(&mut self) { let mut nav_model = segmented_button::ModelBuilder::default(); - nav_model = nav_model.insert(|b| { - b.text(fl!("recents")) - .icon(icon::from_name("document-open-recent-symbolic")) - .data(Location::Recents) - }); + if self.config.show_recents { + nav_model = nav_model.insert(|b| { + b.text(fl!("recents")) + .icon(icon::from_name("document-open-recent-symbolic")) + .data(Location::Recents) + }); + } for (favorite_i, favorite) in self.config.favorites.iter().enumerate() { if let Some(path) = favorite.path_opt() { @@ -2059,6 +2066,10 @@ impl App { }, ) }) + .add({ + widget::settings::item::builder(fl!("show-recents")) + .toggler(self.config.show_recents, Message::SetShowRecents) + }) .into(), ]) .into() @@ -2961,12 +2972,14 @@ impl Application for App { { match spawn_detached(&mut command) { Ok(()) => { - let _ = recently_used_xbel::update_recently_used( - &path, - Self::APP_ID.to_string(), - "cosmic-files".to_string(), - None, - ); + if self.config.show_recents { + let _ = recently_used_xbel::update_recently_used( + &path, + Self::APP_ID.to_string(), + "cosmic-files".to_string(), + None, + ); + } } Err(err) => { log::warn!( @@ -4029,6 +4042,10 @@ impl Application for App { config_set!(show_details, show_details); return self.update_config(); } + Message::SetShowRecents(show_recents) => { + config_set!(show_recents, show_recents); + return self.update_config(); + } Message::SetTypeToSearch(type_to_search) => { config_set!(type_to_search, type_to_search); return self.update_config(); @@ -4831,7 +4848,9 @@ impl Application for App { } }, Message::Recents => { - return self.open_tab(Location::Recents, false, None); + if self.config.show_recents { + return self.open_tab(Location::Recents, false, None); + } } #[cfg(all(feature = "wayland", feature = "desktop-applet"))] Message::OutputEvent(output_event, output) => { @@ -6346,12 +6365,15 @@ impl Application for App { std::future::pending().await }), ), - #[cfg(all( - not(feature = "desktop-applet"), - not(target_os = "ios"), - not(target_os = "android") - ))] - Subscription::run_with_id( + ]; + + #[cfg(all( + not(feature = "desktop-applet"), + not(target_os = "ios"), + not(target_os = "android") + ))] + if self.config.show_recents { + subscriptions.push(Subscription::run_with_id( TypeId::of::(), stream::channel(1, |mut output| async move { let Some(recents_path) = recently_used_xbel::dir() else { @@ -6411,8 +6433,8 @@ impl Application for App { std::future::pending().await }), - ), - ]; + )); + } if let Some(scroll_speed) = self.auto_scroll_speed { subscriptions.push( diff --git a/src/config.rs b/src/config.rs index 7f606bd..cbe84a6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -167,6 +167,7 @@ pub struct Config { pub thumb_cfg: ThumbCfg, pub favorites: Vec, pub show_details: bool, + pub show_recents: bool, pub tab: TabConfig, pub type_to_search: TypeToSearch, } @@ -229,6 +230,7 @@ impl Default for Config { Favorite::Videos, ], show_details: false, + show_recents: true, tab: TabConfig::default(), type_to_search: TypeToSearch::Recursive, } diff --git a/src/dialog.rs b/src/dialog.rs index a5b9c4a..bede7d5 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -1609,12 +1609,14 @@ impl Application for App { && let Some(path) = item.path_opt() { paths.push(path.clone()); - let _ = update_recently_used( - path, - Self::APP_ID.to_string(), - "cosmic-files".to_string(), - None, - ); + if self.flags.config.show_recents { + let _ = update_recently_used( + path, + Self::APP_ID.to_string(), + "cosmic-files".to_string(), + None, + ); + } } } } diff --git a/src/lib.rs b/src/lib.rs index e2bd675..0489098 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,12 @@ pub fn main() -> Result<(), Box> { } else if &arg == "--trash" { Location::Trash } else if &arg == "--recents" { - Location::Recents + if config.show_recents { + Location::Recents + } else { + log::warn!("recents feature is disabled in config"); + continue; + } } else if &arg == "--network" { Location::Network("network:///".to_string(), fl!("networks"), None) } else {