Web build: desktop-only control, settings store and file panels are gated with their callers; dialog ids serialise as numbers; the shortcut-set save writes through Services::write; FileDialogFn and friends are exported again

This commit is contained in:
aiongg committed 2026-11-17 17:46:50 +00:00
1 parent f698beef33
commit 0df7ad11c4
17 files changed
+42 -15

No files matched your search

+2
View File
@@ -507,6 +507,7 @@ pub fn confirm(app: &mut PhotocraftApp, ctx: &egui::Context, id: DialogId) -> Re
}
// Automation confirming a dialog that stands for a command is judged as that command, whichever way the answer
// arrives (a control request or synthetic input).
#[cfg(not(target_arch = "wasm32"))]
if app.automation_input
&& let Some(authorize) = app.services.automation_command.as_ref()
&& let Some((command, params)) = crate::control::dialogs::hosted_command(app, id)
@@ -514,6 +515,7 @@ pub fn confirm(app: &mut PhotocraftApp, ctx: &egui::Context, id: DialogId) -> Re
authorize(&command, &params)?;
}
// Synthetic input answering Save on the unsaved-changes prompt is judged as `file.save`, as a control answer is.
#[cfg(not(target_arch = "wasm32"))]
if app.automation_input && crate::control::dialogs::is_save_answer(app, id) {
crate::discard_ui::authorize_save(app, false)?;
}
@@ -1,5 +1,7 @@
use super::open::{open, open_smart_filter};
use super::{LayerId, PhotocraftApp, Value, describe, dismiss, take_with};
use super::{LayerId, PhotocraftApp, Value, describe};
#[cfg(not(target_arch = "wasm32"))]
use super::{dismiss, take_with};
/// The menu id of the RAW Develop workspace.
const ID: &str = "filter.cameraRaw";
@@ -27,6 +29,14 @@ pub fn menu(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Val
})();
return Some(opened);
}
#[cfg(not(target_arch = "wasm32"))]
return workspace_request(app, ctx, params);
#[cfg(target_arch = "wasm32")]
None
}
#[cfg(not(target_arch = "wasm32"))]
fn workspace_request(app: &mut PhotocraftApp, ctx: &egui::Context, params: &Value) -> Option<Result<Value, String>> {
let ui = params.get("ui")?;
app.raw_reply = None;
let was_closed = app.raw.is_none();
@@ -30,7 +30,7 @@ pub fn intercept(app: &mut PhotocraftApp, command: &str, params: &Value) -> Opti
let tag = PendingDelete { doc: state.doc.id.0, selected: selected.iter().map(|id| id.0).collect(), params: params.clone() };
let prompt = StandardPrompt::confirm_delete(names, ids.len()).dont_show_again().tag(tag);
Some(Ok(match alerts::open_prompt(app, prompt) {
Ok(id) => json!({"dialog": id, "confirmationPending": true}),
Ok(id) => json!({"dialog": id.value(), "confirmationPending": true}),
Err(_) => json!({"confirmationPending": true}),
}))
}
@@ -30,7 +30,7 @@ pub(crate) fn intercept(app: &mut PhotocraftApp, doc: DocId, path: &str, flat: b
}
let prompt = StandardPrompt::changed_on_disk(crate::file_open::display_name(path)).tag(HeldSave { doc, path: path.to_owned(), flat, choices });
Some(Ok(match alerts::open_prompt(app, prompt) {
Ok(id) => json!({"dialog": id, "confirmationPending": true}),
Ok(id) => json!({"dialog": id.value(), "confirmationPending": true}),
Err(_) => json!({"confirmationPending": true}),
}))
}
+9
View File
@@ -217,6 +217,7 @@ pub(crate) fn workspace_fields(app: &PhotocraftApp, key: &str) -> Option<Value>
}
/// Whether the workspace `key` names is open.
#[cfg(not(target_arch = "wasm32"))]
fn workspace_open(app: &PhotocraftApp, key: &str) -> bool {
app.framework.dialogs.open_dialogs().iter().any(|d| d.key.as_deref() == Some(key))
}
@@ -266,16 +267,23 @@ pub fn display_doc(app: &PhotocraftApp, idx: usize) -> Option<(Arc<Document>, u6
pub fn menu(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Value) -> Option<Result<Value, String>> {
let empty = params.as_object().is_none_or(|o| o.is_empty());
let ui = params.get("ui");
#[cfg(not(target_arch = "wasm32"))]
let hosted = |app: &mut PhotocraftApp, key: &str, ui: &Value| crate::control::dialogs::workspace_ui(app, ctx, key, ui);
match id {
"filter.filterGallery" if empty => Some(crate::gallery_ui::open(app).map(|_| json!({"gallery": crate::gallery_ui::describe(app)}))),
#[cfg(not(target_arch = "wasm32"))]
"filter.filterGallery" if ui.is_some() && workspace_open(app, id) => Some(hosted(app, id, ui.unwrap_or(&Value::Null))),
"filter.liquify" if empty => Some(crate::liquify_ui::open(app, ctx).map(|_| json!({"liquify": crate::liquify_ui::describe(app)}))),
#[cfg(not(target_arch = "wasm32"))]
"filter.liquify" if ui.is_some() && workspace_open(app, id) => Some(hosted(app, id, ui.unwrap_or(&Value::Null))),
#[cfg(not(target_arch = "wasm32"))]
"edit.contentAwareFill" if ui.is_some() && workspace_open(app, id) => Some(hosted(app, id, ui.unwrap_or(&Value::Null))),
// `ui` addresses the workspace: closed, that is an error, not a fill with the defaults.
#[cfg(not(target_arch = "wasm32"))]
"edit.contentAwareFill" if ui.is_some() => Some(Err("Content-Aware Fill is not open".into())),
#[cfg(not(target_arch = "wasm32"))]
"select.selectAndMask" if ui.is_some() && workspace_open(app, id) => Some(hosted(app, id, ui.unwrap_or(&Value::Null))),
#[cfg(not(target_arch = "wasm32"))]
"select.selectAndMask" if ui.is_some() => Some(Err("Select and Mask is not open".into())),
"select.selectAndMask" => Some(crate::select_mask_ui::open(app).map(|_| json!({"selectAndMask": crate::select_mask_ui::describe(app)}))),
"edit.puppetWarp" | "layer.smartObjects.puppetWarp" if empty => {
@@ -291,6 +299,7 @@ pub fn menu(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Val
Some(crate::perspective_ui::control(app, ui.unwrap_or(&Value::Null)))
}
"filter.vanishingPoint" if empty => Some(crate::vp_ui::begin(app, ctx).map(|_| json!({"vanishingPoint": crate::vp_ui::describe(app)}))),
#[cfg(not(target_arch = "wasm32"))]
"filter.vanishingPoint" if ui.is_some() && workspace_open(app, id) => Some(hosted(app, id, ui.unwrap_or(&Value::Null))),
_ => None,
}
@@ -56,7 +56,7 @@ pub fn intercept(app: &mut PhotocraftApp, command: &str, params: &Value) -> Opti
StandardPrompt::trash_mask().can_apply(app.session.is_enabled_with(LAYER_MASK_APPLY, &json!({"layer": layer})))
};
Some(Ok(match alerts::open_prompt(app, prompt.tag(tag)) {
Ok(id) => json!({"dialog": id, "confirmationPending": true}),
Ok(id) => json!({"dialog": id.value(), "confirmationPending": true}),
Err(_) => json!({"confirmationPending": true}),
}))
}
@@ -168,7 +168,7 @@ pub fn intercept_filter(app: &mut PhotocraftApp, id: &str, params: &Value) -> Op
filter: Some((id.to_owned(), params.clone())),
});
let dialog = alerts::open_prompt(app, prompt).unwrap_or_else(|open| open);
Some(Ok(json!({"dialog": dialog})))
Some(Ok(json!({"dialog": dialog.value()})))
}
/// The `PROMPTS` entry: Proceed rasterizes, Alternate converts to a Smart Object (the filter prompt
@@ -278,6 +278,7 @@ pub fn menu(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Val
if id != KEY {
return None;
}
#[cfg(not(target_arch = "wasm32"))]
if let Some(ui) = params.get("ui") {
return Some(if app.wide_angle.is_some() {
crate::control::dialogs::workspace_ui(app, ctx, KEY, ui)
+2
View File
@@ -76,6 +76,8 @@ pub use craft::window::{
Prefix,
policy::{self as window_policy, Backend, Decision, Frame, TitleBarPref},
};
#[cfg(target_arch = "wasm32")]
pub use file_dialog::{FileDialogAnswer, FileDialogFn, FileDialogReply, FileDialogRequest};
pub use file_open::OsEvent;
pub use state::{Tool, UiState};
+3 -3
View File
@@ -608,7 +608,7 @@ fn open_path(app: &mut PhotocraftApp, path: &str) -> Result<Value, String> {
fn invoke_export_command(app: &mut PhotocraftApp, id: &str, params: &Value) -> Result<Option<Result<Value, String>>, String> {
let result = match id {
"file.export.exportAs" => Some(Ok(json!({"dialog": crate::export_dialog::open(app)?}))),
"file.export.exportAs" => Some(Ok(json!({"dialog": crate::export_dialog::open(app)?.value()}))),
"file.export.quickExportAsPng" => Some(crate::export_dialog::quick_export_png(app)),
"file.export.renderVideo" if params.get("dir").is_none() => {
#[cfg(target_arch = "wasm32")]
@@ -631,9 +631,9 @@ fn invoke_export_command(app: &mut PhotocraftApp, id: &str, params: &Value) -> R
// Several layers (artboards, say) selected: one file each (#3629).
let layers = app.session.active().map(|document| document.selected_layers()).unwrap_or_default();
if layers.len() > 1 {
Some(Ok(json!({"dialog": crate::export_dialog::open_layers(app, &layers)?})))
Some(Ok(json!({"dialog": crate::export_dialog::open_layers(app, &layers)?.value()})))
} else {
Some(Ok(json!({"dialog": crate::export_dialog::open_layer(app, selected)?})))
Some(Ok(json!({"dialog": crate::export_dialog::open_layer(app, selected)?.value()})))
}
} else {
Some(crate::export_dialog::quick_export_selected_layers_png(app))
+2 -2
View File
@@ -36,7 +36,7 @@ pub(super) fn new_set_dialog(app: &mut PhotocraftApp) -> Result<Value, String> {
let rows = vec![Param::new("name", tl!("Name:"), ParamKind::text(name.clone()))];
ParamDialog::command(NEW_SET, tl!("New Set"), rows).values(Bind::bound(fields))
});
Ok(json!({"dialog": id}))
Ok(json!({"dialog": id.value()}))
}
/// Makes the set and selects it, so New Action records into it.
@@ -74,7 +74,7 @@ pub(super) fn insert_stop_dialog(app: &mut PhotocraftApp) -> Result<Value, Strin
];
ParamDialog::command(INSERT_STOP, tl!("Insert Stop"), rows).values(Bind::bound(fields))
});
Ok(json!({"dialog": id}))
Ok(json!({"dialog": id.value()}))
}
/// Inserts the Stop step into the captured action, selects it and opens its action.
+1 -1
View File
@@ -143,7 +143,7 @@ fn ask(app: &mut PhotocraftApp, held: Held) -> Result<Value, String> {
let env = Env::of_root(app.ctx());
let prompt = held.prompt.prompt(&env.words::<ActionsWords>(), &env.words::<CommonWords>());
match alerts::open_prompt(app, prompt.tag(held)) {
Ok(id) => Ok(json!({"dialog": id})),
Ok(id) => Ok(json!({"dialog": id.value()})),
Err(_) => Err(tl!("Answer the open question first.").into()),
}
}
@@ -51,7 +51,7 @@ pub(super) fn open(app: &mut PhotocraftApp, action: usize, at: Option<usize>) ->
ParamDialog::command(KEY, tl!("Insert Menu Item"), rows).values(Bind::bound(fields))
});
app.held_insert_menu = Some(Held { dialog, revision: app.session.actions.list.revision(), target, gate, automated });
Ok(json!({"dialog": dialog}))
Ok(json!({"dialog": dialog.value()}))
}
/// The insertion the chooser's answer asks for, once the chooser, its action list and its authority are unchanged:
@@ -152,7 +152,7 @@ pub(super) fn open_dialog(app: &mut PhotocraftApp) -> Result<Value, String> {
let id = params::open_param(app, KEY, DialogFields::new(), Value::Null, move |fields: &mut DialogFields| {
ParamDialog::command(KEY, tl!("Playback Options"), rows(&performance, seconds, single)).values(Bind::bound(fields)).alert_title(tl!("PhotoCraft"))
});
Ok(json!({"dialog": id}))
Ok(json!({"dialog": id.value()}))
}
/// Refuses seconds that are not a whole number in range, which the field cannot show.
@@ -73,7 +73,7 @@ pub(super) fn open(app: &mut PhotocraftApp, action: usize, step: usize) -> Resul
super::runner::hold_editor_ok(app, dialog);
held.dialog = dialog;
app.held_record_again = Some(held);
Ok(json!({"dialog": dialog}))
Ok(json!({"dialog": dialog.value()}))
}
/// Guard both actual preview routes before parsing LUT files or evaluating a command.
@@ -225,7 +225,8 @@ fn save_text(app: &mut PhotocraftApp, state: &mut DialogState, suggested: &str,
// A set name can hold characters a file name can't.
let name: String = suggested.chars().map(|c| if matches!(c, '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|') { '_' } else { c }).collect();
let saved = app.pick_save(&name, move |app, path| {
app.framework.files().write(std::path::Path::new(&path), text.as_bytes()).map_err(|e| e.to_string())?;
let write = app.services.write.as_mut().ok_or("no writer configured")?;
write(&path, text.as_bytes())?;
Ok(json!({"path": path}))
});
if let Err(e) = saved {
+2
View File
@@ -508,8 +508,10 @@ pub struct Services {
/// The file service the app's host answers file picks with (`HostBuilder::files`); `None` in tests that install none.
pub files: Option<std::sync::Arc<dyn craft::host::Files>>,
/// The main-thread side of the native file panels, pumped by the app.
#[cfg(not(target_arch = "wasm32"))]
pub file_panels: Option<craft::dialogs::service::FilePanels>,
/// The opened settings store and what opening it reported; `None` in the web build.
#[cfg(not(target_arch = "wasm32"))]
pub settings: Option<(craft::settings::SettingsStore<photocraft_engine::prefs::SavedPrefs>, craft::settings::LoadReport)>,
/// Decode a file's bytes into a document (PSD, PNG, JPEG, …).
pub import: Option<ImportFn>,