diff options
author | 2021-10-10 10:42:20 +0200 | |
---|---|---|
committer | 2021-10-10 10:42:20 +0200 | |
commit | a673c2b577a31437c91a0b498e69b0753d62aa58 (patch) | |
tree | 50d52df3ff9d78828ca06a24ef438e31b062ca56 /src | |
parent | remove unused 'conventional-changelog' npm package. Change the url for the ch... (diff) | |
download | ferdium-app-a673c2b577a31437c91a0b498e69b0753d62aa58.tar.gz ferdium-app-a673c2b577a31437c91a0b498e69b0753d62aa58.tar.zst ferdium-app-a673c2b577a31437c91a0b498e69b0753d62aa58.zip |
chore: convert index file to TS (#2049)
Diffstat (limited to 'src')
-rw-r--r-- | src/electron/ipc-api/appIndicator.ts | 34 | ||||
-rw-r--r-- | src/electron/ipc-api/index.ts | 2 | ||||
-rw-r--r-- | src/index.ts (renamed from src/index.js) | 176 |
3 files changed, 141 insertions, 71 deletions
diff --git a/src/electron/ipc-api/appIndicator.ts b/src/electron/ipc-api/appIndicator.ts index a51ed8161..bd5f6a68f 100644 --- a/src/electron/ipc-api/appIndicator.ts +++ b/src/electron/ipc-api/appIndicator.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { app, ipcMain } from 'electron'; | 1 | import { app, ipcMain, BrowserWindow, Tray } from 'electron'; |
2 | import { join } from 'path'; | 2 | import { join } from 'path'; |
3 | import { autorun } from 'mobx'; | 3 | import { autorun } from 'mobx'; |
4 | import { isMac, isWindows, isLinux } from '../../environment'; | 4 | import { isMac, isWindows, isLinux } from '../../environment'; |
@@ -21,29 +21,38 @@ function getAsset(type: 'tray' | 'taskbar', asset: string) { | |||
21 | ); | 21 | ); |
22 | } | 22 | } |
23 | 23 | ||
24 | export default params => { | 24 | export default (params: { |
25 | mainWindow: BrowserWindow; | ||
26 | settings: any; | ||
27 | trayIcon: Tray; | ||
28 | }) => { | ||
25 | autorun(() => { | 29 | autorun(() => { |
26 | isTrayIconEnabled = params.settings.app.get('enableSystemTray'); | 30 | isTrayIconEnabled = params.settings.app.get('enableSystemTray'); |
27 | 31 | ||
28 | if (!isTrayIconEnabled) { | 32 | if (!isTrayIconEnabled) { |
33 | // @ts-expect-error Property 'hide' does not exist on type 'Tray'. | ||
29 | params.trayIcon.hide(); | 34 | params.trayIcon.hide(); |
30 | } else if (isTrayIconEnabled) { | 35 | } else if (isTrayIconEnabled) { |
36 | // @ts-expect-error Property 'show' does not exist on type 'Tray'. | ||
31 | params.trayIcon.show(); | 37 | params.trayIcon.show(); |
32 | } | 38 | } |
33 | }); | 39 | }); |
34 | 40 | ||
35 | ipcMain.on('updateAppIndicator', (_event, args) => { | 41 | ipcMain.on('updateAppIndicator', (_event, args) => { |
36 | // Flash TaskBar for windows, bounce Dock on Mac | 42 | // Flash TaskBar for windows, bounce Dock on Mac |
37 | if (!(app as any).mainWindow.isFocused() && params.settings.app.get('notifyTaskBarOnMessage')) { | 43 | if ( |
38 | if (isWindows) { | 44 | !params.mainWindow.isFocused() && |
39 | (app as any).mainWindow.flashFrame(true); | 45 | params.settings.app.get('notifyTaskBarOnMessage') |
40 | (app as any).mainWindow.once('focus', () => | 46 | ) { |
41 | (app as any).mainWindow.flashFrame(false), | 47 | if (isWindows) { |
42 | ); | 48 | params.mainWindow.flashFrame(true); |
43 | } else if (isMac) { | 49 | params.mainWindow.once('focus', () => |
44 | app.dock.bounce('informational'); | 50 | params.mainWindow.flashFrame(false), |
45 | } | 51 | ); |
52 | } else if (isMac) { | ||
53 | app.dock.bounce('informational'); | ||
46 | } | 54 | } |
55 | } | ||
47 | 56 | ||
48 | // Update badge | 57 | // Update badge |
49 | if (isMac && typeof args.indicator === 'string') { | 58 | if (isMac && typeof args.indicator === 'string') { |
@@ -57,6 +66,7 @@ export default params => { | |||
57 | if (isWindows) { | 66 | if (isWindows) { |
58 | if (typeof args.indicator === 'number' && args.indicator !== 0) { | 67 | if (typeof args.indicator === 'number' && args.indicator !== 0) { |
59 | params.mainWindow.setOverlayIcon( | 68 | params.mainWindow.setOverlayIcon( |
69 | // @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'NativeImage | null'. | ||
60 | getAsset( | 70 | getAsset( |
61 | 'taskbar', | 71 | 'taskbar', |
62 | `${INDICATOR_TASKBAR}-${ | 72 | `${INDICATOR_TASKBAR}-${ |
@@ -67,6 +77,7 @@ export default params => { | |||
67 | ); | 77 | ); |
68 | } else if (typeof args.indicator === 'string') { | 78 | } else if (typeof args.indicator === 'string') { |
69 | params.mainWindow.setOverlayIcon( | 79 | params.mainWindow.setOverlayIcon( |
80 | // @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'NativeImage | null'. | ||
70 | getAsset('taskbar', `${INDICATOR_TASKBAR}-alert`), | 81 | getAsset('taskbar', `${INDICATOR_TASKBAR}-alert`), |
71 | '', | 82 | '', |
72 | ); | 83 | ); |
@@ -76,6 +87,7 @@ export default params => { | |||
76 | } | 87 | } |
77 | 88 | ||
78 | // Update Tray | 89 | // Update Tray |
90 | // @ts-expect-error Property 'setIndicator' does not exist on type 'Tray'. | ||
79 | params.trayIcon.setIndicator(args.indicator); | 91 | params.trayIcon.setIndicator(args.indicator); |
80 | }); | 92 | }); |
81 | }; | 93 | }; |
diff --git a/src/electron/ipc-api/index.ts b/src/electron/ipc-api/index.ts index f03f61517..1f69c04ee 100644 --- a/src/electron/ipc-api/index.ts +++ b/src/electron/ipc-api/index.ts | |||
@@ -12,7 +12,7 @@ import focusState from './focusState'; | |||
12 | export default (params: { | 12 | export default (params: { |
13 | mainWindow: BrowserWindow; | 13 | mainWindow: BrowserWindow; |
14 | settings: any; | 14 | settings: any; |
15 | tray: Tray; | 15 | trayIcon: Tray; |
16 | }) => { | 16 | }) => { |
17 | settings(params); | 17 | settings(params); |
18 | sessionStorage(); | 18 | sessionStorage(); |
diff --git a/src/index.js b/src/index.ts index 933637688..7beaa86f6 100644 --- a/src/index.js +++ b/src/index.ts | |||
@@ -1,6 +1,13 @@ | |||
1 | /* eslint-disable import/first */ | 1 | /* eslint-disable import/first */ |
2 | 2 | ||
3 | import { app, BrowserWindow, globalShortcut, ipcMain, session, dialog } from 'electron'; | 3 | import { |
4 | app, | ||
5 | BrowserWindow, | ||
6 | globalShortcut, | ||
7 | ipcMain, | ||
8 | session, | ||
9 | dialog, | ||
10 | } from 'electron'; | ||
4 | 11 | ||
5 | import { emptyDirSync, ensureFileSync } from 'fs-extra'; | 12 | import { emptyDirSync, ensureFileSync } from 'fs-extra'; |
6 | import { join } from 'path'; | 13 | import { join } from 'path'; |
@@ -13,12 +20,7 @@ initializeRemote(); | |||
13 | 20 | ||
14 | import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS } from './config'; | 21 | import { DEFAULT_APP_SETTINGS, DEFAULT_WINDOW_OPTIONS } from './config'; |
15 | 22 | ||
16 | import { | 23 | import { isMac, isWindows, isLinux, altKey } from './environment'; |
17 | isMac, | ||
18 | isWindows, | ||
19 | isLinux, | ||
20 | altKey, | ||
21 | } from './environment'; | ||
22 | import { | 24 | import { |
23 | isDevMode, | 25 | isDevMode, |
24 | aboutAppDetails, | 26 | aboutAppDetails, |
@@ -34,7 +36,8 @@ import DBus from './lib/DBus'; | |||
34 | import Settings from './electron/Settings'; | 36 | import Settings from './electron/Settings'; |
35 | import handleDeepLink from './electron/deepLinking'; | 37 | import handleDeepLink from './electron/deepLinking'; |
36 | import { isPositionValid } from './electron/windowUtils'; | 38 | import { isPositionValid } from './electron/windowUtils'; |
37 | import { appId } from './package.json'; // eslint-disable-line import/no-unresolved | 39 | // @ts-expect-error Cannot find module './package.json' or its corresponding type declarations. |
40 | import { appId } from './package.json'; | ||
38 | import './electron/exception'; | 41 | import './electron/exception'; |
39 | 42 | ||
40 | import { asarPath } from './helpers/asar-helpers'; | 43 | import { asarPath } from './helpers/asar-helpers'; |
@@ -49,13 +52,18 @@ app.userAgentFallback = userAgent(); | |||
49 | 52 | ||
50 | // Keep a global reference of the window object, if you don't, the window will | 53 | // Keep a global reference of the window object, if you don't, the window will |
51 | // be closed automatically when the JavaScript object is garbage collected. | 54 | // be closed automatically when the JavaScript object is garbage collected. |
52 | let mainWindow; | 55 | let mainWindow: BrowserWindow | undefined; |
53 | let willQuitApp = false; | 56 | let willQuitApp = false; |
54 | 57 | ||
55 | // Register methods to be called once the window has been loaded. | 58 | // Register methods to be called once the window has been loaded. |
56 | let onDidLoadFns = []; | 59 | let onDidLoadFns: any[] | null = []; |
57 | 60 | ||
58 | function onDidLoad(fn) { | 61 | function onDidLoad(fn: { |
62 | (window: BrowserWindow): void; | ||
63 | (window: BrowserWindow): void; | ||
64 | (window: BrowserWindow): void; | ||
65 | (arg0: BrowserWindow): void; | ||
66 | }) { | ||
59 | if (onDidLoadFns) { | 67 | if (onDidLoadFns) { |
60 | onDidLoadFns.push(fn); | 68 | onDidLoadFns.push(fn); |
61 | } else if (mainWindow) { | 69 | } else if (mainWindow) { |
@@ -76,7 +84,7 @@ if (isWindows) { | |||
76 | const settings = new Settings('app', DEFAULT_APP_SETTINGS); | 84 | const settings = new Settings('app', DEFAULT_APP_SETTINGS); |
77 | const proxySettings = new Settings('proxy'); | 85 | const proxySettings = new Settings('proxy'); |
78 | 86 | ||
79 | const retrieveSettingValue = (key, defaultValue) => | 87 | const retrieveSettingValue = (key: string, defaultValue: boolean) => |
80 | ifUndefinedBoolean(settings.get(key), defaultValue); | 88 | ifUndefinedBoolean(settings.get(key), defaultValue); |
81 | 89 | ||
82 | if (retrieveSettingValue('sentry', DEFAULT_APP_SETTINGS.sentry)) { | 90 | if (retrieveSettingValue('sentry', DEFAULT_APP_SETTINGS.sentry)) { |
@@ -96,7 +104,7 @@ const gotTheLock = liftSingleInstanceLock | |||
96 | if (!gotTheLock) { | 104 | if (!gotTheLock) { |
97 | app.quit(); | 105 | app.quit(); |
98 | } else { | 106 | } else { |
99 | app.on('second-instance', (event, argv) => { | 107 | app.on('second-instance', (_event, argv) => { |
100 | // Someone tried to run a second instance, we should focus our window. | 108 | // Someone tried to run a second instance, we should focus our window. |
101 | if (mainWindow) { | 109 | if (mainWindow) { |
102 | if (!mainWindow.isVisible()) { | 110 | if (!mainWindow.isVisible()) { |
@@ -108,7 +116,7 @@ if (!gotTheLock) { | |||
108 | mainWindow.focus(); | 116 | mainWindow.focus(); |
109 | 117 | ||
110 | if (isWindows) { | 118 | if (isWindows) { |
111 | onDidLoad(window => { | 119 | onDidLoad((window: BrowserWindow) => { |
112 | // Keep only command line / deep linked arguments | 120 | // Keep only command line / deep linked arguments |
113 | const url = argv.slice(1); | 121 | const url = argv.slice(1); |
114 | if (url) { | 122 | if (url) { |
@@ -145,6 +153,7 @@ if (!gotTheLock) { | |||
145 | // https://github.com/electron/electron/issues/9046 | 153 | // https://github.com/electron/electron/issues/9046 |
146 | if ( | 154 | if ( |
147 | isLinux && | 155 | isLinux && |
156 | process.env.XDG_CURRENT_DESKTOP && | ||
148 | ['Pantheon', 'Unity:Unity7'].includes(process.env.XDG_CURRENT_DESKTOP) | 157 | ['Pantheon', 'Unity:Unity7'].includes(process.env.XDG_CURRENT_DESKTOP) |
149 | ) { | 158 | ) { |
150 | process.env.XDG_CURRENT_DESKTOP = 'Unity'; | 159 | process.env.XDG_CURRENT_DESKTOP = 'Unity'; |
@@ -196,16 +205,20 @@ const createWindow = () => { | |||
196 | frame: isLinux, | 205 | frame: isLinux, |
197 | backgroundColor, | 206 | backgroundColor, |
198 | webPreferences: { | 207 | webPreferences: { |
199 | spellcheck: retrieveSettingValue('enableSpellchecking', DEFAULT_APP_SETTINGS.enableSpellchecking), | 208 | spellcheck: retrieveSettingValue( |
209 | 'enableSpellchecking', | ||
210 | DEFAULT_APP_SETTINGS.enableSpellchecking, | ||
211 | ), | ||
200 | nodeIntegration: true, | 212 | nodeIntegration: true, |
201 | contextIsolation: false, | 213 | contextIsolation: false, |
202 | webviewTag: true, | 214 | webviewTag: true, |
203 | preload: join(__dirname, 'sentry.js'), | 215 | preload: join(__dirname, 'sentry.js'), |
216 | // @ts-expect-error Object literal may only specify known properties, and 'enableRemoteModule' does not exist in type 'WebPreferences'. | ||
204 | enableRemoteModule: true, | 217 | enableRemoteModule: true, |
205 | }, | 218 | }, |
206 | }); | 219 | }); |
207 | 220 | ||
208 | app.on('web-contents-created', (e, contents) => { | 221 | app.on('web-contents-created', (_e, contents) => { |
209 | if (contents.getType() === 'webview') { | 222 | if (contents.getType() === 'webview') { |
210 | contents.on('new-window', event => { | 223 | contents.on('new-window', event => { |
211 | event.preventDefault(); | 224 | event.preventDefault(); |
@@ -225,7 +238,7 @@ const createWindow = () => { | |||
225 | }); | 238 | }); |
226 | 239 | ||
227 | // Initialize System Tray | 240 | // Initialize System Tray |
228 | const trayIcon = new Tray(); | 241 | const trayIcon: Tray = new Tray(); |
229 | 242 | ||
230 | // Initialize DBus interface | 243 | // Initialize DBus interface |
231 | const dbus = new DBus(trayIcon); | 244 | const dbus = new DBus(trayIcon); |
@@ -256,7 +269,7 @@ const createWindow = () => { | |||
256 | 269 | ||
257 | // Windows deep linking handling on app launch | 270 | // Windows deep linking handling on app launch |
258 | if (isWindows) { | 271 | if (isWindows) { |
259 | onDidLoad(window => { | 272 | onDidLoad((window: BrowserWindow) => { |
260 | const url = process.argv.slice(1); | 273 | const url = process.argv.slice(1); |
261 | if (url) { | 274 | if (url) { |
262 | handleDeepLink(window, url.toString()); | 275 | handleDeepLink(window, url.toString()); |
@@ -270,24 +283,35 @@ const createWindow = () => { | |||
270 | // Dereference the window object, usually you would store windows | 283 | // Dereference the window object, usually you would store windows |
271 | // in an array if your app supports multi windows, this is the time | 284 | // in an array if your app supports multi windows, this is the time |
272 | // when you should delete the corresponding element. | 285 | // when you should delete the corresponding element. |
273 | if (!willQuitApp && retrieveSettingValue('runInBackground', DEFAULT_APP_SETTINGS.runInBackground)) { | 286 | if ( |
287 | !willQuitApp && | ||
288 | retrieveSettingValue( | ||
289 | 'runInBackground', | ||
290 | DEFAULT_APP_SETTINGS.runInBackground, | ||
291 | ) | ||
292 | ) { | ||
274 | e.preventDefault(); | 293 | e.preventDefault(); |
275 | if (isWindows) { | 294 | if (isWindows) { |
276 | debug('Window: minimize'); | 295 | debug('Window: minimize'); |
277 | mainWindow.minimize(); | 296 | mainWindow?.minimize(); |
278 | 297 | ||
279 | if (retrieveSettingValue('closeToSystemTray', DEFAULT_APP_SETTINGS.closeToSystemTray)) { | 298 | if ( |
299 | retrieveSettingValue( | ||
300 | 'closeToSystemTray', | ||
301 | DEFAULT_APP_SETTINGS.closeToSystemTray, | ||
302 | ) | ||
303 | ) { | ||
280 | debug('Skip taskbar: true'); | 304 | debug('Skip taskbar: true'); |
281 | mainWindow.setSkipTaskbar(true); | 305 | mainWindow?.setSkipTaskbar(true); |
282 | } | 306 | } |
283 | } else if (isMac && mainWindow.isFullScreen()) { | 307 | } else if (isMac && mainWindow?.isFullScreen()) { |
284 | debug('Window: leaveFullScreen and hide'); | 308 | debug('Window: leaveFullScreen and hide'); |
285 | mainWindow.once('show', () => mainWindow.setFullScreen(true)); | 309 | mainWindow.once('show', () => mainWindow?.setFullScreen(true)); |
286 | mainWindow.once('leave-full-screen', () => mainWindow.hide()); | 310 | mainWindow.once('leave-full-screen', () => mainWindow?.hide()); |
287 | mainWindow.setFullScreen(false); | 311 | mainWindow.setFullScreen(false); |
288 | } else { | 312 | } else { |
289 | debug('Window: hide'); | 313 | debug('Window: hide'); |
290 | mainWindow.hide(); | 314 | mainWindow?.hide(); |
291 | } | 315 | } |
292 | } else { | 316 | } else { |
293 | dbus.stop(); | 317 | dbus.stop(); |
@@ -298,35 +322,49 @@ const createWindow = () => { | |||
298 | // For Windows we need to store a flag to properly restore the window | 322 | // For Windows we need to store a flag to properly restore the window |
299 | // if the window was maximized before minimizing it so system tray | 323 | // if the window was maximized before minimizing it so system tray |
300 | mainWindow.on('minimize', () => { | 324 | mainWindow.on('minimize', () => { |
325 | // @ts-expect-error Property 'wasMaximized' does not exist on type 'App'. | ||
301 | app.wasMaximized = app.isMaximized; | 326 | app.wasMaximized = app.isMaximized; |
302 | 327 | ||
303 | if (retrieveSettingValue('minimizeToSystemTray', DEFAULT_APP_SETTINGS.minimizeToSystemTray)) { | 328 | if ( |
329 | retrieveSettingValue( | ||
330 | 'minimizeToSystemTray', | ||
331 | DEFAULT_APP_SETTINGS.minimizeToSystemTray, | ||
332 | ) | ||
333 | ) { | ||
304 | debug('Skip taskbar: true'); | 334 | debug('Skip taskbar: true'); |
305 | mainWindow.setSkipTaskbar(true); | 335 | mainWindow?.setSkipTaskbar(true); |
306 | trayIcon.show(); | 336 | trayIcon.show(); |
307 | } | 337 | } |
308 | }); | 338 | }); |
309 | 339 | ||
310 | mainWindow.on('maximize', () => { | 340 | mainWindow.on('maximize', () => { |
311 | debug('Window: maximize'); | 341 | debug('Window: maximize'); |
342 | // @ts-expect-error Property 'isMaximized' does not exist on type 'App'. | ||
312 | app.isMaximized = true; | 343 | app.isMaximized = true; |
313 | }); | 344 | }); |
314 | 345 | ||
315 | mainWindow.on('unmaximize', () => { | 346 | mainWindow.on('unmaximize', () => { |
316 | debug('Window: unmaximize'); | 347 | debug('Window: unmaximize'); |
348 | // @ts-expect-error Property 'isMaximized' does not exist on type 'App'. | ||
317 | app.isMaximized = false; | 349 | app.isMaximized = false; |
318 | }); | 350 | }); |
319 | 351 | ||
320 | mainWindow.on('restore', () => { | 352 | mainWindow.on('restore', () => { |
321 | debug('Window: restore'); | 353 | debug('Window: restore'); |
322 | mainWindow.setSkipTaskbar(false); | 354 | mainWindow?.setSkipTaskbar(false); |
323 | 355 | ||
356 | // @ts-expect-error Property 'wasMaximized' does not exist on type 'App'. | ||
324 | if (app.wasMaximized) { | 357 | if (app.wasMaximized) { |
325 | debug('Window: was maximized before, maximize window'); | 358 | debug('Window: was maximized before, maximize window'); |
326 | mainWindow.maximize(); | 359 | mainWindow?.maximize(); |
327 | } | 360 | } |
328 | 361 | ||
329 | if (!retrieveSettingValue('enableSystemTray', DEFAULT_APP_SETTINGS.enableSystemTray)) { | 362 | if ( |
363 | !retrieveSettingValue( | ||
364 | 'enableSystemTray', | ||
365 | DEFAULT_APP_SETTINGS.enableSystemTray, | ||
366 | ) | ||
367 | ) { | ||
330 | debug('Tray: hiding tray icon'); | 368 | debug('Tray: hiding tray icon'); |
331 | trayIcon.hide(); | 369 | trayIcon.hide(); |
332 | } | 370 | } |
@@ -340,10 +378,10 @@ const createWindow = () => { | |||
340 | 378 | ||
341 | mainWindow.on('show', () => { | 379 | mainWindow.on('show', () => { |
342 | debug('Skip taskbar: true'); | 380 | debug('Skip taskbar: true'); |
343 | mainWindow.setSkipTaskbar(false); | 381 | mainWindow?.setSkipTaskbar(false); |
344 | }); | 382 | }); |
345 | 383 | ||
346 | app.mainWindow = mainWindow; | 384 | // @ts-expect-error Property 'isMaximized' does not exist on type 'App'. |
347 | app.isMaximized = mainWindow.isMaximized(); | 385 | app.isMaximized = mainWindow.isMaximized(); |
348 | 386 | ||
349 | mainWindow.webContents.on('new-window', (e, url) => { | 387 | mainWindow.webContents.on('new-window', (e, url) => { |
@@ -351,14 +389,21 @@ const createWindow = () => { | |||
351 | openExternalUrl(url); | 389 | openExternalUrl(url); |
352 | }); | 390 | }); |
353 | 391 | ||
354 | if (retrieveSettingValue('startMinimized', DEFAULT_APP_SETTINGS.startMinimized)) { | 392 | if ( |
393 | retrieveSettingValue('startMinimized', DEFAULT_APP_SETTINGS.startMinimized) | ||
394 | ) { | ||
355 | mainWindow.hide(); | 395 | mainWindow.hide(); |
356 | } else { | 396 | } else { |
357 | mainWindow.show(); | 397 | mainWindow.show(); |
358 | } | 398 | } |
359 | 399 | ||
360 | app.whenReady().then(() => { | 400 | app.whenReady().then(() => { |
361 | if (retrieveSettingValue('enableGlobalHideShortcut', DEFAULT_APP_SETTINGS.enableGlobalHideShortcut)) { | 401 | if ( |
402 | retrieveSettingValue( | ||
403 | 'enableGlobalHideShortcut', | ||
404 | DEFAULT_APP_SETTINGS.enableGlobalHideShortcut, | ||
405 | ) | ||
406 | ) { | ||
362 | // Toggle the window on 'Alt+X' | 407 | // Toggle the window on 'Alt+X' |
363 | globalShortcut.register(`${altKey()}+X`, () => { | 408 | globalShortcut.register(`${altKey()}+X`, () => { |
364 | trayIcon.trayMenuTemplate[0].click(); | 409 | trayIcon.trayMenuTemplate[0].click(); |
@@ -410,11 +455,11 @@ app.on('ready', () => { | |||
410 | if (isWindows) { | 455 | if (isWindows) { |
411 | const extraArgs = isDevMode ? `${__dirname} ` : ''; | 456 | const extraArgs = isDevMode ? `${__dirname} ` : ''; |
412 | const iconPath = asarPath( | 457 | const iconPath = asarPath( |
413 | join( | 458 | join( |
414 | isDevMode ? `${__dirname}../src/` : __dirname, | 459 | isDevMode ? `${__dirname}../src/` : __dirname, |
415 | 'assets/images/taskbar/win32/display.ico', | 460 | 'assets/images/taskbar/win32/display.ico', |
416 | ), | 461 | ), |
417 | ); | 462 | ); |
418 | app.setUserTasks([ | 463 | app.setUserTasks([ |
419 | { | 464 | { |
420 | program: process.execPath, | 465 | program: process.execPath, |
@@ -430,7 +475,7 @@ app.on('ready', () => { | |||
430 | iconPath, | 475 | iconPath, |
431 | iconIndex: 0, | 476 | iconIndex: 0, |
432 | title: 'Quit Ferdi', | 477 | title: 'Quit Ferdi', |
433 | description: null, | 478 | description: '', |
434 | }, | 479 | }, |
435 | ]); | 480 | ]); |
436 | } | 481 | } |
@@ -446,7 +491,8 @@ app.on('ready', () => { | |||
446 | const noop = () => null; | 491 | const noop = () => null; |
447 | let authCallback = noop; | 492 | let authCallback = noop; |
448 | 493 | ||
449 | app.on('login', (event, webContents, request, authInfo, callback) => { | 494 | app.on('login', (event, _webContents, _request, authInfo, callback) => { |
495 | // @ts-expect-error Type '(username?: string | undefined, password?: string | undefined) => void' is not assignable to type '() => null'. | ||
450 | authCallback = callback; | 496 | authCallback = callback; |
451 | debug('browser login event', authInfo); | 497 | debug('browser login event', authInfo); |
452 | event.preventDefault(); | 498 | event.preventDefault(); |
@@ -458,14 +504,15 @@ app.on('login', (event, webContents, request, authInfo, callback) => { | |||
458 | }); | 504 | }); |
459 | 505 | ||
460 | // TODO: evaluate if we need to store the authCallback for every service | 506 | // TODO: evaluate if we need to store the authCallback for every service |
461 | ipcMain.on('feature-basic-auth-credentials', (e, { user, password }) => { | 507 | ipcMain.on('feature-basic-auth-credentials', (_e, { user, password }) => { |
462 | debug('Received basic auth credentials', user, '********'); | 508 | debug('Received basic auth credentials', user, '********'); |
463 | 509 | ||
510 | // @ts-expect-error Expected 0 arguments, but got 2. | ||
464 | authCallback(user, password); | 511 | authCallback(user, password); |
465 | authCallback = noop; | 512 | authCallback = noop; |
466 | }); | 513 | }); |
467 | 514 | ||
468 | ipcMain.on('open-browser-window', (e, { url, serviceId }) => { | 515 | ipcMain.on('open-browser-window', (_e, { url, serviceId }) => { |
469 | const serviceSession = session.fromPartition(`persist:service-${serviceId}`); | 516 | const serviceSession = session.fromPartition(`persist:service-${serviceId}`); |
470 | const child = new BrowserWindow({ | 517 | const child = new BrowserWindow({ |
471 | parent: mainWindow, | 518 | parent: mainWindow, |
@@ -483,7 +530,7 @@ ipcMain.on('open-browser-window', (e, { url, serviceId }) => { | |||
483 | 530 | ||
484 | ipcMain.on( | 531 | ipcMain.on( |
485 | 'modifyRequestHeaders', | 532 | 'modifyRequestHeaders', |
486 | (e, { modifiedRequestHeaders, serviceId }) => { | 533 | (_e, { modifiedRequestHeaders, serviceId }) => { |
487 | debug( | 534 | debug( |
488 | `Received modifyRequestHeaders ${modifiedRequestHeaders} for serviceId ${serviceId}`, | 535 | `Received modifyRequestHeaders ${modifiedRequestHeaders} for serviceId ${serviceId}`, |
489 | ); | 536 | ); |
@@ -504,7 +551,7 @@ ipcMain.on( | |||
504 | }, | 551 | }, |
505 | ); | 552 | ); |
506 | 553 | ||
507 | ipcMain.on('knownCertificateHosts', (e, { knownHosts, serviceId }) => { | 554 | ipcMain.on('knownCertificateHosts', (_e, { knownHosts, serviceId }) => { |
508 | debug( | 555 | debug( |
509 | `Received knownCertificateHosts ${knownHosts} for serviceId ${serviceId}`, | 556 | `Received knownCertificateHosts ${knownHosts} for serviceId ${serviceId}`, |
510 | ); | 557 | ); |
@@ -513,7 +560,10 @@ ipcMain.on('knownCertificateHosts', (e, { knownHosts, serviceId }) => { | |||
513 | .setCertificateVerifyProc((request, callback) => { | 560 | .setCertificateVerifyProc((request, callback) => { |
514 | // To know more about these callbacks: https://www.electronjs.org/docs/api/session#sessetcertificateverifyprocproc | 561 | // To know more about these callbacks: https://www.electronjs.org/docs/api/session#sessetcertificateverifyprocproc |
515 | const { hostname } = request; | 562 | const { hostname } = request; |
516 | if (knownHosts.find(item => item.includes(hostname)).length > 0) { | 563 | if ( |
564 | knownHosts.find((item: string | string[]) => item.includes(hostname)) | ||
565 | .length > 0 | ||
566 | ) { | ||
517 | callback(0); | 567 | callback(0); |
518 | } else { | 568 | } else { |
519 | callback(-2); | 569 | callback(-2); |
@@ -524,6 +574,7 @@ ipcMain.on('knownCertificateHosts', (e, { knownHosts, serviceId }) => { | |||
524 | ipcMain.on('feature-basic-auth-cancel', () => { | 574 | ipcMain.on('feature-basic-auth-cancel', () => { |
525 | debug('Cancel basic auth'); | 575 | debug('Cancel basic auth'); |
526 | 576 | ||
577 | // @ts-expect-error Expected 0 arguments, but got 2. | ||
527 | authCallback(null); | 578 | authCallback(null); |
528 | authCallback = noop; | 579 | authCallback = noop; |
529 | }); | 580 | }); |
@@ -532,7 +583,7 @@ ipcMain.on('feature-basic-auth-cancel', () => { | |||
532 | 583 | ||
533 | ipcMain.on('find-in-page', (e, text, options) => { | 584 | ipcMain.on('find-in-page', (e, text, options) => { |
534 | const { sender: webContents } = e; | 585 | const { sender: webContents } = e; |
535 | if (webContents !== mainWindow.webContents && typeof text === 'string') { | 586 | if (webContents !== mainWindow?.webContents && typeof text === 'string') { |
536 | const sanitizedOptions = {}; | 587 | const sanitizedOptions = {}; |
537 | for (const option of ['forward', 'findNext', 'matchCase']) { | 588 | for (const option of ['forward', 'findNext', 'matchCase']) { |
538 | if (option in options) { | 589 | if (option in options) { |
@@ -549,7 +600,7 @@ ipcMain.on('find-in-page', (e, text, options) => { | |||
549 | 600 | ||
550 | ipcMain.on('stop-find-in-page', (e, action) => { | 601 | ipcMain.on('stop-find-in-page', (e, action) => { |
551 | const { sender: webContents } = e; | 602 | const { sender: webContents } = e; |
552 | if (webContents !== mainWindow.webContents) { | 603 | if (webContents !== mainWindow?.webContents) { |
553 | const validActions = [ | 604 | const validActions = [ |
554 | 'clearSelection', | 605 | 'clearSelection', |
555 | 'keepSelection', | 606 | 'keepSelection', |
@@ -562,7 +613,7 @@ ipcMain.on('stop-find-in-page', (e, action) => { | |||
562 | e.returnValue = null; | 613 | e.returnValue = null; |
563 | }); | 614 | }); |
564 | 615 | ||
565 | ipcMain.on('set-spellchecker-locales', (e, { locale, serviceId }) => { | 616 | ipcMain.on('set-spellchecker-locales', (_e, { locale, serviceId }) => { |
566 | if (serviceId === undefined) { | 617 | if (serviceId === undefined) { |
567 | return; | 618 | return; |
568 | } | 619 | } |
@@ -580,7 +631,12 @@ ipcMain.on('set-spellchecker-locales', (e, { locale, serviceId }) => { | |||
580 | app.on('window-all-closed', () => { | 631 | app.on('window-all-closed', () => { |
581 | // On OS X it is common for applications and their menu bar | 632 | // On OS X it is common for applications and their menu bar |
582 | // to stay active until the user quits explicitly with Cmd + Q | 633 | // to stay active until the user quits explicitly with Cmd + Q |
583 | if (retrieveSettingValue('runInBackground', DEFAULT_APP_SETTINGS.runInBackground)) { | 634 | if ( |
635 | retrieveSettingValue( | ||
636 | 'runInBackground', | ||
637 | DEFAULT_APP_SETTINGS.runInBackground, | ||
638 | ) | ||
639 | ) { | ||
584 | debug('Window: all windows closed, quit app'); | 640 | debug('Window: all windows closed, quit app'); |
585 | app.quit(); | 641 | app.quit(); |
586 | } else { | 642 | } else { |
@@ -591,8 +647,10 @@ app.on('window-all-closed', () => { | |||
591 | app.on('before-quit', event => { | 647 | app.on('before-quit', event => { |
592 | const yesButtonIndex = 0; | 648 | const yesButtonIndex = 0; |
593 | let selection = yesButtonIndex; | 649 | let selection = yesButtonIndex; |
594 | if (retrieveSettingValue('confirmOnQuit', DEFAULT_APP_SETTINGS.confirmOnQuit)) { | 650 | if ( |
595 | selection = dialog.showMessageBoxSync(app.mainWindow, { | 651 | retrieveSettingValue('confirmOnQuit', DEFAULT_APP_SETTINGS.confirmOnQuit) |
652 | ) { | ||
653 | selection = dialog.showMessageBoxSync(mainWindow!, { | ||
596 | type: 'question', | 654 | type: 'question', |
597 | message: 'Quit', | 655 | message: 'Quit', |
598 | detail: 'Do you really want to quit Ferdi?', | 656 | detail: 'Do you really want to quit Ferdi?', |
@@ -612,12 +670,12 @@ app.on('activate', () => { | |||
612 | if (mainWindow === null) { | 670 | if (mainWindow === null) { |
613 | createWindow(); | 671 | createWindow(); |
614 | } else { | 672 | } else { |
615 | mainWindow.show(); | 673 | mainWindow?.show(); |
616 | } | 674 | } |
617 | }); | 675 | }); |
618 | 676 | ||
619 | app.on('web-contents-created', (createdEvent, contents) => { | 677 | app.on('web-contents-created', (_createdEvent, contents) => { |
620 | contents.on('new-window', (event, url, frameNme, disposition) => { | 678 | contents.on('new-window', (event, _url, _frameNme, disposition) => { |
621 | if (disposition === 'foreground-tab') event.preventDefault(); | 679 | if (disposition === 'foreground-tab') event.preventDefault(); |
622 | }); | 680 | }); |
623 | }); | 681 | }); |
@@ -627,7 +685,7 @@ app.on('will-finish-launching', () => { | |||
627 | app.on('open-url', (event, url) => { | 685 | app.on('open-url', (event, url) => { |
628 | event.preventDefault(); | 686 | event.preventDefault(); |
629 | 687 | ||
630 | onDidLoad(window => { | 688 | onDidLoad((window: BrowserWindow) => { |
631 | debug('open-url event', url); | 689 | debug('open-url event', url); |
632 | handleDeepLink(window, url); | 690 | handleDeepLink(window, url); |
633 | }); | 691 | }); |