diff options
author | V <vendicated@riseup.net> | 2023-06-30 15:16:42 +0200 |
---|---|---|
committer | V <vendicated@riseup.net> | 2023-06-30 15:16:42 +0200 |
commit | b592defaaf5f92c942b6c2dc3f39c4761a823ca3 (patch) | |
tree | 93e506bf122dee672d2ffe2646c201dae81c464d | |
parent | 73354973a37a03fffa5acacd49c9251008efbba8 (diff) | |
download | Vencord-b592defaaf5f92c942b6c2dc3f39c4761a823ca3.tar.gz Vencord-b592defaaf5f92c942b6c2dc3f39c4761a823ca3.tar.bz2 Vencord-b592defaaf5f92c942b6c2dc3f39c4761a823ca3.zip |
OpenInApp: Add Epic Games; properly respect settings
-rw-r--r-- | src/main/utils/constants.ts | 3 | ||||
-rw-r--r-- | src/plugins/openInApp.ts | 27 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/main/utils/constants.ts b/src/main/utils/constants.ts index cc9f459..8ebf7f4 100644 --- a/src/main/utils/constants.ts +++ b/src/main/utils/constants.ts @@ -31,7 +31,8 @@ export const ALLOWED_PROTOCOLS = [ "https:", "http:", "steam:", - "spotify:" + "spotify:", + "com.epicgames.launcher:", ]; export const IS_VANILLA = /* @__PURE__ */ process.argv.includes("--vanilla"); diff --git a/src/plugins/openInApp.ts b/src/plugins/openInApp.ts index 52b418f..f3a5983 100644 --- a/src/plugins/openInApp.ts +++ b/src/plugins/openInApp.ts @@ -25,6 +25,7 @@ import { MouseEvent } from "react"; const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/; const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/(.+)(?:\?.+?)?$/; const SteamMatcher = /^https:\/\/(steamcommunity\.com|(?:help|store)\.steampowered\.com)\/.+$/; +const EpicMatcher = /^https:\/\/store\.epicgames\.com\/(.+)$/; const settings = definePluginSettings({ spotify: { @@ -36,12 +37,17 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, description: "Open Steam links in the Steam app", default: true, + }, + epic: { + type: OptionType.BOOLEAN, + description: "Open Epic Games links in the Epic Games Launcher", + default: true, } }); export default definePlugin({ name: "OpenInApp", - description: "Open Spotify and Steam URLs in the Spotify and Steam app instead of your Browser", + description: "Open Spotify, Steam and Epic Games URLs in their respective apps instead of your browser", authors: [Devs.Ven], settings, @@ -56,7 +62,7 @@ export default definePlugin({ // Make Spotify profile activity links open in app on web { find: "WEB_OPEN(", - predicate: () => !IS_DISCORD_DESKTOP, + predicate: () => !IS_DISCORD_DESKTOP && settings.store.spotify, replacement: { match: /\i\.\i\.isProtocolRegistered\(\)(.{0,100})window.open/g, replace: "true$1VencordNative.native.openExternal" @@ -100,7 +106,6 @@ export default definePlugin({ if (!SteamMatcher.test(url)) break steam; VencordNative.native.openExternal(`steam://openurl/${url}`); - event.preventDefault(); // Steam does not focus itself so show a toast so it's slightly less confusing @@ -108,6 +113,18 @@ export default definePlugin({ return true; } + epic: { + if (!settings.store.epic) break epic; + + const match = EpicMatcher.exec(url); + if (!match) break epic; + + VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`); + event.preventDefault(); + + return true; + } + // in case short url didn't end up being something we can handle if (event.defaultPrevented) { window.open(url, "_blank"); @@ -118,10 +135,10 @@ export default definePlugin({ }, handleAccountView(event: { preventDefault(): void; }, platformType: string, userId: string) { - if (platformType === "spotify") { + if (platformType === "spotify" && settings.store.spotify) { VencordNative.native.openExternal(`spotify:user:${userId}`); event.preventDefault(); - } else if (platformType === "steam") { + } else if (platformType === "steam" && settings.store.steam) { VencordNative.native.openExternal(`steam://openurl/https://steamcommunity.com/profiles/${userId}`); showToast("Opened link in Steam", Toasts.Type.SUCCESS); event.preventDefault(); |