mirror of
https://github.com/element-hq/element-desktop
synced 2025-03-13 07:48:39 +01:00
Add support for io.element.desktop
scheme
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
f81adfea0c
commit
14b1510baa
@ -119,7 +119,7 @@ const config: Writable<Configuration> = {
|
|||||||
maintainer: "support@element.io",
|
maintainer: "support@element.io",
|
||||||
icon: "build/icons",
|
icon: "build/icons",
|
||||||
desktop: {
|
desktop: {
|
||||||
MimeType: "x-scheme-handler/element",
|
MimeType: "x-scheme-handler/io.element.desktop;x-scheme-handler/element",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
deb: {
|
deb: {
|
||||||
@ -167,7 +167,7 @@ const config: Writable<Configuration> = {
|
|||||||
protocols: [
|
protocols: [
|
||||||
{
|
{
|
||||||
name: "element",
|
name: "element",
|
||||||
schemes: ["element"],
|
schemes: ["io.element.desktop", "element"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,8 @@ import { URL } from "url";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
const PROTOCOL = "element:";
|
const LEGACY_PROTOCOL = "element";
|
||||||
|
const PROTOCOL = "io.element.desktop";
|
||||||
const SEARCH_PARAM = "element-desktop-ssoid";
|
const SEARCH_PARAM = "element-desktop-ssoid";
|
||||||
const STORE_FILE_NAME = "sso-sessions.json";
|
const STORE_FILE_NAME = "sso-sessions.json";
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ function processUrl(url: string): void {
|
|||||||
// sanity check: we only register for the one protocol, so we shouldn't
|
// sanity check: we only register for the one protocol, so we shouldn't
|
||||||
// be getting anything else unless the user is forcing a URL to open
|
// be getting anything else unless the user is forcing a URL to open
|
||||||
// with the Element app.
|
// with the Element app.
|
||||||
if (parsed.protocol !== PROTOCOL) {
|
if (parsed.protocol !== `${PROTOCOL}:` && parsed.protocol !== `${LEGACY_PROTOCOL}:`) {
|
||||||
console.log("Ignoring unexpected protocol: ", parsed.protocol);
|
console.log("Ignoring unexpected protocol: ", parsed.protocol);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,10 +83,10 @@ export function recordSSOSession(sessionID: string): void {
|
|||||||
|
|
||||||
export function getProfileFromDeeplink(args: string[]): string | undefined {
|
export function getProfileFromDeeplink(args: string[]): string | undefined {
|
||||||
// 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 = args.find((arg) => arg.startsWith(PROTOCOL + "//"));
|
const deeplinkUrl = args.find((arg) => arg.startsWith(`${PROTOCOL}://`) || arg.startsWith(`${LEGACY_PROTOCOL}://`));
|
||||||
if (deeplinkUrl?.includes(SEARCH_PARAM)) {
|
if (deeplinkUrl?.includes(SEARCH_PARAM)) {
|
||||||
const parsedUrl = new URL(deeplinkUrl);
|
const parsedUrl = new URL(deeplinkUrl);
|
||||||
if (parsedUrl.protocol === PROTOCOL) {
|
if (parsedUrl.protocol === `${PROTOCOL}:` || parsedUrl.protocol === `${LEGACY_PROTOCOL}:`) {
|
||||||
const store = readStore();
|
const store = readStore();
|
||||||
let ssoID = parsedUrl.searchParams.get(SEARCH_PARAM);
|
let ssoID = parsedUrl.searchParams.get(SEARCH_PARAM);
|
||||||
if (!ssoID) {
|
if (!ssoID) {
|
||||||
@ -105,11 +106,13 @@ export function protocolInit(): void {
|
|||||||
// --profile/--profile-dir are passed via the SEARCH_PARAM var in the callback url
|
// --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");
|
const args = process.argv.slice(1).filter((arg) => arg !== "--hidden" && arg !== "-hidden");
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
app.setAsDefaultProtocolClient("element", process.execPath, args);
|
app.setAsDefaultProtocolClient(PROTOCOL, process.execPath, args);
|
||||||
|
app.setAsDefaultProtocolClient(LEGACY_PROTOCOL, process.execPath, args);
|
||||||
} else if (process.platform === "win32") {
|
} else if (process.platform === "win32") {
|
||||||
// on Mac/Linux this would just cause the electron binary to open
|
// 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
|
// special handler for running without being packaged, e.g `electron .` by passing our app path to electron
|
||||||
app.setAsDefaultProtocolClient("element", process.execPath, [app.getAppPath(), ...args]);
|
app.setAsDefaultProtocolClient(PROTOCOL, process.execPath, [app.getAppPath(), ...args]);
|
||||||
|
app.setAsDefaultProtocolClient(LEGACY_PROTOCOL, process.execPath, [app.getAppPath(), ...args]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === "darwin") {
|
if (process.platform === "darwin") {
|
||||||
@ -122,7 +125,7 @@ export function protocolInit(): void {
|
|||||||
// 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(PROTOCOL + "//")) return;
|
if (!url.startsWith(`${PROTOCOL}://`) && !url.startsWith(`${LEGACY_PROTOCOL}://`)) return;
|
||||||
processUrl(url);
|
processUrl(url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user