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
This commit is contained in:
Vishwas Shashidhar
2018-05-21 13:27:53 +05:30
committed by GitHub
parent 8037d16000
commit c36b639296
2 changed files with 13 additions and 6 deletions

View File

@@ -364,17 +364,15 @@ function processProtocolAction(argv) {
} }
let protocolUri = getCmdLineArg(argv, 'symphony://', false); let protocolUri = getCmdLineArg(argv, 'symphony://', false);
log.send(logLevels.INFO, `Trying to process a protocol action for uri ${protocolUri}`);
if (protocolUri) { if (protocolUri) {
const parsedURL = urlParser.parse(protocolUri); const parsedURL = urlParser.parse(protocolUri);
if (!parsedURL.protocol || !parsedURL.slashes) { if (!parsedURL.protocol || !parsedURL.slashes) {
return; return;
} }
log.send(logLevels.INFO, `Parsing protocol url successful for ${parsedURL}`);
handleProtocolAction(protocolUri); handleProtocolAction(protocolUri);
} }
} }
@@ -384,10 +382,12 @@ function processProtocolAction(argv) {
*/ */
function handleProtocolAction(uri) { function handleProtocolAction(uri) {
if (!isAppAlreadyOpen) { 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 // app is opened by the protocol url, cache the protocol url to be used later
protocolHandler.setProtocolUrl(uri); protocolHandler.setProtocolUrl(uri);
} else { } else {
// app is already open, so, just trigger the protocol action method // app is already open, so, just trigger the protocol action method
log.send(logLevels.INFO, `App opened by protocol url ${uri}`);
protocolHandler.processProtocolAction(uri); protocolHandler.processProtocolAction(uri);
} }
} }

View File

@@ -11,8 +11,13 @@ let protocolUrl;
* @param {String} uri - the uri opened in the format 'symphony://...' * @param {String} uri - the uri opened in the format 'symphony://...'
*/ */
function processProtocolAction(uri) { function processProtocolAction(uri) {
log.send(logLevels.INFO, 'protocol action, uri=' + uri); log.send(logLevels.INFO, `protocol action, uri ${uri}`);
if (protocolWindow && uri && uri.startsWith('symphony://')) { 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); protocolWindow.send('protocol-action', uri);
} }
} }
@@ -29,7 +34,9 @@ function setProtocolWindow(win) {
* checks to see if the app was opened by a uri * checks to see if the app was opened by a uri
*/ */
function checkProtocolAction() { function checkProtocolAction() {
log.send(logLevels.INFO, `checking if we have a cached protocol url`);
if (protocolUrl) { if (protocolUrl) {
log.send(logLevels.INFO, `found a cached protocol url, processing it!`);
processProtocolAction(protocolUrl); processProtocolAction(protocolUrl);
protocolUrl = undefined; protocolUrl = undefined;
} }