Wall displays: a night schedule that dims or blanks the board
A named display can dim the board or blank it (so a tablet or computer may sleep) between two times on the screen's own clock. A critical alert brings the board back unless told not to, and a touch or key press brings it back for two minutes. A share link that opens the display follows the same schedule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
168d01dc7b
commit
a69d0a611d
17 files changed
+9948
-22
No files matched your search
@@ -2,7 +2,7 @@ import { useEffect, useState, type ReactNode } from "react";
|
||||
import type { WallGroup, WallTile } from "../api/client";
|
||||
import { formatDate, formatTime } from "../utils/date";
|
||||
import { formatRemaining } from "../utils/duration";
|
||||
import { applyDisplay, groupMembers, pageOrOverview, ROTATE_CHOICES, stepPage, wallPages } from "../utils/wallPages";
|
||||
import { applyDisplay, groupMembers, nightState, pageOrOverview, ROTATE_CHOICES, stepPage, WAKE_FOR_MS, wallPages, type WallNight } from "../utils/wallPages";
|
||||
import { t } from "../i18n";
|
||||
|
||||
export const REFRESH_MS = 30_000;
|
||||
@@ -82,9 +82,10 @@ function useClock(): Date {
|
||||
return now;
|
||||
}
|
||||
|
||||
/** Keeps the screen awake while the page is open, where the browser allows it. */
|
||||
function useWakeLock() {
|
||||
/** Keeps the screen awake while the page is open, where the browser allows it — and lets go while `enabled` is false (a blank night screen, so the device may sleep). */
|
||||
function useWakeLock(enabled = true) {
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
let lock: { release: () => Promise<void> } | null = null;
|
||||
let gone = false;
|
||||
const request = async () => {
|
||||
@@ -103,7 +104,7 @@ function useWakeLock() {
|
||||
document.removeEventListener("visibilitychange", onVisible);
|
||||
void lock?.release().catch(() => {});
|
||||
};
|
||||
}, []);
|
||||
}, [enabled]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,12 +122,26 @@ export default function WallView({
|
||||
idle: boolean;
|
||||
footerActions: ReactNode;
|
||||
/** A named display: its name (shown in the footer) and which pages it rotates through, in order; none listed is every page. */
|
||||
display?: { name: string; pages: string[] } | null;
|
||||
display?: { name: string; pages: string[]; night?: WallNight | null } | null;
|
||||
/** How the pages rotate (seconds each, null for the overview alone) and how to change it; absent on a board that does not rotate. */
|
||||
rotation?: { seconds: number | null; onChange: (seconds: number | null) => void };
|
||||
}) {
|
||||
const now = useClock();
|
||||
useWakeLock();
|
||||
|
||||
// The night: dimmed or blank by the screen's own clock, unless something is critical (and the schedule says to show it) or somebody has just touched the screen.
|
||||
const [wokenUntil, setWokenUntil] = useState<number | null>(null);
|
||||
const night = nightState(now, display?.night, { critical: data.level === "critical", wokenUntil });
|
||||
useWakeLock(night !== "off");
|
||||
useEffect(() => {
|
||||
if (!display?.night) return;
|
||||
const wake = () => setWokenUntil(Date.now() + WAKE_FOR_MS);
|
||||
window.addEventListener("pointerdown", wake);
|
||||
window.addEventListener("keydown", wake);
|
||||
return () => {
|
||||
window.removeEventListener("pointerdown", wake);
|
||||
window.removeEventListener("keydown", wake);
|
||||
};
|
||||
}, [display?.night]);
|
||||
|
||||
// The pages: the overview, what needs attention (while something does), and one for each group of integrations.
|
||||
const rotating = !!rotation && rotation.seconds !== null;
|
||||
@@ -162,7 +177,8 @@ export default function WallView({
|
||||
const showsDetail = data.problems !== null || data.windows !== null || data.integrations !== null;
|
||||
|
||||
return (
|
||||
<div className={`wall ${idle ? "wall-idle" : ""}`} data-bs-theme="dark">
|
||||
<div className={`wall ${idle ? "wall-idle" : ""} ${night !== "day" ? `wall-night-${night}` : ""}`} data-bs-theme="dark" aria-hidden={night === "off" ? true : undefined}>
|
||||
{night === "off" && <div className="wall-night-note">{t("Night — touch the screen to wake it")}</div>}
|
||||
<header className="wall-header">
|
||||
<img src="/logo.webp" alt="Homelab Manager" width={901} height={460} className="wall-logo" />
|
||||
{data.environmentName && <span className="badge env-badge">{data.environmentName}</span>}
|
||||
|
||||
Reference in new issue
Block a user