From cd1e815174f25fd61ca773064bb012289554b63f Mon Sep 17 00:00:00 2001 From: James Babcock Date: Fri, 11 Sep 2026 19:10:26 -0700 Subject: [PATCH] Glanceboard: Adjust styling; show timers on system card --- app/apps/glanceboard/widgets/music-widget.ts | 42 ++++++++++-- app/apps/glanceboard/widgets/system-card.ts | 67 ++++++++++++++++++-- app/apps/timer/timer-engine.ts | 5 ++ 3 files changed, 105 insertions(+), 9 deletions(-) diff --git a/app/apps/glanceboard/widgets/music-widget.ts b/app/apps/glanceboard/widgets/music-widget.ts index 632ccfcb..b142f28f 100644 --- a/app/apps/glanceboard/widgets/music-widget.ts +++ b/app/apps/glanceboard/widgets/music-widget.ts @@ -1,4 +1,5 @@ -import { type GrayImage } from "../../../graphics/image"; +import { GrayImage } from "../../../graphics/image"; +import { renderIcon } from "../../../graphics/icons"; import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; import { truncateText } from "../../../graphics/textwrap"; import { mediaControllerBridge, type MediaControllerState } from "../../../native/media-controller"; @@ -7,6 +8,33 @@ import { type GlanceWidget } from "../widget"; const PAD = 8; const ART_SIZE = 96; +/** The idle note: the Music app's icon, at this size and the dimmest shade. */ +const IDLE_NOTE_SIZE = 64; +const IDLE_NOTE_VALUE = 20; +let idleNote: GrayImage | null | undefined; + +/** + * The music icon reduced to a single dim shade: every pixel the renderer + * lit at least half becomes IDLE_NOTE_VALUE, the rest stay transparent + * (scaling the antialiased original down would quantize its edges away). + * Built once and kept, so drawImage's content-addressed cache holds. + */ +function idleNoteImage(): GrayImage | null { + if (idleNote !== undefined) return idleNote; + const icon = renderIcon("music", IDLE_NOTE_SIZE); + if (!icon) { + idleNote = null; + return null; + } + const note = new GrayImage(icon.width, icon.height, 0); + for (let y = 0; y < icon.height; y++) { + for (let x = 0; x < icon.width; x++) { + if (icon.getPixel(x, y) >= 128) note.setPixel(x, y, IDLE_NOTE_VALUE); + } + } + idleNote = note; + return note; +} const ART_X = PAD; const PROGRESS_BAR_HEIGHT = 5; @@ -52,9 +80,15 @@ export class MusicWidget implements GlanceWidget { const media = mediaControllerBridge.snapshot(); this.media = media; if (!media.available || (!media.title && !media.artist)) { - image.drawText(small, PAD, PAD, "Music", 150); - const text = media.accessEnabled ? "Nothing playing" : "Notification access needed"; - image.drawText(small, PAD, PAD + small.lineHeight + 6, text, 140); + if (!media.accessEnabled) { + // Actionable, so it stays as text. + image.drawText(small, PAD, PAD, "Music", 150); + image.drawText(small, PAD, PAD + small.lineHeight + 6, "Notification access needed", 140); + return; + } + // Nothing playing: a dim note, centred, and nothing else. + const note = idleNoteImage(); + if (note) image.drawImage(note, ((image.width - note.width) / 2) | 0, ((image.height - note.height) / 2) | 0); return; } diff --git a/app/apps/glanceboard/widgets/system-card.ts b/app/apps/glanceboard/widgets/system-card.ts index e2ee113d..ef60ac24 100644 --- a/app/apps/glanceboard/widgets/system-card.ts +++ b/app/apps/glanceboard/widgets/system-card.ts @@ -15,6 +15,10 @@ import { } from "../../../ui/dashboard-settings"; import { shell } from "../../../ui/shell/shell"; import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../../util/render-freshness"; +import { truncateText } from "../../../graphics/textwrap"; +import { timerEngine } from "../../timer/timer-engine"; +import { formatCountdown, sortTimers, timerDisplayName, timerPhase, timerRemainingMs } from "../../timer/timer-model"; +import { lineStep } from "../../../ui/metrics"; import { type GlanceWidget } from "../widget"; const PAD = 8; @@ -26,32 +30,55 @@ const BATTERY_LABEL_VALUE = 150; type BatteryItem = { label: string; percent: number; charging: boolean }; /** - * Date and time, the phone's notification icons, and the phone/G2/R1 - * battery indicators: the top bar's contents, laid out for a card. Battery - * style and per-device visibility follow Settings > Display > Battery - * indicators, so the card agrees with the bar. + * Date and time, the phone's notification icons, the phone/G2/R1 battery + * indicators, and the Timers app's countdowns: the top bar's contents plus + * timers, laid out for a card. Battery style and per-device visibility + * follow Settings > Display > Battery indicators, so the card agrees with + * the bar. Countdowns tick once a second only while one is running. */ export class SystemCardWidget implements GlanceWidget { private requestRender: (() => void) | null = null; private minuteTimer: ReturnType | null = null; + private secondTimer: ReturnType | null = null; private unsubscribeNotifications: (() => void) | null = null; private unsubscribeSettings: (() => void) | null = null; + private unsubscribeTimers: (() => void) | null = null; start(requestRender: () => void): void { this.requestRender = requestRender; this.scheduleMinuteTick(); this.unsubscribeNotifications = onAndroidNotificationPosted(() => this.requestRender?.()); this.unsubscribeSettings = onAnySettingChanged(() => this.requestRender?.()); + this.unsubscribeTimers = timerEngine.onChange(() => { + this.syncSecondTick(); + this.requestRender?.(); + }); + this.syncSecondTick(); } stop(): void { this.requestRender = null; if (this.minuteTimer !== null) clearTimeout(this.minuteTimer); this.minuteTimer = null; + if (this.secondTimer !== null) clearInterval(this.secondTimer); + this.secondTimer = null; this.unsubscribeNotifications?.(); this.unsubscribeNotifications = null; this.unsubscribeSettings?.(); this.unsubscribeSettings = null; + this.unsubscribeTimers?.(); + this.unsubscribeTimers = null; + } + + /** Countdowns change every second; run that clock only while one is running. */ + private syncSecondTick(): void { + const running = timerEngine.timers().some((timer) => timerPhase(timer) === "running"); + if (running && this.secondTimer === null) { + this.secondTimer = setInterval(() => this.requestRender?.(), 1_000); + } else if (!running && this.secondTimer !== null) { + clearInterval(this.secondTimer); + this.secondTimer = null; + } } /** Repaint on the minute boundary, so the clock never shows a stale minute. */ @@ -82,9 +109,12 @@ export class SystemCardWidget implements GlanceWidget { image.drawText(timeFont, PAD, y, timeText, 230); y += timeFont.lineHeight + 2; image.drawText(medium, PAD, y, formatClockDate(now), 170); + y += medium.lineHeight + 4; - // Notification icons along the bottom, as many as fit. + // Notification icons along the bottom, as many as fit; the Timers app's + // countdowns take the band between the date and the icons. const iconY = image.height - PAD - NOTIFICATION_ICON_SIZE; + drawTimers(image, small, PAD, y, textWidth, iconY - 4, now.getTime()); const maxIcons = Math.max(0, ((image.width - 2 * PAD + NOTIFICATION_ICON_GAP) / (NOTIFICATION_ICON_SIZE + NOTIFICATION_ICON_GAP)) | 0); if (maxIcons > 0) { const { icons, stale } = readActiveNotificationIcons(maxIcons, renderPassAllowsStaleData()); @@ -171,3 +201,30 @@ function drawBatteryValue( const icon = drawBattery(item.percent, item.charging); image.bitBlt(icon, x, lineTop + Math.max(0, ((font.lineHeight - gaugeHeight) / 2) | 0), { transparentZero: true }); } + +/** + * The Timers app's countdowns, soonest first: remaining time (or "Done" once + * rung, inverted so it is noticed; "paused" for a paused one) and the + * timer's name, one per line while they fit between `top` and `bottom`. + */ +function drawTimers(image: GrayImage, font: UiFont, x: number, top: number, width: number, bottom: number, nowMs: number): void { + const timers = sortTimers(timerEngine.timers(), nowMs); + const step = lineStep(font); + let y = top; + for (const timer of timers) { + if (y + font.lineHeight > bottom) break; + const phase = timerPhase(timer); + const clock = phase === "rung" ? "Done" : formatCountdown(timerRemainingMs(timer, nowMs)); + const clockWidth = font.measureText(clock); + if (phase === "rung") { + image.fillRect(x - 2, y - 1, clockWidth + 4, font.lineHeight + 2, 230); + image.drawText(font, x, y, clock, 1); + } else { + image.drawText(font, x, y, clock, phase === "paused" ? 120 : 200); + } + const nameX = x + clockWidth + 8; + const name = phase === "paused" ? `${timerDisplayName(timer)} (paused)` : timerDisplayName(timer); + image.drawText(font, nameX, y, truncateText(font, name, Math.max(0, x + width - nameX)), 160); + y += step; + } +} diff --git a/app/apps/timer/timer-engine.ts b/app/apps/timer/timer-engine.ts index 61efa9c7..57bb5e88 100644 --- a/app/apps/timer/timer-engine.ts +++ b/app/apps/timer/timer-engine.ts @@ -266,6 +266,11 @@ export class TimerEngine { ); } + /** Every countdown timer (running, paused or rung), unsorted. */ + timers(): readonly CountdownTimer[] { + return this.state.timers; + } + ringingItems(): RingingItem[] { const items: RingingItem[] = []; for (const timer of this.state.timers) {