macOS: File menu dialogs open as sheets, so a drag over the window can't abort the app (#511)
The file dialogs were blocking rfd::FileDialog calls made inside eframe's frame, that is inside winit's event handler. On macOS the dialog runs a nested modal event loop there; a file dragged over the window while it was open reached winit's handler again, which refuses re-entry with a panic across the Objective-C boundary, aborting the app (Import with Cmd+I, then a drag). Hooks gains file_dialog_async: a host that sets it shows a command's file dialog (Import, Open, Save As, Save Frame As, presets, guides, templates, Collect Files, Relink...) without blocking, and the command runs with the answer on a later frame (menus::dialog_answered, drained at the start of each frame); a cancelled dialog runs nothing. The macOS app implements it with rfd::AsyncFileDialog, a sheet on the window answered when it closes, outside the frame. Other platforms keep the blocking dialogs (winit queues their re-entrant events), as do the few panel buttons that pick a file in place (Settings paths, shortcut import/export, effect file pickers). Test: with a non-blocking hook, Save As and Save Frame As return at once without the blocking dialog, the save happens when the answer arrives from another thread, and a cancelled dialog writes nothing. The macOS sheet itself needs a manual check (Cmd+I, drag a file over the window, pick or cancel). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QiAJeFttZp83Fh7YuzAR5f
This commit is contained in:
@@ -21,6 +21,9 @@ mod control_server;
|
||||
mod launch_guard;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod native_menu;
|
||||
// Built everywhere so it stays checked; only the macOS app uses it.
|
||||
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
|
||||
mod sheet_dialogs;
|
||||
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use serde_json::json;
|
||||
@@ -227,6 +230,9 @@ fn main() -> eframe::Result {
|
||||
}));
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
// The commands' file dialogs open as sheets instead of nested modal loops (#511).
|
||||
let ctx = cc.egui_ctx.clone();
|
||||
app.hooks.file_dialog_async = Some(Box::new(move |dialog, done| sheet_dialogs::show(dialog, done, ctx.clone())));
|
||||
app.hooks.app_action = Some(Box::new(native_menu::app_action));
|
||||
app.hooks.clipboard_text = Some(Box::new(native_menu::clipboard_text));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user