aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-06-29 16:06:21 +0200
committerV <vendicated@riseup.net>2023-06-29 16:15:07 +0200
commit73354973a37a03fffa5acacd49c9251008efbba8 (patch)
tree7ad74dff97a838aa12069d15f055c334567e8037 /src/plugins
parente12c0e546c9042bebc31431b3b870d3c036d744d (diff)
downloadVencord-73354973a37a03fffa5acacd49c9251008efbba8.tar.gz
Vencord-73354973a37a03fffa5acacd49c9251008efbba8.tar.bz2
Vencord-73354973a37a03fffa5acacd49c9251008efbba8.zip
OpenInApp: Support steam; integrate with SpotifyControls & ShowConnections
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/openInApp.ts90
-rw-r--r--src/plugins/showConnections/index.tsx7
-rw-r--r--src/plugins/spotifyControls/PlayerComponent.tsx3
-rw-r--r--src/plugins/spotifyControls/SpotifyStore.ts2
4 files changed, 83 insertions, 19 deletions
diff --git a/src/plugins/openInApp.ts b/src/plugins/openInApp.ts
index 8249ed7..52b418f 100644
--- a/src/plugins/openInApp.ts
+++ b/src/plugins/openInApp.ts
@@ -16,22 +16,41 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
-import definePlugin from "@utils/types";
+import definePlugin, { OptionType } from "@utils/types";
+import { showToast, Toasts } from "@webpack/common";
+import { MouseEvent } from "react";
-const SpotifyMatcher = /https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/([^S]+)/;
+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 settings = definePluginSettings({
+ spotify: {
+ type: OptionType.BOOLEAN,
+ description: "Open Spotify links in the Spotify app",
+ default: true,
+ },
+ steam: {
+ type: OptionType.BOOLEAN,
+ description: "Open Steam links in the Steam app",
+ default: true,
+ }
+});
export default definePlugin({
name: "OpenInApp",
- description: "Open spotify URLs in app",
+ description: "Open Spotify and Steam URLs in the Spotify and Steam app instead of your Browser",
authors: [Devs.Ven],
+ settings,
patches: [
{
find: '"MaskedLinkStore"',
replacement: {
match: /return ((\i)\.apply\(this,arguments\))(?=\}function \i.{0,200}\.trusted)/,
- replace: "return $self.handleLink(...arguments)||$1"
+ replace: "return $self.handleLink(...arguments).then(handled => handled || $1)"
}
},
// Make Spotify profile activity links open in app on web
@@ -52,23 +71,60 @@ export default definePlugin({
}
],
- handleLink(data: { href: string; }, event: MouseEvent) {
- if (!data) return;
+ async handleLink(data: { href: string; }, event: MouseEvent) {
+ if (!data) return false;
+
+ let url = data.href;
+ if (!IS_WEB && ShortUrlMatcher.test(url)) {
+ event.preventDefault();
+ // CORS jumpscare
+ url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url);
+ }
- const match = SpotifyMatcher.exec(data.href);
- if (!match) return;
+ spotify: {
+ if (!settings.store.spotify) break spotify;
- const [, type, id] = match;
- VencordNative.native.openExternal(`spotify:${type}:${id}`);
- event.preventDefault();
+ const match = SpotifyMatcher.exec(url);
+ if (!match) break spotify;
- return Promise.resolve();
- },
+ const [, type, id] = match;
+ VencordNative.native.openExternal(`spotify:${type}:${id}`);
+
+ event.preventDefault();
+ return true;
+ }
+
+ steam: {
+ if (!settings.store.steam) break steam;
- handleAccountView(event: MouseEvent, platformType: string, otherUserId: string) {
- if (platformType !== "spotify") return;
+ if (!SteamMatcher.test(url)) break steam;
- VencordNative.native.openExternal(`spotify:user:${otherUserId}`);
- event.preventDefault();
+ VencordNative.native.openExternal(`steam://openurl/${url}`);
+
+ 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);
+ return true;
+ }
+
+ // in case short url didn't end up being something we can handle
+ if (event.defaultPrevented) {
+ window.open(url, "_blank");
+ return true;
+ }
+
+ return false;
+ },
+
+ handleAccountView(event: { preventDefault(): void; }, platformType: string, userId: string) {
+ if (platformType === "spotify") {
+ VencordNative.native.openExternal(`spotify:user:${userId}`);
+ event.preventDefault();
+ } else if (platformType === "steam") {
+ VencordNative.native.openExternal(`steam://openurl/https://steamcommunity.com/profiles/${userId}`);
+ showToast("Opened link in Steam", Toasts.Type.SUCCESS);
+ event.preventDefault();
+ }
}
});
diff --git a/src/plugins/showConnections/index.tsx b/src/plugins/showConnections/index.tsx
index 50fcfe1..404a8db 100644
--- a/src/plugins/showConnections/index.tsx
+++ b/src/plugins/showConnections/index.tsx
@@ -147,6 +147,13 @@ function CompactConnectionComponent({ connection, theme }: { connection: Connect
className="vc-user-connection"
href={url}
target="_blank"
+ onClick={e => {
+ if (Vencord.Plugins.isPluginEnabled("OpenInApp")) {
+ const OpenInApp = Vencord.Plugins.plugins.OpenInApp as any as typeof import("../openInApp").default;
+ // handleLink will .preventDefault() if applicable
+ OpenInApp.handleLink(e.currentTarget, e);
+ }
+ }}
>
{img}
</a>
diff --git a/src/plugins/spotifyControls/PlayerComponent.tsx b/src/plugins/spotifyControls/PlayerComponent.tsx
index f4c7c81..c0ba0fe 100644
--- a/src/plugins/spotifyControls/PlayerComponent.tsx
+++ b/src/plugins/spotifyControls/PlayerComponent.tsx
@@ -23,6 +23,7 @@ import { Flex } from "@components/Flex";
import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons";
import { Link } from "@components/Link";
import { debounce } from "@utils/debounce";
+import { openImageModal } from "@utils/discord";
import { classes, copyWithToast } from "@utils/misc";
import { ContextMenu, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common";
@@ -231,7 +232,7 @@ function AlbumContextMenu({ track }: { track: Track; }) {
id="view-cover"
label="View Album Cover"
// trolley
- action={() => (Vencord.Plugins.plugins.ViewIcons as any).openImage(track.album.image.url)}
+ action={() => openImageModal(track.album.image.url)}
icon={ImageIcon}
/>
<Menu.MenuControlItem
diff --git a/src/plugins/spotifyControls/SpotifyStore.ts b/src/plugins/spotifyControls/SpotifyStore.ts
index c713249..d65be74 100644
--- a/src/plugins/spotifyControls/SpotifyStore.ts
+++ b/src/plugins/spotifyControls/SpotifyStore.ts
@@ -89,7 +89,7 @@ export const SpotifyStore = proxyLazy(() => {
public isSettingPosition = false;
public openExternal(path: string) {
- const url = Settings.plugins.SpotifyControls.useSpotifyUris
+ const url = Settings.plugins.SpotifyControls.useSpotifyUris || Vencord.Plugins.isPluginEnabled("OpenInApp")
? "spotify:" + path.replaceAll("/", (_, idx) => idx === 0 ? "" : ":")
: "https://open.spotify.com" + path;