aboutsummaryrefslogtreecommitdiffstats
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js72
1 files changed, 51 insertions, 21 deletions
diff --git a/src/index.js b/src/index.js
index ae75865c6..1f3510361 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';
@@ -10,6 +10,7 @@ import ms from 'ms';
10 10
11require('@electron/remote/main').initialize(); 11require('@electron/remote/main').initialize();
12 12
13import osName from 'os-name';
13import { DEFAULT_WINDOW_OPTIONS } from './config'; 14import { DEFAULT_WINDOW_OPTIONS } from './config';
14 15
15import { 16import {
@@ -18,10 +19,14 @@ import {
18 isMac, 19 isMac,
19 isWindows, 20 isWindows,
20 isLinux, 21 isLinux,
21 aboutAppDetails,
22 userDataRecipesPath, 22 userDataRecipesPath,
23 userDataPath, 23 userDataPath,
24 ferdiVersion,
25 electronVersion,
26 chromeVersion,
27 nodeVersion,
24} from './environment'; 28} from './environment';
29import { ifUndefinedBoolean } from './jsUtils';
25 30
26import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; 31import { mainIpcHandler as basicAuthHandler } from './features/basicAuth';
27import ipcApi from './electron/ipc-api'; 32import ipcApi from './electron/ipc-api';
@@ -36,6 +41,7 @@ import './electron/exception';
36import { asarPath } from './helpers/asar-helpers'; 41import { asarPath } from './helpers/asar-helpers';
37import { openExternalUrl } from './helpers/url-helpers'; 42import { openExternalUrl } from './helpers/url-helpers';
38import userAgent from './helpers/userAgent-helpers'; 43import userAgent from './helpers/userAgent-helpers';
44import * as buildInfo from './buildInfo.json'; // eslint-disable-line import/no-unresolved
39 45
40const debug = require('debug')('Ferdi:App'); 46const debug = require('debug')('Ferdi:App');
41 47
@@ -77,13 +83,14 @@ if (isWindows) {
77const settings = new Settings('app', DEFAULT_APP_SETTINGS); 83const settings = new Settings('app', DEFAULT_APP_SETTINGS);
78const proxySettings = new Settings('proxy'); 84const proxySettings = new Settings('proxy');
79 85
80if (settings.get('sentry')) { 86const retrieveSettingValue = (key, defaultValue = true) => ifUndefinedBoolean(settings.get(key), defaultValue);
87
88if (retrieveSettingValue('sentry')) {
81 // eslint-disable-next-line global-require 89 // eslint-disable-next-line global-require
82 require('./sentry'); 90 require('./sentry');
83} 91}
84 92
85// add `liftSingleInstanceLock` to settings.json to override the single instance lock 93const liftSingleInstanceLock = retrieveSettingValue('liftSingleInstanceLock', false);
86const liftSingleInstanceLock = settings.get('liftSingleInstanceLock') || false;
87 94
88// Force single window 95// Force single window
89const gotTheLock = liftSingleInstanceLock 96const gotTheLock = liftSingleInstanceLock
@@ -147,13 +154,23 @@ if (
147} 154}
148 155
149// Disable GPU acceleration 156// Disable GPU acceleration
150if (!settings.get('enableGPUAcceleration')) { 157if (!retrieveSettingValue('enableGPUAcceleration', false)) {
151 debug('Disable GPU Acceleration'); 158 debug('Disable GPU Acceleration');
152 app.disableHardwareAcceleration(); 159 app.disableHardwareAcceleration();
153} 160}
154 161
155app.setAboutPanelOptions({ 162app.setAboutPanelOptions({
156 applicationVersion: aboutAppDetails(), 163 applicationVersion: [
164 `Version: ${ferdiVersion}`,
165 `Electron: ${electronVersion}`,
166 `Chrome: ${chromeVersion}`,
167 `Node.js: ${nodeVersion}`,
168 `Platform: ${osName()}`,
169 `Arch: ${process.arch}`,
170 `Build date: ${new Date(Number(buildInfo.timestamp))}`,
171 `Git SHA: ${buildInfo.gitHashShort}`,
172 `Git branch: ${buildInfo.gitBranch}`,
173 ].join('\n'),
157 version: '', 174 version: '',
158}); 175});
159 176
@@ -176,7 +193,7 @@ const createWindow = () => {
176 } 193 }
177 194
178 // Create the browser window. 195 // Create the browser window.
179 const backgroundColor = settings.get('darkMode') 196 const backgroundColor = retrieveSettingValue('darkMode', false)
180 ? '#1E1E1E' 197 ? '#1E1E1E'
181 : settings.get('accentColor'); 198 : settings.get('accentColor');
182 199
@@ -190,7 +207,7 @@ const createWindow = () => {
190 show: false, 207 show: false,
191 titleBarStyle: isMac ? 'hidden' : '', 208 titleBarStyle: isMac ? 'hidden' : '',
192 frame: isLinux, 209 frame: isLinux,
193 spellcheck: settings.get('enableSpellchecking'), 210 spellcheck: retrieveSettingValue('enableSpellchecking'),
194 backgroundColor, 211 backgroundColor,
195 webPreferences: { 212 webPreferences: {
196 nodeIntegration: true, 213 nodeIntegration: true,
@@ -268,15 +285,14 @@ const createWindow = () => {
268 // when you should delete the corresponding element. 285 // when you should delete the corresponding element.
269 if ( 286 if (
270 !willQuitApp && 287 !willQuitApp &&
271 (settings.get('runInBackground') === undefined || 288 retrieveSettingValue('runInBackground')
272 settings.get('runInBackground'))
273 ) { 289 ) {
274 e.preventDefault(); 290 e.preventDefault();
275 if (isWindows) { 291 if (isWindows) {
276 debug('Window: minimize'); 292 debug('Window: minimize');
277 mainWindow.minimize(); 293 mainWindow.minimize();
278 294
279 if (settings.get('closeToSystemTray')) { 295 if (retrieveSettingValue('closeToSystemTray')) {
280 debug('Skip taskbar: true'); 296 debug('Skip taskbar: true');
281 mainWindow.setSkipTaskbar(true); 297 mainWindow.setSkipTaskbar(true);
282 } 298 }
@@ -300,7 +316,7 @@ const createWindow = () => {
300 mainWindow.on('minimize', () => { 316 mainWindow.on('minimize', () => {
301 app.wasMaximized = app.isMaximized; 317 app.wasMaximized = app.isMaximized;
302 318
303 if (settings.get('minimizeToSystemTray')) { 319 if (retrieveSettingValue('minimizeToSystemTray')) {
304 debug('Skip taskbar: true'); 320 debug('Skip taskbar: true');
305 mainWindow.setSkipTaskbar(true); 321 mainWindow.setSkipTaskbar(true);
306 trayIcon.show(); 322 trayIcon.show();
@@ -326,7 +342,7 @@ const createWindow = () => {
326 mainWindow.maximize(); 342 mainWindow.maximize();
327 } 343 }
328 344
329 if (!settings.get('enableSystemTray')) { 345 if (!retrieveSettingValue('enableSystemTray')) {
330 debug('Tray: hiding tray icon'); 346 debug('Tray: hiding tray icon');
331 trayIcon.hide(); 347 trayIcon.hide();
332 } 348 }
@@ -351,7 +367,7 @@ const createWindow = () => {
351 openExternalUrl(url); 367 openExternalUrl(url);
352 }); 368 });
353 369
354 if (settings.get('startMinimized')) { 370 if (retrieveSettingValue('startMinimized', false)) {
355 mainWindow.hide(); 371 mainWindow.hide();
356 } else { 372 } else {
357 mainWindow.show(); 373 mainWindow.show();
@@ -551,10 +567,7 @@ ipcMain.on('stop-find-in-page', (e, action) => {
551app.on('window-all-closed', () => { 567app.on('window-all-closed', () => {
552 // On OS X it is common for applications and their menu bar 568 // On OS X it is common for applications and their menu bar
553 // to stay active until the user quits explicitly with Cmd + Q 569 // to stay active until the user quits explicitly with Cmd + Q
554 if ( 570 if (retrieveSettingValue('runInBackground')) {
555 settings.get('runInBackground') === undefined ||
556 settings.get('runInBackground')
557 ) {
558 debug('Window: all windows closed, quit app'); 571 debug('Window: all windows closed, quit app');
559 app.quit(); 572 app.quit();
560 } else { 573 } else {
@@ -562,8 +575,25 @@ app.on('window-all-closed', () => {
562 } 575 }
563}); 576});
564 577
565app.on('before-quit', () => { 578app.on('before-quit', (event) => {
566 willQuitApp = true; 579 const yesButtonIndex = 0;
580 let selection = yesButtonIndex;
581 if (retrieveSettingValue('confirmOnQuit')) {
582 selection = dialog.showMessageBoxSync(app.mainWindow, {
583 type: 'question',
584 message: 'Quit',
585 detail: 'Do you really want to quit Ferdi?',
586 buttons: [
587 'Yes',
588 'No',
589 ],
590 });
591 }
592 if (selection === yesButtonIndex) {
593 willQuitApp = true;
594 } else {
595 event.preventDefault();
596 }
567}); 597});
568 598
569app.on('activate', () => { 599app.on('activate', () => {