From a86d44a29e5da1fa03eb45767ec4d843272d20c2 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sun, 6 Jul 2025 21:24:45 -0700 Subject: [PATCH] fix(queue): random start index when play shuffled center control is enabled, play mode is now, no start specified --- src/renderer/store/player.store.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/renderer/store/player.store.ts b/src/renderer/store/player.store.ts index 6f0ae2ae..5229ebe1 100644 --- a/src/renderer/store/player.store.ts +++ b/src/renderer/store/player.store.ts @@ -1,5 +1,6 @@ import map from 'lodash/map'; import merge from 'lodash/merge'; +import random from 'lodash/random'; import shuffle from 'lodash/shuffle'; import { nanoid } from 'nanoid/non-secure'; import { devtools, persist, subscribeWithSelector } from 'zustand/middleware'; @@ -144,8 +145,14 @@ export const usePlayerStore = createWithEqualityFn()( // If the queue is empty, next/last should behave the same as now if (playType === Play.NOW || queue.length === 0) { - const index = initialIndex || 0; if (get().shuffle === PlayerShuffle.TRACK) { + // If the initial index is specified (double click), use that for + // shuffle start. Otherwise (e.g., big play button), use random start. + const index = + initialIndex !== undefined + ? initialIndex + : random(0, songsToAddToQueue.length, false); + const initialSong = songsToAddToQueue[index]; const queueCopy = [...songsToAddToQueue]; @@ -172,6 +179,7 @@ export const usePlayerStore = createWithEqualityFn()( state.current.song = initialSong; }); } else { + const index = initialIndex || 0; set((state) => { state.queue.default = songsToAddToQueue; state.current.time = 0;