OpenInApp: Add Epic Games; properly respect settings

This commit is contained in:
V 2023-06-30 15:16:42 +02:00
parent 73354973a3
commit b592defaaf
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
2 changed files with 24 additions and 6 deletions

View file

@ -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");

View file

@ -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();