From 1af08311dd710412564fce8a9c81b1cfa5aeab79 Mon Sep 17 00:00:00 2001 From: audric Date: Fri, 13 Aug 2021 15:44:32 +1000 Subject: [PATCH] fix tray cannot be destroyed Relates #https://github.com/electron/electron/issues/17622 --- main.js | 13 ++++++++----- preload.js | 2 +- .../session/settings/SessionSettings.tsx | 17 +++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index 3c3f8393d..83ba30ed4 100644 --- a/main.js +++ b/main.js @@ -766,6 +766,10 @@ app.on('before-quit', () => { shouldQuit: windowState.shouldQuit(), }); + if (tray) { + tray.destroy(); + } + windowState.markShouldQuit(); }); @@ -876,16 +880,15 @@ ipc.on('password-window-login', async (event, passPhrase) => { ipc.on('start-in-tray-on-start', async (event, newValue) => { try { userConfig.set('startInTray', newValue); - if (newValue) { if (!tray) { tray = createTrayIcon(getMainWindow, locale.messages); } } else { - if (tray) { - tray.destroy(); - } - tray = null; + // destroy is not working for a lot of desktop env. So for simplicity, we don't destroy it here but just + // show a toast to explain to the user that he needs to restart + // tray.destroy(); + // tray = null; } event.sender.send('start-in-tray-on-start-response', null); } catch (e) { diff --git a/preload.js b/preload.js index c1d31f23b..1c4a95d77 100644 --- a/preload.js +++ b/preload.js @@ -114,7 +114,7 @@ window.setPassword = (passPhrase, oldPhrase) => window.setStartInTray = startInTray => new Promise((resolve, reject) => { - ipc.once('start-in-tray-on-start-response', (event, error) => { + ipc.once('start-in-tray-on-start-response', (_event, error) => { if (error) { return reject(error); } diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index ae29ff8f6..03beff923 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -22,6 +22,7 @@ import { toggleAudioAutoplay } from '../../../state/ducks/userConfig'; import { sessionPassword } from '../../../state/ducks/modalDialog'; import { PasswordAction } from '../../dialog/SessionPasswordDialog'; import { SessionIconButton, SessionIconSize, SessionIconType } from '../icon'; +import { ToastUtils } from '../../../session/utils'; export enum SessionSettingCategory { Appearance = 'appearance', @@ -377,10 +378,18 @@ class SettingsViewInner extends React.Component { type: SessionSettingType.Toggle, category: SessionSettingCategory.Appearance, setFn: async () => { - const newValue = !(await window.getStartInTray()); - await window.setStartInTray(newValue); - // make sure to write it here too, as this is the value used on the UI to mark the toggle as true/false - window.setSettingValue('start-in-tray-setting', newValue); + try { + const newValue = !(await window.getStartInTray()); + + // make sure to write it here too, as this is the value used on the UI to mark the toggle as true/false + window.setSettingValue('start-in-tray-setting', newValue); + await window.setStartInTray(newValue); + if (!newValue) { + ToastUtils.pushRestartNeeded(); + } + } catch (e) { + window.log.warn('start in tray change error:', e); + } }, content: undefined, comparisonValue: undefined,