From c4a3f6c02459805f35a1be6d652effb373c83d03 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 23 May 2017 08:06:18 -0700 Subject: [PATCH] simplify protocol handler api (#96) * simplify protocol handler api * update registerProtocolHandler doc * more documentation updates --- js/enums/api.js | 1 - js/mainApiMgr.js | 6 +----- js/preload/preloadMain.js | 31 +++++++++++++------------------ 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/js/enums/api.js b/js/enums/api.js index 269deb25..a48c1abd 100644 --- a/js/enums/api.js +++ b/js/enums/api.js @@ -10,7 +10,6 @@ const cmds = keyMirror({ activate: null, registerBoundsChange: null, registerProtocolHandler: null, - checkProtocolAction: null, registerActivityDetection: null, }); diff --git a/js/mainApiMgr.js b/js/mainApiMgr.js index 3d55d6f6..14811c89 100644 --- a/js/mainApiMgr.js +++ b/js/mainApiMgr.js @@ -70,13 +70,9 @@ electron.ipcMain.on(apiName, (event, arg) => { return; } - if (arg.cmd === apiCmds.checkProtocolAction) { - protocolHandler.checkProtocolAction(); - return; - } - if (arg.cmd === apiCmds.registerProtocolHandler) { protocolHandler.setProtocolWindow(event.sender); + protocolHandler.checkProtocolAction(); } if (arg.cmd === apiCmds.badgeDataUrl && typeof arg.dataUrl === 'string' && diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index ffc04c1d..0f78d090 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -32,13 +32,6 @@ const throttledSetBadgeCount = throttle(1000, function(count) { }); }); -// check to see if the app was opened via a url -const checkProtocolAction = function () { - local.ipcRenderer.send(apiName, { - cmd: apiCmds.checkProtocolAction - }); -}; - createAPI(); // creates API exposed from electron. @@ -83,13 +76,6 @@ function createAPI() { throttledSetBadgeCount(count); }, - /** - * checks to see if the app was opened from a url. - */ - checkProtocolAction: function () { - checkProtocolAction(); - }, - /** * provides api similar to html5 Notification, see details * in notify/notifyImpl.js @@ -149,11 +135,21 @@ function createAPI() { }, /** - * allows JS to register a protocol handler that can be used by the electron main process. - * @param protocolHandler {Object} protocolHandler a callback to register the protocol handler + * allows JS to register a protocol handler that can be used by the + * electron main process. + * + * @param protocolHandler {Function} callback will be called when app is + * invoked with registered protocol (e.g., symphony). The callback + * receives a single string argument: full uri that the app was + * invoked with e.g., symphony://?streamId=xyz123&streamType=chatroom + * + * Note: this function should only be called after client app is fully + * able for protocolHandler callback to be invoked. It is possible + * the app was started using protocol handler, in this case as soon as + * this registration func is invoked then the protocolHandler callback + * will be immediately called. */ registerProtocolHandler: function (protocolHandler) { - if (typeof protocolHandler === 'function') { local.processProtocolAction = protocolHandler; @@ -163,7 +159,6 @@ function createAPI() { }); } - }, /**