diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-13 20:49:56 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-13 20:49:56 +0100 |
| commit | 896163d7961d86b4e023a50ce4f6e19a30006a3f (patch) | |
| tree | 9a2266a1120f8913616991d9350fa6667c248f0e /static/hold.js | |
| parent | 69e6ce2bf7272797cf08ee4fbe0ff9fe0fc3b1f4 (diff) | |
| download | deck-it-896163d7961d86b4e023a50ce4f6e19a30006a3f.tar.gz deck-it-896163d7961d86b4e023a50ce4f6e19a30006a3f.zip | |
feat(vm): tablet tiles with screen, trends and a power button
Each VM is a tile: its screen from virsh screenshot (JPEG through
ffmpeg, every 5s while the tab shows), booting until sshd answers at
the ssh -G host and port, CPU and RAM trends, and a big power button,
tap for the gentle action and hold to force off. A tap on the tile
opens a sheet with every action as an icon and the snapshots as a
timeline with their age. hold.js is now the one press and hold, K1C's
stop included, and vibrates the tablet when it fires; the Windows
long-press buzzes too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/hold.js')
| -rw-r--r-- | static/hold.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/static/hold.js b/static/hold.js new file mode 100644 index 0000000..e937a25 --- /dev/null +++ b/static/hold.js @@ -0,0 +1,46 @@ +// deck-it - press and hold, for buttons a stray touch must not fire +// 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. + +export const HOLD_MS = 800; + +// The tablet buzzes when a hold fires (or a long press opens a menu), so +// the finger knows it can let go. +export const buzz = () => navigator.vibrate?.(40); + +// fire runs after the button is held ms; releasing early cancels, and runs +// tap instead when one is given. The button gets .holding meanwhile and +// --hold for the CSS fill. +export function hold(btn, fire, { ms = HOLD_MS, tap } = {}) { + let timer = null; + const cancel = () => { + clearTimeout(timer); + timer = null; + btn.classList.remove("holding"); + }; + btn.style.setProperty("--hold", `${ms}ms`); + btn.addEventListener("pointerdown", (e) => { + e.preventDefault(); + e.stopPropagation(); + btn.setPointerCapture(e.pointerId); + btn.classList.add("holding"); + timer = setTimeout(() => { cancel(); buzz(); fire(); }, ms); + }); + btn.addEventListener("pointerup", () => { + if (timer && tap) tap(); + cancel(); + }); + btn.addEventListener("pointercancel", cancel); +} |
