Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shuffle+): add an option to shuffle queue #2923

Merged
merged 4 commits into from Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 41 additions & 3 deletions Extensions/shuffle+.js
Expand Up @@ -12,6 +12,7 @@

const { React } = Spicetify;
const { useState } = React;
let playbarButton = null;

function getConfig() {
try {
Expand All @@ -22,7 +23,7 @@
throw "";
} catch {
Spicetify.LocalStorage.set("shufflePlus:settings", "{}");
return { artistMode: "all", artistNameMust: false };
return { artistMode: "all", artistNameMust: false, enableQueueButton: false };
}
}

Expand Down Expand Up @@ -180,12 +181,18 @@
React.createElement(checkBoxItem, {
name: "Chosen artist must be included",
field: "artistNameMust"
}),
React.createElement(checkBoxItem, {
name: "Enable Shuffle+ Queue Tracks button in Playbar",
field: "enableQueueButton",
onclickFun: () => renderQueuePlaybarButton()
})
);

Spicetify.PopupModal.display({
title: "Shuffle+",
content: settingsDOMContent
content: settingsDOMContent,
isLarge: true
});
}

Expand Down Expand Up @@ -265,6 +272,24 @@
"playlist-folder"
).register();

renderQueuePlaybarButton();
function renderQueuePlaybarButton() {
if (!playbarButton) {
playbarButton = new Spicetify.Playbar.Button(
"Shuffle+ Queue Tracks",
"enhance",
async () => {
await fetchAndPlay("queue");
},
false,
false
);
}

if (CONFIG.enableQueueButton) playbarButton.register();
else playbarButton.deregister();
}

async function fetchPlaylistTracks(uri) {
const res = await Spicetify.CosmosAsync.get(`sp://core-playlist/v1/playlist/spotify:playlist:${uri}/rows`, {
policy: { link: true, playable: true }
Expand Down Expand Up @@ -407,6 +432,16 @@
return res.map(track => track.uri);
}

function fetchQueue() {
const { _queueState } = Spicetify.Platform.PlayerAPI._queue;
const nextUp = _queueState.nextUp.map(track => track.uri);
const queued = _queueState.queued.map(track => track.uri);
const array = [...new Set([...nextUp, ...queued])];
const current = _queueState.current?.uri;
if (current) array.push(current);
return array;
}

async function fetchCollection(uriObj) {
const { category, type } = uriObj;
const { pathname } = Spicetify.Platform.History.location;
Expand Down Expand Up @@ -528,7 +563,10 @@
let uri;

try {
if (typeof rawUri === "object") {
if (rawUri === "queue") {
list = fetchQueue();
context = null;
} else if (typeof rawUri === "object") {
list = rawUri;
context = null;
} else {
Expand Down