From 49cdd35696dcbe2a90c63dccc2d88db46e2aa8a9 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 5 Dec 2017 16:04:27 +0100 Subject: WIP: add deep linking --- src/index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 6a08e5e5a..4b6241f13 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ import { isDevMode, isWindows } from './environment'; import ipcApi from './electron/ipc-api'; import Tray from './lib/Tray'; import Settings from './electron/Settings'; +import handleDeepLink from './electron/deepLinking'; import { appId } from './package.json'; // eslint-disable-line import/no-unresolved import './electron/exception'; @@ -26,10 +27,18 @@ if (isWindows) { } // Force single window -const isSecondInstance = app.makeSingleInstance(() => { +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); + + console.log(url); + handleDeepLink(mainWindow, url); + } } }); @@ -70,7 +79,8 @@ const createWindow = () => { const trayIcon = new Tray(); // Initialize ipcApi - ipcApi({ mainWindow, settings, trayIcon }); + const franzIpcApi = ipcApi({ mainWindow, settings, trayIcon }); + console.log(franzIpcApi); // Manage Window State mainWindowState.manage(mainWindow); @@ -176,3 +186,15 @@ app.on('activate', () => { mainWindow.show(); } }); + +app.on('will-finish-launching', () => { + // Protocol handler for osx + app.on('open-url', (event, url) => { + event.preventDefault(); + console.log(`open-url event: ${url}`); + handleDeepLink(mainWindow, url); + }); +}); + +// Register App URL +app.setAsDefaultProtocolClient('franz'); -- cgit v1.2.3-54-g00ecf