diff options
author | 2019-01-09 12:57:11 +0100 | |
---|---|---|
committer | 2019-01-09 12:57:11 +0100 | |
commit | eee1fe620473b50ac74ce41a030dee5693227be8 (patch) | |
tree | f9cb24aa00a490b0f0a6e13db6957522fba150b1 /src/index.js | |
parent | Ignore ERR_NETWORK_CHANGED error (diff) | |
parent | Add TODO (diff) | |
download | ferdium-app-eee1fe620473b50ac74ce41a030dee5693227be8.tar.gz ferdium-app-eee1fe620473b50ac74ce41a030dee5693227be8.tar.zst ferdium-app-eee1fe620473b50ac74ce41a030dee5693227be8.zip |
Merge branch 'feature/basicAuth' into develop
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/index.js b/src/index.js index 75da4ff88..195e9e863 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')); |
@@ -263,23 +271,43 @@ app.on('ready', () => { | |||
263 | }); | 271 | }); |
264 | 272 | ||
265 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 | 273 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 |
274 | // TODO: rewrite to handle multiple login calls | ||
275 | const noop = () => null; | ||
276 | let authCallback = noop; | ||
266 | app.on('login', (event, webContents, request, authInfo, callback) => { | 277 | app.on('login', (event, webContents, request, authInfo, callback) => { |
267 | event.preventDefault(); | 278 | authCallback = callback; |
268 | debug('browser login event', authInfo); | 279 | debug('browser login event', authInfo); |
280 | event.preventDefault(); | ||
269 | if (authInfo.isProxy && authInfo.scheme === 'basic') { | 281 | if (authInfo.isProxy && authInfo.scheme === 'basic') { |
270 | webContents.send('get-service-id'); | 282 | webContents.send('get-service-id'); |
271 | 283 | ||
272 | ipcMain.on('service-id', (e, id) => { | 284 | ipcMain.once('service-id', (e, id) => { |
273 | debug('Received service id', id); | 285 | debug('Received service id', id); |
274 | 286 | ||
275 | const ps = proxySettings.get(id); | 287 | const ps = proxySettings.get(id); |
276 | callback(ps.user, ps.password); | 288 | callback(ps.user, ps.password); |
277 | }); | 289 | }); |
278 | } else { | 290 | } else if (authInfo.scheme === 'basic') { |
279 | // TODO: implement basic auth | 291 | debug('basic auth handler', authInfo); |
292 | basicAuthHandler(mainWindow, authInfo); | ||
280 | } | 293 | } |
281 | }); | 294 | }); |
282 | 295 | ||
296 | // TODO: evaluate if we need to store the authCallback for every service | ||
297 | ipcMain.on('feature-basic-auth-credentials', (e, { user, password }) => { | ||
298 | debug('Received basic auth credentials', user, '********'); | ||
299 | |||
300 | authCallback(user, password); | ||
301 | authCallback = noop; | ||
302 | }); | ||
303 | |||
304 | ipcMain.on('feature-basic-auth-cancel', () => { | ||
305 | debug('Cancel basic auth'); | ||
306 | |||
307 | authCallback(null); | ||
308 | authCallback = noop; | ||
309 | }); | ||
310 | |||
283 | // Quit when all windows are closed. | 311 | // Quit when all windows are closed. |
284 | app.on('window-all-closed', () => { | 312 | app.on('window-all-closed', () => { |
285 | // On OS X it is common for applications and their menu bar | 313 | // On OS X it is common for applications and their menu bar |