arrpc: fix link handling

This commit is contained in:
Vendicated
2025-07-06 17:54:23 +02:00
parent 8aa91b4f01
commit 4baf6de472
3 changed files with 23 additions and 15 deletions

View File

@@ -29,19 +29,19 @@ export async function initArRPC() {
transferList: [workerPort] transferList: [workerPort]
}); });
hostPort.on("message", async (e: ArRpcEvent) => { hostPort.on("message", async ({ type, nonce, data }: ArRpcEvent) => {
switch (e.type) { switch (type) {
case "activity": { case "activity": {
sendRendererCommand(IpcCommands.RPC_ACTIVITY, e.data); sendRendererCommand(IpcCommands.RPC_ACTIVITY, data);
break; break;
} }
case "invite": { case "invite": {
const invite = String(e.data); const invite = String(data);
const response: ArRpcHostEvent = { const response: ArRpcHostEvent = {
type: "ack-invite", type: "ack-invite",
nonce: e.nonce, nonce,
data: false data: false
}; };
@@ -56,19 +56,13 @@ export async function initArRPC() {
} }
case "link": { case "link": {
const link = String(e.data);
const response: ArRpcHostEvent = { const response: ArRpcHostEvent = {
type: "ack-link", type: "ack-link",
nonce: e.nonce, nonce: nonce,
data: false data: false
}; };
if (!inviteCodeRegex.test(link)) { response.data = await sendRendererCommand(IpcCommands.RPC_DEEP_LINK, data).catch(() => false);
return hostPort.postMessage(response);
}
response.data = await sendRendererCommand(IpcCommands.RPC_DEEP_LINK, link).catch(() => false);
hostPort.postMessage(response); hostPort.postMessage(response);
break; break;

View File

@@ -9,6 +9,7 @@ export type ArRpcHostEvent = ArRpcHostAckInviteEvent | ArRpcHostAckLinkEvent;
export interface ArRpcActivityEvent { export interface ArRpcActivityEvent {
type: "activity"; type: "activity";
nonce: string;
data: string; data: string;
} }
@@ -21,7 +22,7 @@ export interface ArRpcInviteEvent {
export interface ArRpcLinkEvent { export interface ArRpcLinkEvent {
type: "link"; type: "link";
nonce: string; nonce: string;
data: string; data: any;
} }
export interface ArRpcHostAckInviteEvent { export interface ArRpcHostAckInviteEvent {

View File

@@ -26,7 +26,8 @@ const linkCallbacks = new Map<string, LinkCallback>();
server.on("activity", (data: any) => { server.on("activity", (data: any) => {
const event: ArRpcEvent = { const event: ArRpcEvent = {
type: "activity", type: "activity",
data: JSON.stringify(data) data: JSON.stringify(data),
nonce: randomUUID()
}; };
workerPort.postMessage(event); workerPort.postMessage(event);
}); });
@@ -43,6 +44,18 @@ const linkCallbacks = new Map<string, LinkCallback>();
workerPort.postMessage(event); workerPort.postMessage(event);
}); });
server.on("link", async (data: any, callback: LinkCallback) => {
const nonce = randomUUID();
linkCallbacks.set(nonce, callback);
const event: ArRpcEvent = {
type: "link",
data,
nonce
};
workerPort.postMessage(event);
});
workerPort.on("message", (e: ArRpcHostEvent) => { workerPort.on("message", (e: ArRpcHostEvent) => {
switch (e.type) { switch (e.type) {
case "ack-invite": { case "ack-invite": {