diff --git a/.changes/event-reopen.md b/.changes/event-reopen.md new file mode 100644 index 000000000..484929df3 --- /dev/null +++ b/.changes/event-reopen.md @@ -0,0 +1,7 @@ +--- +'tauri': 'minor:feat' +'tauri-runtime': 'minor:feat' +'tauri-runtime-wry': 'minor:feat' +--- + +Add `RunEvent::Reopen` for handle click on dock icon on macOS. diff --git a/core/tauri-runtime-wry/Cargo.toml b/core/tauri-runtime-wry/Cargo.toml index bfce72066..a15b7c4b9 100644 --- a/core/tauri-runtime-wry/Cargo.toml +++ b/core/tauri-runtime-wry/Cargo.toml @@ -14,7 +14,7 @@ rust-version = { workspace = true } [dependencies] wry = { version = "0.39.3", default-features = false, features = [ "drag-drop", "protocol", "os-webview" ] } -tao = { version = "0.27", default-features = false, features = [ "rwh_06" ] } +tao = { version = "0.28", default-features = false, features = [ "rwh_06" ] } tauri-runtime = { version = "2.0.0-beta.15", path = "../tauri-runtime" } tauri-utils = { version = "2.0.0-beta.14", path = "../tauri-utils" } raw-window-handle = "0.6" diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 3b016145e..13774f0ab 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -3441,6 +3441,13 @@ fn handle_event_loop( Event::Opened { urls } => { callback(RunEvent::Opened { urls }); } + #[cfg(target_os = "macos")] + Event::Reopen { + has_visible_windows, + .. + } => callback(RunEvent::Reopen { + has_visible_windows, + }), _ => (), } } diff --git a/core/tauri-runtime/src/lib.rs b/core/tauri-runtime/src/lib.rs index 64ef2692d..2dc595a91 100644 --- a/core/tauri-runtime/src/lib.rs +++ b/core/tauri-runtime/src/lib.rs @@ -235,6 +235,12 @@ pub enum RunEvent { /// Emitted when the user wants to open the specified resource with the app. #[cfg(any(target_os = "macos", target_os = "ios"))] Opened { urls: Vec }, + /// Emitted when the NSApplicationDelegate's applicationShouldHandleReopen gets called + #[cfg(target_os = "macos")] + Reopen { + /// Indicates whether the NSApplication object found any visible windows in your application. + has_visible_windows: bool, + }, /// A custom event defined by the user. UserEvent(T), } diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 1be4436d8..a11766d0e 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -239,6 +239,14 @@ pub enum RunEvent { #[cfg(all(desktop, feature = "tray-icon"))] #[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))] TrayIconEvent(crate::tray::TrayIconEvent), + /// Emitted when the NSApplicationDelegate's applicationShouldHandleReopen gets called + #[non_exhaustive] + #[cfg(target_os = "macos")] + #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))] + Reopen { + /// Indicates whether the NSApplication object found any visible windows in your application. + has_visible_windows: bool, + }, } impl From for RunEvent { @@ -1918,6 +1926,12 @@ fn on_event_loop_event( } #[cfg(any(target_os = "macos", target_os = "ios"))] RuntimeRunEvent::Opened { urls } => RunEvent::Opened { urls }, + #[cfg(target_os = "macos")] + RuntimeRunEvent::Reopen { + has_visible_windows, + } => RunEvent::Reopen { + has_visible_windows, + }, _ => unimplemented!(), };