diff options
author | 2019-02-11 12:48:04 +0100 | |
---|---|---|
committer | 2019-02-11 12:48:04 +0100 | |
commit | 3262ab46335ba42fe521c0b3f6165b87b990dbdd (patch) | |
tree | b88bcbf50e7ca8d3723eeb7b4765fbaf3acec054 /src/index.js | |
parent | fix(App): Ignore network changed error (diff) | |
download | ferdium-app-3262ab46335ba42fe521c0b3f6165b87b990dbdd.tar.gz ferdium-app-3262ab46335ba42fe521c0b3f6165b87b990dbdd.tar.zst ferdium-app-3262ab46335ba42fe521c0b3f6165b87b990dbdd.zip |
Add option to login via deep link
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/src/index.js b/src/index.js index f34df8c17..8d3b04845 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -4,7 +4,6 @@ import { | |||
4 | shell, | 4 | shell, |
5 | ipcMain, | 5 | ipcMain, |
6 | } from 'electron'; | 6 | } from 'electron'; |
7 | |||
8 | import fs from 'fs-extra'; | 7 | import fs from 'fs-extra'; |
9 | import path from 'path'; | 8 | import path from 'path'; |
10 | import windowStateKeeper from 'electron-window-state'; | 9 | import windowStateKeeper from 'electron-window-state'; |
@@ -44,6 +43,17 @@ const debug = require('debug')('Franz:App'); | |||
44 | let mainWindow; | 43 | let mainWindow; |
45 | let willQuitApp = false; | 44 | let willQuitApp = false; |
46 | 45 | ||
46 | // Register methods to be called once the window has been loaded. | ||
47 | let onDidLoadFns = []; | ||
48 | |||
49 | function onDidLoad(fn) { | ||
50 | if (onDidLoadFns) { | ||
51 | onDidLoadFns.push(fn); | ||
52 | } else if (mainWindow) { | ||
53 | fn(mainWindow); | ||
54 | } | ||
55 | } | ||
56 | |||
47 | // Ensure that the recipe directory exists | 57 | // Ensure that the recipe directory exists |
48 | fs.emptyDirSync(path.join(app.getPath('userData'), 'recipes', 'temp')); | 58 | fs.emptyDirSync(path.join(app.getPath('userData'), 'recipes', 'temp')); |
49 | fs.ensureFileSync(path.join(app.getPath('userData'), 'window-state.json')); | 59 | fs.ensureFileSync(path.join(app.getPath('userData'), 'window-state.json')); |
@@ -83,40 +93,7 @@ if (!gotTheLock) { | |||
83 | } | 93 | } |
84 | } | 94 | } |
85 | }); | 95 | }); |
86 | |||
87 | // Create myWindow, load the rest of the app, etc... | ||
88 | app.on('ready', () => { | ||
89 | }); | ||
90 | } | 96 | } |
91 | // const isSecondInstance = app.makeSingleInstance((argv) => { | ||
92 | // if (mainWindow) { | ||
93 | // if (mainWindow.isMinimized()) mainWindow.restore(); | ||
94 | // mainWindow.focus(); | ||
95 | |||
96 | // if (process.platform === 'win32') { | ||
97 | // // Keep only command line / deep linked arguments | ||
98 | // const url = argv.slice(1); | ||
99 | |||
100 | // if (url) { | ||
101 | // handleDeepLink(mainWindow, url.toString()); | ||
102 | // } | ||
103 | // } | ||
104 | // } | ||
105 | |||
106 | // if (argv.includes('--reset-window')) { | ||
107 | // // Needs to be delayed to not interfere with mainWindow.restore(); | ||
108 | // setTimeout(() => { | ||
109 | // debug('Resetting windows via Task'); | ||
110 | // mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); | ||
111 | // mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); | ||
112 | // }, 1); | ||
113 | // } | ||
114 | // }); | ||
115 | |||
116 | // if (isSecondInstance) { | ||
117 | // console.log('An instance of Franz is already running. Exiting...'); | ||
118 | // app.exit(); | ||
119 | // } | ||
120 | 97 | ||
121 | // Fix Unity indicator issue | 98 | // Fix Unity indicator issue |
122 | // https://github.com/electron/electron/issues/9046 | 99 | // https://github.com/electron/electron/issues/9046 |
@@ -166,6 +143,14 @@ const createWindow = () => { | |||
166 | }, | 143 | }, |
167 | }); | 144 | }); |
168 | 145 | ||
146 | mainWindow.webContents.on('did-finish-load', () => { | ||
147 | const fns = onDidLoadFns; | ||
148 | onDidLoadFns = null; | ||
149 | for (const fn of fns) { | ||
150 | fn(mainWindow); | ||
151 | } | ||
152 | }); | ||
153 | |||
169 | // Initialize System Tray | 154 | // Initialize System Tray |
170 | const trayIcon = new Tray(); | 155 | const trayIcon = new Tray(); |
171 | 156 | ||
@@ -259,6 +244,13 @@ const createWindow = () => { | |||
259 | // initialization and is ready to create browser windows. | 244 | // initialization and is ready to create browser windows. |
260 | // Some APIs can only be used after this event occurs. | 245 | // Some APIs can only be used after this event occurs. |
261 | app.on('ready', () => { | 246 | app.on('ready', () => { |
247 | // Register App URL | ||
248 | app.setAsDefaultProtocolClient('franz'); | ||
249 | |||
250 | if (isDevMode) { | ||
251 | app.setAsDefaultProtocolClient('franz-dev'); | ||
252 | } | ||
253 | |||
262 | if (process.platform === 'win32') { | 254 | if (process.platform === 'win32') { |
263 | app.setUserTasks([{ | 255 | app.setUserTasks([{ |
264 | program: process.execPath, | 256 | program: process.execPath, |
@@ -336,13 +328,13 @@ app.on('activate', () => { | |||
336 | }); | 328 | }); |
337 | 329 | ||
338 | app.on('will-finish-launching', () => { | 330 | app.on('will-finish-launching', () => { |
339 | // Protocol handler for osx | 331 | // Protocol handler for macOS |
340 | app.on('open-url', (event, url) => { | 332 | app.on('open-url', (event, url) => { |
341 | event.preventDefault(); | 333 | event.preventDefault(); |
342 | console.log(`open-url event: ${url}`); | 334 | |
343 | handleDeepLink(mainWindow, url); | 335 | onDidLoad((window) => { |
336 | debug('open-url event', url); | ||
337 | handleDeepLink(window, url); | ||
338 | }); | ||
344 | }); | 339 | }); |
345 | }); | 340 | }); |
346 | |||
347 | // Register App URL | ||
348 | app.setAsDefaultProtocolClient('franz'); | ||