From 994c3b3c92ccb510facd726a3ceecdb987263f79 Mon Sep 17 00:00:00 2001 From: V Date: Tue, 4 Jul 2023 17:52:52 +0200 Subject: [PATCH] OpenInApp: Fix bot buttons --- src/plugins/openInApp.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/openInApp.ts b/src/plugins/openInApp.ts index f3a59835..7d3d7d1c 100644 --- a/src/plugins/openInApp.ts +++ b/src/plugins/openInApp.ts @@ -20,7 +20,6 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { showToast, Toasts } from "@webpack/common"; -import { MouseEvent } from "react"; const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/; 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; let url = data.href; if (!IS_WEB && ShortUrlMatcher.test(url)) { - event.preventDefault(); + event?.preventDefault(); // CORS jumpscare url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url); } @@ -96,7 +95,7 @@ export default definePlugin({ const [, type, id] = match; VencordNative.native.openExternal(`spotify:${type}:${id}`); - event.preventDefault(); + event?.preventDefault(); return true; } @@ -106,7 +105,7 @@ export default definePlugin({ if (!SteamMatcher.test(url)) break steam; 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 showToast("Opened link in Steam", Toasts.Type.SUCCESS); @@ -120,13 +119,13 @@ export default definePlugin({ if (!match) break epic; VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`); - event.preventDefault(); + event?.preventDefault(); return true; } // in case short url didn't end up being something we can handle - if (event.defaultPrevented) { + if (event?.defaultPrevented) { window.open(url, "_blank"); return true; }