Files
faceclaw/app/ui/dashboard/settings-menus.ts
T
James Babcock 16fc0bcfb6 Fix padding in notifications; reorder settings in Customization section
<details>
<summary>Prompts Used</summary>
User: On the single notification view (focusing a notification on the bottom bar, or in the notifications app), the page title "Notification" and the notification itself can overlap, depending on configured font size.

Opus 5.5:
> I fixed the overlap in the single-notification view, but I haven't checked it on the glasses. The build and typecheck pass.
>
> **Cause:** In `drawDetailContent` (`app/ui/notifications.ts`), the "Notification" title was drawn at y=21, but the icon and the app-name/time line under it were at fixed spots (y=36 and y=42). Only the body text below them moved with the font. Small-font line heights go up to 21px, and once the line height passes about 15px, the title runs into the app-name line.
>
> **Fix:** The header now sits below the title's text line: 3px below it, then a row as tall as the icon or the text line, whichever is bigger. The app name is centred vertically against the icon, and the body starts 4px below that row. At the 12px default everything lands exactly where it did before, so only larger fonts look different. The menu on the right was never affected.
>
> This covers both places you hit it: the bottom-bar tray and the Notifications app's detail view. The pop-up for a new notification uses the same view, so it gets the fix too.
>
> One thing I left alone: this title sits at (24, 21), but list screens like the Notifications list put their title at (18, 10). So the title jumps a little when you open a notification from the list. Moving it to (18, 10) would make the two match and give large fonts about 11px more room. Say if you want that.

<hr>

User: Thanks. Next up, in the Customization section of the Settings app, reorder the settings so that Font is first.

Opus 5.5:
> Font is now the first row in Settings > Customization, whichever app-switcher position is set (left/right, bottom or popup). The other rows keep their order: app switcher position, then the bottom/popup-only rows, then Battery indicators, Animations and Time format.
>
> The change is in `customizationRows()` in `app/ui/dashboard/settings-menus.ts`. Nothing else relies on the row order, and the build passes. I haven't installed it on a device.
</details>
2026-10-03 01:29:59 -07:00

544 lines
20 KiB
TypeScript

import { remoteInputMenuItem } from "./remote-input-menu";
import { knownFolders } from "@nativescript/core";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import type { GrayImage } from "../../graphics/image";
import { getDashboardLogo } from "../../graphics/logo";
import { wrapText } from "../../graphics/textwrap";
import { FACECLAW_VERSION } from "../../version";
import {
cancelLocalModelDownload,
deleteLocalModel,
LOCAL_MODEL,
localModelState,
onLocalModelStateChanged,
startLocalModelDownload,
} from "../../native/llama";
import {
ASR_MODELS,
asrModelState,
cancelAsrModelDownload,
deleteAsrModel,
onAsrModelStateChanged,
startAsrModelDownload,
type AsrModelId,
} from "../../native/asr-model";
import { TextViewerLayer } from "../../apps/files/text-viewer";
import type { LayerContext } from "../layers";
import { drawRightValueMenuItem, openModalMenu, submenuItem, type MenuItem } from "../menu";
import { shell } from "../shell/shell";
import {
anthropicApiKeySetting,
appSwitcherPositionSetting,
statusBarPositionSetting,
statusBarVisibilitySetting,
windowBorderSetting,
uiDepthSetting,
assistantAllowProactiveSetting,
assistantBackendSetting,
assistantBridgeHostSetting,
assistantBridgePortSetting,
assistantBridgeTokenSetting,
assistantModelSetting,
assistantSkipConfirmationSetting,
batteryDisplayModeSetting,
brightnessSetting,
autoBrightnessMinSetting,
autoBrightnessMaxSetting,
autoBrightnessCurveSetting,
glassesBatteryVisibilitySetting,
phoneBatteryVisibilitySetting,
ringBatteryVisibilitySetting,
watchBatteryVisibilitySetting,
displayModeSetting,
elevenLabsApiKeySetting,
mapboxApiKeySetting,
mirrorTouchSetting,
openAiApiKeySetting,
previewColorSetting,
phoneRotationSetting,
ringConnectionModeSetting,
sonioxApiKeySetting,
screenFadeSetting,
enumSettingMenuItem,
firmwareDebugFlagsSetting,
lockScreenEnabledSetting,
menuAnimationSetting,
saveVoiceRecordingsSetting,
showBleBandwidthSetting,
suspendEvenHubWhenScreenOffSetting,
textSettingMenuItem,
timeFormatSetting,
toggleSettingMenuItem,
useMicControlSetting,
verticalPositionSetting,
voiceProviderSetting,
screenTimeoutSetting,
wakeWordActionSetting,
watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
watchMirrorAssistantSetting,
watchRemoteEnabledSetting,
} from "../dashboard-settings";
import { wearBridge } from "../../native/wear-bridge";
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
import { uiFontPickerMenuItem } from "../font-picker";
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
export function createSettingsPanelLayer(): SettingsPanelLayer {
return new SettingsPanelLayer(settingsSections());
}
function settingsSections(): SettingsSection[] {
const customizationItems = customizationRows();
const sections: SettingsSection[] = [
{
label: "Display",
items: [
// Auto (ambient sensor) or an exact level; pushed to the glasses by
// the dashboard controller when changed and on each connect.
enumSettingMenuItem(brightnessSetting),
autoBrightnessMenuItem(),
enumSettingMenuItem(screenTimeoutSetting, {
onChange: () => {
shell.noteUserActivity();
},
}),
toggleSettingMenuItem(lockScreenEnabledSetting),
// Where min-height windows (and the sidebar) sit vertically on the
// screen; the dashboard controller repositions surfaces on change.
enumSettingMenuItem(verticalPositionSetting),
// Band / tall / full-panel; the dashboard controller reflows windows.
enumSettingMenuItem(displayModeSetting),
],
},
{
label: "Customization",
// Depth only applies (and only shows) with the app switcher at the
// bottom; the panel re-reads the rows each paint.
get items() {
return customizationItems();
},
},
{
label: "Voice",
items: [
enumSettingMenuItem(wakeWordActionSetting),
enumSettingMenuItem(voiceProviderSetting),
asrModelMenuItem("moonshine"),
asrModelMenuItem("whisper-base-en"),
],
},
{
label: "Assistant",
items: [
// iOS offers cloud APIs; Android also supports local models and the bridge.
enumSettingMenuItem(assistantBackendSetting),
enumSettingMenuItem(assistantModelSetting),
...(!global.isIOS ? [localModelMenuItem()] : []),
toggleSettingMenuItem(assistantSkipConfirmationSetting),
// iOS has no local LLM or agent bridge yet.
...(!global.isIOS ? [
textSettingMenuItem(assistantBridgeHostSetting),
textSettingMenuItem(assistantBridgePortSetting),
textSettingMenuItem(assistantBridgeTokenSetting),
toggleSettingMenuItem(assistantAllowProactiveSetting),
] : []),
],
},
{
label: "API Keys",
items: [
remoteInputMenuItem(),
textSettingMenuItem(elevenLabsApiKeySetting),
textSettingMenuItem(openAiApiKeySetting),
textSettingMenuItem(sonioxApiKeySetting),
textSettingMenuItem(anthropicApiKeySetting),
textSettingMenuItem(mapboxApiKeySetting),
],
},
{
label: "Phone display",
// The phone app's mirror of the glasses screen and its controls
// (app/phone-ui/): all read live by the main page.
items: [
enumSettingMenuItem(phoneRotationSetting),
enumSettingMenuItem(previewColorSetting),
toggleSettingMenuItem(mirrorTouchSetting),
],
},
{
label: "Watch",
// Wear OS remote (wear/); the status line above the items says whether
// a watch running the companion app is currently reachable.
items: [
toggleSettingMenuItem(watchRemoteEnabledSetting),
toggleSettingMenuItem(watchCrownClockwiseNextSetting),
toggleSettingMenuItem(watchCanUnlockSetting),
toggleSettingMenuItem(watchMirrorAssistantSetting),
],
renderDetail: renderWatchStatus,
},
{
label: "Developer",
items: [
// Whether the phone opens its own BLE link to the R1 ring; the
// glasses relay ring gestures either way. Applied at connect time.
enumSettingMenuItem(ringConnectionModeSetting),
toggleSettingMenuItem(saveVoiceRecordingsSetting),
toggleSettingMenuItem(firmwareDebugFlagsSetting),
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),
toggleSettingMenuItem(useMicControlSetting),
toggleSettingMenuItem(showBleBandwidthSetting),
],
},
{
label: "About",
// The version/license blurb (renderDetail) draws above the bundled
// project docs, in both the preview and the focused states.
items: [
bundledDocMenuItem("README.md", "README"),
bundledDocMenuItem("LICENSE", "License"),
bundledDocMenuItem("PRIVACY", "Privacy policy"),
bundledDocMenuItem("ACKNOWLEDGEMENTS.md", "Acknowledgements"),
],
renderDetail: renderAbout,
},
{
label: "Quit",
items: [
{
label: "Disconnect from glasses",
description: "Close the Bluetooth connection to the glasses and return them to standby.",
onSelect: async (ctx) => {
ctx.stack.clearToBase();
await ctx.actions.disconnect();
},
},
],
},
];
if (!global.isIOS) return sections;
const deferred = new Set(["Watch"]);
return sections.map(section => {
if (section.label === "Developer") return { ...section, items: [toggleSettingMenuItem(showBleBandwidthSetting)] };
if (section.label === "Voice") return { label: "Voice", items: [enumSettingMenuItem(wakeWordActionSetting), {
label: "On-device dictation (Apple)", disabled: true, onSelect: () => {},
description: "Uses the glasses microphone and your iPhone's speech language. No transcription API key needed. Say Hey Even for hands-free input, or open Voice from the menu and click when finished.",
}] };
if (deferred.has(section.label)) return { label: section.label, items: [{
label: "Not available on iOS yet", disabled: true, onSelect: () => {},
description: `${section.label} integration has not been ported to iOS.`,
}] };
if (section.label === "Display") return { ...section, items: section.items.filter(item =>
item.label !== screenTimeoutSetting.label) };
return section;
});
}
/**
* The Customization rows, as a function of the current settings: the same
* array while the switcher position stays put, so the panel's menu sees a
* stable list between paints.
*/
function customizationRows(): () => MenuItem[] {
// Opens the modal font picker (face, weight, size) for UI text.
const font = uiFontPickerMenuItem();
// Left / right / bottom edge, or popup; the dashboard controller moves or
// resizes windows on change.
const position = enumSettingMenuItem(appSwitcherPositionSetting);
// The whole display's stereo depth; the shell sends it with its scene.
const depth = enumSettingMenuItem(uiDepthSetting);
// Top bar, or the bottom: the right end of a bottom switcher's row, or a
// bar under the window with a popup switcher; the dashboard controller
// resizes or moves windows on change.
const statusBar = enumSettingMenuItem(statusBarPositionSetting);
// Popup switcher only: whether the status bar shows only in the switcher
// (windows then grow into its rows), and the foreground window's border.
const statusBarVisibility = enumSettingMenuItem(statusBarVisibilitySetting);
const windowBorder = toggleSettingMenuItem(windowBorderSetting);
const rest = [
// Submenu: top-bar battery indicator style plus per-device visibility.
batteryIndicatorsMenuItem(),
// Submenu: toggles for menu/icon-grid motion and the screen on/off fade.
animationsMenuItem(),
// Controls the top-bar clock (24-hour vs 12-hour).
enumSettingMenuItem(timeFormatSetting),
];
const bottomRows = [font, position, depth, statusBar, ...rest];
const popupRows = [font, position, depth, statusBar, statusBarVisibility, windowBorder, ...rest];
const sideRows = [font, position, ...rest];
return () => {
switch (appSwitcherPositionSetting.get()) {
case "bottom":
return bottomRows;
case "popup":
return popupRows;
default:
return sideRows;
}
};
}
function autoBrightnessMenuItem(): MenuItem {
return submenuItem(
"Auto-brightness",
(ctx) => {
openSettingsSubMenu(ctx, "Auto-brightness", [
enumSettingMenuItem(autoBrightnessMinSetting),
enumSettingMenuItem(autoBrightnessMaxSetting),
textSettingMenuItem(autoBrightnessCurveSetting),
]);
},
{ description: "Adjust the minimum, maximum, and ambient-light curve used by Auto brightness." },
);
}
/**
* The Customization section's "Battery indicators" row: opens a modal submenu with
* the style (icon / percentage / stacked) and, per device, when its
* indicator is visible. The row itself shows the current style.
*/
function batteryIndicatorsMenuItem(): MenuItem {
return {
label: "Battery indicators",
description:
"Top-bar battery indicators for the phone, Wear OS watch, glasses, and ring: their style, and whether each shows always, only when low, or never.",
onSelect: (ctx) => {
openSettingsSubMenu(ctx, "Battery indicators", [
enumSettingMenuItem(batteryDisplayModeSetting),
enumSettingMenuItem(phoneBatteryVisibilitySetting),
enumSettingMenuItem(watchBatteryVisibilitySetting),
enumSettingMenuItem(glassesBatteryVisibilitySetting),
enumSettingMenuItem(ringBatteryVisibilitySetting),
]);
},
render: ({ image, x, y, width }) => {
drawRightValueMenuItem(
image,
getDefaultSmallFont(),
x,
y,
width,
"Battery indicators",
batteryDisplayModeSetting.displayValue(),
);
},
};
}
/** The Customization section's "Animations" row: opens a modal submenu of animation toggles. */
function animationsMenuItem(): MenuItem {
return submenuItem(
"Animations",
(ctx) => {
openSettingsSubMenu(ctx, "Animations", [
toggleSettingMenuItem(menuAnimationSetting),
toggleSettingMenuItem(screenFadeSetting),
]);
},
{ description: "Turn off menu and icon-grid motion, or the fade when the screen turns on and off." },
);
}
const LOCAL_MODEL_GB = `${(LOCAL_MODEL.sizeBytes / 1e9).toFixed(1)}GB`;
// While a download is running, re-render on progress updates so the row's
// percentage stays live; the watch tears itself down when the download ends.
let localModelRenderUnsub: (() => void) | null = null;
function watchLocalModelDownload(ctx: LayerContext): void {
localModelRenderUnsub?.();
localModelRenderUnsub = onLocalModelStateChanged((state) => {
ctx.actions.requestRender();
if (state.status !== "downloading") {
localModelRenderUnsub?.();
localModelRenderUnsub = null;
}
});
}
function localModelStatusText(): string {
const state = localModelState();
if (state.status === "ready") return "downloaded";
if (state.status === "downloading") {
const pct = state.totalBytes > 0 ? Math.floor((state.bytesDownloaded / state.totalBytes) * 100) : 0;
return `${pct}% of ${LOCAL_MODEL_GB}`;
}
return "not downloaded";
}
/** Download/cancel/delete management for the on-phone assistant model. */
function localModelMenuItem(): MenuItem {
return {
label: "On-phone model",
description:
`${LOCAL_MODEL.label} (${LOCAL_MODEL_GB} download over Wi-Fi recommended). ` +
"Answers assistant queries on the phone itself, with no API key or cloud service. " +
"Slower and simpler than the cloud models, but free and private. " +
"Used automatically when no API key is set. An interrupted download resumes where it left off.",
onSelect: (ctx) => {
const state = localModelState();
const action: MenuItem =
state.status === "downloading"
? {
label: "Cancel download",
onSelect: (innerCtx) => {
cancelLocalModelDownload();
innerCtx.stack.pop();
},
}
: state.status === "ready"
? {
label: "Delete model",
onSelect: (innerCtx) => {
deleteLocalModel();
innerCtx.stack.pop();
},
}
: {
label: `Download (${LOCAL_MODEL_GB})`,
onSelect: (innerCtx) => {
startLocalModelDownload();
watchLocalModelDownload(innerCtx);
innerCtx.stack.pop();
},
};
openModalMenu(ctx, "On-phone model", [action], 0);
},
render: ({ image, x, y, width }) => {
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, "On-phone model", localModelStatusText());
},
};
}
function asrModelMb(id: AsrModelId): string {
return `${Math.round(ASR_MODELS[id].totalBytes / 1e6)}MB`;
}
const asrModelRenderUnsub: Partial<Record<AsrModelId, () => void>> = {};
function watchAsrModelDownload(id: AsrModelId, ctx: LayerContext): void {
asrModelRenderUnsub[id]?.();
asrModelRenderUnsub[id] = onAsrModelStateChanged(id, (state) => {
ctx.actions.requestRender();
if (state.status !== "downloading") {
asrModelRenderUnsub[id]?.();
asrModelRenderUnsub[id] = undefined;
}
});
}
function asrModelStatusText(id: AsrModelId): string {
const state = asrModelState(id);
if (state.status === "ready") return "downloaded";
if (state.status === "downloading") {
const pct = state.totalBytes > 0 ? Math.floor((state.bytesDownloaded / state.totalBytes) * 100) : 0;
return `${pct}% of ${asrModelMb(id)}`;
}
return "not downloaded";
}
/** Download/cancel/delete management for one on-device transcription model. */
function asrModelMenuItem(id: AsrModelId): MenuItem {
const def = ASR_MODELS[id];
const rowLabel = `On-device model: ${def.label}`;
return {
label: rowLabel,
description:
`${def.label} (${asrModelMb(id)} download). ` +
"Transcribes voice input on the phone itself, with no API key or cloud service. " +
"Required for its matching Transcription Provider option; the other providers work without it. " +
"An interrupted download resumes where it left off.",
onSelect: (ctx) => {
const state = asrModelState(id);
const action: MenuItem =
state.status === "downloading"
? {
label: "Cancel download",
onSelect: (innerCtx) => {
cancelAsrModelDownload(id);
innerCtx.stack.pop();
},
}
: state.status === "ready"
? {
label: "Delete model",
onSelect: (innerCtx) => {
deleteAsrModel(id);
innerCtx.stack.pop();
},
}
: {
label: `Download (${asrModelMb(id)})`,
onSelect: (innerCtx) => {
startAsrModelDownload(id);
watchAsrModelDownload(id, innerCtx);
innerCtx.stack.pop();
},
};
openModalMenu(ctx, rowLabel, [action], 0);
},
render: ({ image, x, y, width }) => {
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, rowLabel, asrModelStatusText(id));
},
};
}
/** A row that opens one of the project docs (copied into the bundle under
* about/ by webpack.config.js) in the paged text viewer. */
function bundledDocMenuItem(fileName: string, label: string): MenuItem {
return {
label,
onSelect: (ctx) => {
ctx.stack.push(new TextViewerLayer(readBundledDoc(fileName), label));
},
};
}
function readBundledDoc(fileName: string): string {
try {
const text = knownFolders.currentApp().getFile(`about/${fileName}`).readTextSync();
return text || `(${fileName} is missing from this build)`;
} catch {
return `(${fileName} is missing from this build)`;
}
}
function renderWatchStatus(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
let status: string;
if (!wearBridge.isAvailable()) {
status = "Google Play services is unavailable on this phone, so no watch can connect.";
} else {
const connection = wearBridge.getWatchConnection();
status = connection.reachable
? `Connected to ${connection.watchName || "a watch"}.`
: "No watch connected. Install the Faceclaw watch app (wear/ in the source tree) on a Wear OS watch paired with this phone.";
}
const lines = wrapText(font, status, width);
for (let i = 0; i < lines.length; i++) {
image.drawText(font, x, y + i * font.lineHeight, lines[i]!, 170);
}
return lines.length * font.lineHeight + 10;
}
function renderAbout(args: { image: GrayImage; x: number; y: number; width: number }): number {
const { image, x, y, width } = args;
const font = getDefaultSmallFont();
const logo = getDashboardLogo();
if (logo) {
image.bitBlt(logo, x, y + 4, { transparentZero: true });
}
const textX = logo ? x + logo.width + 12 : x;
image.drawText(font, textX, y + 8, "Faceclaw", 220);
image.drawText(font, textX, y + 24, `v${FACECLAW_VERSION}`, 170);
const blurb = "By James Babcock and other contributors. Distributed under the GNU General Public License, version 3.";
const blurbY = y + Math.max(64, logo ? logo.height + 12 : 0);
const blurbLines = wrapText(font, blurb, width);
for (let i = 0; i < blurbLines.length; i++) {
image.drawText(font, x, blurbY + i * font.lineHeight, blurbLines[i]!, 170);
}
return blurbY - y + blurbLines.length * font.lineHeight + 10;
}