Skip to content

Commit

Permalink
feat(tray): remove from tray on Drop on macOS (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 4, 2022
1 parent c3e076e commit aca4d3f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/drop-tray-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Remove the NSStatusItem from the menu bar when the `SystemTray` instance is dropped.
8 changes: 8 additions & 0 deletions src/platform_impl/macos/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ pub struct SystemTray {
pub(crate) ns_status_bar: id,
}

impl Drop for SystemTray {
fn drop(&mut self) {
unsafe {
NSStatusBar::systemStatusBar(nil).removeStatusItem_(self.ns_status_bar);
}
}
}

impl SystemTray {
pub fn set_icon(&mut self, icon: Icon) {
// update our icon
Expand Down
2 changes: 1 addition & 1 deletion src/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SystemTrayBuilder {
/// **Linux:**
/// - Dropping the tray too early could lead to a default icon.
/// - Dropping the tray after the icon has been added to the system tray may not remove it.
/// **Windows:** Dropping the tray will effectively remove the icon from the system tray.
/// **Windows / macOS:** Dropping the tray will effectively remove the icon from the system tray.
pub struct SystemTray(pub SystemTrayPlatform);

impl SystemTray {
Expand Down

0 comments on commit aca4d3f

Please sign in to comment.