fix(tray): Linux tray icon duplicates and dead menus on minimize-to-tray toggle - #5086
Open
jing2uo wants to merge 1 commit into
Open
fix(tray): Linux tray icon duplicates and dead menus on minimize-to-tray toggle#5086jing2uo wants to merge 1 commit into
jing2uo wants to merge 1 commit into
Conversation
Toggling "Minimize to tray" off then on repeatedly left a dead icon in the system tray every time (waybar, KDE Plasma); each opened a menu but only the newest one worked, and the pile only cleared when Folo fully quit. setTrayConfig(false) calls tray.destroy(), which on a StatusNotifierItem host does not remove the icon: Chromium's StatusIconLinuxDbus registers the item by object path on the process-wide shared session-bus connection and, on teardown, un-exports its own objects but never tells org.kde.StatusNotifierWatcher the item is gone. The connection name outlives the tray, so the host gets no NameOwnerChanged and keeps a dead icon. Re-enabling then calls new Tray() again and Chromium registers a fresh /org/chromium/StatusNotifierItem/<n+1>. - Linux: keep the single Tray instance for the app's lifetime instead of destroying/recreating it on the toggle. registerAppTray() already guards new Tray() behind `if (tray)`, and the close handler reads getTrayConfig() live, so a tray icon that outlives a disabled setting is inert. - The icon can't be removed from a running process on Linux (Electron's Tray has no hide API), so setTrayConfig now returns whether a restart is needed; the renderer shows a toast with a "Restart now" action wired to a new app.relaunch IPC. Enabling the tray, and all macOS/Windows behavior, is unchanged and immediate. The real fix belongs upstream in Chromium/Electron (StatusIconLinuxDbus should own a per-item well-known bus name and release it on teardown); this is a workaround. Refs: RSSNext#3940, RSSNext#4985, RSSNext#3207 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QmyAEEXr4eHiNFSWGbZk7x
Contributor
Author
|
@DIYgod 这个方便看下不~ 问题是: linux 下每次点关闭到托盘, 都会多一个托盘图标, 反复点的话会出一堆但只有最新那个可以点击. 必须关闭应用才能正常. |
Contributor
@DIYgod Is this convenient? The problem is: every time you click Close to the tray under Linux, there will be an extra tray icon. If you click it repeatedly, a bunch of them will appear, but only the latest one can be clicked. You must close the application to normal. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Linux, toggling Settings → General → "Minimize to tray" off and on again
leaves a dead icon in the system tray every time. After a few toggles the tray
shows a stack of Folo icons; each opens a context menu but only the newest one's
menu does anything. The pile only clears when Folo fully quits.
Root cause:
setTrayConfig(false)callstray.destroy(). On aStatusNotifierItem host (waybar, KDE Plasma, …) that does not remove the icon —
Chromium's
StatusIconLinuxDbusregisters the item by object path on theprocess-wide shared session-bus connection and, on teardown, un-exports its own
objects but never tells
org.kde.StatusNotifierWatcherthe item is gone. Theconnection name outlives the tray, so the host gets no
NameOwnerChangedandkeeps a dead icon. Re-enabling then calls
new Tray()again and Chromiumregisters a fresh
/org/chromium/StatusNotifierItem/<n+1>, stacking another.Fix (commit 1): on Linux, keep the single
Trayinstance for the app'slifetime instead of destroying/recreating it on the toggle.
registerAppTray()already guards
new Tray()behindif (tray), and the window close handlerreads
getTrayConfig()on every close, so a tray icon that outlives a disabledsetting is inert.
Follow-up (commit 2): the icon genuinely can't be removed from a running
process on Linux (Electron's
Trayhas no hide/visibility API), sosetTrayConfignow returns whether a restart is needed (true only whendisabling on Linux with a tray present).
settings.setMinimizeToTrayforwardsthat and the renderer shows a toast with a "Restart now" action wired to a new
app.relaunchIPC. Enabling the tray, and all behavior on macOS/Windows, isunchanged and takes effect immediately.
The real fix belongs upstream in Chromium/Electron (
StatusIconLinuxDbusshouldown a per-item well-known bus name and release it on teardown so hosts get
NameOwnerChanged); this is a workaround until then.PR Type
Screenshots (if UI change)
Demo Video (if new feature)
Linked Issues
Fixes #3940
Related: #4985, #3207
Additional context
Verified on Debian + Hyprland + waybar (Flatpak build, 1.13.0 / Electron 43.1.0).
D-Bus evidence:
RegisteredStatusNotifierItemsheld four:1.XXX/org/chromium/StatusNotifierItem/1..4entries from a single process;busctl --user treeshowed only/4actually exported;dbus-monitorshowedone
RegisterStatusNotifierItemper toggle and never an unregister; on quit,the host dropped all of them at once.
For review — the trade-off in commit 2: after disabling on Linux the icon
lingers until the app restarts (the toast's "Restart now" is optional; ignoring
it just leaves one inert icon, no stacking). Happy to switch to auto-relaunch or
drop the prompt entirely. The two new i18n strings fall back to
enin otherlocales.
Changelog
(
apps/desktop/changelog/next.md— desktop-only change)