From 1a712e75a61d6f8462bca5b37dd2dfb169edc5bb Mon Sep 17 00:00:00 2001 From: Joona <69722179+Masterjoona@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:35:21 +0300 Subject: [PATCH] fix(SpotifyControls): sync with external shuffle toggles (#2767) Co-authored-by: v --- src/plugins/spotifyControls/SpotifyStore.ts | 2 ++ src/plugins/spotifyControls/index.tsx | 23 ++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/plugins/spotifyControls/SpotifyStore.ts b/src/plugins/spotifyControls/SpotifyStore.ts index 7fdd6bba1..5c0c5fe4e 100644 --- a/src/plugins/spotifyControls/SpotifyStore.ts +++ b/src/plugins/spotifyControls/SpotifyStore.ts @@ -55,6 +55,7 @@ interface PlayerState { // added by patch actual_repeat: Repeat; + shuffle: boolean; } interface Device { @@ -182,6 +183,7 @@ export const SpotifyStore = proxyLazyWebpack(() => { store.isPlaying = e.isPlaying ?? false; store.volume = e.volumePercent ?? 0; store.repeat = e.actual_repeat || "off"; + store.shuffle = e.shuffle ?? false; store.position = e.position ?? 0; store.isSettingPosition = false; store.emitChange(); diff --git a/src/plugins/spotifyControls/index.tsx b/src/plugins/spotifyControls/index.tsx index ae5fbcd82..1e15ef560 100644 --- a/src/plugins/spotifyControls/index.tsx +++ b/src/plugins/spotifyControls/index.tsx @@ -70,21 +70,20 @@ export default definePlugin({ replace: "false", }] }, - // Discord doesn't give you the repeat kind, only a boolean { find: 'repeat:"off"!==', - replacement: { - match: /repeat:"off"!==(.{1,3}),/, - replace: "actual_repeat:$1,$&" - } + replacement: [ + { + // Discord doesn't give you shuffle state and the repeat kind, only a boolean + match: /repeat:"off"!==(\i),/, + replace: "shuffle:arguments[2]?.shuffle_state??false,actual_repeat:$1,$&" + }, + { + match: /(?<=artists.filter\(\i=>).{0,10}\i\.id\)&&/, + replace: "" + } + ] }, - { - find: "artists.filter", - replacement: { - match: /(?<=artists.filter\(\i=>).{0,10}\i\.id\)&&/, - replace: "" - } - } ], start: () => toggleHoverControls(Settings.plugins.SpotifyControls.hoverControls),