diff options
author | 2019-02-01 10:35:18 +0100 | |
---|---|---|
committer | 2019-02-01 10:35:18 +0100 | |
commit | da92cd426cbf350313945e3459f96638a79bd44e (patch) | |
tree | 931d18bbf62854366ccf7021d6206de7e0c42636 /src/index.js | |
parent | Update stale.yml (diff) | |
parent | b23 (diff) | |
download | ferdium-app-da92cd426cbf350313945e3459f96638a79bd44e.tar.gz ferdium-app-da92cd426cbf350313945e3459f96638a79bd44e.tar.zst ferdium-app-da92cd426cbf350313945e3459f96638a79bd44e.zip |
Merge branch 'develop'v5.0.0-beta.23
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 123 |
1 files changed, 94 insertions, 29 deletions
diff --git a/src/index.js b/src/index.js index 830166dcf..f34df8c17 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -1,5 +1,8 @@ | |||
1 | import { | 1 | import { |
2 | app, BrowserWindow, shell, ipcMain, | 2 | app, |
3 | BrowserWindow, | ||
4 | shell, | ||
5 | ipcMain, | ||
3 | } from 'electron'; | 6 | } from 'electron'; |
4 | 7 | ||
5 | import fs from 'fs-extra'; | 8 | import fs from 'fs-extra'; |
@@ -7,9 +10,14 @@ import path from 'path'; | |||
7 | import windowStateKeeper from 'electron-window-state'; | 10 | import windowStateKeeper from 'electron-window-state'; |
8 | 11 | ||
9 | import { | 12 | import { |
10 | isDevMode, isMac, isWindows, isLinux, | 13 | isDevMode, |
14 | isMac, | ||
15 | isWindows, | ||
16 | isLinux, | ||
11 | } from './environment'; | 17 | } from './environment'; |
12 | 18 | ||
19 | import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; | ||
20 | |||
13 | // DEV MODE: Save user data into FranzDev | 21 | // DEV MODE: Save user data into FranzDev |
14 | if (isDevMode) { | 22 | if (isDevMode) { |
15 | app.setPath('userData', path.join(app.getPath('appData'), 'FranzDev')); | 23 | app.setPath('userData', path.join(app.getPath('appData'), 'FranzDev')); |
@@ -46,35 +54,69 @@ if (isWindows) { | |||
46 | } | 54 | } |
47 | 55 | ||
48 | // Force single window | 56 | // Force single window |
49 | const isSecondInstance = app.makeSingleInstance((argv) => { | 57 | const gotTheLock = app.requestSingleInstanceLock(); |
50 | if (mainWindow) { | 58 | if (!gotTheLock) { |
51 | if (mainWindow.isMinimized()) mainWindow.restore(); | 59 | app.quit(); |
52 | mainWindow.focus(); | 60 | } else { |
61 | app.on('second-instance', (event, argv) => { | ||
62 | // Someone tried to run a second instance, we should focus our window. | ||
63 | if (mainWindow) { | ||
64 | if (mainWindow.isMinimized()) mainWindow.restore(); | ||
65 | mainWindow.focus(); | ||
53 | 66 | ||
54 | if (process.platform === 'win32') { | 67 | if (isWindows) { |
55 | // Keep only command line / deep linked arguments | 68 | // Keep only command line / deep linked arguments |
56 | const url = argv.slice(1); | 69 | const url = argv.slice(1); |
57 | 70 | ||
58 | if (url) { | 71 | if (url) { |
59 | handleDeepLink(mainWindow, url.toString()); | 72 | handleDeepLink(mainWindow, url.toString()); |
73 | } | ||
60 | } | 74 | } |
61 | } | ||
62 | } | ||
63 | 75 | ||
64 | if (argv.includes('--reset-window')) { | 76 | if (argv.includes('--reset-window')) { |
65 | // Needs to be delayed to not interfere with mainWindow.restore(); | 77 | // Needs to be delayed to not interfere with mainWindow.restore(); |
66 | setTimeout(() => { | 78 | setTimeout(() => { |
67 | debug('Resetting windows via Task'); | 79 | debug('Resetting windows via Task'); |
68 | mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); | 80 | mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); |
69 | mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); | 81 | mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); |
70 | }, 1); | 82 | }, 1); |
71 | } | 83 | } |
72 | }); | 84 | } |
85 | }); | ||
73 | 86 | ||
74 | if (isSecondInstance) { | 87 | // Create myWindow, load the rest of the app, etc... |
75 | console.log('An instance of Franz is already running. Exiting...'); | 88 | app.on('ready', () => { |
76 | app.exit(); | 89 | }); |
77 | } | 90 | } |
91 | // const isSecondInstance = app.makeSingleInstance((argv) => { | ||
92 | // if (mainWindow) { | ||
93 | // if (mainWindow.isMinimized()) mainWindow.restore(); | ||
94 | // mainWindow.focus(); | ||
95 | |||
96 | // if (process.platform === 'win32') { | ||
97 | // // Keep only command line / deep linked arguments | ||
98 | // const url = argv.slice(1); | ||
99 | |||
100 | // if (url) { | ||
101 | // handleDeepLink(mainWindow, url.toString()); | ||
102 | // } | ||
103 | // } | ||
104 | // } | ||
105 | |||
106 | // if (argv.includes('--reset-window')) { | ||
107 | // // Needs to be delayed to not interfere with mainWindow.restore(); | ||
108 | // setTimeout(() => { | ||
109 | // debug('Resetting windows via Task'); | ||
110 | // mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); | ||
111 | // mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); | ||
112 | // }, 1); | ||
113 | // } | ||
114 | // }); | ||
115 | |||
116 | // if (isSecondInstance) { | ||
117 | // console.log('An instance of Franz is already running. Exiting...'); | ||
118 | // app.exit(); | ||
119 | // } | ||
78 | 120 | ||
79 | // Fix Unity indicator issue | 121 | // Fix Unity indicator issue |
80 | // https://github.com/electron/electron/issues/9046 | 122 | // https://github.com/electron/electron/issues/9046 |
@@ -119,6 +161,9 @@ const createWindow = () => { | |||
119 | titleBarStyle: isMac ? 'hidden' : '', | 161 | titleBarStyle: isMac ? 'hidden' : '', |
120 | frame: isLinux, | 162 | frame: isLinux, |
121 | backgroundColor: !settings.get('darkMode') ? '#3498db' : '#1E1E1E', | 163 | backgroundColor: !settings.get('darkMode') ? '#3498db' : '#1E1E1E', |
164 | webPreferences: { | ||
165 | nodeIntegration: true, | ||
166 | }, | ||
122 | }); | 167 | }); |
123 | 168 | ||
124 | // Initialize System Tray | 169 | // Initialize System Tray |
@@ -229,23 +274,43 @@ app.on('ready', () => { | |||
229 | }); | 274 | }); |
230 | 275 | ||
231 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 | 276 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 |
277 | // TODO: rewrite to handle multiple login calls | ||
278 | const noop = () => null; | ||
279 | let authCallback = noop; | ||
232 | app.on('login', (event, webContents, request, authInfo, callback) => { | 280 | app.on('login', (event, webContents, request, authInfo, callback) => { |
233 | event.preventDefault(); | 281 | authCallback = callback; |
234 | debug('browser login event', authInfo); | 282 | debug('browser login event', authInfo); |
283 | event.preventDefault(); | ||
235 | if (authInfo.isProxy && authInfo.scheme === 'basic') { | 284 | if (authInfo.isProxy && authInfo.scheme === 'basic') { |
236 | webContents.send('get-service-id'); | 285 | webContents.send('get-service-id'); |
237 | 286 | ||
238 | ipcMain.on('service-id', (e, id) => { | 287 | ipcMain.once('service-id', (e, id) => { |
239 | debug('Received service id', id); | 288 | debug('Received service id', id); |
240 | 289 | ||
241 | const ps = proxySettings.get(id); | 290 | const ps = proxySettings.get(id); |
242 | callback(ps.user, ps.password); | 291 | callback(ps.user, ps.password); |
243 | }); | 292 | }); |
244 | } else { | 293 | } else if (authInfo.scheme === 'basic') { |
245 | // TODO: implement basic auth | 294 | debug('basic auth handler', authInfo); |
295 | basicAuthHandler(mainWindow, authInfo); | ||
246 | } | 296 | } |
247 | }); | 297 | }); |
248 | 298 | ||
299 | // TODO: evaluate if we need to store the authCallback for every service | ||
300 | ipcMain.on('feature-basic-auth-credentials', (e, { user, password }) => { | ||
301 | debug('Received basic auth credentials', user, '********'); | ||
302 | |||
303 | authCallback(user, password); | ||
304 | authCallback = noop; | ||
305 | }); | ||
306 | |||
307 | ipcMain.on('feature-basic-auth-cancel', () => { | ||
308 | debug('Cancel basic auth'); | ||
309 | |||
310 | authCallback(null); | ||
311 | authCallback = noop; | ||
312 | }); | ||
313 | |||
249 | // Quit when all windows are closed. | 314 | // Quit when all windows are closed. |
250 | app.on('window-all-closed', () => { | 315 | app.on('window-all-closed', () => { |
251 | // On OS X it is common for applications and their menu bar | 316 | // On OS X it is common for applications and their menu bar |