2017-05-13 13:23:44 -05:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-31 23:39:08 -05:00
|
|
|
const log = require('../log.js');
|
|
|
|
const logLevels = require('../enums/logLevels.js');
|
|
|
|
|
2017-05-13 13:23:44 -05:00
|
|
|
let protocolWindow;
|
|
|
|
let protocolUrl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* processes a protocol uri
|
|
|
|
* @param {String} uri - the uri opened in the format 'symphony://...'
|
|
|
|
*/
|
|
|
|
function processProtocolAction(uri) {
|
2018-05-21 02:57:53 -05:00
|
|
|
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://')) {
|
2017-05-13 13:23:44 -05:00
|
|
|
protocolWindow.send('protocol-action', uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets the protocol window
|
|
|
|
* @param {Object} win - the renderer window
|
|
|
|
*/
|
|
|
|
function setProtocolWindow(win) {
|
|
|
|
protocolWindow = win;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks to see if the app was opened by a uri
|
|
|
|
*/
|
|
|
|
function checkProtocolAction() {
|
2018-05-21 02:57:53 -05:00
|
|
|
log.send(logLevels.INFO, `checking if we have a cached protocol url`);
|
2017-05-13 13:23:44 -05:00
|
|
|
if (protocolUrl) {
|
2018-05-21 02:57:53 -05:00
|
|
|
log.send(logLevels.INFO, `found a cached protocol url, processing it!`);
|
2017-05-13 13:23:44 -05:00
|
|
|
processProtocolAction(protocolUrl);
|
|
|
|
protocolUrl = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* caches the protocol uri
|
|
|
|
* @param {String} uri - the uri opened in the format 'symphony://...'
|
|
|
|
*/
|
|
|
|
function setProtocolUrl(uri) {
|
|
|
|
protocolUrl = uri;
|
|
|
|
}
|
|
|
|
|
2017-08-24 05:48:32 -05:00
|
|
|
/**
|
|
|
|
* gets the protocol url set against an instance
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
2017-05-13 13:23:44 -05:00
|
|
|
function getProtocolUrl() {
|
|
|
|
return protocolUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
processProtocolAction: processProtocolAction,
|
|
|
|
setProtocolWindow: setProtocolWindow,
|
|
|
|
checkProtocolAction: checkProtocolAction,
|
|
|
|
setProtocolUrl: setProtocolUrl,
|
|
|
|
getProtocolUrl: getProtocolUrl
|
|
|
|
};
|