From 46a164e797c0fd77ee67e2bae9bec5c02ad1de2d Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 9 Nov 2026 18:26:00 +0100 Subject: fix: add stats, music and windows panels --- static/modules/music.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 static/modules/music.js (limited to 'static/modules/music.js') diff --git a/static/modules/music.js b/static/modules/music.js new file mode 100644 index 0000000..de9df7f --- /dev/null +++ b/static/modules/music.js @@ -0,0 +1,48 @@ +async function post(action) { + try { + await fetch(`/api/music/${action}`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: "{}", + }); + } catch { + // the next poll shows the real state + } +} + +function button(label, action) { + const b = document.createElement("button"); + b.textContent = label; + b.onclick = () => post(action); + return b; +} + +export default { + title: "Music", + interval: 2, + + mount(el) { + const box = document.createElement("div"); + box.className = "music"; + box.innerHTML = ` +
—
+
+
`; + box.querySelector(".controls").append( + button("⏮", "prev"), button("⏯", "play"), button("⏭", "next")); + box.querySelector(".vol").append( + button("Vol−", "voldown"), button("Mute", "mute"), button("Vol+", "volup")); + el.append(box); + }, + + update(st, el) { + const box = el.querySelector(".music"); + box.querySelector(".title").textContent = st.title || "Nothing playing"; + box.querySelector(".artist").textContent = st.artist || ""; + box.querySelector(".controls button:nth-child(2)").textContent = + st.status === "Playing" ? "⏸" : "▶"; + const mute = box.querySelector(".vol button:nth-child(2)"); + mute.classList.toggle("on", Boolean(st.volume?.muted)); + mute.textContent = st.volume?.muted ? "Unmute" : "Mute"; + }, +}; -- cgit v1.2.3