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(tray): remove from tray on Drop on macOS #520

Merged
merged 1 commit into from
Aug 4, 2022
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/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