diff --git a/extension/spotiqueue.js b/extension/spotiqueue.js index 2ea38d1..625ba59 100644 --- a/extension/spotiqueue.js +++ b/extension/spotiqueue.js @@ -114,14 +114,19 @@ class SpotiQueue { return; } - if (data.c === "next_song" && data.d && data.d.song) { - try { - Spicetify.Player.playUri(data.d.song); - Spicetify.Player.setRepeat(false); + if (data.c === "next_song") { + if (data.d && data.d.song) { + try { + Spicetify.Player.playUri(data.d.song); + Spicetify.Player.setRepeat(false); + this.startedPlaying = true; + console.log("[SpotiQueue] New song received!"); + } catch (err) { + console.error("[SpotiQueue] Error playing received song:", err); + } + } else { + Spicetify.Player.play(); this.startedPlaying = true; - console.log("[SpotiQueue] New song received!"); - } catch (err) { - console.error("[SpotiQueue] Error playing received song:", err); } } @@ -144,7 +149,6 @@ class SpotiQueue { includeAuthors: true, }); - console.log(data); songs = data.searchV2.tracksV2.items.reduce((o, c) => { const item = c.item.data; @@ -204,27 +208,23 @@ class SpotiQueue { } if (this.button && !this.closing) { - this.button.style.color = "" + this.button.style.color = ""; } this.closing = false; } initUi() { - const btn = new Spicetify.Topbar.Button( - "SpotiQueue", - "enhance", - () => {}, - ); + const btn = new Spicetify.Topbar.Button("SpotiQueue", "enhance", () => {}); this.button = btn.button; - this.button.style.color = "#e22134" + this.button.style.color = "#e22134"; this.button.addEventListener("click", (e) => { console.log(e.pointerId); if (this.socket) { this.stop(); - return - } + return; + } if (Spicetify.GraphQL.Definitions.searchDesktop === undefined) { Spicetify.Platform.History.push("/search/"); @@ -236,7 +236,7 @@ class SpotiQueue { } this.closing = false; - this.button.style.color = "" + this.button.style.color = ""; this.connect(); }); @@ -272,4 +272,3 @@ class SpotiQueue { globalThis.spotiQueue = new SpotiQueue(); globalThis.spotiQueue.initUi(); })(); - diff --git a/src/spotify.ts b/src/spotify.ts index d68f29a..9611c16 100644 --- a/src/spotify.ts +++ b/src/spotify.ts @@ -46,7 +46,10 @@ export class SpotifyWS { public sendSong(uri?: string) { const song = uri ?? playerManager.getNext()?.uri; - if (!song) return; + if (!song) { + this.send(buildCommand("next_song")); + return + }; this.send(buildCommand("next_song", { song })); }