DioxusLabs / DioxusLabs/dioxus

Default tray icon behavior is lackluster

Open
#5,432 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

Current implementation of `handle_tray_icon_event` in app.rs is this
```rust
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
pub fn handle_tray_icon_event(&mut self, event: tray_icon::TrayIconEvent) {
if let tray_icon::TrayIconEvent::Click {
id: _,
position: _,
rect: _,
button,
button_state: _,
} = event
{
if button == tray_icon::MouseButton::Left && self.tray_icon_show_window_on_click {
for webview in self.webviews.values() {
webview.desktop_context.window.set_visible(true);
webview.desktop_context.window.set_focus();
}
}
}
}
```
I'm in the process of building a [macOS menu bar app](https://github.com/brodmo-dev/GroupCtrl) and I haven't found this default implementation helpful, quite the opposite. Now thankfully, #5361 adds a flag to disable it, so that solves the issue for me. Still, I think this default implementation should be improved. Here are my issues with it.

### It fires twice
Since button_state is a wildcard, the logic runs twice, on button down and button up. It should be just button down.

### It shows, but doesn't hide
This might be constrained to macOS, but I think that clicking the icon again to hide the window is expected behavior. Since visibility detection is tricky adding window hiding without disabling the default implementation requires an [ungodly workaround](https://github.com/brodmo-dev/GroupCtrl/blob/5a790d6dc8bb56256f750516d4f69aefa7641a71/src/ui/tray_icon.rs#L27). I think it should hide or show depending on visibility instead of always hide.

### It focuses multiple windows in a non-deterministic order
This is my biggest gripe. The webview iteration order is non-deterministic, so it's random which window ends up with the final focus. Especially for a keyboard-driven app this is lethal. For me, it would randomly focus my invisible pop-up, which was really hard to debug. I don't have a good solution to this, though. Maybe the default implementation should just do nothing if there are multiple webviews? I'm not sure.

I'm willing to implement a solution to this, but since it mainly boils down to design questions I would like some input first.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.