diff --git a/.changes/exit-loop-destroyed.md b/.changes/exit-loop-destroyed.md new file mode 100644 index 000000000..df1b506e8 --- /dev/null +++ b/.changes/exit-loop-destroyed.md @@ -0,0 +1,5 @@ +--- +"tauri-runtime-wry": patch +--- + +Emit `RunEvent::Exit` on `tao::event::Event::LoopDestroyed` instead of after `RunEvent::ExitRequested`. diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index e14c9b19d..0e146d198 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -2300,14 +2300,10 @@ fn handle_event_loop( #[cfg(feature = "system-tray")] tray_context, } = context; - if *control_flow == ControlFlow::Exit { - return RunIteration { - window_count: windows.lock().expect("poisoned webview collection").len(), - }; + if *control_flow != ControlFlow::Exit { + *control_flow = ControlFlow::Wait; } - *control_flow = ControlFlow::Wait; - match event { Event::NewEvents(StartCause::Init) => { callback(RunEvent::Ready); @@ -2321,6 +2317,10 @@ fn handle_event_loop( callback(RunEvent::MainEventsCleared); } + Event::LoopDestroyed => { + callback(RunEvent::Exit); + } + Event::GlobalShortcutEvent(accelerator_id) => { for (id, handler) in &*global_shortcut_manager_handle.listeners.lock().unwrap() { if accelerator_id == *id { @@ -2565,7 +2565,6 @@ fn on_window_close<'a, T: UserEvent>( if !should_prevent { *control_flow = ControlFlow::Exit; - callback(RunEvent::Exit); } } Some(webview)