fix: add error handling to save dialog and auto_save false test
This commit is contained in:
@@ -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
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user