diff options
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/index.js b/src/index.js index 5ba901b89..663f81cc9 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -1,10 +1,16 @@ | |||
1 | import { app, BrowserWindow, shell } from 'electron'; | 1 | import { app, BrowserWindow, shell, ipcMain } from 'electron'; |
2 | |||
2 | import fs from 'fs-extra'; | 3 | import fs from 'fs-extra'; |
3 | import path from 'path'; | 4 | import path from 'path'; |
4 | |||
5 | import windowStateKeeper from 'electron-window-state'; | 5 | import windowStateKeeper from 'electron-window-state'; |
6 | 6 | ||
7 | import { isDevMode, isMac, isWindows, isLinux } from './environment'; | 7 | import { isDevMode, isMac, isWindows, isLinux } from './environment'; |
8 | |||
9 | // DEV MODE: Save user data into FranzDev | ||
10 | if (isDevMode) { | ||
11 | app.setPath('userData', path.join(app.getPath('appData'), 'FranzDev')); | ||
12 | } | ||
13 | /* eslint-disable import/first */ | ||
8 | import ipcApi from './electron/ipc-api'; | 14 | import ipcApi from './electron/ipc-api'; |
9 | import Tray from './lib/Tray'; | 15 | import Tray from './lib/Tray'; |
10 | import Settings from './electron/Settings'; | 16 | import Settings from './electron/Settings'; |
@@ -12,7 +18,10 @@ import handleDeepLink from './electron/deepLinking'; | |||
12 | import { appId } from './package.json'; // eslint-disable-line import/no-unresolved | 18 | import { appId } from './package.json'; // eslint-disable-line import/no-unresolved |
13 | import './electron/exception'; | 19 | import './electron/exception'; |
14 | 20 | ||
15 | const debug = require('debug')('App'); | 21 | import { DEFAULT_APP_SETTINGS } from './config'; |
22 | /* eslint-enable import/first */ | ||
23 | |||
24 | const debug = require('debug')('Franz:App'); | ||
16 | 25 | ||
17 | // Keep a global reference of the window object, if you don't, the window will | 26 | // Keep a global reference of the window object, if you don't, the window will |
18 | // be closed automatically when the JavaScript object is garbage collected. | 27 | // be closed automatically when the JavaScript object is garbage collected. |
@@ -57,7 +66,8 @@ if (isLinux && ['Pantheon', 'Unity:Unity7'].indexOf(process.env.XDG_CURRENT_DESK | |||
57 | } | 66 | } |
58 | 67 | ||
59 | // Initialize Settings | 68 | // Initialize Settings |
60 | const settings = new Settings(); | 69 | const settings = new Settings('app', DEFAULT_APP_SETTINGS); |
70 | const proxySettings = new Settings('proxy'); | ||
61 | 71 | ||
62 | // Disable GPU acceleration | 72 | // Disable GPU acceleration |
63 | if (!settings.get('enableGPUAcceleration')) { | 73 | if (!settings.get('enableGPUAcceleration')) { |
@@ -82,14 +92,21 @@ const createWindow = () => { | |||
82 | minHeight: 500, | 92 | minHeight: 500, |
83 | titleBarStyle: isMac ? 'hidden' : '', | 93 | titleBarStyle: isMac ? 'hidden' : '', |
84 | frame: isLinux, | 94 | frame: isLinux, |
85 | backgroundColor: '#3498db', | 95 | backgroundColor: !settings.get('darkMode') ? '#3498db' : '#1E1E1E', |
86 | }); | 96 | }); |
87 | 97 | ||
88 | // Initialize System Tray | 98 | // Initialize System Tray |
89 | const trayIcon = new Tray(); | 99 | const trayIcon = new Tray(); |
90 | 100 | ||
91 | // Initialize ipcApi | 101 | // Initialize ipcApi |
92 | ipcApi({ mainWindow, settings, trayIcon }); | 102 | ipcApi({ |
103 | mainWindow, | ||
104 | settings: { | ||
105 | app: settings, | ||
106 | proxy: proxySettings, | ||
107 | }, | ||
108 | trayIcon, | ||
109 | }); | ||
93 | 110 | ||
94 | // Manage Window State | 111 | // Manage Window State |
95 | mainWindowState.manage(mainWindow); | 112 | mainWindowState.manage(mainWindow); |
@@ -115,7 +132,7 @@ const createWindow = () => { | |||
115 | mainWindow.hide(); | 132 | mainWindow.hide(); |
116 | } | 133 | } |
117 | 134 | ||
118 | if (isWindows && settings.get('minimizeToSystemTray')) { | 135 | if (isWindows) { |
119 | mainWindow.setSkipTaskbar(true); | 136 | mainWindow.setSkipTaskbar(true); |
120 | } | 137 | } |
121 | } else { | 138 | } else { |
@@ -172,6 +189,24 @@ const createWindow = () => { | |||
172 | // Some APIs can only be used after this event occurs. | 189 | // Some APIs can only be used after this event occurs. |
173 | app.on('ready', createWindow); | 190 | app.on('ready', createWindow); |
174 | 191 | ||
192 | // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 | ||
193 | app.on('login', (event, webContents, request, authInfo, callback) => { | ||
194 | event.preventDefault(); | ||
195 | debug('browser login event', authInfo); | ||
196 | if (authInfo.isProxy && authInfo.scheme === 'basic') { | ||
197 | webContents.send('get-service-id'); | ||
198 | |||
199 | ipcMain.on('service-id', (e, id) => { | ||
200 | debug('Received service id', id); | ||
201 | |||
202 | const ps = proxySettings.get(id); | ||
203 | callback(ps.user, ps.password); | ||
204 | }); | ||
205 | } else { | ||
206 | // TODO: implement basic auth | ||
207 | } | ||
208 | }); | ||
209 | |||
175 | // Quit when all windows are closed. | 210 | // Quit when all windows are closed. |
176 | app.on('window-all-closed', () => { | 211 | app.on('window-all-closed', () => { |
177 | // On OS X it is common for applications and their menu bar | 212 | // On OS X it is common for applications and their menu bar |