Skip to content

Commit

Permalink
Support schildichat protocol
Browse files Browse the repository at this point in the history
Currently, the desktop app supports element:// but there is no specific
protocol for schildichat.  This change adds support for schildichat:// in
addition to element://
  • Loading branch information
AndrewRyanChama committed Mar 4, 2022
1 parent 592337d commit 4114f60
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
16 changes: 15 additions & 1 deletion overlay-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@
"entitlements": "build/entitlements.mas.plist",
"provisioningProfile": "build/schildi_dev.provisionprofile",
"hardenedRuntime": false
}
},
"protocols": [
{
"name": "element",
"schemes": [
"element"
]
},
{
"name": "schildichat",
"schemes": [
"schildichat"
]
}
]
}
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@
"schemes": [
"element"
]
},
{
"name": "schildichat",
"schemes": [
"schildichat"
]
}
],
"deb": {
Expand Down
12 changes: 7 additions & 5 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { URL } from "url";
import path from "path";
import fs from "fs";

const PROTOCOL = "element:";
const PROTOCOLS = new Set(["element:", "schildichat:"]);
const SEARCH_PARAM = "element-desktop-ssoid";
const STORE_FILE_NAME = "sso-sessions.json";

Expand All @@ -33,7 +33,7 @@ function processUrl(url: string): void {
// 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
// with the Element app.
if (parsed.protocol !== PROTOCOL) {
if (!PROTOCOLS.has(parsed.protocol)) {
console.log("Ignoring unexpected protocol: ", parsed.protocol);
return;
}
Expand Down Expand Up @@ -82,10 +82,12 @@ export function recordSSOSession(sessionID: string): void {

export function getProfileFromDeeplink(args): string | undefined {
// 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 => [...PROTOCOLS]
.map(protocol => protocol + '//')
.some(prefix => arg.startsWith(prefix)));
if (deeplinkUrl && deeplinkUrl.includes(SEARCH_PARAM)) {
const parsedUrl = new URL(deeplinkUrl);
if (parsedUrl.protocol === PROTOCOL) {
if (PROTOCOLS.has(parsedUrl.protocol)) {
const ssoID = parsedUrl.searchParams.get(SEARCH_PARAM);
const store = readStore();
console.log("Forwarding to profile: ", store[ssoID]);
Expand Down Expand Up @@ -116,7 +118,7 @@ export function protocolInit(): void {
// Protocol handler for win32/Linux
app.on('second-instance', (ev, commandLine) => {
const url = commandLine[commandLine.length - 1];
if (!url.startsWith(PROTOCOL + '//')) return;
if (![...PROTOCOLS].map(protocol => protocol + '//').some(prefix => url.startsWith(prefix))) return;
processUrl(url);
});
}
Expand Down

0 comments on commit 4114f60

Please sign in to comment.