Jelajahi Sumber

refactor(wry): emit `RunEvent::Exit` on `Event::LoopDestroyed` (#3785)

Lucas Fernandes Nogueira 3 tahun lalu
induk
melakukan
3c4ee7c997
2 mengubah file dengan 11 tambahan dan 7 penghapusan
  1. 5 0
      .changes/exit-loop-destroyed.md
  2. 6 7
      core/tauri-runtime-wry/src/lib.rs

+ 5 - 0
.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`.

+ 6 - 7
core/tauri-runtime-wry/src/lib.rs

@@ -2300,14 +2300,10 @@ fn handle_event_loop<T: UserEvent>(
     #[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<T: UserEvent>(
       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)