From e98f268e59f19853564f631771f093feb94fb968 Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 31 Jul 2026 09:37:16 -0700 Subject: [PATCH 1/2] refactor: do not format each ImageError this makes the code much nicer, but also it reduces the amount of extra fluff in the error messages. --- src/utils.rs | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 12512cf..dafd1f2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,48 +1,20 @@ use std::path::{Path, PathBuf}; use iced::widget; -use image::{DynamicImage, ImageDecoder, ImageReader, RgbaImage}; +use image::{DynamicImage, ImageDecoder, ImageReader, ImageResult, RgbaImage}; use rfd::FileDialog; pub fn load_image(path: impl AsRef) -> Result { - let path = path.as_ref(); + _load_image(path).map_err(|e| e.to_string()) +} +fn _load_image(path: impl AsRef) -> ImageResult { + let mut decoder = ImageReader::open(path)? + .with_guessed_format()? + .into_decoder()?; - let image_reader = match ImageReader::open(path).and_then(|r| r.with_guessed_format()) { - Ok(r) => r, - Err(e) => { - return Err(format!( - "failed to create image reader for '{}': {e}", - path.display() - )); - } - }; + let oreintation = decoder.orientation()?; - let mut decoder = match image_reader.into_decoder() { - Ok(d) => d, - Err(e) => { - return Err(format!( - "failed to create decoder for '{}': {e}", - path.display() - )); - } - }; - - let oreintation = match decoder.orientation() { - Ok(o) => o, - Err(e) => { - return Err(format!( - "failed to get oreintation of '{}': {e}", - path.display() - )); - } - }; - - let mut decoded_image = match DynamicImage::from_decoder(decoder) { - Ok(i) => i, - Err(e) => { - return Err(format!("failed to decode image '{}': {e}", path.display())); - } - }; + let mut decoded_image = DynamicImage::from_decoder(decoder)?; decoded_image.apply_orientation(oreintation); @@ -75,7 +47,7 @@ pub fn save_image(image: Option<&RgbaImage>) -> Result<(), String> { }; if let Err(e) = image.save(&path) { - return Err(format!("failed to save '{}': {e}", path.display())); + return Err(e.to_string()); }; Ok(()) From 5a84b56025c69c3e5ac78bb35921c95ebfa639c1 Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 31 Jul 2026 09:55:08 -0700 Subject: [PATCH 2/2] build: use libdbus over zenity I completely misunderstood the RFD doc comments, thought that save file dialogs were not avaliable on linux outside of gtk this helps avoid the wrapper, which is nice; but I imagine it would fail if portals are unavaliable. --- flake.nix | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index 2fc6470..40636f4 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,9 @@ name = cargoToml.package.name; dlDeps = with pkgs; [ + # libdbus, for rfd + dbus + # needed for both x11 and wayland libxkbcommon libGL @@ -77,19 +80,13 @@ // { inherit cargoArtifacts; - nativeBuildInputs = - commonArgs.nativeBuildInputs - ++ [ - pkgs.autoPatchelfHook - ] - ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.makeBinaryWrapper; + nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ + pkgs.autoPatchelfHook + ]; - buildInputs = - commonArgs.buildInputs - ++ [ - pkgs.libgcc - ] - ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.zenity; + buildInputs = commonArgs.buildInputs ++ [ + pkgs.libgcc + ]; runtimeDependencies = dlDeps; @@ -98,10 +95,6 @@ postFixup = '' mkdir -p "$out/share/applications" ln -s "${desktopItem}"/share/applications/* "$out/share/applications/" - '' - + lib.optionalString pkgs.stdenv.hostPlatform.isLinux /* sh */ '' - wrapProgram $out/bin/${name} \ - --prefix PATH : ${lib.makeBinPath [ pkgs.zenity ]} ''; } );