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

+14
View File
@@ -17,6 +17,7 @@ export type NightscoutSettings = {
apiToken: string;
};
export type BatteryDisplayMode = "icon" | "percentage";
export type TimeFormat = "24h" | "12h";
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "never";
type ConfigSettingOptions<TValue, TId extends string> = {
@@ -179,6 +180,15 @@ export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMod
formatValue: batteryDisplayModeLabel,
});
export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
id: "timeFormat",
label: "Time format",
storageKey: "display.timeFormat",
defaultValue: "24h",
values: ["24h", "12h"],
formatValue: timeFormatLabel,
});
export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>({
id: "screen-timeout",
label: "Screen timeout",
@@ -308,6 +318,10 @@ export function batteryDisplayModeLabel(value: BatteryDisplayMode): string {
return value === "icon" ? "Icon" : "Percentage";
}
export function timeFormatLabel(value: TimeFormat): string {
return value === "12h" ? "12-hour" : "24-hour";
}
export function loadNightscoutSettings(): NightscoutSettings {
return {
siteUrl: nightscoutSiteUrlSetting.get(),
+3 -1
View File
@@ -1,7 +1,7 @@
import { APP_VIEWPORT } from "../shell/geometry";
import { MenuLayer, type MenuLayout } from "../menu";
import { shell } from "../shell/shell";
import { batteryDisplayModeSetting, elevenLabsApiKeySetting, enumSettingMenuItem, firmwareDebugFlagsSetting, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, terminalAuthTokenSetting, terminalHostSetting, terminalPortSetting, textSettingMenuItem, toggleSettingMenuItem, voiceProviderSetting, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
import { batteryDisplayModeSetting, elevenLabsApiKeySetting, enumSettingMenuItem, firmwareDebugFlagsSetting, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, terminalAuthTokenSetting, terminalHostSetting, terminalPortSetting, textSettingMenuItem, timeFormatSetting, toggleSettingMenuItem, voiceProviderSetting, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
import { AboutPage } from "./about-page";
// Rendered in the Settings app window (viewport-sized); cap height to it.
@@ -94,6 +94,8 @@ function createDisplaySettingsMenuLayer(): MenuLayer {
}),
// Controls the top-bar battery indicators (icon vs percentage).
enumSettingMenuItem(batteryDisplayModeSetting),
// Controls the top-bar clock (24-hour vs 12-hour).
enumSettingMenuItem(timeFormatSetting),
],
SETTINGS_MENU_LAYOUT,
);
+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;
+25
View File
@@ -5,6 +5,7 @@ import { DashboardInputEvent, LayerActions, LayerStack } from "../layers";
import { MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer } from "../apps/voice-input";
import { SingleNotificationLayer } from "../notifications";
import { batteryDisplayModeSetting, onAnySettingChanged, timeFormatSetting } from "../dashboard-settings";
import { ShellChromeLayer, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
import { ShellModalLayer } from "./modal-layer";
import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
@@ -113,9 +114,33 @@ class Shell {
this.actions,
);
// Top-bar settings we mirror into the chrome; a change to either repaints
// the shell surface so the top bar reflects it immediately.
private topBarSettingsSubscribed = false;
private lastBatteryDisplayMode: string | null = null;
private lastTimeFormat: string | null = null;
configure(config: ShellConfig): void {
this.config = config;
this.stack.setActions(config.actions);
this.subscribeToTopBarSettings();
}
private subscribeToTopBarSettings(): void {
if (this.topBarSettingsSubscribed) return;
this.topBarSettingsSubscribed = true;
this.lastBatteryDisplayMode = batteryDisplayModeSetting.get();
this.lastTimeFormat = timeFormatSetting.get();
onAnySettingChanged(() => {
const batteryMode = batteryDisplayModeSetting.get();
const timeFormat = timeFormatSetting.get();
if (batteryMode === this.lastBatteryDisplayMode && timeFormat === this.lastTimeFormat) {
return;
}
this.lastBatteryDisplayMode = batteryMode;
this.lastTimeFormat = timeFormat;
this.config.requestShellRender();
});
}
/** Add a window (or replace one with the same windowId, keeping its slot). */