chore: clippy

This commit is contained in:
Vukašin Vojinović 2025-10-03 03:24:44 +02:00 • committed by Ashley Wulber
parent 4a4d5c0a9e
commit 909577b364
9 changed files with 121 additions and 146 deletions

49
Cargo.lock generated
View file

@ -965,9 +965,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.39" version = "1.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f" checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"jobserver", "jobserver",
@ -1438,7 +1438,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-config" name = "cosmic-config"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"atomicwrites", "atomicwrites",
"cosmic-config-derive", "cosmic-config-derive",
@ -1459,7 +1459,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-config-derive" name = "cosmic-config-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"quote", "quote",
"syn 2.0.106", "syn 2.0.106",
@ -1621,7 +1621,7 @@ dependencies = [
[[package]] [[package]]
name = "cosmic-theme" name = "cosmic-theme"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"almost", "almost",
"cosmic-config", "cosmic-config",
@ -2343,9 +2343,9 @@ dependencies = [
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.2" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3"
[[package]] [[package]]
name = "fixed_decimal" name = "fixed_decimal"
@ -3177,7 +3177,7 @@ dependencies = [
[[package]] [[package]]
name = "iced" name = "iced"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"dnd", "dnd",
"iced_accessibility", "iced_accessibility",
@ -3195,7 +3195,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_accessibility" name = "iced_accessibility"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"accesskit", "accesskit",
"accesskit_winit", "accesskit_winit",
@ -3204,7 +3204,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_core" name = "iced_core"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"bitflags 2.9.4", "bitflags 2.9.4",
"bytes", "bytes",
@ -3228,7 +3228,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_futures" name = "iced_futures"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"futures", "futures",
"iced_core", "iced_core",
@ -3254,7 +3254,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_graphics" name = "iced_graphics"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"bitflags 2.9.4", "bitflags 2.9.4",
"bytemuck", "bytemuck",
@ -3276,7 +3276,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_renderer" name = "iced_renderer"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"iced_graphics", "iced_graphics",
"iced_tiny_skia", "iced_tiny_skia",
@ -3288,7 +3288,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_runtime" name = "iced_runtime"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"bytes", "bytes",
"cosmic-client-toolkit", "cosmic-client-toolkit",
@ -3303,7 +3303,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_tiny_skia" name = "iced_tiny_skia"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cosmic-text", "cosmic-text",
@ -3319,7 +3319,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_wgpu" name = "iced_wgpu"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"as-raw-xcb-connection", "as-raw-xcb-connection",
"bitflags 2.9.4", "bitflags 2.9.4",
@ -3350,7 +3350,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_widget" name = "iced_widget"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"cosmic-client-toolkit", "cosmic-client-toolkit",
"dnd", "dnd",
@ -3369,7 +3369,7 @@ dependencies = [
[[package]] [[package]]
name = "iced_winit" name = "iced_winit"
version = "0.14.0-dev" version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"cosmic-client-toolkit", "cosmic-client-toolkit",
"dnd", "dnd",
@ -4454,7 +4454,7 @@ checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174"
[[package]] [[package]]
name = "libcosmic" name = "libcosmic"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#6c5b799b343f877c310d9f9bf23ea3f282bdf1a2" source = "git+https://github.com/pop-os/libcosmic.git#ad1672b8815389f7c13643615c54968597ffc07e"
dependencies = [ dependencies = [
"apply", "apply",
"ashpd 0.12.0", "ashpd 0.12.0",
@ -6608,9 +6608,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_with" name = "serde_with"
version = "3.14.1" version = "3.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c522100790450cf78eeac1507263d0a350d4d5b30df0c8e1fe051a10c22b376e" checksum = "6093cd8c01b25262b84927e0f7151692158fab02d961e04c979d3903eba7ecc5"
dependencies = [ dependencies = [
"base64", "base64",
"chrono", "chrono",
@ -6619,8 +6619,7 @@ dependencies = [
"indexmap 2.11.4", "indexmap 2.11.4",
"schemars 0.9.0", "schemars 0.9.0",
"schemars 1.0.4", "schemars 1.0.4",
"serde", "serde_core",
"serde_derive",
"serde_json", "serde_json",
"serde_with_macros", "serde_with_macros",
"time", "time",
@ -6628,9 +6627,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_with_macros" name = "serde_with_macros"
version = "3.14.1" version = "3.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327ada00f7d64abaac1e55a6911e90cf665aa051b9a561c7006c157f4633135e" checksum = "a7e6c180db0816026a61afa1cff5344fb7ebded7e4d3062772179f2501481c27"
dependencies = [ dependencies = [
"darling 0.21.3", "darling 0.21.3",
"proc-macro2", "proc-macro2",

View file

@ -534,6 +534,12 @@ pub struct DialogPages {
pages: VecDeque<DialogPage>, pages: VecDeque<DialogPage>,
} }
impl Default for DialogPages {
fn default() -> Self {
Self::new()
}
}
impl DialogPages { impl DialogPages {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -996,7 +1002,6 @@ impl App {
self.margin = overlaps; self.margin = overlaps;
} }
#[must_use]
fn open_tab_entity( fn open_tab_entity(
&mut self, &mut self,
location: Location, location: Location,
@ -1061,7 +1066,6 @@ impl App {
} }
// This wrapper ensures that local folders use trash and remote folders permanently delete with a dialog // This wrapper ensures that local folders use trash and remote folders permanently delete with a dialog
#[must_use]
fn delete(&mut self, paths: Vec<PathBuf>) -> Task<Message> { fn delete(&mut self, paths: Vec<PathBuf>) -> Task<Message> {
let mut dialog_paths = Vec::new(); let mut dialog_paths = Vec::new();
let mut trash_paths = Vec::new(); let mut trash_paths = Vec::new();
@ -1069,10 +1073,7 @@ impl App {
for path in paths { for path in paths {
//TODO: is there a smarter way to check this? (like checking for trash folders) //TODO: is there a smarter way to check this? (like checking for trash folders)
let can_trash = match path.metadata() { let can_trash = match path.metadata() {
Ok(metadata) => match tab::fs_kind(&metadata) { Ok(metadata) => matches!(tab::fs_kind(&metadata), tab::FsKind::Local),
tab::FsKind::Local => true,
_ => false,
},
Err(err) => { Err(err) => {
log::warn!("failed to get metadata for {:?}: {}", path, err); log::warn!("failed to get metadata for {:?}: {}", path, err);
false false
@ -1097,7 +1098,6 @@ impl App {
Task::batch(tasks) Task::batch(tasks)
} }
#[must_use]
fn operation(&mut self, operation: Operation) -> Task<Message> { fn operation(&mut self, operation: Operation) -> Task<Message> {
let id = self.pending_operation_id; let id = self.pending_operation_id;
let controller = Controller::default(); let controller = Controller::default();
@ -1157,7 +1157,6 @@ impl App {
} }
} }
#[must_use]
fn rescan_operation_selection(&mut self, op_sel: OperationSelection) -> Task<Message> { fn rescan_operation_selection(&mut self, op_sel: OperationSelection) -> Task<Message> {
log::info!("rescan_operation_selection {:?}", op_sel); log::info!("rescan_operation_selection {:?}", op_sel);
let entity = self.tab_model.active(); let entity = self.tab_model.active();
@ -2023,7 +2022,7 @@ impl App {
} }
} }
return false; false
} }
} }
@ -2085,7 +2084,7 @@ impl Application for App {
.unwrap() .unwrap()
.block_on(async move { .block_on(async move {
while let Some(task) = compio_rx.recv().await { while let Some(task) = compio_rx.recv().await {
_ = compio::runtime::spawn(task).detach(); compio::runtime::spawn(task).detach();
} }
}) })
}); });
@ -2242,7 +2241,7 @@ impl Application for App {
if location_opt if location_opt
.and_then(|x| x.path_opt()) .and_then(|x| x.path_opt())
.map_or(false, |x| x.is_file()) .is_some_and(|x| x.is_file())
{ {
items.push(cosmic::widget::menu::Item::Button( items.push(cosmic::widget::menu::Item::Button(
fl!("open"), fl!("open"),
@ -2320,14 +2319,14 @@ impl Application for App {
found |= item.path().is_some_and(|p| path.starts_with(&p)) found |= item.path().is_some_and(|p| path.starts_with(&p))
|| item.name() == *name || item.name() == *name
|| item.uri() == *uri; || item.uri() == *uri;
(!item.is_mounted() && found).then(|| *k) (!item.is_mounted() && found).then_some(*k)
}) })
}) })
.or(if found { .or(if found {
None None
} else { } else {
// TODO do we need to choose the correct mounter? // TODO do we need to choose the correct mounter?
self.mounter_items.iter().map(|(k, _)| *k).next() self.mounter_items.keys().map(|k| *k).next()
}) })
{ {
if let Some(mounter) = MOUNTERS.get(&key) { if let Some(mounter) = MOUNTERS.get(&key) {
@ -3079,7 +3078,7 @@ impl Application for App {
} }
Message::NetworkDriveSubmit => { Message::NetworkDriveSubmit => {
//TODO: know which mounter to use for network drives //TODO: know which mounter to use for network drives
for (mounter_key, mounter) in MOUNTERS.iter() { if let Some((mounter_key, mounter)) = MOUNTERS.iter().next() {
self.network_drive_connecting = self.network_drive_connecting =
Some((*mounter_key, self.network_drive_input.clone())); Some((*mounter_key, self.network_drive_input.clone()));
return mounter return mounter
@ -3877,7 +3876,7 @@ impl Application for App {
}; };
let window_id = WindowId::unique(); let window_id = WindowId::unique();
self.windows.insert( self.windows.insert(
window_id.clone(), window_id,
WindowKind::ContextMenu(entity, widget::Id::unique()), WindowKind::ContextMenu(entity, widget::Id::unique()),
); );
commands.push(self.update(Message::Surface( commands.push(self.update(Message::Surface(
@ -3901,7 +3900,7 @@ impl Application for App {
parent: parent_id.unwrap_or( parent: parent_id.unwrap_or(
app.core app.core
.main_window_id() .main_window_id()
.unwrap_or_else(|| WindowId::NONE), .unwrap_or(WindowId::NONE),
), ),
id: window_id, id: window_id,
positioner, positioner,
@ -4062,7 +4061,7 @@ impl Application for App {
.sort_names .sort_names
.get(&location_str) .get(&location_str)
.or_else(|| SORT_OPTION_FALLBACK.get(&location_str)) .or_else(|| SORT_OPTION_FALLBACK.get(&location_str))
.unwrap_or_else(|| &(HeadingOptions::Name, true)); .unwrap_or(&(HeadingOptions::Name, true));
tab.sort_name = sort.0; tab.sort_name = sort.0;
tab.sort_direction = sort.1; tab.sort_direction = sort.1;
@ -4377,7 +4376,7 @@ impl Application for App {
.and_then(|x| x.path_opt()) .and_then(|x| x.path_opt())
.map(ToOwned::to_owned) .map(ToOwned::to_owned)
{ {
return self.open_file(&[path]).into(); return self.open_file(&[path]);
} }
} }
NavMenuAction::OpenWith(entity) => { NavMenuAction::OpenWith(entity) => {
@ -4635,7 +4634,7 @@ impl Application for App {
if let Some(p) = paths.first() { if let Some(p) = paths.first() {
{ {
for (k, mounter_items) in &self.mounter_items { for (k, mounter_items) in &self.mounter_items {
if let Some(mounter) = MOUNTERS.get(&k) { if let Some(mounter) = MOUNTERS.get(k) {
if let Some(item) = mounter_items if let Some(item) = mounter_items
.iter() .iter()
.find(|item| item.path().is_some_and(|path| path == *p)) .find(|item| item.path().is_some_and(|path| path == *p))
@ -4767,10 +4766,7 @@ impl Application for App {
); );
} }
} }
let dialog_page = self.dialog_pages.front()?;
let Some(dialog_page) = self.dialog_pages.front() else {
return None;
};
let cosmic_theme::Spacing { let cosmic_theme::Spacing {
space_xxs, space_s, .. space_xxs, space_s, ..
@ -4855,8 +4851,7 @@ impl Application for App {
archive_type: archive_types[index], archive_type: archive_types[index],
password: password.clone(), password: password.clone(),
}) })
}) }),
.into(),
]) ])
.align_y(Alignment::Center) .align_y(Alignment::Center)
.spacing(space_xxs) .spacing(space_xxs)
@ -5963,8 +5958,7 @@ impl Application for App {
// watching the trash which is slow but also properly get events. // watching the trash which is slow but also properly get events.
let trash_paths = trash_bins let trash_paths = trash_bins
.into_iter() .into_iter()
.map(|path| [path.join("files"), path]) .flat_map(|path| [path.join("files"), path]);
.flatten();
for path in trash_paths { for path in trash_paths {
if let Err(e) = if let Err(e) =
watcher.watch(&path, notify::RecursiveMode::NonRecursive) watcher.watch(&path, notify::RecursiveMode::NonRecursive)

View file

@ -159,11 +159,9 @@ impl<T: AsRef<str>> From<T> for DialogLabel {
let underline = next_underline; let underline = next_underline;
next_underline = false; next_underline = false;
if c == '_' { if c == '_' && !underline {
if !underline { next_underline = true;
next_underline = true; continue;
continue;
}
} }
if underline && key_bind_opt.is_none() { if underline && key_bind_opt.is_none() {
@ -1041,10 +1039,7 @@ impl Application for App {
); );
} }
let dialog_page = match self.dialog_pages.front() { let dialog_page = self.dialog_pages.front()?;
Some(some) => some,
None => return None,
};
let dialog = match dialog_page { let dialog = match dialog_page {
DialogPage::NewFolder { parent, name } => { DialogPage::NewFolder { parent, name } => {
@ -1628,7 +1623,7 @@ impl Application for App {
}; };
use cosmic::iced::Rectangle; use cosmic::iced::Rectangle;
let window_id = window::Id::unique(); let window_id = window::Id::unique();
self.context_menu_window = Some(window_id.clone()); self.context_menu_window = Some(window_id);
let autosize_id = widget::Id::unique(); let autosize_id = widget::Id::unique();
commands.push(self.update(Message::Surface( commands.push(self.update(Message::Surface(
cosmic::surface::action::app_popup( cosmic::surface::action::app_popup(

View file

@ -535,13 +535,13 @@ pub fn menu_bar<'a>(
menu::Item::CheckBox( menu::Item::CheckBox(
label, label,
None, None,
sort_options.map_or(false, |(sort_name, sort_direction, _)| { sort_options.is_some_and(|(sort_name, sort_direction, _)| {
sort_name == sort && sort_direction == dir sort_name == sort && sort_direction == dir
}), }),
Action::SetSort(sort, dir), Action::SetSort(sort, dir),
) )
}; };
let in_trash = tab_opt.map_or(false, |tab| tab.location == Location::Trash); let in_trash = tab_opt.is_some_and(|tab| tab.location == Location::Trash);
let mut selected_dir = 0; let mut selected_dir = 0;
let mut selected = 0; let mut selected = 0;
@ -637,26 +637,26 @@ pub fn menu_bar<'a>(
menu::Item::CheckBox( menu::Item::CheckBox(
fl!("grid-view"), fl!("grid-view"),
None, None,
tab_opt.map_or(false, |tab| matches!(tab.config.view, tab::View::Grid)), tab_opt.is_some_and(|tab| matches!(tab.config.view, tab::View::Grid)),
Action::TabViewGrid, Action::TabViewGrid,
), ),
menu::Item::CheckBox( menu::Item::CheckBox(
fl!("list-view"), fl!("list-view"),
None, None,
tab_opt.map_or(false, |tab| matches!(tab.config.view, tab::View::List)), tab_opt.is_some_and(|tab| matches!(tab.config.view, tab::View::List)),
Action::TabViewList, Action::TabViewList,
), ),
menu::Item::Divider, menu::Item::Divider,
menu::Item::CheckBox( menu::Item::CheckBox(
fl!("show-hidden-files"), fl!("show-hidden-files"),
None, None,
tab_opt.map_or(false, |tab| tab.config.show_hidden), tab_opt.is_some_and(|tab| tab.config.show_hidden),
Action::ToggleShowHidden, Action::ToggleShowHidden,
), ),
menu::Item::CheckBox( menu::Item::CheckBox(
fl!("list-directories-first"), fl!("list-directories-first"),
None, None,
tab_opt.map_or(false, |tab| tab.config.folders_first), tab_opt.is_some_and(|tab| tab.config.folders_first),
Action::ToggleFoldersFirst, Action::ToggleFoldersFirst,
), ),
menu::Item::CheckBox( menu::Item::CheckBox(

View file

@ -439,7 +439,7 @@ impl MimeAppCache {
fn get_default_terminal(&self) -> Option<String> { fn get_default_terminal(&self) -> Option<String> {
let output = process::Command::new("xdg-mime") let output = process::Command::new("xdg-mime")
.args(&["query", "default", "x-scheme-handler/terminal"]) .args(["query", "default", "x-scheme-handler/terminal"])
.output() .output()
.ok()?; .ok()?;

View file

@ -69,7 +69,7 @@ pub fn mime_for_path<P: AsRef<Path>>(
gb.file_name(file_name); gb.file_name(file_name);
} }
} else { } else {
gb.path(&path); gb.path(path);
} }
if let Some(metadata) = metadata_opt { if let Some(metadata) = metadata_opt {
gb.metadata(metadata.clone()); gb.metadata(metadata.clone());
@ -77,7 +77,7 @@ pub fn mime_for_path<P: AsRef<Path>>(
let guess = gb.guess(); let guess = gb.guess();
if guess.uncertain() { if guess.uncertain() {
// If uncertain, try mime_guess. This could happen on platforms without shared-mime-info // If uncertain, try mime_guess. This could happen on platforms without shared-mime-info
mime_guess::from_path(&path).first_or_octet_stream() mime_guess::from_path(path).first_or_octet_stream()
} else { } else {
guess.mime_type().clone() guess.mime_type().clone()
} }

View file

@ -99,10 +99,7 @@ fn network_scan(uri: &str, sizes: IconSizes) -> Result<Vec<tab::Item>, String> {
let metadata = if !force_dir && !info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE) { let metadata = if !force_dir && !info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE) {
let mtime = info.attribute_uint64(gio::FILE_ATTRIBUTE_TIME_MODIFIED); let mtime = info.attribute_uint64(gio::FILE_ATTRIBUTE_TIME_MODIFIED);
let is_dir = match info.file_type() { let is_dir = matches!(info.file_type(), gio::FileType::Directory);
gio::FileType::Directory => true,
_ => false,
};
let size_opt = match is_dir { let size_opt = match is_dir {
true => None, true => None,
false => Some(info.size() as u64), false => Some(info.size() as u64),

View file

@ -309,24 +309,24 @@ fn tab_complete(path: &Path) -> Result<Vec<(String, PathBuf)>, Box<dyn Error>> {
.ok_or_else(|| format!("path has no parent {:?}", path))? .ok_or_else(|| format!("path has no parent {:?}", path))?
}; };
let child_os = path.strip_prefix(&parent)?; let child_os = path.strip_prefix(parent)?;
let child = child_os let child = child_os
.to_str() .to_str()
.ok_or_else(|| format!("invalid UTF-8 {:?}", child_os))?; .ok_or_else(|| format!("invalid UTF-8 {:?}", child_os))?;
let pattern = format!("^{}", regex::escape(&child)); let pattern = format!("^{}", regex::escape(child));
let regex = regex::RegexBuilder::new(&pattern) let regex = regex::RegexBuilder::new(&pattern)
.case_insensitive(true) .case_insensitive(true)
.build()?; .build()?;
let mut completions = Vec::new(); let mut completions = Vec::new();
for entry_res in fs::read_dir(&parent)? { for entry_res in fs::read_dir(parent)? {
let entry = entry_res?; let entry = entry_res?;
let file_name_os = entry.file_name(); let file_name_os = entry.file_name();
let Some(file_name) = file_name_os.to_str() else { let Some(file_name) = file_name_os.to_str() else {
continue; continue;
}; };
if regex.is_match(&file_name) { if regex.is_match(file_name) {
completions.push((file_name.to_string(), entry.path())); completions.push((file_name.to_string(), entry.path()));
} }
} }
@ -610,10 +610,7 @@ pub fn item_from_gvfs_info(path: PathBuf, file_info: gio::FileInfo, sizes: IconS
let mtime = file_info.attribute_uint64(gio::FILE_ATTRIBUTE_TIME_MODIFIED); let mtime = file_info.attribute_uint64(gio::FILE_ATTRIBUTE_TIME_MODIFIED);
let mut display_name = Item::display_name(&file_info.display_name()); let mut display_name = Item::display_name(&file_info.display_name());
let remote = file_info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE); let remote = file_info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE);
let is_dir = match file_info.file_type() { let is_dir = matches!(file_info.file_type(), gio::FileType::Directory);
gio::FileType::Directory => true,
_ => false,
};
let size_opt = match is_dir { let size_opt = match is_dir {
true => None, true => None,
@ -881,11 +878,11 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
{ {
if let Ok(path_meta) = fs::metadata(tab_path) { if let Ok(path_meta) = fs::metadata(tab_path) {
if fs_kind(&path_meta) == FsKind::Gvfs { if fs_kind(&path_meta) == FsKind::Gvfs {
let file = gio::File::for_path(&tab_path); let file = gio::File::for_path(tab_path);
// gio crate expects a comma delimited string // gio crate expects a comma delimited string
let mut attr_string = String::new(); let mut attr_string = String::new();
for attr in vec![ for attr in [
gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE, gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE,
gio::FILE_ATTRIBUTE_TIME_MODIFIED, gio::FILE_ATTRIBUTE_TIME_MODIFIED,
@ -906,11 +903,9 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
) { ) {
Ok(res) => { Ok(res) => {
remote_scannable = true; remote_scannable = true;
for file in res { for file in res.flatten() {
if let Ok(file) = file { let full_path = Path::new(tab_path).join(file.name());
let full_path = Path::new(tab_path).join(file.name()); items.push(item_from_gvfs_info(full_path, file, sizes));
items.push(item_from_gvfs_info(full_path, file, sizes));
}
} }
} }
Err(err) => { Err(err) => {
@ -1821,36 +1816,33 @@ impl ItemThumbnail {
} }
}; };
match dyn_img { if let Some(dyn_img) = dyn_img {
Some(dyn_img) => { if let Ok(cacher) = thumbnail_cacher.as_ref() {
if let Ok(cacher) = thumbnail_cacher.as_ref() { match cacher.update_with_image(dyn_img) {
match cacher.update_with_image(dyn_img) { Ok(path) => {
Ok(path) => { return ItemThumbnail::Image(
return ItemThumbnail::Image( widget::image::Handle::from_path(path),
widget::image::Handle::from_path(path), None,
None, );
); }
} Err(err) => {
Err(err) => { log::warn!("cacher failed to decode {:?}: {}", path, err);
log::warn!("cacher failed to decode {:?}: {}", path, err);
}
} }
} else {
// Fallback for when thumbnail cacher isn't available.
let thumbnail = dyn_img
.thumbnail(thumbnail_size, thumbnail_size)
.into_rgba8();
return ItemThumbnail::Image(
widget::image::Handle::from_rgba(
thumbnail.width(),
thumbnail.height(),
thumbnail.into_raw(),
),
Some((dyn_img.width(), dyn_img.height())),
);
} }
} else {
// Fallback for when thumbnail cacher isn't available.
let thumbnail = dyn_img
.thumbnail(thumbnail_size, thumbnail_size)
.into_rgba8();
return ItemThumbnail::Image(
widget::image::Handle::from_rgba(
thumbnail.width(),
thumbnail.height(),
thumbnail.into_raw(),
),
Some((dyn_img.width(), dyn_img.height())),
);
} }
None => (),
} }
} }
@ -1924,7 +1916,7 @@ impl ItemThumbnail {
thumbnail_dir: Option<&Path>, thumbnail_dir: Option<&Path>,
) -> Option<(ItemThumbnail, NamedTempFile)> { ) -> Option<(ItemThumbnail, NamedTempFile)> {
// Try external thumbnailers // Try external thumbnailers
for thumbnailer in thumbnailer(&mime) { for thumbnailer in thumbnailer(mime) {
let is_evince = thumbnailer.exec.starts_with("evince-thumbnailer "); let is_evince = thumbnailer.exec.starts_with("evince-thumbnailer ");
let prefix = if is_evince { let prefix = if is_evince {
//TODO: apparmor config for evince-thumbnailer does not allow /tmp/cosmic-files* //TODO: apparmor config for evince-thumbnailer does not allow /tmp/cosmic-files*
@ -1934,15 +1926,13 @@ impl ItemThumbnail {
}; };
// It's preferable to create the tempfile in the same directory as the final cached // It's preferable to create the tempfile in the same directory as the final cached
// thumbnail to ensure that no copies accross filesytems need to be made. However, // thumbnail to ensure that no copies across filesytems need to be made. However,
// the apparmor config for evince-thumbnailer does not allow this, so we need to // the apparmor config for evince-thumbnailer does not allow this, so we need to
// fallback to the system tempdir. // fallback to the system tempdir.
let file = if thumbnail_dir.is_none() || is_evince { let dir = if is_evince { None } else { thumbnail_dir };
tempfile::Builder::new().prefix(prefix).tempfile() let file = match dir {
} else { Some(d) => tempfile::Builder::new().prefix(prefix).tempfile_in(d),
tempfile::Builder::new() None => tempfile::Builder::new().prefix(prefix).tempfile(),
.prefix(prefix)
.tempfile_in(thumbnail_dir.unwrap())
}; };
let file = match file { let file = match file {
Ok(ok) => ok, Ok(ok) => ok,
@ -2060,7 +2050,7 @@ impl Item {
widget::image(handle.clone()).into() widget::image(handle.clone()).into()
} }
ItemThumbnail::Svg(handle) => widget::svg(handle.clone()).into(), ItemThumbnail::Svg(handle) => widget::svg(handle.clone()).into(),
ItemThumbnail::Text(content) => widget::text_editor(&content) ItemThumbnail::Text(content) => widget::text_editor(content)
.class(cosmic::theme::iced::TextEditor::Custom(Box::new( .class(cosmic::theme::iced::TextEditor::Custom(Box::new(
text_editor_class, text_editor_class,
))) )))
@ -2544,7 +2534,7 @@ impl Tab {
.and_then(|opts| opts.get(&location_str)) .and_then(|opts| opts.get(&location_str))
.or_else(|| SORT_OPTION_FALLBACK.get(&location_str)) .or_else(|| SORT_OPTION_FALLBACK.get(&location_str))
.cloned() .cloned()
.unwrap_or_else(|| (HeadingOptions::Name, true)); .unwrap_or((HeadingOptions::Name, true));
let location = location.normalize(); let location = location.normalize();
let location_ancestors = location.ancestors(); let location_ancestors = location.ancestors();
let location_title = location.title(); let location_title = location.title();
@ -3404,10 +3394,10 @@ impl Tab {
// Try to select previous item in current row // Try to select previous item in current row
if !col if !col
.checked_sub(1) .checked_sub(1)
.map_or(false, |col| self.select_position(row, col, mod_shift)) .is_some_and(|col| self.select_position(row, col, mod_shift))
{ {
// Try to select last item in previous row // Try to select last item in previous row
if !row.checked_sub(1).map_or(false, |row| { if !row.checked_sub(1).is_some_and(|row| {
let mut col = 0; let mut col = 0;
if let Some(ref items) = self.items_opt { if let Some(ref items) = self.items_opt {
for item in items.iter() { for item in items.iter() {
@ -3496,7 +3486,7 @@ impl Tab {
// Try to select item in last row // Try to select item in last row
if !row if !row
.checked_sub(1) .checked_sub(1)
.map_or(false, |row| self.select_position(row, col, mod_shift)) .is_some_and(|row| self.select_position(row, col, mod_shift))
{ {
// Ensure current item is still selected if there are no other items // Ensure current item is still selected if there are no other items
self.select_position(row, col, mod_shift); self.select_position(row, col, mod_shift);
@ -3596,9 +3586,9 @@ impl Tab {
self.update(Message::Click(click_i_opt), modifiers); self.update(Message::Click(click_i_opt), modifiers);
} }
if let Some(ref mut items) = self.items_opt { if let Some(ref mut items) = self.items_opt {
if !click_i_opt.map_or(false, |click_i| { if !click_i_opt
items.get(click_i).map_or(false, |x| x.selected) .is_some_and(|click_i| items.get(click_i).is_some_and(|x| x.selected))
}) { {
// If item not selected, clear selection on other items // If item not selected, clear selection on other items
for (i, item) in items.iter_mut().enumerate() { for (i, item) in items.iter_mut().enumerate() {
item.selected = Some(i) == click_i_opt; item.selected = Some(i) == click_i_opt;
@ -3972,7 +3962,7 @@ impl Tab {
} }
} }
if location != self.location || selected_paths.is_some() { if location != self.location || selected_paths.is_some() {
if location.path_opt().map_or(true, |path| path.is_dir()) { if location.path_opt().is_none_or(|path| path.is_dir()) {
if selected_paths.is_none() { if selected_paths.is_none() {
selected_paths = self selected_paths = self
.location .location
@ -3995,10 +3985,10 @@ impl Tab {
// Update context menu popup // Update context menu popup
if self.context_menu != last_context_menu { if self.context_menu != last_context_menu {
if last_context_menu.is_some() { if last_context_menu.is_some() {
commands.push(Command::ContextMenu(None, self.window_id.clone())); commands.push(Command::ContextMenu(None, self.window_id));
} }
if let Some(point) = self.context_menu { if let Some(point) = self.context_menu {
commands.push(Command::ContextMenu(Some(point), self.window_id.clone())); commands.push(Command::ContextMenu(Some(point), self.window_id));
} }
} }
@ -4221,7 +4211,7 @@ impl Tab {
ItemThumbnail::Text(text) => { ItemThumbnail::Text(text) => {
element_opt = Some( element_opt = Some(
widget::container( widget::container(
widget::text_editor(&text).padding(space_xxs).class( widget::text_editor(text).padding(space_xxs).class(
cosmic::theme::iced::TextEditor::Custom(Box::new( cosmic::theme::iced::TextEditor::Custom(Box::new(
text_editor_class, text_editor_class,
)), )),
@ -5387,7 +5377,7 @@ impl Tab {
height: s.height - top_deduct as f32, height: s.height - top_deduct as f32,
})); }));
let spacer_height = size.height - y as f32 - top_deduct as f32; let spacer_height = size.height - y - top_deduct as f32;
if spacer_height > 0. { if spacer_height > 0. {
children.push( children.push(
widget::container(Space::with_height(Length::Fixed(spacer_height))).into(), widget::container(Space::with_height(Length::Fixed(spacer_height))).into(),
@ -5490,7 +5480,7 @@ impl Tab {
.on_right_press(move |p| { .on_right_press(move |p| {
Message::ContextMenu( Message::ContextMenu(
if self.context_menu.is_some() { None } else { p }, if self.context_menu.is_some() { None } else { p },
self.window_id.clone(), self.window_id,
) )
}) })
.wayland_on_right_press_window_position(); .wayland_on_right_press_window_position();
@ -5604,7 +5594,7 @@ impl Tab {
pub fn subscription(&self, preview: bool) -> Subscription<Message> { pub fn subscription(&self, preview: bool) -> Subscription<Message> {
//TODO: how many thumbnail loads should be in flight at once? //TODO: how many thumbnail loads should be in flight at once?
let jobs = self.thumb_config.jobs.get().clone() as usize; let jobs = self.thumb_config.jobs.get() as usize;
let mut subscriptions = Vec::with_capacity(jobs + 3); let mut subscriptions = Vec::with_capacity(jobs + 3);
if let Some(items) = &self.items_opt { if let Some(items) = &self.items_opt {
@ -5650,9 +5640,9 @@ impl Tab {
}; };
if can_thumbnail { if can_thumbnail {
let mime = item.mime.clone(); let mime = item.mime.clone();
let max_jobs = jobs.clone(); let max_jobs = jobs;
let max_mb = self.thumb_config.max_mem_mb.get().clone() as u64; let max_mb = self.thumb_config.max_mem_mb.get() as u64;
let max_size = self.thumb_config.max_size_mb.get().clone() as u64; let max_size = self.thumb_config.max_size_mb.get() as u64;
subscriptions.push(Subscription::run_with_id( subscriptions.push(Subscription::run_with_id(
("thumbnail", path.clone()), ("thumbnail", path.clone()),
stream::channel(1, move |mut output| async move { stream::channel(1, move |mut output| async move {

View file

@ -160,9 +160,9 @@ impl ThumbnailCacher {
let mut image_data = vec![ let mut image_data = vec![
0; 0;
reader.output_buffer_size().ok_or_else( reader
|| "The required image buffer size is too large." .output_buffer_size()
)? .ok_or("The required image buffer size is too large.")?
]; ];
reader.next_frame(&mut image_data)?; reader.next_frame(&mut image_data)?;