aboutsummaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
authorChristophe Hamerling <chamerling@linagora.com>2020-06-10 14:21:13 +0200
committerGitHub <noreply@github.com>2020-06-10 14:21:13 +0200
commitd12611d79cc21f5b7b3c900c3930dcffa2fa001e (patch)
tree7970bae46bfff32c53e2ad9723e9ee79b19c6383 /main.js
parentb662c93ac76eff9ffc989458df7d36dfb289007b (diff)
Add protocol to open conference links with the app
Co-authored-by: Christophe HAMERLING <chamerling@linagora.com> Co-authored-by: Klemens Arro <klemens.arro@admcloudtech.com> Co-authored-by: Goran Urukalo <goran.urukalo@teletrader.com>
Diffstat (limited to 'main.js')
-rw-r--r--main.js94
1 files changed, 93 insertions, 1 deletions
diff --git a/main.js b/main.js
index 296741d..0ca6cde 100644
--- a/main.js
+++ b/main.js
@@ -4,6 +4,7 @@ const {
BrowserWindow,
Menu,
app,
+ ipcMain,
shell
} = require('electron');
const contextMenu = require('electron-context-menu');
@@ -72,6 +73,14 @@ if (isDev) {
let mainWindow = null;
/**
+ * Add protocol data
+ */
+const appProtocolSurplus = `${config.default.appProtocolPrefix}://`;
+let rendererReady = false;
+let protocolDataForFrontApp = null;
+
+
+/**
* Sets the application menu. It is hidden on all platforms except macOS because
* otherwise copy and paste functionality is not available.
*/
@@ -211,6 +220,44 @@ function createJitsiMeetWindow() {
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
+
+ /**
+ * This is for windows [win32]
+ * so when someone tries to enter something like jitsi-meet://test
+ * while app is closed
+ * it will trigger this event below
+ */
+ if (process.platform === 'win32') {
+ handleProtocolCall(process.argv.pop());
+ }
+}
+
+/**
+ * Handler for application protocol links to initiate a conference.
+ */
+function handleProtocolCall(fullProtocolCall) {
+ // don't touch when something is bad
+ if (
+ !fullProtocolCall
+ || fullProtocolCall.trim() === ''
+ || fullProtocolCall.indexOf(appProtocolSurplus) !== 0
+ ) {
+ return;
+ }
+
+ const inputURL = fullProtocolCall.replace(appProtocolSurplus, '');
+
+ if (app.isReady() && mainWindow === null) {
+ createJitsiMeetWindow();
+ }
+
+ protocolDataForFrontApp = inputURL;
+
+ if (rendererReady) {
+ mainWindow
+ .webContents
+ .send('protocol-data-msg', inputURL);
+ }
}
/**
@@ -247,7 +294,7 @@ app.on('certificate-error',
app.on('ready', createJitsiMeetWindow);
-app.on('second-instance', () => {
+app.on('second-instance', (event, commandLine) => {
/**
* If someone creates second instance of the application, set focus on
* existing window.
@@ -255,6 +302,13 @@ app.on('second-instance', () => {
if (mainWindow) {
mainWindow.isMinimized() && mainWindow.restore();
mainWindow.focus();
+
+ /**
+ * This is for windows [win32]
+ * so when someone tries to enter something like jitsi-meet://test
+ * while app is opened it will trigger protocol handler.
+ */
+ handleProtocolCall(commandLine.pop());
}
});
@@ -264,3 +318,41 @@ app.on('window-all-closed', () => {
app.quit();
}
});
+
+// remove so we can register each time as we run the app.
+app.removeAsDefaultProtocolClient(config.default.appProtocolPrefix);
+
+// If we are running a non-packaged version of the app && on windows
+if (isDev && process.platform === 'win32') {
+ // Set the path of electron.exe and your app.
+ // These two additional parameters are only available on windows.
+ app.setAsDefaultProtocolClient(
+ config.default.appProtocolPrefix,
+ process.execPath,
+ [ path.resolve(process.argv[1]) ]
+ );
+} else {
+ app.setAsDefaultProtocolClient(config.default.appProtocolPrefix);
+}
+
+/**
+ * This is for mac [darwin]
+ * so when someone tries to enter something like jitsi-meet://test
+ * it will trigger this event below
+ */
+app.on('open-url', (event, data) => {
+ event.preventDefault();
+ handleProtocolCall(data);
+});
+
+/**
+ * This is to notify main.js [this] that front app is ready to receive messages.
+ */
+ipcMain.on('renderer-ready', () => {
+ rendererReady = true;
+ if (protocolDataForFrontApp) {
+ mainWindow
+ .webContents
+ .send('protocol-data-msg', protocolDataForFrontApp);
+ }
+});