Fix Electron SSO handling to support multiple profiles

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-04-04 00:22:15 +01:00
parent a377ca7b85
commit 8ca9e4ccb1
2 changed files with 21 additions and 1 deletions

View File

@ -68,7 +68,14 @@ if (argv["help"]) {
app.exit(); app.exit();
} }
if (argv['profile-dir']) { // check if we are passed a profile in the SSO callback url
const deeplinkUrl = argv["_"].find(arg => arg.startsWith('riot://'));
if (deeplinkUrl && deeplinkUrl.includes('riot-desktop-user-data-path')) {
const parsedUrl = new URL(deeplinkUrl);
if (parsedUrl.protocol === 'riot:') {
app.setPath('userData', parsedUrl.searchParams.get('riot-desktop-user-data-path'));
}
} else if (argv['profile-dir']) {
app.setPath('userData', argv['profile-dir']); app.setPath('userData', argv['profile-dir']);
} else if (argv['profile']) { } else if (argv['profile']) {
app.setPath('userData', `${app.getPath('userData')}-${argv['profile']}`); app.setPath('userData', `${app.getPath('userData')}-${argv['profile']}`);
@ -233,6 +240,11 @@ ipcMain.on('ipcCall', async function(ev, payload) {
case 'getConfig': case 'getConfig':
ret = vectorConfig; ret = vectorConfig;
break; break;
case 'getUserDataPath':
if (argv['profile-dir'] || argv['profile']) {
ret = app.getPath('userData');
}
break;
default: default:
mainWindow.webContents.send('ipcReply', { mainWindow.webContents.send('ipcReply', {

View File

@ -228,6 +228,11 @@ export default class ElectronPlatform extends VectorBasePlatform {
description: _td("Open user settings"), description: _td("Open user settings"),
}); });
} }
// we assume this happens before any SSO actions occur but do not block.
this._ipcCall('getUserDataPath').then(userDataPath => {
this.userDataPath = userDataPath;
});
} }
async getConfig(): Promise<{}> { async getConfig(): Promise<{}> {
@ -424,6 +429,9 @@ export default class ElectronPlatform extends VectorBasePlatform {
getSSOCallbackUrl(hsUrl: string, isUrl: string): URL { getSSOCallbackUrl(hsUrl: string, isUrl: string): URL {
const url = super.getSSOCallbackUrl(hsUrl, isUrl); const url = super.getSSOCallbackUrl(hsUrl, isUrl);
url.protocol = "riot"; url.protocol = "riot";
if (this.userDataPath) {
url.searchParams.set("riot-desktop-user-data-path", this.userDataPath);
}
return url; return url;
} }