diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 10:34:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 10:34:04 +0200 |
commit | 979ec02c9a1019152be08705986337e470eabb57 (patch) | |
tree | 6021179ad8649112717a499780f475275af487f2 /src/index.js | |
parent | refactor: defensive programming to avoid javascript error for unread badges (diff) | |
download | ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.gz ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.zst ferdium-app-979ec02c9a1019152be08705986337e470eabb57.zip |
chore: codebase improvements (#1930)
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/index.js b/src/index.js index 7f1f77b4e..08d9a3a45 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -78,14 +78,18 @@ if (isWindows) { | |||
78 | const settings = new Settings('app', DEFAULT_APP_SETTINGS); | 78 | const settings = new Settings('app', DEFAULT_APP_SETTINGS); |
79 | const proxySettings = new Settings('proxy'); | 79 | const proxySettings = new Settings('proxy'); |
80 | 80 | ||
81 | const retrieveSettingValue = (key, defaultValue = true) => ifUndefinedBoolean(settings.get(key), defaultValue); | 81 | const retrieveSettingValue = (key, defaultValue = true) => |
82 | ifUndefinedBoolean(settings.get(key), defaultValue); | ||
82 | 83 | ||
83 | if (retrieveSettingValue('sentry')) { | 84 | if (retrieveSettingValue('sentry')) { |
84 | // eslint-disable-next-line global-require | 85 | // eslint-disable-next-line global-require |
85 | require('./sentry'); | 86 | require('./sentry'); |
86 | } | 87 | } |
87 | 88 | ||
88 | const liftSingleInstanceLock = retrieveSettingValue('liftSingleInstanceLock', false); | 89 | const liftSingleInstanceLock = retrieveSettingValue( |
90 | 'liftSingleInstanceLock', | ||
91 | false, | ||
92 | ); | ||
89 | 93 | ||
90 | // Force single window | 94 | // Force single window |
91 | const gotTheLock = liftSingleInstanceLock | 95 | const gotTheLock = liftSingleInstanceLock |
@@ -190,11 +194,11 @@ const createWindow = () => { | |||
190 | minWidth: 600, | 194 | minWidth: 600, |
191 | minHeight: 500, | 195 | minHeight: 500, |
192 | show: false, | 196 | show: false, |
193 | titleBarStyle: isMac ? 'hidden' : '', | 197 | titleBarStyle: isMac ? 'hidden' : 'default', |
194 | frame: isLinux, | 198 | frame: isLinux, |
195 | spellcheck: retrieveSettingValue('enableSpellchecking'), | ||
196 | backgroundColor, | 199 | backgroundColor, |
197 | webPreferences: { | 200 | webPreferences: { |
201 | spellcheck: retrieveSettingValue('enableSpellchecking'), | ||
198 | nodeIntegration: true, | 202 | nodeIntegration: true, |
199 | contextIsolation: false, | 203 | contextIsolation: false, |
200 | webviewTag: true, | 204 | webviewTag: true, |
@@ -268,10 +272,7 @@ const createWindow = () => { | |||
268 | // Dereference the window object, usually you would store windows | 272 | // Dereference the window object, usually you would store windows |
269 | // in an array if your app supports multi windows, this is the time | 273 | // in an array if your app supports multi windows, this is the time |
270 | // when you should delete the corresponding element. | 274 | // when you should delete the corresponding element. |
271 | if ( | 275 | if (!willQuitApp && retrieveSettingValue('runInBackground')) { |
272 | !willQuitApp && | ||
273 | retrieveSettingValue('runInBackground') | ||
274 | ) { | ||
275 | e.preventDefault(); | 276 | e.preventDefault(); |
276 | if (isWindows) { | 277 | if (isWindows) { |
277 | debug('Window: minimize'); | 278 | debug('Window: minimize'); |
@@ -471,7 +472,9 @@ ipcMain.on('open-browser-window', (e, { url, serviceId }) => { | |||
471 | ipcMain.on( | 472 | ipcMain.on( |
472 | 'modifyRequestHeaders', | 473 | 'modifyRequestHeaders', |
473 | (e, { modifiedRequestHeaders, serviceId }) => { | 474 | (e, { modifiedRequestHeaders, serviceId }) => { |
474 | debug(`Received modifyRequestHeaders ${modifiedRequestHeaders} for serviceId ${serviceId}`); | 475 | debug( |
476 | `Received modifyRequestHeaders ${modifiedRequestHeaders} for serviceId ${serviceId}`, | ||
477 | ); | ||
475 | modifiedRequestHeaders.forEach(headerFilterSet => { | 478 | modifiedRequestHeaders.forEach(headerFilterSet => { |
476 | const { headers, requestFilters } = headerFilterSet; | 479 | const { headers, requestFilters } = headerFilterSet; |
477 | session | 480 | session |
@@ -489,23 +492,22 @@ ipcMain.on( | |||
489 | }, | 492 | }, |
490 | ); | 493 | ); |
491 | 494 | ||
492 | ipcMain.on( | 495 | ipcMain.on('knownCertificateHosts', (e, { knownHosts, serviceId }) => { |
493 | 'knownCertificateHosts', | 496 | debug( |
494 | (e, { knownHosts, serviceId }) => { | 497 | `Received knownCertificateHosts ${knownHosts} for serviceId ${serviceId}`, |
495 | debug(`Received knownCertificateHosts ${knownHosts} for serviceId ${serviceId}`); | 498 | ); |
496 | session | 499 | session |
497 | .fromPartition(`persist:service-${serviceId}`) | 500 | .fromPartition(`persist:service-${serviceId}`) |
498 | .setCertificateVerifyProc((request, callback) => { | 501 | .setCertificateVerifyProc((request, callback) => { |
499 | // To know more about these callbacks: https://www.electronjs.org/docs/api/session#sessetcertificateverifyprocproc | 502 | // To know more about these callbacks: https://www.electronjs.org/docs/api/session#sessetcertificateverifyprocproc |
500 | const { hostname } = request; | 503 | const { hostname } = request; |
501 | if (knownHosts.find(item => item.includes(hostname)).length > 0) { | 504 | if (knownHosts.find(item => item.includes(hostname)).length > 0) { |
502 | callback(0); | 505 | callback(0); |
503 | } else { | 506 | } else { |
504 | callback(-2); | 507 | callback(-2); |
505 | } | 508 | } |
506 | }); | 509 | }); |
507 | }, | 510 | }); |
508 | ); | ||
509 | 511 | ||
510 | ipcMain.on('feature-basic-auth-cancel', () => { | 512 | ipcMain.on('feature-basic-auth-cancel', () => { |
511 | debug('Cancel basic auth'); | 513 | debug('Cancel basic auth'); |
@@ -560,7 +562,7 @@ app.on('window-all-closed', () => { | |||
560 | } | 562 | } |
561 | }); | 563 | }); |
562 | 564 | ||
563 | app.on('before-quit', (event) => { | 565 | app.on('before-quit', event => { |
564 | const yesButtonIndex = 0; | 566 | const yesButtonIndex = 0; |
565 | let selection = yesButtonIndex; | 567 | let selection = yesButtonIndex; |
566 | if (retrieveSettingValue('confirmOnQuit')) { | 568 | if (retrieveSettingValue('confirmOnQuit')) { |
@@ -568,10 +570,7 @@ app.on('before-quit', (event) => { | |||
568 | type: 'question', | 570 | type: 'question', |
569 | message: 'Quit', | 571 | message: 'Quit', |
570 | detail: 'Do you really want to quit Ferdi?', | 572 | detail: 'Do you really want to quit Ferdi?', |
571 | buttons: [ | 573 | buttons: ['Yes', 'No'], |
572 | 'Yes', | ||
573 | 'No', | ||
574 | ], | ||
575 | }); | 574 | }); |
576 | } | 575 | } |
577 | if (selection === yesButtonIndex) { | 576 | if (selection === yesButtonIndex) { |