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: add set_icon_with_as_template #204

Merged
merged 5 commits into from
Nov 21, 2024
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/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;
mrexox marked this conversation as resolved.
Show resolved Hide resolved
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
Loading