feat: add setting to enable/disable the "recents" feature

This commit is contained in:
Sebastiano Giordano 2026-02-05 20:13:56 +01:00 committed by Ashley Wulber
parent 8909689245
commit 5d3d893c9e
5 changed files with 72 additions and 40 deletions

View file

@ -298,6 +298,7 @@ calculating = Calculating...
## Settings ## Settings
settings = Settings settings = Settings
single-click = Single click to open single-click = Single click to open
show-recents = Show recents
### Appearance ### Appearance
appearance = Appearance appearance = Appearance

View file

@ -424,6 +424,7 @@ pub enum Message {
SearchClear, SearchClear,
SearchInput(String), SearchInput(String),
SetShowDetails(bool), SetShowDetails(bool),
SetShowRecents(bool),
SetTypeToSearch(TypeToSearch), SetTypeToSearch(TypeToSearch),
SystemThemeModeChange, SystemThemeModeChange,
Size(window::Id, Size), Size(window::Id, Size),
@ -842,6 +843,7 @@ impl App {
for path in paths { for path in paths {
match open::that_detached(&path) { match open::that_detached(&path) {
Ok(()) => { Ok(()) => {
if self.config.show_recents {
let _ = recently_used_xbel::update_recently_used( let _ = recently_used_xbel::update_recently_used(
&path, &path,
Self::APP_ID.to_string(), Self::APP_ID.to_string(),
@ -849,6 +851,7 @@ impl App {
None, None,
); );
} }
}
Err(err) => { Err(err) => {
log::warn!("failed to open {}: {}", path.display(), err); log::warn!("failed to open {}: {}", path.display(), err);
} }
@ -911,6 +914,7 @@ impl App {
for (i, mut command) in commands.into_iter().enumerate() { for (i, mut command) in commands.into_iter().enumerate() {
match spawn_detached(&mut command) { match spawn_detached(&mut command) {
Ok(()) => { Ok(()) => {
if self.config.show_recents {
for path in paths { for path in paths {
let _ = recently_used_xbel::update_recently_used( let _ = recently_used_xbel::update_recently_used(
&path.into(), &path.into(),
@ -919,6 +923,7 @@ impl App {
None, None,
); );
} }
}
return true; return true;
} }
@ -1548,11 +1553,13 @@ impl App {
fn update_nav_model(&mut self) { fn update_nav_model(&mut self) {
let mut nav_model = segmented_button::ModelBuilder::default(); let mut nav_model = segmented_button::ModelBuilder::default();
if self.config.show_recents {
nav_model = nav_model.insert(|b| { nav_model = nav_model.insert(|b| {
b.text(fl!("recents")) b.text(fl!("recents"))
.icon(icon::from_name("document-open-recent-symbolic")) .icon(icon::from_name("document-open-recent-symbolic"))
.data(Location::Recents) .data(Location::Recents)
}); });
}
for (favorite_i, favorite) in self.config.favorites.iter().enumerate() { for (favorite_i, favorite) in self.config.favorites.iter().enumerate() {
if let Some(path) = favorite.path_opt() { 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(),
]) ])
.into() .into()
@ -2961,6 +2972,7 @@ impl Application for App {
{ {
match spawn_detached(&mut command) { match spawn_detached(&mut command) {
Ok(()) => { Ok(()) => {
if self.config.show_recents {
let _ = recently_used_xbel::update_recently_used( let _ = recently_used_xbel::update_recently_used(
&path, &path,
Self::APP_ID.to_string(), Self::APP_ID.to_string(),
@ -2968,6 +2980,7 @@ impl Application for App {
None, None,
); );
} }
}
Err(err) => { Err(err) => {
log::warn!( log::warn!(
"failed to open {} with {:?}: {}", "failed to open {} with {:?}: {}",
@ -4029,6 +4042,10 @@ impl Application for App {
config_set!(show_details, show_details); config_set!(show_details, show_details);
return self.update_config(); return self.update_config();
} }
Message::SetShowRecents(show_recents) => {
config_set!(show_recents, show_recents);
return self.update_config();
}
Message::SetTypeToSearch(type_to_search) => { Message::SetTypeToSearch(type_to_search) => {
config_set!(type_to_search, type_to_search); config_set!(type_to_search, type_to_search);
return self.update_config(); return self.update_config();
@ -4831,8 +4848,10 @@ impl Application for App {
} }
}, },
Message::Recents => { Message::Recents => {
if self.config.show_recents {
return self.open_tab(Location::Recents, false, None); return self.open_tab(Location::Recents, false, None);
} }
}
#[cfg(all(feature = "wayland", feature = "desktop-applet"))] #[cfg(all(feature = "wayland", feature = "desktop-applet"))]
Message::OutputEvent(output_event, output) => { Message::OutputEvent(output_event, output) => {
match output_event { match output_event {
@ -6346,12 +6365,15 @@ impl Application for App {
std::future::pending().await std::future::pending().await
}), }),
), ),
];
#[cfg(all( #[cfg(all(
not(feature = "desktop-applet"), not(feature = "desktop-applet"),
not(target_os = "ios"), not(target_os = "ios"),
not(target_os = "android") not(target_os = "android")
))] ))]
Subscription::run_with_id( if self.config.show_recents {
subscriptions.push(Subscription::run_with_id(
TypeId::of::<RecentsWatcherSubscription>(), TypeId::of::<RecentsWatcherSubscription>(),
stream::channel(1, |mut output| async move { stream::channel(1, |mut output| async move {
let Some(recents_path) = recently_used_xbel::dir() else { let Some(recents_path) = recently_used_xbel::dir() else {
@ -6411,8 +6433,8 @@ impl Application for App {
std::future::pending().await std::future::pending().await
}), }),
), ));
]; }
if let Some(scroll_speed) = self.auto_scroll_speed { if let Some(scroll_speed) = self.auto_scroll_speed {
subscriptions.push( subscriptions.push(

View file

@ -167,6 +167,7 @@ pub struct Config {
pub thumb_cfg: ThumbCfg, pub thumb_cfg: ThumbCfg,
pub favorites: Vec<Favorite>, pub favorites: Vec<Favorite>,
pub show_details: bool, pub show_details: bool,
pub show_recents: bool,
pub tab: TabConfig, pub tab: TabConfig,
pub type_to_search: TypeToSearch, pub type_to_search: TypeToSearch,
} }
@ -229,6 +230,7 @@ impl Default for Config {
Favorite::Videos, Favorite::Videos,
], ],
show_details: false, show_details: false,
show_recents: true,
tab: TabConfig::default(), tab: TabConfig::default(),
type_to_search: TypeToSearch::Recursive, type_to_search: TypeToSearch::Recursive,
} }

View file

@ -1609,6 +1609,7 @@ impl Application for App {
&& let Some(path) = item.path_opt() && let Some(path) = item.path_opt()
{ {
paths.push(path.clone()); paths.push(path.clone());
if self.flags.config.show_recents {
let _ = update_recently_used( let _ = update_recently_used(
path, path,
Self::APP_ID.to_string(), Self::APP_ID.to_string(),
@ -1618,6 +1619,7 @@ impl Application for App {
} }
} }
} }
}
// Ensure selection is allowed // Ensure selection is allowed
//TODO: improve tab logic so this doesn't block the open button so often //TODO: improve tab logic so this doesn't block the open button so often

View file

@ -123,7 +123,12 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
} else if &arg == "--trash" { } else if &arg == "--trash" {
Location::Trash Location::Trash
} else if &arg == "--recents" { } else if &arg == "--recents" {
if config.show_recents {
Location::Recents Location::Recents
} else {
log::warn!("recents feature is disabled in config");
continue;
}
} else if &arg == "--network" { } else if &arg == "--network" {
Location::Network("network:///".to_string(), fl!("networks"), None) Location::Network("network:///".to_string(), fl!("networks"), None)
} else { } else {