forked from matrix/element-web
rejig
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
8ca9e4ccb1
commit
67cf1e7536
|
@ -35,7 +35,7 @@ const tray = require('./tray');
|
||||||
const vectorMenu = require('./vectormenu');
|
const vectorMenu = require('./vectormenu');
|
||||||
const webContentsHandler = require('./webcontents-handler');
|
const webContentsHandler = require('./webcontents-handler');
|
||||||
const updater = require('./updater');
|
const updater = require('./updater');
|
||||||
const protocolInit = require('./protocol');
|
const {getProfileFromDeeplink, protocolInit} = require('./protocol');
|
||||||
|
|
||||||
const windowStateKeeper = require('electron-window-state');
|
const windowStateKeeper = require('electron-window-state');
|
||||||
const Store = require('electron-store');
|
const Store = require('electron-store');
|
||||||
|
@ -69,12 +69,9 @@ if (argv["help"]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we are passed a profile in the SSO callback url
|
// check if we are passed a profile in the SSO callback url
|
||||||
const deeplinkUrl = argv["_"].find(arg => arg.startsWith('riot://'));
|
const userDataPathInProtocol = getProfileFromDeeplink(argv["_"]);
|
||||||
if (deeplinkUrl && deeplinkUrl.includes('riot-desktop-user-data-path')) {
|
if (userDataPathInProtocol) {
|
||||||
const parsedUrl = new URL(deeplinkUrl);
|
app.setPath('userData', userDataPathInProtocol);
|
||||||
if (parsedUrl.protocol === 'riot:') {
|
|
||||||
app.setPath('userData', parsedUrl.searchParams.get('riot-desktop-user-data-path'));
|
|
||||||
}
|
|
||||||
} else if (argv['profile-dir']) {
|
} 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']) {
|
||||||
|
|
|
@ -16,38 +16,55 @@ limitations under the License.
|
||||||
|
|
||||||
const {app} = require('electron');
|
const {app} = require('electron');
|
||||||
|
|
||||||
|
const PROTOCOL = "riot://";
|
||||||
|
const SEARCH_PARAM = "riot-desktop-user-data-path";
|
||||||
|
|
||||||
const processUrl = (url) => {
|
const processUrl = (url) => {
|
||||||
if (!global.mainWindow) return;
|
if (!global.mainWindow) return;
|
||||||
console.log("Handling link: ", url);
|
console.log("Handling link: ", url);
|
||||||
global.mainWindow.loadURL(url.replace("riot://", "vector://"));
|
global.mainWindow.loadURL(url.replace(PROTOCOL, "vector://"));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = {
|
||||||
// get all args except `hidden` as it'd mean the app would not get focused
|
getProfileFromDeeplink: (args) => {
|
||||||
// XXX: passing args to protocol handlers only works on Windows,
|
// check if we are passed a profile in the SSO callback url
|
||||||
// so unpackaged deep-linking and --profile passing won't work on Mac/Linux
|
const deeplinkUrl = args.find(arg => arg.startsWith('riot://'));
|
||||||
const args = process.argv.slice(1).filter(arg => arg !== "--hidden" && arg !== "-hidden");
|
if (deeplinkUrl && deeplinkUrl.includes(SEARCH_PARAM)) {
|
||||||
if (app.isPackaged) {
|
const parsedUrl = new URL(deeplinkUrl);
|
||||||
app.setAsDefaultProtocolClient('riot', process.execPath, args);
|
if (parsedUrl.protocol === 'riot:') {
|
||||||
} else if (process.platform === 'win32') { // on Mac/Linux this would just cause the electron binary to open
|
const profile = parsedUrl.searchParams.get(SEARCH_PARAM);
|
||||||
// special handler for running without being packaged, e.g `electron .` by passing our app path to electron
|
console.log("Forwarding to profile: ", profile);
|
||||||
app.setAsDefaultProtocolClient('riot', process.execPath, [app.getAppPath(), ...args]);
|
return profile;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
protocolInit: () => {
|
||||||
|
// 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
|
||||||
|
// --profile/--profile-dir are passed via the SEARCH_PARAM var in the callback url
|
||||||
|
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') {
|
if (process.platform === 'darwin') {
|
||||||
// Protocol handler for macos
|
// Protocol handler for macos
|
||||||
app.on('open-url', function(ev, url) {
|
app.on('open-url', function(ev, url) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
processUrl(url);
|
processUrl(url);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Protocol handler for win32/Linux
|
// Protocol handler for win32/Linux
|
||||||
app.on('second-instance', (ev, commandLine) => {
|
app.on('second-instance', (ev, commandLine) => {
|
||||||
const url = commandLine[commandLine.length - 1];
|
const url = commandLine[commandLine.length - 1];
|
||||||
if (!url.startsWith("riot://")) return;
|
if (!url.startsWith(PROTOCOL)) return;
|
||||||
processUrl(url);
|
processUrl(url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue