diff --git a/flake.nix b/flake.nix index 40636f4..2fc6470 100644 --- a/flake.nix +++ b/flake.nix @@ -20,9 +20,6 @@ name = cargoToml.package.name; dlDeps = with pkgs; [ - # libdbus, for rfd - dbus - # needed for both x11 and wayland libxkbcommon libGL @@ -80,13 +77,19 @@ // { inherit cargoArtifacts; - nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ - pkgs.autoPatchelfHook - ]; + nativeBuildInputs = + commonArgs.nativeBuildInputs + ++ [ + pkgs.autoPatchelfHook + ] + ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.makeBinaryWrapper; - buildInputs = commonArgs.buildInputs ++ [ - pkgs.libgcc - ]; + buildInputs = + commonArgs.buildInputs + ++ [ + pkgs.libgcc + ] + ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.zenity; runtimeDependencies = dlDeps; @@ -95,6 +98,10 @@ 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 ]} ''; } ); diff --git a/src/utils.rs b/src/utils.rs index dafd1f2..12512cf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,20 +1,48 @@ use std::path::{Path, PathBuf}; use iced::widget; -use image::{DynamicImage, ImageDecoder, ImageReader, ImageResult, RgbaImage}; +use image::{DynamicImage, ImageDecoder, ImageReader, RgbaImage}; use rfd::FileDialog; pub fn load_image(path: impl AsRef) -> Result { - _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 path = path.as_ref(); - let oreintation = decoder.orientation()?; + 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 mut decoded_image = DynamicImage::from_decoder(decoder)?; + 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())); + } + }; decoded_image.apply_orientation(oreintation); @@ -47,7 +75,7 @@ pub fn save_image(image: Option<&RgbaImage>) -> Result<(), String> { }; if let Err(e) = image.save(&path) { - return Err(e.to_string()); + return Err(format!("failed to save '{}': {e}", path.display())); }; Ok(())