Skip to content

Commit

Permalink
refactor!: renamed TrayIconBuilder/TrayIcon::on_tray_event to `Tray…
Browse files Browse the repository at this point in the history
…IconBuilder/TrayIcon::on_tray_icon_event` (#7943)
  • Loading branch information
amrbashir committed Oct 3, 2023
1 parent b7fd88e commit c0d03af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
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

0 comments on commit c0d03af

Please sign in to comment.