Support invite modal launch from web
This commit is contained in:
@@ -5,17 +5,36 @@
|
||||
*/
|
||||
|
||||
import Server from "arrpc";
|
||||
import { send as sendToBridge } from "arrpc/src/bridge";
|
||||
|
||||
import { mainWin } from "./mainWindow";
|
||||
import { Settings } from "./settings";
|
||||
|
||||
let server: any;
|
||||
|
||||
const inviteCodeRegex = /^(\w|-)+$/;
|
||||
|
||||
export async function initArRPC() {
|
||||
if (server || !Settings.store.arRPC) return;
|
||||
|
||||
server = await new Server();
|
||||
server.on("activity", sendToBridge);
|
||||
try {
|
||||
// This module starts a server as a side effect, so it needs to be lazy imported
|
||||
const { send: sendToBridge } = await import("arrpc/src/bridge");
|
||||
|
||||
server = await new Server();
|
||||
server.on("activity", sendToBridge);
|
||||
server.on("invite", (invite: string, callback: (valid: boolean) => void) => {
|
||||
invite = String(invite);
|
||||
if (!inviteCodeRegex.test(invite)) return callback(false);
|
||||
|
||||
mainWin.webContents
|
||||
// Safety: Result of JSON.stringify should always be safe to equal
|
||||
// Also, just to be super super safe, invite is regex validated above
|
||||
.executeJavaScript(`VencordDesktop.openInviteModal(${JSON.stringify(invite)})`)
|
||||
.then(callback);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Failed to start arRPC server", e);
|
||||
}
|
||||
}
|
||||
|
||||
Settings.addChangeListener("arRPC", initArRPC);
|
||||
|
||||
Reference in New Issue
Block a user