diff options
author | V <vendicated@riseup.net> | 2023-06-29 16:06:21 +0200 |
---|---|---|
committer | V <vendicated@riseup.net> | 2023-06-29 16:15:07 +0200 |
commit | 73354973a37a03fffa5acacd49c9251008efbba8 (patch) | |
tree | 7ad74dff97a838aa12069d15f055c334567e8037 /src/main | |
parent | e12c0e546c9042bebc31431b3b870d3c036d744d (diff) | |
download | Vencord-73354973a37a03fffa5acacd49c9251008efbba8.tar.gz Vencord-73354973a37a03fffa5acacd49c9251008efbba8.tar.bz2 Vencord-73354973a37a03fffa5acacd49c9251008efbba8.zip |
OpenInApp: Support steam; integrate with SpotifyControls & ShowConnections
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/ipcMain.ts | 1 | ||||
-rw-r--r-- | src/main/ipcPlugins.ts | 46 |
2 files changed, 47 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>. +*/ + +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<string>((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 |