fix tray cannot be destroyed

Relates #https://github.com/electron/electron/issues/17622
pull/1839/head
audric 4 years ago
parent 6a50484597
commit 1af08311dd

@ -766,6 +766,10 @@ app.on('before-quit', () => {
shouldQuit: windowState.shouldQuit(), shouldQuit: windowState.shouldQuit(),
}); });
if (tray) {
tray.destroy();
}
windowState.markShouldQuit(); windowState.markShouldQuit();
}); });
@ -876,16 +880,15 @@ ipc.on('password-window-login', async (event, passPhrase) => {
ipc.on('start-in-tray-on-start', async (event, newValue) => { ipc.on('start-in-tray-on-start', async (event, newValue) => {
try { try {
userConfig.set('startInTray', newValue); userConfig.set('startInTray', newValue);
if (newValue) { if (newValue) {
if (!tray) { if (!tray) {
tray = createTrayIcon(getMainWindow, locale.messages); tray = createTrayIcon(getMainWindow, locale.messages);
} }
} else { } else {
if (tray) { // destroy is not working for a lot of desktop env. So for simplicity, we don't destroy it here but just
tray.destroy(); // show a toast to explain to the user that he needs to restart
} // tray.destroy();
tray = null; // tray = null;
} }
event.sender.send('start-in-tray-on-start-response', null); event.sender.send('start-in-tray-on-start-response', null);
} catch (e) { } catch (e) {

@ -114,7 +114,7 @@ window.setPassword = (passPhrase, oldPhrase) =>
window.setStartInTray = startInTray => window.setStartInTray = startInTray =>
new Promise((resolve, reject) => { 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) { if (error) {
return reject(error); return reject(error);
} }

@ -22,6 +22,7 @@ import { toggleAudioAutoplay } from '../../../state/ducks/userConfig';
import { sessionPassword } from '../../../state/ducks/modalDialog'; import { sessionPassword } from '../../../state/ducks/modalDialog';
import { PasswordAction } from '../../dialog/SessionPasswordDialog'; import { PasswordAction } from '../../dialog/SessionPasswordDialog';
import { SessionIconButton, SessionIconSize, SessionIconType } from '../icon'; import { SessionIconButton, SessionIconSize, SessionIconType } from '../icon';
import { ToastUtils } from '../../../session/utils';
export enum SessionSettingCategory { export enum SessionSettingCategory {
Appearance = 'appearance', Appearance = 'appearance',
@ -377,10 +378,18 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
type: SessionSettingType.Toggle, type: SessionSettingType.Toggle,
category: SessionSettingCategory.Appearance, category: SessionSettingCategory.Appearance,
setFn: async () => { setFn: async () => {
const newValue = !(await window.getStartInTray()); try {
await window.setStartInTray(newValue); 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); // 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, content: undefined,
comparisonValue: undefined, comparisonValue: undefined,

Loading…
Cancel
Save