aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/Tray.js
diff options
context:
space:
mode:
authorLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-09-07 18:15:46 +0530
committerLibravatar GitHub <noreply@github.com>2021-09-07 18:15:46 +0530
commitd5fd04626ce22d6194924b75f268fefa41aa2db5 (patch)
tree7181612feeb035fb07940cef4e41c491befd45ab /src/lib/Tray.js
parentNew translations (#1877) (diff)
downloadferdium-app-d5fd04626ce22d6194924b75f268fefa41aa2db5.tar.gz
ferdium-app-d5fd04626ce22d6194924b75f268fefa41aa2db5.tar.zst
ferdium-app-d5fd04626ce22d6194924b75f268fefa41aa2db5.zip
Add a confirmation when quitting Ferdi and a preference to toggle it (implements #1857) (#1879)
Works for the 'Ferdi > Quit' menu, the shortcut key to quit (Cmd/Ctrl+Q) and also from the tray icon.
Diffstat (limited to 'src/lib/Tray.js')
-rw-r--r--src/lib/Tray.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/Tray.js b/src/lib/Tray.js
index f5970f7e7..c897d597a 100644
--- a/src/lib/Tray.js
+++ b/src/lib/Tray.js
@@ -1,5 +1,5 @@
1import { 1import {
2 app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, ipcMain, 2 app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, ipcMain, dialog,
3} from 'electron'; 3} from 'electron';
4import { join } from 'path'; 4import { join } from 'path';
5import macosVersion from 'macos-version'; 5import macosVersion from 'macos-version';
@@ -43,9 +43,7 @@ export default class TrayIcon {
43 }, 43 },
44 { 44 {
45 label: 'Quit Ferdi', 45 label: 'Quit Ferdi',
46 click() { 46 click: this.quitApp,
47 app.quit();
48 },
49 }, 47 },
50 ]; 48 ];
51 49
@@ -178,4 +176,22 @@ export default class TrayIcon {
178 __dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`, 176 __dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`,
179 )); 177 ));
180 } 178 }
179
180 // TODO: Extract this into a reusable component and remove the duplications
181 quitApp = () => {
182 const yesButtonIndex = 0;
183 let selection = yesButtonIndex;
184 if (window.ferdi.stores.settings.app.confirmOnQuit) {
185 selection = dialog.showMessageBoxSync(app.mainWindow, {
186 // TODO: Externalize strings
187 type: 'question',
188 message: 'Quit',
189 detail: 'Do you really want to quit Ferdi?',
190 buttons: ['Yes', 'No'],
191 });
192 }
193 if (selection === yesButtonIndex) {
194 app.quit();
195 }
196 };
181} 197}