diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 11:32:07 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 11:32:07 +0100 |
| commit | 1a2607a7a5f6ad9a0b22d6544de3228c7fafc9d8 (patch) | |
| tree | dc2b1e9d0d03de0d2c554121ca482175417b28ef /static/modules/tablet.js | |
| parent | 24ffea5a7f25b179a8b2fb7f3605a4977c854069 (diff) | |
| download | deck-it-1a2607a7a5f6ad9a0b22d6544de3228c7fafc9d8.tar.gz deck-it-1a2607a7a5f6ad9a0b22d6544de3228c7fafc9d8.zip | |
feat(tablet): battery and Wi-Fi card on the dashboard
Reads `dumpsys battery` and `cmd wifi status` (Android 11+) over adb
from the device whose reverse carries the dashboard socket, so a switch
between USB and Wi-Fi is followed. Reads are cached for 10s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/modules/tablet.js')
| -rw-r--r-- | static/modules/tablet.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/static/modules/tablet.js b/static/modules/tablet.js new file mode 100644 index 0000000..cb38416 --- /dev/null +++ b/static/modules/tablet.js @@ -0,0 +1,77 @@ +// deck-it - tablet panel +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +// The tablet's battery and Wi-Fi, in the System card's tile style. + +import { offline } from "../offline.js"; + +function tile(label, value, sub, cls = "", badge = "") { + const d = document.createElement("div"); + d.className = "mtile"; + d.innerHTML = `<span class="mlabel"></span><span class="mvalue num ${cls}"></span><span class="msub"></span>`; + d.children[0].textContent = label; + d.children[0].insertAdjacentHTML("beforeend", badge); + d.children[1].textContent = value; + d.children[2].textContent = sub || ""; + return d; +} + +// Four bars in the label, lit by Android's thresholds: -55 dBm and up is full. +function bars(rssi) { + const n = rssi == null ? 0 : rssi >= -55 ? 4 : rssi >= -66 ? 3 : rssi >= -77 ? 2 : 1; + const rects = [0, 1, 2, 3].map((i) => + `<rect x="${i * 4}" y="${9 - i * 3}" width="3" height="${3 + i * 3}" rx="1"${i < n ? ' class="lit"' : ""}/>`); + return `<svg class="bars" viewBox="0 0 15 12" aria-hidden="true">${rects.join("")}</svg>`; +} + +export default { + title: "Tablet", + interval: 10, + + mount(el) { + el.innerHTML = `<div class="tablet"><div class="stats"></div></div>`; + }, + + update(st, el) { + const box = el.querySelector(".stats"); + if (!st.connected) { + offline(box, { + icon: "/icons/smartphone.svg", + title: "Tablet not reachable over adb", + detail: "Its battery and Wi-Fi show here once deck-it's tunnel is up.", + reason: st.error, + }); + return; + } + box.textContent = ""; + const b = st.battery; + const w = st.wifi; + const low = b.level <= 20 && b.status !== "charging"; + box.append( + tile("Battery", `${b.level}%`, + [b.status, b.plug, b.temp != null ? `${b.temp}°C` : ""].filter(Boolean).join(" · "), + low ? "bad" : b.status === "charging" ? "good" : ""), + w.connected + ? tile("Wi-Fi", `${w.rssi ?? "?"} dBm`, + [w.ssid, w.band, w.speed ? `${w.speed} Mbps` : ""].filter(Boolean).join(" · "), "", bars(w.rssi)) + : tile("Wi-Fi", "off", "not connected", "warn"), + ); + const foot = document.createElement("div"); + foot.className = "mfoot"; + foot.textContent = `linked over ${st.link}`; + box.append(foot); + }, +}; |
