From abe074e43e69717b6fc307e04854eb0a8da15f7a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 15:04:51 +0000 Subject: [PATCH 1/8] riot-desktop open SSO in browser so user doesn't have to auth twice --- build/entitlements.mac.plist | 15 +++++++++++++++ package.json | 6 +++++- src/electron-main.js | 4 ++++ src/webcontents-handler.js | 17 ++++------------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/build/entitlements.mac.plist b/build/entitlements.mac.plist index 3fdab97..45940b5 100644 --- a/build/entitlements.mac.plist +++ b/build/entitlements.mac.plist @@ -24,5 +24,20 @@ com.apple.security.device.audio-input + + + CFBundleURLTypes + + + CFBundleURLSchemes + + riot + + CFBundleURLName + riot-web + CFBundleTypeRole + None + + diff --git a/package.json b/package.json index 5d5d88c..8188d93 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,10 @@ "directories": { "output": "dist" }, - "afterSign": "scripts/electron_afterSign.js" + "afterSign": "scripts/electron_afterSign.js", + "protocols": [{ + "name": "riot", + "schemes": ["riot"] + }] } } diff --git a/src/electron-main.js b/src/electron-main.js index 7350592..f518351 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -35,6 +35,7 @@ const tray = require('./tray'); const vectorMenu = require('./vectormenu'); const webContentsHandler = require('./webcontents-handler'); const updater = require('./updater'); +const protocolInit = require('./protocol'); const windowStateKeeper = require('electron-window-state'); const Store = require('electron-store'); @@ -511,6 +512,9 @@ if (!gotLock) { app.exit(); } +// do this after we know we are the primary instance of the app +protocolInit(); + // Register the scheme the app is served from as 'standard' // which allows things like relative URLs and IndexedDB to // work. diff --git a/src/webcontents-handler.js b/src/webcontents-handler.js index a749e0a..8030646 100644 --- a/src/webcontents-handler.js +++ b/src/webcontents-handler.js @@ -198,19 +198,10 @@ function onEditableContextMenu(ev, params) { module.exports = (webContents) => { webContents.on('new-window', onWindowOrNavigate); - // XXX: The below now does absolutely nothing because of - // https://github.com/electron/electron/issues/8841 - // Whilst this isn't a security issue since without - // node integration and with the sandbox, it should be - // no worse than opening the site in Chrome, it obviously - // means the user has to restart Riot to make it usable - // again (often unintuitive because it minimises to the - // system tray). We therefore need to be vigilant about - // putting target="_blank" on links in Riot (although - // we should generally be doing this anyway since links - // navigating you away from Riot in the browser is - // also annoying). - webContents.on('will-navigate', onWindowOrNavigate); + webContents.on('will-navigate', (ev, target) => { + if (target.startsWith("vector://")) return; + return onWindowOrNavigate(ev, target); + }); webContents.on('context-menu', function(ev, params) { if (params.linkURL || params.srcURL) { From d4dec89d24144671fce9f030c51d167e2b863819 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 15:20:51 +0000 Subject: [PATCH 2/8] bump to electron 8.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8188d93..2811afd 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ }, "build": { "appId": "im.riot.app", - "electronVersion": "8.0.1", + "electronVersion": "8.0.2", "files": [ "package.json", { From bbc44801c2198ace0409b50ac6035c5f4781416d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 15:49:37 +0000 Subject: [PATCH 3/8] add missing protocol.js --- src/protocol.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/protocol.js diff --git a/src/protocol.js b/src/protocol.js new file mode 100644 index 0000000..a001a5d --- /dev/null +++ b/src/protocol.js @@ -0,0 +1,51 @@ +/* +Copyright 2020 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +const {app} = require('electron'); + +const processUrl = (url) => { + if (!global.mainWindow) return; + console.log("Handling link: ", url); + global.mainWindow.loadURL(url.replace("riot://", "vector://")); +}; + +module.exports = () => { + // get all args except `hidden` as it'd mean the app would not get focused + const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden"); + if (app.isPackaged) { + app.setAsDefaultProtocolClient('riot', process.execPath, args); + } else { + // special handler for running without being packaged, e.g `electron .` by passing our app path to electron + app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]); + } + + // Protocol handler for macos + app.on('open-url', function(ev, url) { + ev.preventDefault(); + processUrl(url); + }); + + // Protocol handler for win32/Linux + if (process.platform !== 'darwin') { + app.on('second-instance', (ev, commandLine) => { + const url = commandLine[commandLine.length - 1]; + if (!url.startsWith("riot://")) return; + processUrl(url); + }); + } +}; + + From 1f1cf95906d21fd5668dabf39ed1a4863f935c8f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 16:34:04 +0000 Subject: [PATCH 4/8] Fix entitlements.mac.plist --- build/entitlements.mac.plist | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/build/entitlements.mac.plist b/build/entitlements.mac.plist index 45940b5..3fdab97 100644 --- a/build/entitlements.mac.plist +++ b/build/entitlements.mac.plist @@ -24,20 +24,5 @@ com.apple.security.device.audio-input - - - CFBundleURLTypes - - - CFBundleURLSchemes - - riot - - CFBundleURLName - riot-web - CFBundleTypeRole - None - - From eac811845222065e5f6976fa1adfbb2a3fff6071 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 16:45:28 +0000 Subject: [PATCH 5/8] Small comment tweaks --- scripts/in-docker.sh | 2 +- src/protocol.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/in-docker.sh b/scripts/in-docker.sh index 499a7b8..9758fc3 100755 --- a/scripts/in-docker.sh +++ b/scripts/in-docker.sh @@ -2,7 +2,7 @@ docker inspect riot-desktop-dockerbuild 2> /dev/null > /dev/null if [ $? != 0 ]; then - echo "Docker image riot-desktop-builder not found. Have you run yarn run docker:setup?" + echo "Docker image riot-desktop-dockerbuild not found. Have you run yarn run docker:setup?" exit 1 fi diff --git a/src/protocol.js b/src/protocol.js index a001a5d..78d3408 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -24,6 +24,7 @@ const processUrl = (url) => { module.exports = () => { // get all args except `hidden` as it'd mean the app would not get focused + // XXX: passing args to protocol handlers only works on Windows, so unpackaged deep-linking won't work on Mac/Linux const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden"); if (app.isPackaged) { app.setAsDefaultProtocolClient('riot', process.execPath, args); From d7ebad284e38d98338728b945af7756f04134542 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 16:46:50 +0000 Subject: [PATCH 6/8] update comment --- src/protocol.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/protocol.js b/src/protocol.js index 78d3408..f05d3f1 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -24,12 +24,13 @@ const processUrl = (url) => { module.exports = () => { // get all args except `hidden` as it'd mean the app would not get focused - // XXX: passing args to protocol handlers only works on Windows, so unpackaged deep-linking won't work on Mac/Linux const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden"); if (app.isPackaged) { app.setAsDefaultProtocolClient('riot', process.execPath, args); } else { // special handler for running without being packaged, e.g `electron .` by passing our app path to electron + // XXX: passing args to protocol handlers only works on Windows, + // so unpackaged (electron .) deep-linking won't work on Mac/Linux app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]); } From dd450082913ed344cd87d146401616bc75fa3719 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 16:49:04 +0000 Subject: [PATCH 7/8] update comments and win32 specialcase --- src/protocol.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index f05d3f1..de7f0b7 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -24,13 +24,13 @@ const processUrl = (url) => { module.exports = () => { // get all args except `hidden` as it'd mean the app would not get focused + // XXX: passing args to protocol handlers only works on Windows, + // so unpackaged deep-linking and --profile passing won't work on Mac/Linux const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden"); if (app.isPackaged) { app.setAsDefaultProtocolClient('riot', process.execPath, args); - } else { + } else if (process.platform === 'win32') { // on Mac/Linux this would just cause the electron binary to open // special handler for running without being packaged, e.g `electron .` by passing our app path to electron - // XXX: passing args to protocol handlers only works on Windows, - // so unpackaged (electron .) deep-linking won't work on Mac/Linux app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]); } From 4b8b32c3e5dfac48bd4f35ac9d8ef7ff4754de36 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Mar 2020 16:49:55 +0000 Subject: [PATCH 8/8] only register open-url handler on macos --- src/protocol.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index de7f0b7..153ff64 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -34,14 +34,14 @@ module.exports = () => { app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]); } - // Protocol handler for macos - app.on('open-url', function(ev, url) { - ev.preventDefault(); - processUrl(url); - }); - - // Protocol handler for win32/Linux - if (process.platform !== 'darwin') { + if (process.platform === 'darwin') { + // Protocol handler for macos + app.on('open-url', function(ev, url) { + ev.preventDefault(); + processUrl(url); + }); + } else { + // Protocol handler for win32/Linux app.on('second-instance', (ev, commandLine) => { const url = commandLine[commandLine.length - 1]; if (!url.startsWith("riot://")) return;