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

View file

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

View file

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

View file

@ -535,13 +535,13 @@ pub fn menu_bar<'a>(
menu::Item::CheckBox(
label,
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
}),
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 = 0;
@ -637,26 +637,26 @@ pub fn menu_bar<'a>(
menu::Item::CheckBox(
fl!("grid-view"),
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,
),
menu::Item::CheckBox(
fl!("list-view"),
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,
),
menu::Item::Divider,
menu::Item::CheckBox(
fl!("show-hidden-files"),
None,
tab_opt.map_or(false, |tab| tab.config.show_hidden),
tab_opt.is_some_and(|tab| tab.config.show_hidden),
Action::ToggleShowHidden,
),
menu::Item::CheckBox(
fl!("list-directories-first"),
None,
tab_opt.map_or(false, |tab| tab.config.folders_first),
tab_opt.is_some_and(|tab| tab.config.folders_first),
Action::ToggleFoldersFirst,
),
menu::Item::CheckBox(

View file

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

View file

@ -69,7 +69,7 @@ pub fn mime_for_path<P: AsRef<Path>>(
gb.file_name(file_name);
}
} else {
gb.path(&path);
gb.path(path);
}
if let Some(metadata) = metadata_opt {
gb.metadata(metadata.clone());
@ -77,7 +77,7 @@ pub fn mime_for_path<P: AsRef<Path>>(
let guess = gb.guess();
if guess.uncertain() {
// 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 {
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 mtime = info.attribute_uint64(gio::FILE_ATTRIBUTE_TIME_MODIFIED);
let is_dir = match info.file_type() {
gio::FileType::Directory => true,
_ => false,
};
let is_dir = matches!(info.file_type(), gio::FileType::Directory);
let size_opt = match is_dir {
true => None,
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))?
};
let child_os = path.strip_prefix(&parent)?;
let child_os = path.strip_prefix(parent)?;
let child = child_os
.to_str()
.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)
.case_insensitive(true)
.build()?;
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 file_name_os = entry.file_name();
let Some(file_name) = file_name_os.to_str() else {
continue;
};
if regex.is_match(&file_name) {
if regex.is_match(file_name) {
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 mut display_name = Item::display_name(&file_info.display_name());
let remote = file_info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE);
let is_dir = match file_info.file_type() {
gio::FileType::Directory => true,
_ => false,
};
let is_dir = matches!(file_info.file_type(), gio::FileType::Directory);
let size_opt = match is_dir {
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 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
let mut attr_string = String::new();
for attr in vec![
for attr in [
gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE,
gio::FILE_ATTRIBUTE_TIME_MODIFIED,
@ -906,11 +903,9 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
) {
Ok(res) => {
remote_scannable = true;
for file in res {
if let Ok(file) = file {
let full_path = Path::new(tab_path).join(file.name());
items.push(item_from_gvfs_info(full_path, file, sizes));
}
for file in res.flatten() {
let full_path = Path::new(tab_path).join(file.name());
items.push(item_from_gvfs_info(full_path, file, sizes));
}
}
Err(err) => {
@ -1821,36 +1816,33 @@ impl ItemThumbnail {
}
};
match dyn_img {
Some(dyn_img) => {
if let Ok(cacher) = thumbnail_cacher.as_ref() {
match cacher.update_with_image(dyn_img) {
Ok(path) => {
return ItemThumbnail::Image(
widget::image::Handle::from_path(path),
None,
);
}
Err(err) => {
log::warn!("cacher failed to decode {:?}: {}", path, err);
}
if let Some(dyn_img) = dyn_img {
if let Ok(cacher) = thumbnail_cacher.as_ref() {
match cacher.update_with_image(dyn_img) {
Ok(path) => {
return ItemThumbnail::Image(
widget::image::Handle::from_path(path),
None,
);
}
Err(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>,
) -> Option<(ItemThumbnail, NamedTempFile)> {
// Try external thumbnailers
for thumbnailer in thumbnailer(&mime) {
for thumbnailer in thumbnailer(mime) {
let is_evince = thumbnailer.exec.starts_with("evince-thumbnailer ");
let prefix = if is_evince {
//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
// 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
// fallback to the system tempdir.
let file = if thumbnail_dir.is_none() || is_evince {
tempfile::Builder::new().prefix(prefix).tempfile()
} else {
tempfile::Builder::new()
.prefix(prefix)
.tempfile_in(thumbnail_dir.unwrap())
let dir = if is_evince { None } else { thumbnail_dir };
let file = match dir {
Some(d) => tempfile::Builder::new().prefix(prefix).tempfile_in(d),
None => tempfile::Builder::new().prefix(prefix).tempfile(),
};
let file = match file {
Ok(ok) => ok,
@ -2060,7 +2050,7 @@ impl Item {
widget::image(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(
text_editor_class,
)))
@ -2544,7 +2534,7 @@ impl Tab {
.and_then(|opts| opts.get(&location_str))
.or_else(|| SORT_OPTION_FALLBACK.get(&location_str))
.cloned()
.unwrap_or_else(|| (HeadingOptions::Name, true));
.unwrap_or((HeadingOptions::Name, true));
let location = location.normalize();
let location_ancestors = location.ancestors();
let location_title = location.title();
@ -3404,10 +3394,10 @@ impl Tab {
// Try to select previous item in current row
if !col
.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
if !row.checked_sub(1).map_or(false, |row| {
if !row.checked_sub(1).is_some_and(|row| {
let mut col = 0;
if let Some(ref items) = self.items_opt {
for item in items.iter() {
@ -3496,7 +3486,7 @@ impl Tab {
// Try to select item in last row
if !row
.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
self.select_position(row, col, mod_shift);
@ -3596,9 +3586,9 @@ impl Tab {
self.update(Message::Click(click_i_opt), modifiers);
}
if let Some(ref mut items) = self.items_opt {
if !click_i_opt.map_or(false, |click_i| {
items.get(click_i).map_or(false, |x| x.selected)
}) {
if !click_i_opt
.is_some_and(|click_i| items.get(click_i).is_some_and(|x| x.selected))
{
// If item not selected, clear selection on other items
for (i, item) in items.iter_mut().enumerate() {
item.selected = Some(i) == click_i_opt;
@ -3972,7 +3962,7 @@ impl Tab {
}
}
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() {
selected_paths = self
.location
@ -3995,10 +3985,10 @@ impl Tab {
// Update context menu popup
if self.context_menu != last_context_menu {
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 {
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) => {
element_opt = Some(
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(
text_editor_class,
)),
@ -5387,7 +5377,7 @@ impl Tab {
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. {
children.push(
widget::container(Space::with_height(Length::Fixed(spacer_height))).into(),
@ -5490,7 +5480,7 @@ impl Tab {
.on_right_press(move |p| {
Message::ContextMenu(
if self.context_menu.is_some() { None } else { p },
self.window_id.clone(),
self.window_id,
)
})
.wayland_on_right_press_window_position();
@ -5604,7 +5594,7 @@ impl Tab {
pub fn subscription(&self, preview: bool) -> Subscription<Message> {
//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);
if let Some(items) = &self.items_opt {
@ -5650,9 +5640,9 @@ impl Tab {
};
if can_thumbnail {
let mime = item.mime.clone();
let max_jobs = jobs.clone();
let max_mb = self.thumb_config.max_mem_mb.get().clone() as u64;
let max_size = self.thumb_config.max_size_mb.get().clone() as u64;
let max_jobs = jobs;
let max_mb = self.thumb_config.max_mem_mb.get() as u64;
let max_size = self.thumb_config.max_size_mb.get() as u64;
subscriptions.push(Subscription::run_with_id(
("thumbnail", path.clone()),
stream::channel(1, move |mut output| async move {

View file

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