From b592defaaf5f92c942b6c2dc3f39c4761a823ca3 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 30 Jun 2023 15:16:42 +0200 Subject: [PATCH] OpenInApp: Add Epic Games; properly respect settings --- src/main/utils/constants.ts | 3 ++- 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 cc9f459c..8ebf7f47 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 52b418f2..f3a59835 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();