From 232d0aa6c8ca5d9deca498afafb2cfcf8951c6f0 Mon Sep 17 00:00:00 2001 From: Masterjoona <69722179+Masterjoona@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:16:57 +0000 Subject: [PATCH 1/3] Fix shuffle sync --- 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 7fdd6bba17c..5c0c5fe4ebe 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 ae5fbcd82b9..a424070b281 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"!==(.{1,3}),/, + replace: "shuffle:arguments[2].shuffle_state,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), From d06a12151f0d657d02fa2847475a732db5994148 Mon Sep 17 00:00:00 2001 From: Joona <69722179+Masterjoona@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:54:30 +0300 Subject: [PATCH 2/3] use \i Co-authored-by: v --- src/plugins/spotifyControls/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/spotifyControls/index.tsx b/src/plugins/spotifyControls/index.tsx index a424070b281..89445a91271 100644 --- a/src/plugins/spotifyControls/index.tsx +++ b/src/plugins/spotifyControls/index.tsx @@ -75,7 +75,7 @@ export default definePlugin({ replacement: [ { // Discord doesn't give you shuffle state and the repeat kind, only a boolean - match: /repeat:"off"!==(.{1,3}),/, + match: /repeat:"off"!==(\i),/, replace: "shuffle:arguments[2].shuffle_state,actual_repeat:$1,$&" }, { From b7c086852d131f5d2a8f8d2caf85d15469b8055a Mon Sep 17 00:00:00 2001 From: Joona <69722179+Masterjoona@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:54:58 +0300 Subject: [PATCH 3/3] safety Co-authored-by: v --- src/plugins/spotifyControls/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/spotifyControls/index.tsx b/src/plugins/spotifyControls/index.tsx index 89445a91271..1e15ef56083 100644 --- a/src/plugins/spotifyControls/index.tsx +++ b/src/plugins/spotifyControls/index.tsx @@ -76,7 +76,7 @@ export default definePlugin({ { // Discord doesn't give you shuffle state and the repeat kind, only a boolean match: /repeat:"off"!==(\i),/, - replace: "shuffle:arguments[2].shuffle_state,actual_repeat:$1,$&" + replace: "shuffle:arguments[2]?.shuffle_state??false,actual_repeat:$1,$&" }, { match: /(?<=artists.filter\(\i=>).{0,10}\i\.id\)&&/,