From 4aa33a127dea9cc2933e5cd733e24a586b81ac06 Mon Sep 17 00:00:00 2001 From: David Meza Date: Mon, 9 Oct 2017 16:33:02 -0500 Subject: [PATCH] Make deepliking work on windows --- src/main.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index e35c5f1f..c579d9ee 100644 --- a/src/main.js +++ b/src/main.js @@ -154,7 +154,10 @@ if (app.makeSingleInstance((commandLine/*, workingDirectory*/) => { // argv: An array of the second instance’s (command line / deep linked) arguments if (process.platform === 'win32') { // Keep only command line / deep linked arguments - deeplinkingUrl = commandLine.slice(1); + if (Array.isArray(commandLine.slice(1)) && commandLine.slice(1).length > 0) { + setDeeplinkingUrl(commandLine.slice(1)[0]); + mainWindow.webContents.send('protocol-deeplink', deeplinkingUrl); + } } // Someone tried to run a second instance, we should focus our window. @@ -327,12 +330,16 @@ ipcMain.on('download-url', (event, URL) => { }); }); -app.setAsDefaultProtocolClient('Mattermost'); +app.setAsDefaultProtocolClient('mattermost'); + +function setDeeplinkingUrl(url) { + deeplinkingUrl = url.replace('mattermost', 'https'); +} // Protocol handler for osx -app.on('open-url', function(event, url) { +app.on('open-url', (event, url) => { event.preventDefault(); - deeplinkingUrl = url.replace('Mattermost', 'https'); + setDeeplinkingUrl(url); mainWindow.webContents.send('protocol-deeplink', deeplinkingUrl); }); @@ -351,7 +358,9 @@ app.on('ready', () => { // Protocol handler for win32 if (process.platform === 'win32') { // Keep only command line / deep linked arguments - deeplinkingUrl = process.argv.slice(1); + if (Array.isArray(process.argv.slice(1)) && process.argv.slice(1).length > 0) { + setDeeplinkingUrl(process.argv.slice(1)[0]); + } } mainWindow = createMainWindow(config, { @@ -359,6 +368,7 @@ app.on('ready', () => { linuxAppIcon: path.join(assetsDir, 'appicon.png'), deeplinkingUrl }); + mainWindow.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time