Compare commits

..
Author SHA1 Message Date
5a84b56025
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.
2026-07-31 09:55:08 -07:00
e98f268e59
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.
2026-07-31 09:51:57 -07:00
2 changed files with 19 additions and 54 deletions

View file

@ -20,6 +20,9 @@
name = cargoToml.package.name; name = cargoToml.package.name;
dlDeps = with pkgs; [ dlDeps = with pkgs; [
# libdbus, for rfd
dbus
# needed for both x11 and wayland # needed for both x11 and wayland
libxkbcommon libxkbcommon
libGL libGL
@ -77,19 +80,13 @@
// { // {
inherit cargoArtifacts; inherit cargoArtifacts;
nativeBuildInputs = nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
commonArgs.nativeBuildInputs
++ [
pkgs.autoPatchelfHook pkgs.autoPatchelfHook
] ];
++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.makeBinaryWrapper;
buildInputs = buildInputs = commonArgs.buildInputs ++ [
commonArgs.buildInputs
++ [
pkgs.libgcc pkgs.libgcc
] ];
++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.zenity;
runtimeDependencies = dlDeps; runtimeDependencies = dlDeps;
@ -98,10 +95,6 @@
postFixup = '' postFixup = ''
mkdir -p "$out/share/applications" mkdir -p "$out/share/applications"
ln -s "${desktopItem}"/share/applications/* "$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 ]}
''; '';
} }
); );

View file

@ -1,48 +1,20 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use iced::widget; use iced::widget;
use image::{DynamicImage, ImageDecoder, ImageReader, RgbaImage}; use image::{DynamicImage, ImageDecoder, ImageReader, ImageResult, RgbaImage};
use rfd::FileDialog; use rfd::FileDialog;
pub fn load_image(path: impl AsRef<Path>) -> Result<RgbaImage, String> { pub fn load_image(path: impl AsRef<Path>) -> Result<RgbaImage, String> {
let path = path.as_ref(); _load_image(path).map_err(|e| e.to_string())
}
fn _load_image(path: impl AsRef<Path>) -> ImageResult<RgbaImage> {
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()) { let oreintation = decoder.orientation()?;
Ok(r) => r,
Err(e) => {
return Err(format!(
"failed to create image reader for '{}': {e}",
path.display()
));
}
};
let mut decoder = match image_reader.into_decoder() { let mut decoded_image = DynamicImage::from_decoder(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); 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) { if let Err(e) = image.save(&path) {
return Err(format!("failed to save '{}': {e}", path.display())); return Err(e.to_string());
}; };
Ok(()) Ok(())