diff options
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/index.js b/src/index.js index 830166dcf..a4bc44a6c 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')); |
@@ -229,23 +237,42 @@ app.on('ready', () => { | |||
229 | }); | 237 | }); |
230 | 238 | ||
231 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 | 239 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 |
240 | // TODO: rewrite to handle multiple login calls | ||
241 | const noop = () => null; | ||
242 | let authCallback = noop; | ||
232 | app.on('login', (event, webContents, request, authInfo, callback) => { | 243 | app.on('login', (event, webContents, request, authInfo, callback) => { |
233 | event.preventDefault(); | 244 | authCallback = callback; |
234 | debug('browser login event', authInfo); | 245 | debug('browser login event', authInfo); |
246 | event.preventDefault(); | ||
235 | if (authInfo.isProxy && authInfo.scheme === 'basic') { | 247 | if (authInfo.isProxy && authInfo.scheme === 'basic') { |
236 | webContents.send('get-service-id'); | 248 | webContents.send('get-service-id'); |
237 | 249 | ||
238 | ipcMain.on('service-id', (e, id) => { | 250 | ipcMain.once('service-id', (e, id) => { |
239 | debug('Received service id', id); | 251 | debug('Received service id', id); |
240 | 252 | ||
241 | const ps = proxySettings.get(id); | 253 | const ps = proxySettings.get(id); |
242 | callback(ps.user, ps.password); | 254 | callback(ps.user, ps.password); |
243 | }); | 255 | }); |
244 | } else { | 256 | } else if (authInfo.scheme === 'basic') { |
245 | // TODO: implement basic auth | 257 | console.log('basic auth handler', authInfo); |
258 | basicAuthHandler(mainWindow, authInfo); | ||
246 | } | 259 | } |
247 | }); | 260 | }); |
248 | 261 | ||
262 | ipcMain.on('feature-basic-auth-credentials', (e, { user, password }) => { | ||
263 | debug('Received basic auth credentials', user, '********'); | ||
264 | |||
265 | authCallback(user, password); | ||
266 | authCallback = noop; | ||
267 | }); | ||
268 | |||
269 | ipcMain.on('feature-basic-auth-cancel', () => { | ||
270 | debug('Cancel basic auth'); | ||
271 | |||
272 | authCallback(null); | ||
273 | authCallback = noop; | ||
274 | }); | ||
275 | |||
249 | // Quit when all windows are closed. | 276 | // Quit when all windows are closed. |
250 | app.on('window-all-closed', () => { | 277 | app.on('window-all-closed', () => { |
251 | // On OS X it is common for applications and their menu bar | 278 | // On OS X it is common for applications and their menu bar |