OpenInApp: Fix bot buttons

This commit is contained in:
V 2023-07-04 17:52:52 +02:00
parent c696c186e8
commit 994c3b3c92
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905

@ -20,7 +20,6 @@ import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { showToast, Toasts } from "@webpack/common"; import { showToast, Toasts } from "@webpack/common";
import { MouseEvent } from "react";
const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/; const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/(.+)(?:\?.+?)?$/; const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/(.+)(?:\?.+?)?$/;
@ -77,12 +76,12 @@ export default definePlugin({
} }
], ],
async handleLink(data: { href: string; }, event: MouseEvent) { async handleLink(data: { href: string; }, event?: MouseEvent) {
if (!data) return false; if (!data) return false;
let url = data.href; let url = data.href;
if (!IS_WEB && ShortUrlMatcher.test(url)) { if (!IS_WEB && ShortUrlMatcher.test(url)) {
event.preventDefault(); event?.preventDefault();
// CORS jumpscare // CORS jumpscare
url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url); url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url);
} }
@ -96,7 +95,7 @@ export default definePlugin({
const [, type, id] = match; const [, type, id] = match;
VencordNative.native.openExternal(`spotify:${type}:${id}`); VencordNative.native.openExternal(`spotify:${type}:${id}`);
event.preventDefault(); event?.preventDefault();
return true; return true;
} }
@ -106,7 +105,7 @@ export default definePlugin({
if (!SteamMatcher.test(url)) break steam; if (!SteamMatcher.test(url)) break steam;
VencordNative.native.openExternal(`steam://openurl/${url}`); VencordNative.native.openExternal(`steam://openurl/${url}`);
event.preventDefault(); event?.preventDefault();
// Steam does not focus itself so show a toast so it's slightly less confusing // Steam does not focus itself so show a toast so it's slightly less confusing
showToast("Opened link in Steam", Toasts.Type.SUCCESS); showToast("Opened link in Steam", Toasts.Type.SUCCESS);
@ -120,13 +119,13 @@ export default definePlugin({
if (!match) break epic; if (!match) break epic;
VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`); VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`);
event.preventDefault(); event?.preventDefault();
return true; return true;
} }
// in case short url didn't end up being something we can handle // in case short url didn't end up being something we can handle
if (event.defaultPrevented) { if (event?.defaultPrevented) {
window.open(url, "_blank"); window.open(url, "_blank");
return true; return true;
} }