mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-08 19:42:12 +00:00
Closing an eframe window on macOS can crash in AppKit's Touch Bar finder after eframe drops the window while the run loop is still running (#3). craft-quit routes a window close through -[NSApplication terminate:], the path Cmd+Q already takes, so the process ends before another display cycle runs. - quit(): schedules terminate: on the main queue on macOS, no-op elsewhere - on_close_request() (feature "egui"): cancels the root window's close and quits through the platform path instead Also commits Cargo.lock and ignores .idea/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
901 B
Rust
20 lines
901 B
Rust
//! `-[NSApplication terminate:]`, scheduled on the main queue. All safe objc2 calls.
|
|
|
|
use dispatch2::DispatchQueue;
|
|
use objc2::MainThreadMarker;
|
|
use objc2_app_kit::NSApplication;
|
|
|
|
/// Send `terminate:` from the main queue rather than from the caller. The caller is inside winit's
|
|
/// event handler, and `terminate:` makes winit deliver its exit event, which it can't do while
|
|
/// another event is being handled. From the main queue winit is idle: its
|
|
/// `applicationWillTerminate:` closes the windows and runs the app's exit handling (eframe saves
|
|
/// and calls `on_exit`), and AppKit ends the process.
|
|
pub(crate) fn terminate_later() {
|
|
DispatchQueue::main().exec_async(|| {
|
|
// The main queue runs on the main thread, so there is always a marker.
|
|
if let Some(mtm) = MainThreadMarker::new() {
|
|
NSApplication::sharedApplication(mtm).terminate(None);
|
|
}
|
|
});
|
|
}
|