fix(macos): default droplets to a writable user directory (#4746)

This commit is contained in:
Nigel Ihza Firdausy authored and GitHub committed 2026-10-13 03:06:27 -04:00
1 parent 5c579ba81a
commit c0e62673f8
1 file changed
+31
+31
View File
@@ -22,6 +22,22 @@ fn default_dir(app: &PhotocraftApp) -> String {
app.session.active().and_then(|d| d.path.as_deref()).and_then(|p| p.rfind(['/', '\\']).map(|i| p[..i].to_string())).unwrap_or_else(|| ".".into())
}
/// A packaged macOS app does not start in a useful writable working directory. A saved
/// document keeps its own folder; otherwise prefer the user's Documents folder.
fn droplet_default_dir(app: &PhotocraftApp) -> String {
let dir = default_dir(app);
if dir != "." {
return dir;
}
#[cfg(target_os = "macos")]
if let Some(home) = std::env::var_os("HOME") {
let home = std::path::PathBuf::from(home);
let documents = home.join("Documents");
return if documents.is_dir() { documents } else { home }.to_string_lossy().into_owned();
}
dir
}
fn doc_stem(app: &PhotocraftApp) -> String {
app.session.active().map(|d| d.doc.name.rsplit_once('.').map_or(d.doc.name.clone(), |(a, _)| a.to_string())).unwrap_or_else(|| tl!("Untitled").into())
}
@@ -71,6 +87,7 @@ pub fn invoke(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &V
json!({"units": ["inches", "cm", "pixels"], "mode": ["rgb", "gray", "cmyk", "lab"]}),
),
"file.automate.createDroplet" => {
let dir = droplet_default_dir(app);
let Some(action) = crate::actions::selected_action(app) else {
return Some(Err("record an action in the Actions panel first".into()));
};
@@ -1064,6 +1081,20 @@ mod tests {
(app, egui::Context::default())
}
#[test]
fn droplet_folder_follows_the_document_or_uses_a_safe_fallback() {
let (mut app, _) = app();
let fallback = droplet_default_dir(&app);
#[cfg(target_os = "macos")]
if std::env::var_os("HOME").is_some() {
assert!(std::path::Path::new(&fallback).is_absolute());
}
#[cfg(not(target_os = "macos"))]
assert_eq!(fallback, ".");
app.session.active_mut().unwrap().path = Some("/tmp/photocraft/drawing.pcraft".into());
assert_eq!(droplet_default_dir(&app), "/tmp/photocraft");
}
#[test]
fn save_for_web_dialog_runs_the_command() {
let (mut app, ctx) = app();