From c36b639296f793bed04db2b692ee770e6a86d45e Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Mon, 21 May 2018 13:27:53 +0530 Subject: [PATCH] ELECTRON-500 / ELECTRON-384: fix protocol handler non-window use case (#372) - fix issue in protocol handler when app is not initialized - fix formatting issues --- js/main.js | 8 ++++---- js/protocolHandler/index.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/js/main.js b/js/main.js index 4aaa3a67..6a7a4187 100644 --- a/js/main.js +++ b/js/main.js @@ -364,17 +364,15 @@ function processProtocolAction(argv) { } let protocolUri = getCmdLineArg(argv, 'symphony://', false); + log.send(logLevels.INFO, `Trying to process a protocol action for uri ${protocolUri}`); if (protocolUri) { - const parsedURL = urlParser.parse(protocolUri); - if (!parsedURL.protocol || !parsedURL.slashes) { return; } - + log.send(logLevels.INFO, `Parsing protocol url successful for ${parsedURL}`); handleProtocolAction(protocolUri); - } } @@ -384,10 +382,12 @@ function processProtocolAction(argv) { */ function handleProtocolAction(uri) { if (!isAppAlreadyOpen) { + log.send(logLevels.INFO, `App started by protocol url ${uri}. We are caching this to be processed later!`); // app is opened by the protocol url, cache the protocol url to be used later protocolHandler.setProtocolUrl(uri); } else { // app is already open, so, just trigger the protocol action method + log.send(logLevels.INFO, `App opened by protocol url ${uri}`); protocolHandler.processProtocolAction(uri); } } diff --git a/js/protocolHandler/index.js b/js/protocolHandler/index.js index e3c7269c..ba97c8ed 100644 --- a/js/protocolHandler/index.js +++ b/js/protocolHandler/index.js @@ -11,8 +11,13 @@ let protocolUrl; * @param {String} uri - the uri opened in the format 'symphony://...' */ function processProtocolAction(uri) { - log.send(logLevels.INFO, 'protocol action, uri=' + uri); - if (protocolWindow && uri && uri.startsWith('symphony://')) { + log.send(logLevels.INFO, `protocol action, uri ${uri}`); + if (!protocolWindow) { + log.send(logLevels.INFO, `protocol window not yet initialized, caching the uri ${uri}`); + setProtocolUrl(uri); + return; + } + if (uri && uri.startsWith('symphony://')) { protocolWindow.send('protocol-action', uri); } } @@ -29,7 +34,9 @@ function setProtocolWindow(win) { * checks to see if the app was opened by a uri */ function checkProtocolAction() { + log.send(logLevels.INFO, `checking if we have a cached protocol url`); if (protocolUrl) { + log.send(logLevels.INFO, `found a cached protocol url, processing it!`); processProtocolAction(protocolUrl); protocolUrl = undefined; }