Skip to content

Commit 3c4ee7c

Browse files
authored
refactor(wry): emit RunEvent::Exit on Event::LoopDestroyed (#3785)
1 parent 9489963 commit 3c4ee7c

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

.changes/exit-loop-destroyed.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-runtime-wry": patch
3+
---
4+
5+
Emit `RunEvent::Exit` on `tao::event::Event::LoopDestroyed` instead of after `RunEvent::ExitRequested`.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,14 +2300,10 @@ fn handle_event_loop<T: UserEvent>(
23002300
#[cfg(feature = "system-tray")]
23012301
tray_context,
23022302
} = context;
2303-
if *control_flow == ControlFlow::Exit {
2304-
return RunIteration {
2305-
window_count: windows.lock().expect("poisoned webview collection").len(),
2306-
};
2303+
if *control_flow != ControlFlow::Exit {
2304+
*control_flow = ControlFlow::Wait;
23072305
}
23082306

2309-
*control_flow = ControlFlow::Wait;
2310-
23112307
match event {
23122308
Event::NewEvents(StartCause::Init) => {
23132309
callback(RunEvent::Ready);
@@ -2321,6 +2317,10 @@ fn handle_event_loop<T: UserEvent>(
23212317
callback(RunEvent::MainEventsCleared);
23222318
}
23232319

2320+
Event::LoopDestroyed => {
2321+
callback(RunEvent::Exit);
2322+
}
2323+
23242324
Event::GlobalShortcutEvent(accelerator_id) => {
23252325
for (id, handler) in &*global_shortcut_manager_handle.listeners.lock().unwrap() {
23262326
if accelerator_id == *id {
@@ -2565,7 +2565,6 @@ fn on_window_close<'a, T: UserEvent>(
25652565

25662566
if !should_prevent {
25672567
*control_flow = ControlFlow::Exit;
2568-
callback(RunEvent::Exit);
25692568
}
25702569
}
25712570
Some(webview)

0 commit comments

Comments
 (0)