Skip to content

Commit 78839b6

Browse files
feat(macos): Expose tao event Event::Reopen, closes #3084 (#4865)
* feat: expose tao event Event::Reopen * Update .changes/event-reopen.md * deps(core::tauri-runtime-wry): update tao to 0.28
1 parent 783ef0f commit 78839b6

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

.changes/event-reopen.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'tauri': 'minor:feat'
3+
'tauri-runtime': 'minor:feat'
4+
'tauri-runtime-wry': 'minor:feat'
5+
---
6+
7+
Add `RunEvent::Reopen` for handle click on dock icon on macOS.

core/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rust-version = { workspace = true }
1414

1515
[dependencies]
1616
wry = { version = "0.39.3", default-features = false, features = [ "drag-drop", "protocol", "os-webview" ] }
17-
tao = { version = "0.27", default-features = false, features = [ "rwh_06" ] }
17+
tao = { version = "0.28", default-features = false, features = [ "rwh_06" ] }
1818
tauri-runtime = { version = "2.0.0-beta.15", path = "../tauri-runtime" }
1919
tauri-utils = { version = "2.0.0-beta.14", path = "../tauri-utils" }
2020
raw-window-handle = "0.6"

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,13 @@ fn handle_event_loop<T: UserEvent>(
34413441
Event::Opened { urls } => {
34423442
callback(RunEvent::Opened { urls });
34433443
}
3444+
#[cfg(target_os = "macos")]
3445+
Event::Reopen {
3446+
has_visible_windows,
3447+
..
3448+
} => callback(RunEvent::Reopen {
3449+
has_visible_windows,
3450+
}),
34443451
_ => (),
34453452
}
34463453
}

core/tauri-runtime/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ pub enum RunEvent<T: UserEvent> {
235235
/// Emitted when the user wants to open the specified resource with the app.
236236
#[cfg(any(target_os = "macos", target_os = "ios"))]
237237
Opened { urls: Vec<url::Url> },
238+
/// Emitted when the NSApplicationDelegate's applicationShouldHandleReopen gets called
239+
#[cfg(target_os = "macos")]
240+
Reopen {
241+
/// Indicates whether the NSApplication object found any visible windows in your application.
242+
has_visible_windows: bool,
243+
},
238244
/// A custom event defined by the user.
239245
UserEvent(T),
240246
}

core/tauri/src/app.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ pub enum RunEvent {
239239
#[cfg(all(desktop, feature = "tray-icon"))]
240240
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
241241
TrayIconEvent(crate::tray::TrayIconEvent),
242+
/// Emitted when the NSApplicationDelegate's applicationShouldHandleReopen gets called
243+
#[non_exhaustive]
244+
#[cfg(target_os = "macos")]
245+
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
246+
Reopen {
247+
/// Indicates whether the NSApplication object found any visible windows in your application.
248+
has_visible_windows: bool,
249+
},
242250
}
243251

244252
impl From<EventLoopMessage> for RunEvent {
@@ -1918,6 +1926,12 @@ fn on_event_loop_event<R: Runtime>(
19181926
}
19191927
#[cfg(any(target_os = "macos", target_os = "ios"))]
19201928
RuntimeRunEvent::Opened { urls } => RunEvent::Opened { urls },
1929+
#[cfg(target_os = "macos")]
1930+
RuntimeRunEvent::Reopen {
1931+
has_visible_windows,
1932+
} => RunEvent::Reopen {
1933+
has_visible_windows,
1934+
},
19211935
_ => unimplemented!(),
19221936
};
19231937

0 commit comments

Comments
 (0)