fix: add error handling to save dialog and auto_save false test

This commit is contained in:
2026-08-03 21:27:36 -04:00
parent d063870bcd
commit d88aadd40f
2 changed files with 21 additions and 1 deletions
+18
View File
@@ -282,4 +282,22 @@ mod tests {
std::fs::remove_dir_all(&dir).ok();
}
#[test]
fn update_color_auto_save_false_does_not_write() {
let dir = std::env::temp_dir().join(format!("auto_save_false_{}", std::process::id()));
std::fs::create_dir_all(&dir).ok();
let file = dir.join("icon.svg");
std::fs::write(&file, SINGLE_COLOR_SVG).unwrap();
let mut scheme = ColorScheme::load(&file).unwrap();
scheme.auto_save = false;
assert!(scheme.update_color("ColorScheme-Text", "#000000").unwrap());
let file_content = std::fs::read_to_string(&file).unwrap();
assert_eq!(file_content, SINGLE_COLOR_SVG, "Disk content should not be modified");
std::fs::remove_dir_all(&dir).ok();
}
}
+3 -1
View File
@@ -126,7 +126,9 @@ fn build_editor(stack: &Stack, window: &ApplicationWindow, icon_path: PathBuf) {
dialog.save(Some(&window), gtk::gio::Cancellable::NONE, move |res| {
if let Ok(file) = res {
if let Some(path) = file.path() {
let _ = std::fs::write(path, comp.borrow().render());
if let Err(e) = std::fs::write(&path, comp.borrow().render()) {
eprintln!("Failed to save composite to {}: {e}", path.display());
}
}
}
});