From c197661be082acfb6fa5223bd9f3898a16c31111 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Mon, 2 Mar 2020 14:59:55 +0000
Subject: [PATCH 1/4] riot-desktop open SSO in browser so user doesn't have to
auth twice
---
src/i18n/strings/en_EN.json | 2 ++
src/vector/platform/ElectronPlatform.js | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index 523e4551..635374d2 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -7,6 +7,8 @@
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",
+ "Single sign-on": "Single sign-on",
+ "Go to the browser to complete login": "Go to the browser to complete login",
"Unknown device": "Unknown device",
"%(appName)s via %(browserName)s on %(osName)s": "%(appName)s via %(browserName)s on %(osName)s",
"You need to be using HTTPS to place a screen-sharing call.": "You need to be using HTTPS to place a screen-sharing call.",
diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js
index 8e29542a..46332c1e 100644
--- a/src/vector/platform/ElectronPlatform.js
+++ b/src/vector/platform/ElectronPlatform.js
@@ -5,6 +5,7 @@ Copyright 2016 Aviral Dasgupta
Copyright 2016 OpenMarket Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
+`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.
@@ -24,6 +25,11 @@ import BaseEventIndexManager from 'matrix-react-sdk/src/indexing/BaseEventIndexM
import dis from 'matrix-react-sdk/src/dispatcher';
import { _t } from 'matrix-react-sdk/src/languageHandler';
import * as rageshake from 'matrix-react-sdk/src/rageshake/rageshake';
+import {MatrixClient} from "matrix-js-sdk";
+import Modal from "matrix-react-sdk/src/Modal";
+import InfoDialog from "matrix-react-sdk/src/components/views/dialogs/InfoDialog";
+import Spinner from "matrix-react-sdk/src/components/views/elements/Spinner";
+import React from "react";
const ipcRenderer = window.ipcRenderer;
@@ -392,4 +398,21 @@ export default class ElectronPlatform extends VectorBasePlatform {
console.error(error);
});
}
+
+ getSSOCallbackUrl(hsUrl: string, isUrl: string): URL {
+ const url = super.getSSOCallbackUrl(hsUrl, isUrl);
+ url.protocol = "riot";
+ return url;
+ }
+
+ startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas") {
+ super.startSingleSignOn(mxClient, loginType); // this will get intercepted by electron-main will-navigate
+ Modal.createTrackedDialog('Electron', 'SSO', InfoDialog, {
+ title: _t("Single sign-on"),
+ description:
+ {_t("Go to the browser to complete login")}
+
+
,
+ });
+ }
}
From 178c61dbf749a0d5aa23498f249d31d6859fcb2b Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Mon, 2 Mar 2020 15:01:06 +0000
Subject: [PATCH 2/4] fix typo
---
src/vector/platform/ElectronPlatform.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js
index 46332c1e..6662b4bc 100644
--- a/src/vector/platform/ElectronPlatform.js
+++ b/src/vector/platform/ElectronPlatform.js
@@ -5,7 +5,7 @@ Copyright 2016 Aviral Dasgupta
Copyright 2016 OpenMarket Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
-`Copyright 2020 The Matrix.org Foundation C.I.C.
+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.
From 09ed0e781ab0609e138eca17a5448d14c3fe1b68 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Mon, 2 Mar 2020 20:04:31 +0000
Subject: [PATCH 3/4] Update copy for SSO modal
---
src/i18n/strings/en_EN.json | 3 +--
src/vector/platform/ElectronPlatform.js | 7 ++-----
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index 635374d2..36f19a75 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -7,8 +7,7 @@
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",
- "Single sign-on": "Single sign-on",
- "Go to the browser to complete login": "Go to the browser to complete login",
+ "Go to your browser to complete Sign In": "Go to your browser to complete Sign In",
"Unknown device": "Unknown device",
"%(appName)s via %(browserName)s on %(osName)s": "%(appName)s via %(browserName)s on %(osName)s",
"You need to be using HTTPS to place a screen-sharing call.": "You need to be using HTTPS to place a screen-sharing call.",
diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js
index 6662b4bc..0d644aa4 100644
--- a/src/vector/platform/ElectronPlatform.js
+++ b/src/vector/platform/ElectronPlatform.js
@@ -408,11 +408,8 @@ export default class ElectronPlatform extends VectorBasePlatform {
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas") {
super.startSingleSignOn(mxClient, loginType); // this will get intercepted by electron-main will-navigate
Modal.createTrackedDialog('Electron', 'SSO', InfoDialog, {
- title: _t("Single sign-on"),
- description:
- {_t("Go to the browser to complete login")}
-
-
,
+ title: _t("Go to your browser to complete Sign In"),
+ description: ,
});
}
}
From bb6afd7c3040b7d6ac7e82ce14f2d6d064abfd18 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Mon, 2 Mar 2020 20:16:41 +0000
Subject: [PATCH 4/4] backport riot-desktop implementation into riot-web
---
electron_app/src/electron-main.js | 4 ++
electron_app/src/protocol.js | 53 +++++++++++++++++++++++++
electron_app/src/webcontents-handler.js | 6 ++-
package.json | 6 ++-
4 files changed, 66 insertions(+), 3 deletions(-)
create mode 100644 electron_app/src/protocol.js
diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js
index 2715a14c..91258c6c 100644
--- a/electron_app/src/electron-main.js
+++ b/electron_app/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');
@@ -427,6 +428,9 @@ if (!gotLock) {
app.exit();
}
+// do this after we know we are the primary instance of the app
+protocolInit();
+
const launcher = new AutoLaunch({
name: vectorConfig.brand || 'Riot',
isHidden: true,
diff --git a/electron_app/src/protocol.js b/electron_app/src/protocol.js
new file mode 100644
index 00000000..153ff640
--- /dev/null
+++ b/electron_app/src/protocol.js
@@ -0,0 +1,53 @@
+/*
+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
+ // 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 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
+ app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]);
+ }
+
+ 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;
+ processUrl(url);
+ });
+ }
+};
+
+
diff --git a/electron_app/src/webcontents-handler.js b/electron_app/src/webcontents-handler.js
index f0aaf4a4..782d12e5 100644
--- a/electron_app/src/webcontents-handler.js
+++ b/electron_app/src/webcontents-handler.js
@@ -174,8 +174,10 @@ function onEditableContextMenu(ev, params) {
module.exports = (webContents) => {
webContents.on('new-window', onWindowOrNavigate);
- // XXX: https://github.com/vector-im/riot-web/issues/8247
- // 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) {
diff --git a/package.json b/package.json
index e008efd8..a731ddf8 100644
--- a/package.json
+++ b/package.json
@@ -188,7 +188,11 @@
"output": "electron_app/dist",
"app": "electron_app"
},
- "afterSign": "scripts/electron_afterSign.js"
+ "afterSign": "scripts/electron_afterSign.js",
+ "protocols": [{
+ "name": "riot",
+ "schemes": ["riot"]
+ }]
},
"jest": {
"modulePathIgnorePatterns": [