Skip to content

Commit 67cf1e7

Browse files
committed
rejig
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 8ca9e4c commit 67cf1e7

2 files changed

Lines changed: 48 additions & 34 deletions

File tree

‎electron_app/src/electron-main.js‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const tray = require('./tray');
3535
const vectorMenu = require('./vectormenu');
3636
const webContentsHandler = require('./webcontents-handler');
3737
const updater = require('./updater');
38-
const protocolInit = require('./protocol');
38+
const {getProfileFromDeeplink, protocolInit} = require('./protocol');
3939

4040
const windowStateKeeper = require('electron-window-state');
4141
const Store = require('electron-store');
@@ -69,12 +69,9 @@ if (argv["help"]) {
6969
}
7070

7171
// check if we are passed a profile in the SSO callback url
72-
const deeplinkUrl = argv["_"].find(arg => arg.startsWith('riot://'));
73-
if (deeplinkUrl && deeplinkUrl.includes('riot-desktop-user-data-path')) {
74-
const parsedUrl = new URL(deeplinkUrl);
75-
if (parsedUrl.protocol === 'riot:') {
76-
app.setPath('userData', parsedUrl.searchParams.get('riot-desktop-user-data-path'));
77-
}
72+
const userDataPathInProtocol = getProfileFromDeeplink(argv["_"]);
73+
if (userDataPathInProtocol) {
74+
app.setPath('userData', userDataPathInProtocol);
7875
} else if (argv['profile-dir']) {
7976
app.setPath('userData', argv['profile-dir']);
8077
} else if (argv['profile']) {

‎electron_app/src/protocol.js‎

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,55 @@ limitations under the License.
1616

1717
const {app} = require('electron');
1818

19+
const PROTOCOL = "riot://";
20+
const SEARCH_PARAM = "riot-desktop-user-data-path";
21+
1922
const processUrl = (url) => {
2023
if (!global.mainWindow) return;
2124
console.log("Handling link: ", url);
22-
global.mainWindow.loadURL(url.replace("riot://", "vector://"));
25+
global.mainWindow.loadURL(url.replace(PROTOCOL, "vector://"));
2326
};
2427

25-
module.exports = () => {
26-
// get all args except `hidden` as it'd mean the app would not get focused
27-
// XXX: passing args to protocol handlers only works on Windows,
28-
// so unpackaged deep-linking and --profile passing won't work on Mac/Linux
29-
const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden");
30-
if (app.isPackaged) {
31-
app.setAsDefaultProtocolClient('riot', process.execPath, args);
32-
} else if (process.platform === 'win32') { // on Mac/Linux this would just cause the electron binary to open
33-
// special handler for running without being packaged, e.g `electron .` by passing our app path to electron
34-
app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]);
35-
}
36-
37-
if (process.platform === 'darwin') {
38-
// Protocol handler for macos
39-
app.on('open-url', function(ev, url) {
40-
ev.preventDefault();
41-
processUrl(url);
42-
});
43-
} else {
44-
// Protocol handler for win32/Linux
45-
app.on('second-instance', (ev, commandLine) => {
46-
const url = commandLine[commandLine.length - 1];
47-
if (!url.startsWith("riot://")) return;
48-
processUrl(url);
49-
});
50-
}
28+
module.exports = {
29+
getProfileFromDeeplink: (args) => {
30+
// check if we are passed a profile in the SSO callback url
31+
const deeplinkUrl = args.find(arg => arg.startsWith('riot://'));
32+
if (deeplinkUrl && deeplinkUrl.includes(SEARCH_PARAM)) {
33+
const parsedUrl = new URL(deeplinkUrl);
34+
if (parsedUrl.protocol === 'riot:') {
35+
const profile = parsedUrl.searchParams.get(SEARCH_PARAM);
36+
console.log("Forwarding to profile: ", profile);
37+
return profile;
38+
}
39+
}
40+
},
41+
protocolInit: () => {
42+
// get all args except `hidden` as it'd mean the app would not get focused
43+
// XXX: passing args to protocol handlers only works on Windows, so unpackaged deep-linking
44+
// --profile/--profile-dir are passed via the SEARCH_PARAM var in the callback url
45+
const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden");
46+
if (app.isPackaged) {
47+
app.setAsDefaultProtocolClient('riot', process.execPath, args);
48+
} else if (process.platform === 'win32') { // on Mac/Linux this would just cause the electron binary to open
49+
// special handler for running without being packaged, e.g `electron .` by passing our app path to electron
50+
app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]);
51+
}
52+
53+
if (process.platform === 'darwin') {
54+
// Protocol handler for macos
55+
app.on('open-url', function(ev, url) {
56+
ev.preventDefault();
57+
processUrl(url);
58+
});
59+
} else {
60+
// Protocol handler for win32/Linux
61+
app.on('second-instance', (ev, commandLine) => {
62+
const url = commandLine[commandLine.length - 1];
63+
if (!url.startsWith(PROTOCOL)) return;
64+
processUrl(url);
65+
});
66+
}
67+
},
5168
};
5269

5370

0 commit comments

Comments
 (0)