From 62972747866740dae84fc7b519fcedd731572329 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 27 Nov 2018 18:06:14 +0100 Subject: feat(App): Add proxy support for services --- src/index.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 7d906ad71..994531dbf 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { app, BrowserWindow, shell } from 'electron'; +import { app, BrowserWindow, shell, ipcMain } from 'electron'; import fs from 'fs-extra'; import path from 'path'; @@ -12,6 +12,8 @@ import handleDeepLink from './electron/deepLinking'; import { appId } from './package.json'; // eslint-disable-line import/no-unresolved import './electron/exception'; +import { DEFAULT_APP_SETTINGS } from './config'; + const debug = require('debug')('Franz:App'); // Keep a global reference of the window object, if you don't, the window will @@ -62,7 +64,8 @@ if (isLinux && ['Pantheon', 'Unity:Unity7'].indexOf(process.env.XDG_CURRENT_DESK } // Initialize Settings -const settings = new Settings(); +const settings = new Settings('app', DEFAULT_APP_SETTINGS); +const proxySettings = new Settings('proxy'); // Disable GPU acceleration if (!settings.get('enableGPUAcceleration')) { @@ -94,7 +97,14 @@ const createWindow = () => { const trayIcon = new Tray(); // Initialize ipcApi - ipcApi({ mainWindow, settings, trayIcon }); + ipcApi({ + mainWindow, + settings: { + app: settings, + proxy: proxySettings, + }, + trayIcon, + }); // Manage Window State mainWindowState.manage(mainWindow); @@ -177,6 +187,24 @@ const createWindow = () => { // Some APIs can only be used after this event occurs. app.on('ready', createWindow); +// This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 +app.on('login', (event, webContents, request, authInfo, callback) => { + event.preventDefault(); + debug('browser login event', authInfo); + if (authInfo.isProxy && authInfo.scheme === 'basic') { + webContents.send('get-service-id'); + + ipcMain.on('service-id', (e, id) => { + debug('Received service id', id); + + const ps = proxySettings.get(id); + callback(ps.user, ps.password); + }); + } else { + // TODO: implement basic auth + } +}); + // Quit when all windows are closed. app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar -- cgit v1.2.3-70-g09d2