From da1e64d89868cf64f51719e24b4d5d488676af1b Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 14 Aug 2026 09:16:54 -0700 Subject: [PATCH 1/2] perf: use tokio not sure how much this helps practically --- Cargo.lock | 11 +++++++++++ Cargo.toml | 3 ++- src/app/mod.rs | 12 ++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c61fd41..a272e0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1429,6 +1429,7 @@ dependencies = [ "rayon", "rfd", "size", + "tokio", "zip", ] @@ -1745,6 +1746,7 @@ dependencies = [ "iced_core", "log", "rustc-hash 2.1.3", + "tokio", "wasm-bindgen-futures", "wasmtimer", ] @@ -4259,6 +4261,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "pin-project-lite", +] + [[package]] name = "toml" version = "1.1.4+spec-1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 8e4dfa2..0a8c2a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,12 @@ kra-image-integration = "0.1.0" rayon = "1.12.0" rfd = "0.17.2" size = "0.5.0" +tokio = "1.53.1" zip = "8.6.0" [dependencies.iced] version = "0.14.0" -features = [ "image" ] +features = [ "image", "tokio" ] [dependencies.image] version = "0.25.10" diff --git a/src/app/mod.rs b/src/app/mod.rs index 0b1f4cd..d4f5ced 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -75,9 +75,13 @@ impl State { let size = 1000 / self.columns as u32; let (task, handle) = Task::perform( async move { - utils::load_thumbnail(&path, size) - .map(|img| (path, handle_from_image(img))) - .map_err(Arc::new) + tokio::task::spawn_blocking(move || { + utils::load_thumbnail(&path, size) + .map(|img| (path, handle_from_image(img))) + .map_err(Arc::new) + }) + .await + .unwrap() }, Message::ImageLoaded, ) @@ -194,7 +198,7 @@ impl State { |handle| widget::image(handle).into(), )) .key(self.key) - .anticipate(2000) + .anticipate(500) .on_show(|_size| Message::LoadImage(path.clone())) .on_hide(Message::UnloadImage(path.clone())), ) From 01f74bdf852143f7b750a64486928a8aba7f6e06 Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 14 Aug 2026 09:18:09 -0700 Subject: [PATCH 2/2] feat: filter method cycling it doesn't work :( --- src/app/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index d4f5ced..b36c466 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -42,6 +42,8 @@ enum Message { struct State { images: BTreeMap, + filter: widget::image::FilterMethod, + columns: usize, key: usize, @@ -53,10 +55,8 @@ impl State { fn new() -> (Self, Task) { ( Self { - images: BTreeMap::new(), columns: 3, - key: 0, - error: None, + ..Default::default() }, Task::done(Message::OpenPath(Some( env::args() @@ -178,6 +178,13 @@ impl State { self.columns = (self.columns - 1).clamp(1, 10) } + keyboard::Key::Character("f") => { + self.filter = match self.filter { + widget::image::FilterMethod::Linear => widget::image::FilterMethod::Nearest, + widget::image::FilterMethod::Nearest => widget::image::FilterMethod::Linear, + } + } + keyboard::Key::Character("q") => { return window::latest().and_then(window::close); } @@ -195,7 +202,7 @@ impl State { widget::container( widget::sensor(maybe_image.handle().map_or_else( || Element::from(widget::space()), - |handle| widget::image(handle).into(), + |handle| widget::image(handle).filter_method(self.filter).into(), )) .key(self.key) .anticipate(500)