From 73354973a37a03fffa5acacd49c9251008efbba8 Mon Sep 17 00:00:00 2001 From: V Date: Thu, 29 Jun 2023 16:06:21 +0200 Subject: OpenInApp: Support steam; integrate with SpotifyControls & ShowConnections --- src/main/ipcMain.ts | 1 + src/main/ipcPlugins.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/ipcPlugins.ts (limited to 'src/main') diff --git a/src/main/ipcMain.ts b/src/main/ipcMain.ts index 5fcf8b7..d62888c 100644 --- a/src/main/ipcMain.ts +++ b/src/main/ipcMain.ts @@ -17,6 +17,7 @@ */ import "./updater"; +import "./ipcPlugins"; import { debounce } from "@utils/debounce"; import { IpcEvents } from "@utils/IpcEvents"; diff --git a/src/main/ipcPlugins.ts b/src/main/ipcPlugins.ts new file mode 100644 index 0000000..ac2f3d7 --- /dev/null +++ b/src/main/ipcPlugins.ts @@ -0,0 +1,46 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { IpcEvents } from "@utils/IpcEvents"; +import { ipcMain } from "electron"; +import { request } from "https"; + +// #region OpenInApp +// These links don't support CORS, so this has to be native +const validRedirectUrls = /^https:\/\/(spotify\.link|s\.team)\/.+$/; + +function getRedirect(url: string) { + return new Promise((resolve, reject) => { + const req = request(new URL(url), { method: "HEAD" }, res => { + resolve( + res.headers.location + ? getRedirect(res.headers.location) + : url + ); + }); + req.on("error", reject); + req.end(); + }); +} + +ipcMain.handle(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, async (_, url: string) => { + if (!validRedirectUrls.test(url)) return url; + + return getRedirect(url); +}); +// #endregion -- cgit