Selaa lähdekoodia

feat(core): add `Resumed` and `MainEventsCleared` events, closes #2127 (#2439)

Lucas Fernandes Nogueira 4 vuotta sitten
vanhempi
sitoutus
6be3f43391

+ 5 - 0
.changes/main-events-cleared-and-resumed.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Adds `Resumed` and `MainEventsCleared` variants to the `Event` enum.

+ 6 - 0
.changes/runtime-main-events-cleared-and-resumed.md

@@ -0,0 +1,6 @@
+---
+"tauri-runtime": minor
+"tauri-runtime-wry": minor
+---
+
+Adds `Resumed` and `MainEventsCleared` variants to the `RunEvent` enum.

+ 8 - 0
core/tauri-runtime-wry/src/lib.rs

@@ -1785,6 +1785,14 @@ fn handle_event_loop(
       callback(RunEvent::Ready);
     }
 
+    Event::NewEvents(StartCause::Poll) => {
+      callback(RunEvent::Resumed);
+    }
+
+    Event::MainEventsCleared => {
+      callback(RunEvent::MainEventsCleared);
+    }
+
     Event::GlobalShortcutEvent(accelerator_id) => {
       for (id, handler) in &*global_shortcut_manager_handle.listeners.lock().unwrap() {
         if accelerator_id == *id {

+ 6 - 0
core/tauri-runtime/src/lib.rs

@@ -186,6 +186,12 @@ pub enum RunEvent {
   WindowClose(String),
   /// Application ready.
   Ready,
+  /// Sent if the event loop is being resumed.
+  Resumed,
+  /// Emitted when all of the event loop’s input events have been processed and redraw processing is about to begin.
+  ///
+  /// This event is useful as a place to put your code that should be run after all state-changing events have been handled and you want to do stuff (updating state, performing calculations, etc) that happens as the “main body” of your event loop.
+  MainEventsCleared,
 }
 
 /// Action to take when the event loop is about to exit

+ 8 - 0
core/tauri/src/app.rs

@@ -97,6 +97,12 @@ pub enum Event {
   WindowClosed(String),
   /// Application ready.
   Ready,
+  /// Sent if the event loop is being resumed.
+  Resumed,
+  /// Emitted when all of the event loop’s input events have been processed and redraw processing is about to begin.
+  ///
+  /// This event is useful as a place to put your code that should be run after all state-changing events have been handled and you want to do stuff (updating state, performing calculations, etc) that happens as the “main body” of your event loop.
+  MainEventsCleared,
 }
 
 /// A menu event that was triggered on a window.
@@ -441,6 +447,8 @@ impl<R: Runtime> App<R> {
             },
             RunEvent::WindowClose(label) => Event::WindowClosed(label),
             RunEvent::Ready => Event::Ready,
+            RunEvent::Resumed => Event::Resumed,
+            RunEvent::MainEventsCleared => Event::MainEventsCleared,
             _ => unimplemented!(),
           },
         );