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

refactor!: renamed TrayIconBuilder/TrayIcon::on_tray_event to TrayIconBuilder/TrayIcon::on_tray_icon_event #7943

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changes/tauri-tray-on-tray-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'patch:breaking'
---

Changed `TrayIconBuilder/TrayIcon::on_tray_event` to `TrayIconBuilder/TrayIcon::on_tray_icon_event` for consistency of naming.
23 changes: 15 additions & 8 deletions core/tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl From<tray_icon::TrayIconEvent> for TrayIconEvent {
#[derive(Default)]
pub struct TrayIconBuilder<R: Runtime> {
on_menu_event: Option<GlobalMenuEventListener<AppHandle<R>>>,
on_tray_event: Option<GlobalTrayIconEventListener<TrayIcon<R>>>,
on_tray_icon_event: Option<GlobalTrayIconEventListener<TrayIcon<R>>>,
inner: tray_icon::TrayIconBuilder,
}

Expand All @@ -124,7 +124,7 @@ impl<R: Runtime> TrayIconBuilder<R> {
Self {
inner: tray_icon::TrayIconBuilder::new(),
on_menu_event: None,
on_tray_event: None,
on_tray_icon_event: None,
}
}

Expand Down Expand Up @@ -223,11 +223,11 @@ impl<R: Runtime> TrayIconBuilder<R> {
}

/// Set a handler for this tray icon events.
pub fn on_tray_event<F: Fn(&TrayIcon<R>, TrayIconEvent) + Sync + Send + 'static>(
pub fn on_tray_icon_event<F: Fn(&TrayIcon<R>, TrayIconEvent) + Sync + Send + 'static>(
mut self,
f: F,
) -> Self {
self.on_tray_event.replace(Box::new(f));
self.on_tray_icon_event.replace(Box::new(f));
self
}

Expand All @@ -247,7 +247,11 @@ impl<R: Runtime> TrayIconBuilder<R> {
app_handle: manager.app_handle().clone(),
};

icon.register(&icon.app_handle, self.on_menu_event, self.on_tray_event);
icon.register(
&icon.app_handle,
self.on_menu_event,
self.on_tray_icon_event,
);

Ok(icon)
}
Expand Down Expand Up @@ -285,7 +289,7 @@ impl<R: Runtime> TrayIcon<R> {
&self,
app_handle: &AppHandle<R>,
on_menu_event: Option<GlobalMenuEventListener<AppHandle<R>>>,
on_tray_event: Option<GlobalTrayIconEventListener<TrayIcon<R>>>,
on_tray_icon_event: Option<GlobalTrayIconEventListener<TrayIcon<R>>>,
) {
if let Some(handler) = on_menu_event {
app_handle
Expand All @@ -297,7 +301,7 @@ impl<R: Runtime> TrayIcon<R> {
.push(handler);
}

if let Some(handler) = on_tray_event {
if let Some(handler) = on_tray_icon_event {
app_handle
.manager
.inner
Expand Down Expand Up @@ -337,7 +341,10 @@ impl<R: Runtime> TrayIcon<R> {
}

/// Register a handler for this tray icon events.
pub fn on_tray_event<F: Fn(&TrayIcon<R>, TrayIconEvent) + Sync + Send + 'static>(&self, f: F) {
pub fn on_tray_icon_event<F: Fn(&TrayIcon<R>, TrayIconEvent) + Sync + Send + 'static>(
&self,
f: F,
) {
self
.app_handle
.manager
Expand Down
Loading