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

This commit is contained in:
Lucas Fernandes Nogueira
2021-08-15 18:14:26 -03:00
committed by GitHub
parent 28c6b7adfe
commit 6be3f43391
5 changed files with 33 additions and 0 deletions

View File

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

View File

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

View File

@@ -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 {

View File

@@ -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 loops 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

View File

@@ -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 loops 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!(),
},
);