aboutsummaryrefslogtreecommitdiffstats
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js53
1 files changed, 34 insertions, 19 deletions
diff --git a/src/index.js b/src/index.js
index ae75865c6..7f1f77b4e 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,6 +1,6 @@
1/* eslint-disable import/first */ 1/* eslint-disable import/first */
2 2
3import { app, BrowserWindow, ipcMain, session } from 'electron'; 3import { app, BrowserWindow, ipcMain, session, dialog } from 'electron';
4 4
5import { emptyDirSync, ensureFileSync } from 'fs-extra'; 5import { emptyDirSync, ensureFileSync } from 'fs-extra';
6import { join } from 'path'; 6import { join } from 'path';
@@ -22,6 +22,7 @@ import {
22 userDataRecipesPath, 22 userDataRecipesPath,
23 userDataPath, 23 userDataPath,
24} from './environment'; 24} from './environment';
25import { ifUndefinedBoolean } from './jsUtils';
25 26
26import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; 27import { mainIpcHandler as basicAuthHandler } from './features/basicAuth';
27import ipcApi from './electron/ipc-api'; 28import ipcApi from './electron/ipc-api';
@@ -77,13 +78,14 @@ if (isWindows) {
77const settings = new Settings('app', DEFAULT_APP_SETTINGS); 78const settings = new Settings('app', DEFAULT_APP_SETTINGS);
78const proxySettings = new Settings('proxy'); 79const proxySettings = new Settings('proxy');
79 80
80if (settings.get('sentry')) { 81const retrieveSettingValue = (key, defaultValue = true) => ifUndefinedBoolean(settings.get(key), defaultValue);
82
83if (retrieveSettingValue('sentry')) {
81 // eslint-disable-next-line global-require 84 // eslint-disable-next-line global-require
82 require('./sentry'); 85 require('./sentry');
83} 86}
84 87
85// add `liftSingleInstanceLock` to settings.json to override the single instance lock 88const liftSingleInstanceLock = retrieveSettingValue('liftSingleInstanceLock', false);
86const liftSingleInstanceLock = settings.get('liftSingleInstanceLock') || false;
87 89
88// Force single window 90// Force single window
89const gotTheLock = liftSingleInstanceLock 91const gotTheLock = liftSingleInstanceLock
@@ -147,7 +149,7 @@ if (
147} 149}
148 150
149// Disable GPU acceleration 151// Disable GPU acceleration
150if (!settings.get('enableGPUAcceleration')) { 152if (!retrieveSettingValue('enableGPUAcceleration', false)) {
151 debug('Disable GPU Acceleration'); 153 debug('Disable GPU Acceleration');
152 app.disableHardwareAcceleration(); 154 app.disableHardwareAcceleration();
153} 155}
@@ -176,7 +178,7 @@ const createWindow = () => {
176 } 178 }
177 179
178 // Create the browser window. 180 // Create the browser window.
179 const backgroundColor = settings.get('darkMode') 181 const backgroundColor = retrieveSettingValue('darkMode', false)
180 ? '#1E1E1E' 182 ? '#1E1E1E'
181 : settings.get('accentColor'); 183 : settings.get('accentColor');
182 184
@@ -190,7 +192,7 @@ const createWindow = () => {
190 show: false, 192 show: false,
191 titleBarStyle: isMac ? 'hidden' : '', 193 titleBarStyle: isMac ? 'hidden' : '',
192 frame: isLinux, 194 frame: isLinux,
193 spellcheck: settings.get('enableSpellchecking'), 195 spellcheck: retrieveSettingValue('enableSpellchecking'),
194 backgroundColor, 196 backgroundColor,
195 webPreferences: { 197 webPreferences: {
196 nodeIntegration: true, 198 nodeIntegration: true,
@@ -268,15 +270,14 @@ const createWindow = () => {
268 // when you should delete the corresponding element. 270 // when you should delete the corresponding element.
269 if ( 271 if (
270 !willQuitApp && 272 !willQuitApp &&
271 (settings.get('runInBackground') === undefined || 273 retrieveSettingValue('runInBackground')
272 settings.get('runInBackground'))
273 ) { 274 ) {
274 e.preventDefault(); 275 e.preventDefault();
275 if (isWindows) { 276 if (isWindows) {
276 debug('Window: minimize'); 277 debug('Window: minimize');
277 mainWindow.minimize(); 278 mainWindow.minimize();
278 279
279 if (settings.get('closeToSystemTray')) { 280 if (retrieveSettingValue('closeToSystemTray')) {
280 debug('Skip taskbar: true'); 281 debug('Skip taskbar: true');
281 mainWindow.setSkipTaskbar(true); 282 mainWindow.setSkipTaskbar(true);
282 } 283 }
@@ -300,7 +301,7 @@ const createWindow = () => {
300 mainWindow.on('minimize', () => { 301 mainWindow.on('minimize', () => {
301 app.wasMaximized = app.isMaximized; 302 app.wasMaximized = app.isMaximized;
302 303
303 if (settings.get('minimizeToSystemTray')) { 304 if (retrieveSettingValue('minimizeToSystemTray')) {
304 debug('Skip taskbar: true'); 305 debug('Skip taskbar: true');
305 mainWindow.setSkipTaskbar(true); 306 mainWindow.setSkipTaskbar(true);
306 trayIcon.show(); 307 trayIcon.show();
@@ -326,7 +327,7 @@ const createWindow = () => {
326 mainWindow.maximize(); 327 mainWindow.maximize();
327 } 328 }
328 329
329 if (!settings.get('enableSystemTray')) { 330 if (!retrieveSettingValue('enableSystemTray')) {
330 debug('Tray: hiding tray icon'); 331 debug('Tray: hiding tray icon');
331 trayIcon.hide(); 332 trayIcon.hide();
332 } 333 }
@@ -351,7 +352,7 @@ const createWindow = () => {
351 openExternalUrl(url); 352 openExternalUrl(url);
352 }); 353 });
353 354
354 if (settings.get('startMinimized')) { 355 if (retrieveSettingValue('startMinimized', false)) {
355 mainWindow.hide(); 356 mainWindow.hide();
356 } else { 357 } else {
357 mainWindow.show(); 358 mainWindow.show();
@@ -551,10 +552,7 @@ ipcMain.on('stop-find-in-page', (e, action) => {
551app.on('window-all-closed', () => { 552app.on('window-all-closed', () => {
552 // On OS X it is common for applications and their menu bar 553 // On OS X it is common for applications and their menu bar
553 // to stay active until the user quits explicitly with Cmd + Q 554 // to stay active until the user quits explicitly with Cmd + Q
554 if ( 555 if (retrieveSettingValue('runInBackground')) {
555 settings.get('runInBackground') === undefined ||
556 settings.get('runInBackground')
557 ) {
558 debug('Window: all windows closed, quit app'); 556 debug('Window: all windows closed, quit app');
559 app.quit(); 557 app.quit();
560 } else { 558 } else {
@@ -562,8 +560,25 @@ app.on('window-all-closed', () => {
562 } 560 }
563}); 561});
564 562
565app.on('before-quit', () => { 563app.on('before-quit', (event) => {
566 willQuitApp = true; 564 const yesButtonIndex = 0;
565 let selection = yesButtonIndex;
566 if (retrieveSettingValue('confirmOnQuit')) {
567 selection = dialog.showMessageBoxSync(app.mainWindow, {
568 type: 'question',
569 message: 'Quit',
570 detail: 'Do you really want to quit Ferdi?',
571 buttons: [
572 'Yes',
573 'No',
574 ],
575 });
576 }
577 if (selection === yesButtonIndex) {
578 willQuitApp = true;
579 } else {
580 event.preventDefault();
581 }
567}); 582});
568 583
569app.on('activate', () => { 584app.on('activate', () => {