diff options
author | 2018-11-27 18:06:14 +0100 | |
---|---|---|
committer | 2018-11-27 18:06:14 +0100 | |
commit | 62972747866740dae84fc7b519fcedd731572329 (patch) | |
tree | 3a74610caa47350ff6b3cc07482f8472f18c1764 /src/index.js | |
parent | Fix listening key (diff) | |
download | ferdium-app-62972747866740dae84fc7b519fcedd731572329.tar.gz ferdium-app-62972747866740dae84fc7b519fcedd731572329.tar.zst ferdium-app-62972747866740dae84fc7b519fcedd731572329.zip |
feat(App): Add proxy support for services
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 34 |
1 files changed, 31 insertions, 3 deletions
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 @@ | |||
1 | import { app, BrowserWindow, shell } from 'electron'; | 1 | import { app, BrowserWindow, shell, ipcMain } from 'electron'; |
2 | import fs from 'fs-extra'; | 2 | import fs from 'fs-extra'; |
3 | import path from 'path'; | 3 | import path from 'path'; |
4 | 4 | ||
@@ -12,6 +12,8 @@ import handleDeepLink from './electron/deepLinking'; | |||
12 | import { appId } from './package.json'; // eslint-disable-line import/no-unresolved | 12 | import { appId } from './package.json'; // eslint-disable-line import/no-unresolved |
13 | import './electron/exception'; | 13 | import './electron/exception'; |
14 | 14 | ||
15 | import { DEFAULT_APP_SETTINGS } from './config'; | ||
16 | |||
15 | const debug = require('debug')('Franz:App'); | 17 | const debug = require('debug')('Franz:App'); |
16 | 18 | ||
17 | // Keep a global reference of the window object, if you don't, the window will | 19 | // 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 | |||
62 | } | 64 | } |
63 | 65 | ||
64 | // Initialize Settings | 66 | // Initialize Settings |
65 | const settings = new Settings(); | 67 | const settings = new Settings('app', DEFAULT_APP_SETTINGS); |
68 | const proxySettings = new Settings('proxy'); | ||
66 | 69 | ||
67 | // Disable GPU acceleration | 70 | // Disable GPU acceleration |
68 | if (!settings.get('enableGPUAcceleration')) { | 71 | if (!settings.get('enableGPUAcceleration')) { |
@@ -94,7 +97,14 @@ const createWindow = () => { | |||
94 | const trayIcon = new Tray(); | 97 | const trayIcon = new Tray(); |
95 | 98 | ||
96 | // Initialize ipcApi | 99 | // Initialize ipcApi |
97 | ipcApi({ mainWindow, settings, trayIcon }); | 100 | ipcApi({ |
101 | mainWindow, | ||
102 | settings: { | ||
103 | app: settings, | ||
104 | proxy: proxySettings, | ||
105 | }, | ||
106 | trayIcon, | ||
107 | }); | ||
98 | 108 | ||
99 | // Manage Window State | 109 | // Manage Window State |
100 | mainWindowState.manage(mainWindow); | 110 | mainWindowState.manage(mainWindow); |
@@ -177,6 +187,24 @@ const createWindow = () => { | |||
177 | // Some APIs can only be used after this event occurs. | 187 | // Some APIs can only be used after this event occurs. |
178 | app.on('ready', createWindow); | 188 | app.on('ready', createWindow); |
179 | 189 | ||
190 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 | ||
191 | app.on('login', (event, webContents, request, authInfo, callback) => { | ||
192 | event.preventDefault(); | ||
193 | debug('browser login event', authInfo); | ||
194 | if (authInfo.isProxy && authInfo.scheme === 'basic') { | ||
195 | webContents.send('get-service-id'); | ||
196 | |||
197 | ipcMain.on('service-id', (e, id) => { | ||
198 | debug('Received service id', id); | ||
199 | |||
200 | const ps = proxySettings.get(id); | ||
201 | callback(ps.user, ps.password); | ||
202 | }); | ||
203 | } else { | ||
204 | // TODO: implement basic auth | ||
205 | } | ||
206 | }); | ||
207 | |||
180 | // Quit when all windows are closed. | 208 | // Quit when all windows are closed. |
181 | app.on('window-all-closed', () => { | 209 | app.on('window-all-closed', () => { |
182 | // On OS X it is common for applications and their menu bar | 210 | // On OS X it is common for applications and their menu bar |