Skip to content

Commit

Permalink
feat: add set_icon_with_as_template (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Nov 21, 2024
1 parent d9bedf8 commit 1f0e1f8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/add-macos-set_icon_with_as_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tray-icon": patch
---

Add `set_icon_with_as_template` method to update icon and `is_template` property, preventing glitchy effects during icon animation on macOS.
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ impl TrayIcon {
let _ = is_template;
}

pub fn set_icon_with_as_template(&self, icon: Option<Icon>, is_template: bool) -> Result<()> {
#[cfg(target_os = "macos")]
return self
.tray
.borrow_mut()
.set_icon_with_as_template(icon, is_template);
#[cfg(not(target_os = "macos"))]
{
let _ = icon;
let _ = is_template;
Ok(())
}
}

/// Disable or enable showing the tray menu on left click.
///
/// ## Platform-specific:
Expand Down
20 changes: 20 additions & 0 deletions src/platform_impl/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ impl TrayIcon {
self.attrs.icon_is_template = is_template;
}

pub fn set_icon_with_as_template(
&mut self,
icon: Option<Icon>,
is_template: bool,
) -> crate::Result<()> {
if let (Some(ns_status_item), Some(tray_target)) = (&self.ns_status_item, &self.tray_target)
{
set_icon_for_ns_status_item_button(
ns_status_item,
icon.clone(),
is_template,
self.mtm,
)?;
tray_target.update_dimensions();
}
self.attrs.icon = icon;
self.attrs.icon_is_template = is_template;
Ok(())
}

pub fn set_show_menu_on_left_click(&mut self, enable: bool) {
if let Some(tray_target) = &self.tray_target {
tray_target.ivars().menu_on_left_click.set(enable);
Expand Down

0 comments on commit 1f0e1f8

Please sign in to comment.