refactor(theme): refactor player execution block

- Refactored player command logic in execute into a lookup map
(playerMap).
This commit is contained in:
Damjan Antevski
2026-08-05 11:15:18 +02:00
parent 48863986a3
commit 0d132ab401
+15 -56
View File
@@ -3,10 +3,7 @@
const style = ` const style = `
#spotui-tui { #spotui-tui {
position: fixed; position: fixed;
top: 0; top: 0; left: 0; right: 0; bottom: 90px;
left: 0;
right: 0;
bottom: 90px;
width: 100vw; width: 100vw;
background: #000; background: #000;
color: #ddd; color: #ddd;
@@ -57,9 +54,7 @@ body.spotui-about-panel #spotui-logo {
#spotui-top-fade { #spotui-top-fade {
display: none; display: none;
position: absolute; position: absolute;
top: 0; top: 0; left: 0; right: 0;
left: 0;
right: 0;
height: 120px; height: 120px;
background: linear-gradient(to bottom, rgba(0,0,0,1) 30%, rgba(0,0,0,0)); background: linear-gradient(to bottom, rgba(0,0,0,1) 30%, rgba(0,0,0,0));
pointer-events: none; pointer-events: none;
@@ -260,8 +255,7 @@ body.spotui-lyrics-panel #spotui-lyrics.spotui-lyrics-active {
.spotui-lyrics-fade { .spotui-lyrics-fade {
pointer-events: none; pointer-events: none;
position: absolute; position: absolute;
left: 0; left: 0; right: 0;
right: 0;
height: 72px; height: 72px;
z-index: 2; z-index: 2;
} }
@@ -1125,26 +1119,19 @@ async function execute(cmd) {
if (command === "clear") { document.getElementById("spotui-output").textContent = ""; return; } if (command === "clear") { document.getElementById("spotui-output").textContent = ""; return; }
if (command === "playlist" || command === "list") { openPlaylistPanel(); return; } if (command === "playlist" || command === "list") { openPlaylistPanel(); return; }
if (command === "play") { const playerMap = {
await runPlayerAction("Play", async () => { play: { fn: () => { if (!Spicetify.Player.isPlaying()) Spicetify.Player.togglePlay(); }, name: "Play", success: "Playing" },
if (!Spicetify.Player.isPlaying()) Spicetify.Player.togglePlay(); pause: { fn: () => { if (Spicetify.Player.isPlaying()) Spicetify.Player.togglePlay(); }, name: "Pause", success: "Paused" },
}, "Playing"); p: { fn: () => { const p = Spicetify.Player.isPlaying(); Spicetify.Player.togglePlay(); return p; }, name: "Play/PauseToggle", success: Spicetify.Player.isPlaying() ? "Paused" : "Playing" },
return; skip: { fn: () => Spicetify.Player.next(), name: "Skip", success: "Skipped to next track" },
} back: { fn: () => Spicetify.Player.back(), name: "Back", success: "Went back to previous track" },
shuffle: { fn: () => { const s = Spicetify.Player.getShuffle(); Spicetify.Player.setShuffle(!s); return s; }, name: "Shuffle", success: !Spicetify.Player.getShuffle() ? "ON" : "OFF" },
like: { fn: async () => { const h = await Spicetify.Player.getHeart(); await Spicetify.Player.toggleHeart(); return h; }, name: "Like", success: Spicetify.Player.getHeart() ? "Unliked song" : "Liked song" }
};
if (command === "pause") { if (playerMap[command]) {
await runPlayerAction("Pause", async () => { const act = playerMap[command];
if (Spicetify.Player.isPlaying()) Spicetify.Player.togglePlay(); await runPlayerAction(act.name, act.fn, act.success);
}, "Paused");
return;
}
if (command === "p") {
await runPlayerAction("Play/PauseToggle", async () => {
const wasPlaying = Spicetify.Player.isPlaying();
Spicetify.Player.togglePlay();
return wasPlaying;
}, Spicetify.Player.isPlaying() ? "Paused" : "Playing");
return; return;
} }
@@ -1154,15 +1141,6 @@ async function execute(cmd) {
return; return;
} }
if (command === "skip") {
await runPlayerAction("Skip", () => Spicetify.Player.next(), "Skipped to next track");
return;
}
if (command === "back") {
await runPlayerAction("Back", () => Spicetify.Player.back(), "Went back to previous track");
return;
}
if (command === "seek" || command === "s") { if (command === "seek" || command === "s") {
await runPlayerAction("Seek", () => { await runPlayerAction("Seek", () => {
if (!argText) throw new Error("Usage: seek <mm:ss>"); if (!argText) throw new Error("Usage: seek <mm:ss>");
@@ -1183,27 +1161,8 @@ async function execute(cmd) {
return; return;
} }
if (command === "shuffle") {
await runPlayerAction("Shuffle", () => {
const current = Spicetify.Player.getShuffle();
Spicetify.Player.setShuffle(!current);
return current;
}, "Shuffle: " + (!Spicetify.Player.getShuffle() ? "ON" : "OFF"));
return;
}
if (command === "loop") { handleRepeatCommand("loop", argText); return; } if (command === "loop") { handleRepeatCommand("loop", argText); return; }
if (command === "superloop") { handleRepeatCommand("superloop", argText); return; } if (command === "superloop") { handleRepeatCommand("superloop", argText); return; }
if (command === "like") {
await runPlayerAction("Like", async () => {
const isLiked = await Spicetify.Player.getHeart();
await Spicetify.Player.toggleHeart();
return isLiked;
}, Spicetify.Player.getHeart() ? "Unliked song" : "Liked song");
return;
}
if (command === "lyrics") { handleLyricsCommand(argText); return; } if (command === "lyrics") { handleLyricsCommand(argText); return; }
print("Unknown command. Type /help"); print("Unknown command. Type /help");