Repaint top bar on settings changes; add 12/24-hour time setting

This commit is contained in:
James Babcock committed 2026-07-10 23:39:36 -07:00
1 parent d97429a21a
commit 17cc0bba83
4 files changed
+55 -3

No files matched your search

+13 -2
View File
@@ -6,7 +6,7 @@ import { readPhoneBatteryState } from "../../native/phone-battery";
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
import { clamp } from "../../util/numeric-util";
import { renderIcon, type IconName } from "../../graphics/icons";
import { batteryDisplayModeSetting } from "../dashboard-settings";
import { batteryDisplayModeSetting, timeFormatSetting } from "../dashboard-settings";
import { Layer } from "../layers";
import { SHELL_OPAQUE_BLACK, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
@@ -166,7 +166,7 @@ export class ShellChromeLayer implements Layer {
const now = new Date();
const clock = `${WEEKDAYS[now.getDay()]} ${now.getDate()} ${MONTHS[now.getMonth()]} ` +
`${now.getHours()}:${String(now.getMinutes()).padStart(2, "0")}`;
formatClockTime(now);
const clockX = SIDEBAR_WIDTH + 10;
const textY = Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
image.drawText(font, clockX, textY, clock, 210);
@@ -299,6 +299,17 @@ function tabLeftInset(yy: number, top: number, bottom: number, radius: number):
return Math.max(0, Math.round(radius - Math.sqrt(Math.max(0, radius * radius - dy * dy))));
}
/** Format the top-bar clock time, honoring the 12/24-hour setting. */
function formatClockTime(now: Date): string {
const minutes = String(now.getMinutes()).padStart(2, "0");
const hour24 = now.getHours();
if (timeFormatSetting.get() === "12h") {
const hour12 = ((hour24 + 11) % 12) + 1;
return `${hour12}:${minutes} ${hour24 < 12 ? "AM" : "PM"}`;
}
return `${hour24}:${minutes}`;
}
/** Small triangle marker for sidebar overflow; direction -1 = up, 1 = down. */
function drawChevron(image: GrayImage, centerX: number, y: number, direction: -1 | 1): void {
const half = 5;