diff options
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/src/index.js b/src/index.js index 6a0ee600f..05c793d98 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -34,6 +34,7 @@ import { | |||
34 | DEFAULT_WINDOW_OPTIONS, | 34 | DEFAULT_WINDOW_OPTIONS, |
35 | } from './config'; | 35 | } from './config'; |
36 | import { asarPath } from './helpers/asar-helpers'; | 36 | import { asarPath } from './helpers/asar-helpers'; |
37 | import { isValidExternalURL } from './helpers/url-helpers'; | ||
37 | /* eslint-enable import/first */ | 38 | /* eslint-enable import/first */ |
38 | 39 | ||
39 | const debug = require('debug')('Franz:App'); | 40 | const debug = require('debug')('Franz:App'); |
@@ -71,7 +72,10 @@ if (!gotTheLock) { | |||
71 | app.on('second-instance', (event, argv) => { | 72 | app.on('second-instance', (event, argv) => { |
72 | // Someone tried to run a second instance, we should focus our window. | 73 | // Someone tried to run a second instance, we should focus our window. |
73 | if (mainWindow) { | 74 | if (mainWindow) { |
74 | if (mainWindow.isMinimized()) mainWindow.restore(); | 75 | mainWindow.show(); |
76 | if (mainWindow.isMinimized()) { | ||
77 | mainWindow.restore(); | ||
78 | } | ||
75 | mainWindow.focus(); | 79 | mainWindow.focus(); |
76 | 80 | ||
77 | if (isWindows) { | 81 | if (isWindows) { |
@@ -101,6 +105,35 @@ if (!gotTheLock) { | |||
101 | } | 105 | } |
102 | }); | 106 | }); |
103 | } | 107 | } |
108 | // const isSecondInstance = app.makeSingleInstance((argv) => { | ||
109 | // if (mainWindow) { | ||
110 | // if (mainWindow.isMinimized()) mainWindow.restore(); | ||
111 | // mainWindow.focus(); | ||
112 | |||
113 | // if (process.platform === 'win32') { | ||
114 | // // Keep only command line / deep linked arguments | ||
115 | // const url = argv.slice(1); | ||
116 | |||
117 | // if (url) { | ||
118 | // handleDeepLink(mainWindow, url.toString()); | ||
119 | // } | ||
120 | // } | ||
121 | // } | ||
122 | |||
123 | // if (argv.includes('--reset-window')) { | ||
124 | // // Needs to be delayed to not interfere with mainWindow.restore(); | ||
125 | // setTimeout(() => { | ||
126 | // debug('Resetting windows via Task'); | ||
127 | // mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); | ||
128 | // mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); | ||
129 | // }, 1); | ||
130 | // } | ||
131 | // }); | ||
132 | |||
133 | // if (isSecondInstance) { | ||
134 | // console.log('An instance of Franz is already running. Exiting...'); | ||
135 | // app.exit(); | ||
136 | // } | ||
104 | 137 | ||
105 | // Fix Unity indicator issue | 138 | // Fix Unity indicator issue |
106 | // https://github.com/electron/electron/issues/9046 | 139 | // https://github.com/electron/electron/issues/9046 |
@@ -194,20 +227,24 @@ const createWindow = () => { | |||
194 | 227 | ||
195 | // Emitted when the window is closed. | 228 | // Emitted when the window is closed. |
196 | mainWindow.on('close', (e) => { | 229 | mainWindow.on('close', (e) => { |
230 | debug('Window: close window'); | ||
197 | // Dereference the window object, usually you would store windows | 231 | // Dereference the window object, usually you would store windows |
198 | // in an array if your app supports multi windows, this is the time | 232 | // in an array if your app supports multi windows, this is the time |
199 | // when you should delete the corresponding element. | 233 | // when you should delete the corresponding element. |
200 | if (!willQuitApp && (settings.get('runInBackground') === undefined || settings.get('runInBackground'))) { | 234 | if (!willQuitApp && (settings.get('runInBackground') === undefined || settings.get('runInBackground'))) { |
201 | e.preventDefault(); | 235 | e.preventDefault(); |
202 | if (isWindows) { | 236 | if (isWindows) { |
237 | debug('Window: minimize'); | ||
203 | mainWindow.minimize(); | 238 | mainWindow.minimize(); |
239 | |||
240 | if (settings.get('minimizeToSystemTray')) { | ||
241 | debug('Skip taskbar: true'); | ||
242 | mainWindow.setSkipTaskbar(true); | ||
243 | } | ||
204 | } else { | 244 | } else { |
245 | debug('Window: hide'); | ||
205 | mainWindow.hide(); | 246 | mainWindow.hide(); |
206 | } | 247 | } |
207 | |||
208 | if (isWindows) { | ||
209 | mainWindow.setSkipTaskbar(true); | ||
210 | } | ||
211 | } else { | 248 | } else { |
212 | app.quit(); | 249 | app.quit(); |
213 | } | 250 | } |
@@ -219,32 +256,39 @@ const createWindow = () => { | |||
219 | app.wasMaximized = app.isMaximized; | 256 | app.wasMaximized = app.isMaximized; |
220 | 257 | ||
221 | if (settings.get('minimizeToSystemTray')) { | 258 | if (settings.get('minimizeToSystemTray')) { |
259 | debug('Skip taskbar: true'); | ||
222 | mainWindow.setSkipTaskbar(true); | 260 | mainWindow.setSkipTaskbar(true); |
223 | trayIcon.show(); | 261 | trayIcon.show(); |
224 | } | 262 | } |
225 | }); | 263 | }); |
226 | 264 | ||
227 | mainWindow.on('maximize', () => { | 265 | mainWindow.on('maximize', () => { |
266 | debug('Window: maximize'); | ||
228 | app.isMaximized = true; | 267 | app.isMaximized = true; |
229 | }); | 268 | }); |
230 | 269 | ||
231 | mainWindow.on('unmaximize', () => { | 270 | mainWindow.on('unmaximize', () => { |
271 | debug('Window: unmaximize'); | ||
232 | app.isMaximized = false; | 272 | app.isMaximized = false; |
233 | }); | 273 | }); |
234 | 274 | ||
235 | mainWindow.on('restore', () => { | 275 | mainWindow.on('restore', () => { |
276 | debug('Window: restore'); | ||
236 | mainWindow.setSkipTaskbar(false); | 277 | mainWindow.setSkipTaskbar(false); |
237 | 278 | ||
238 | if (app.wasMaximized) { | 279 | if (app.wasMaximized) { |
280 | debug('Window: was maximized before, maximize window'); | ||
239 | mainWindow.maximize(); | 281 | mainWindow.maximize(); |
240 | } | 282 | } |
241 | 283 | ||
242 | if (!settings.get('enableSystemTray')) { | 284 | if (!settings.get('enableSystemTray')) { |
285 | debug('Tray: hiding tray icon'); | ||
243 | trayIcon.hide(); | 286 | trayIcon.hide(); |
244 | } | 287 | } |
245 | }); | 288 | }); |
246 | 289 | ||
247 | mainWindow.on('show', () => { | 290 | mainWindow.on('show', () => { |
291 | debug('Skip taskbar: false'); | ||
248 | mainWindow.setSkipTaskbar(false); | 292 | mainWindow.setSkipTaskbar(false); |
249 | }); | 293 | }); |
250 | 294 | ||
@@ -252,8 +296,12 @@ const createWindow = () => { | |||
252 | app.isMaximized = mainWindow.isMaximized(); | 296 | app.isMaximized = mainWindow.isMaximized(); |
253 | 297 | ||
254 | mainWindow.webContents.on('new-window', (e, url) => { | 298 | mainWindow.webContents.on('new-window', (e, url) => { |
299 | debug('Open url', url); | ||
255 | e.preventDefault(); | 300 | e.preventDefault(); |
256 | shell.openExternal(url); | 301 | |
302 | if (isValidExternalURL(url)) { | ||
303 | shell.openExternal(url); | ||
304 | } | ||
257 | }); | 305 | }); |
258 | }; | 306 | }; |
259 | 307 | ||
@@ -331,7 +379,10 @@ app.on('window-all-closed', () => { | |||
331 | // to stay active until the user quits explicitly with Cmd + Q | 379 | // to stay active until the user quits explicitly with Cmd + Q |
332 | if (settings.get('runInBackground') === undefined | 380 | if (settings.get('runInBackground') === undefined |
333 | || settings.get('runInBackground')) { | 381 | || settings.get('runInBackground')) { |
382 | debug('Window: all windows closed, quit app'); | ||
334 | app.quit(); | 383 | app.quit(); |
384 | } else { | ||
385 | debug('Window: don\'t quit app'); | ||
335 | } | 386 | } |
336 | }); | 387 | }); |
337 | 388 | ||