Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macos): Expose tao event Event::Reopen, closes #3084 #4865

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/event-reopen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'tauri': 'minor:feat'
'tauri-runtime': 'minor:feat'
'tauri-runtime-wry': 'minor:feat'
---

Expose tao event `Event::Reopen` for handle click on dock icon on macOS.
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,13 @@ fn handle_event_loop<T: UserEvent>(
Event::Opened { urls } => {
callback(RunEvent::Opened { urls });
}
#[cfg(target_os = "macos")]
Event::Reopen {
has_visible_windows,
..
} => callback(RunEvent::Reopen {
has_visible_windows,
}),
_ => (),
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ pub enum RunEvent<T: UserEvent> {
/// Emitted when the user wants to open the specified resource with the app.
#[cfg(any(target_os = "macos", target_os = "ios"))]
Opened { urls: Vec<url::Url> },
/// 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),
}
Expand Down
14 changes: 14 additions & 0 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventLoopMessage> for RunEvent {
Expand Down Expand Up @@ -1918,6 +1926,12 @@ fn on_event_loop_event<R: Runtime>(
}
#[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!(),
};

Expand Down
Loading