aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules/windows.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-09 18:26:00 +0100
committerDanilo M. <danix@danix.xyz>2026-11-09 18:26:00 +0100
commit46a164e797c0fd77ee67e2bae9bec5c02ad1de2d (patch)
tree566bb56c30b85a37f15b96a529ff252d69acb867 /static/modules/windows.js
parent7f99167f0b6a3c83bf77e20bc5e03942b901fb71 (diff)
downloaddeck-it-46a164e797c0fd77ee67e2bae9bec5c02ad1de2d.tar.gz
deck-it-46a164e797c0fd77ee67e2bae9bec5c02ad1de2d.zip
fix: add stats, music and windows panels
Diffstat (limited to 'static/modules/windows.js')
-rw-r--r--static/modules/windows.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/static/modules/windows.js b/static/modules/windows.js
new file mode 100644
index 0000000..7a2eeb8
--- /dev/null
+++ b/static/modules/windows.js
@@ -0,0 +1,65 @@
+async function post(action, body = {}) {
+ try {
+ await fetch(`/api/windows/${action}`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(body),
+ });
+ } catch {
+ // the next poll shows the real state
+ }
+}
+
+function button(label, onclick) {
+ const b = document.createElement("button");
+ b.textContent = label;
+ b.onclick = onclick;
+ return b;
+}
+
+export default {
+ title: "Windows",
+ interval: 1,
+
+ mount(el) {
+ const box = document.createElement("div");
+ box.className = "windows";
+ box.innerHTML = `
+ <div class="row ws"></div>
+ <div class="winlist"></div>
+ <div class="row launches"></div>`;
+ el.append(box);
+ },
+
+ update(st, el) {
+ const box = el.querySelector(".windows");
+
+ const ws = box.querySelector(".ws");
+ ws.textContent = "";
+ for (const id of st.workspaces ?? []) {
+ const b = button(String(id), () => post("workspace", { n: id }));
+ b.classList.toggle("on", (st.windows ?? []).some((w) => w.workspace === id));
+ ws.append(b);
+ }
+
+ const list = box.querySelector(".winlist");
+ list.textContent = "";
+ for (const w of (st.windows ?? []).slice(0, 12)) {
+ const row = document.createElement("div");
+ row.className = "row";
+ row.classList.toggle("on", Boolean(w.active));
+ const title = document.createElement("span");
+ title.className = "wt";
+ title.textContent = w.title || w.class;
+ title.onclick = () => post("focus", { address: w.address });
+ row.append(title, button("×", () => post("close", { address: w.address })));
+ list.append(row);
+ }
+
+ const launches = box.querySelector(".launches");
+ launches.textContent = "";
+ for (const key of st.launches ?? []) {
+ launches.append(button(key, () => post("launch", { key })));
+ }
+ },
+};