Merge pull request #12590 from vector-im/t3chguy/sso

riot-desktop open SSO in browser so user doesn't have to auth twice
This commit is contained in:
Michael Telatynski 2020-03-03 22:27:46 +00:00 committed by GitHub
commit 48c8f16a4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 3 deletions

View file

@ -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,

View file

@ -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);
});
}
};

View file

@ -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) {