fix(desktop): rebuild tray menu in place instead of recreating the Tray

The old setupTray() called tray.destroy() before creating a new Tray. On
Linux with KDE Plasma 6 Wayland, tray.destroy() does not actually remove
the icon from plasmashell (electron/electron#49517), so the new Tray
registers a fresh dbusmenu while plasmashell keeps talking to the
orphaned one. Menu items still render (cached layout) but every
com.canonical.dbusmenu.Event("clicked", ...) method call from plasmashell
hits the destroyed handler and is dropped, so menu-item click callbacks
stop firing after the frontend triggers a rebuild on login.

Move the one-time Tray construction (icon, tooltip, click handler)
behind a !tray guard and keep setContextMenu in the always-run path. The
desktop:update-quick-entry-shortcut IPC handler keeps calling setupTray()
and the accelerator label updates without touching the native Tray.
This commit is contained in:
Dávid Takács-Tolnai
2026-04-16 22:05:14 +02:00
committed by kolaente
parent 10e5fa915a
commit e624c8a296

View File

@@ -332,12 +332,20 @@ function toggleQuickEntry() {
// ─── System tray ─────────────────────────────────────────────────────
function setupTray() {
if (tray) {
tray.destroy()
if (!tray) {
const iconPath = path.join(__dirname, 'build', 'icon.png')
const icon = nativeImage.createFromPath(iconPath).resize({width: 16, height: 16})
tray = new Tray(icon)
tray.setToolTip('Vikunja')
tray.on('click', () => {
if (mainWindow) {
mainWindow.show()
mainWindow.focus()
} else {
createMainWindow()
}
})
}
const iconPath = path.join(__dirname, 'build', 'icon.png')
const icon = nativeImage.createFromPath(iconPath).resize({width: 16, height: 16})
tray = new Tray(icon)
const contextMenu = Menu.buildFromTemplate([
{
@@ -366,17 +374,7 @@ function setupTray() {
},
])
tray.setToolTip('Vikunja')
tray.setContextMenu(contextMenu)
tray.on('click', () => {
if (mainWindow) {
mainWindow.show()
mainWindow.focus()
} else {
createMainWindow()
}
})
}
// ─── IPC handlers ────────────────────────────────────────────────────