From 3262ab46335ba42fe521c0b3f6165b87b990dbdd Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Mon, 11 Feb 2019 12:48:04 +0100 Subject: Add option to login via deep link --- src/index.js | 72 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 40 deletions(-) (limited to 'src/index.js') 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 { shell, ipcMain, } from 'electron'; - import fs from 'fs-extra'; import path from 'path'; import windowStateKeeper from 'electron-window-state'; @@ -44,6 +43,17 @@ const debug = require('debug')('Franz:App'); let mainWindow; let willQuitApp = false; +// Register methods to be called once the window has been loaded. +let onDidLoadFns = []; + +function onDidLoad(fn) { + if (onDidLoadFns) { + onDidLoadFns.push(fn); + } else if (mainWindow) { + fn(mainWindow); + } +} + // Ensure that the recipe directory exists fs.emptyDirSync(path.join(app.getPath('userData'), 'recipes', 'temp')); fs.ensureFileSync(path.join(app.getPath('userData'), 'window-state.json')); @@ -83,40 +93,7 @@ if (!gotTheLock) { } } }); - - // Create myWindow, load the rest of the app, etc... - app.on('ready', () => { - }); } -// const isSecondInstance = app.makeSingleInstance((argv) => { -// if (mainWindow) { -// if (mainWindow.isMinimized()) mainWindow.restore(); -// mainWindow.focus(); - -// if (process.platform === 'win32') { -// // Keep only command line / deep linked arguments -// const url = argv.slice(1); - -// if (url) { -// handleDeepLink(mainWindow, url.toString()); -// } -// } -// } - -// if (argv.includes('--reset-window')) { -// // Needs to be delayed to not interfere with mainWindow.restore(); -// setTimeout(() => { -// debug('Resetting windows via Task'); -// mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100); -// mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height); -// }, 1); -// } -// }); - -// if (isSecondInstance) { -// console.log('An instance of Franz is already running. Exiting...'); -// app.exit(); -// } // Fix Unity indicator issue // https://github.com/electron/electron/issues/9046 @@ -166,6 +143,14 @@ const createWindow = () => { }, }); + mainWindow.webContents.on('did-finish-load', () => { + const fns = onDidLoadFns; + onDidLoadFns = null; + for (const fn of fns) { + fn(mainWindow); + } + }); + // Initialize System Tray const trayIcon = new Tray(); @@ -259,6 +244,13 @@ const createWindow = () => { // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', () => { + // Register App URL + app.setAsDefaultProtocolClient('franz'); + + if (isDevMode) { + app.setAsDefaultProtocolClient('franz-dev'); + } + if (process.platform === 'win32') { app.setUserTasks([{ program: process.execPath, @@ -336,13 +328,13 @@ app.on('activate', () => { }); app.on('will-finish-launching', () => { - // Protocol handler for osx + // Protocol handler for macOS app.on('open-url', (event, url) => { event.preventDefault(); - console.log(`open-url event: ${url}`); - handleDeepLink(mainWindow, url); + + onDidLoad((window) => { + debug('open-url event', url); + handleDeepLink(window, url); + }); }); }); - -// Register App URL -app.setAsDefaultProtocolClient('franz'); -- cgit v1.2.3-70-g09d2