electron: API tray.destroy is not working
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
- Electron Version:
- 4.0.4
- Operating System:
- Ubuntu 18.10 x64
Expected Behavior
Observed in Zulip desktop app
tray.destroy()api should destroy tray icon in panelshow app tray iconoption in general setting, it should destroy and create tray icon on toggle
Actual Behavior
Previous tray icon are not destroy on toggle and new icon created i.e tray.destroy API is not working

To Reproduce
$ git clone https://github.com/zulip/zulip-electron
$ cd zulip-electron
$ npm install
$ npm start
you can find code in zulip-electron/app/renderer/js/tray.js
function toggleTray() {
let state;
if (window.tray) {
state = false;
window.tray.destroy();
if (window.tray.isDestroyed()) {
window.tray = null;
}
ConfigUtil.setConfigItem('trayIcon', false);
} else {
state = true;
createTray();
if (process.platform === 'linux' || process.platform === 'win32') {
renderNativeImage(unread).then(image => {
window.tray.setImage(image);
window.tray.setToolTip(unread + ' unread messages');
});
}
ConfigUtil.setConfigItem('trayIcon', true);
}
const selector = 'webview:not([class*=disabled])';
const webview = document.querySelector(selector);
const webContents = webview.getWebContents();
webContents.send('toggletray', state);
}
Screenshots

About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 49 (7 by maintainers)
Commits related to this issue
- Don't destroy tray on Linux Gnome Linux with Gnome Desktop cannot destroy the tray due to bug https://github.com/electron/electron/issues/17622 — committed to UofA-SPI21-team7/Zettlr by cskeogh 3 years ago
- fix tray cannot be destroyed Relates #https://github.com/electron/electron/issues/17622 — committed to Bilb/session-desktop by Bilb 3 years ago
- fix: linux: tray icon duplicates on init Tray.destroy() is not working on Linux due to: https://github.com/electron/electron/issues/17622 Which causes tray icon to duplicate on every init. — committed to aleksey-hoffman/sigma-file-manager by aleksey-hoffman 3 years ago
@rrhythmsharma i’ve popped up a PR that i believe should ameliorate this!
This was closed due to inactivity, but It seems this is still not resolved. There is an active issue for keeweb project that is related to this.
same on v17.4.11.
haven’t tried the latest v21 though.
Just bumped from electron
and this bug started to appear. The destroy was working correctly before that.
@codebytere This doesn’t fix the issue. I think this needs to be reopened.
Update https://github.com/meetfranz/franz/issues/1377
check this : https://techbase.kde.org/Projects/Plasma/NewSystemTray
Perhaps you can rewrite the application with PWA and wasm.Though you need chrome ,the user experience will be better on every platforms.
But now I have to manage my codebase in five languages…GOD DAME
https://api.kde.org/pykde-4.4-api/kdeui/KSystemTrayIcon.html
If you want a better Tray experience,you may want to try qt.But I wonder how they achieve it.
Oh sorry .GtkStatusion is a part of gnome so you don’t have to install it Manually . As for libappindicator1 ,you can install it with apt .But actually it doesn’t solve this issue.
you should try kde,at least it doesn’t crash