G2 only: You can pair the glasses with a bluetooth keyboard. It will relay key events, and you can use it to type in some apps and to navigate the UI.
701 lines
26 KiB
TypeScript
701 lines
26 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/local-llm";
|
|
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,
|
|
assistantHermesKeySetting,
|
|
assistantHermesUrlSetting,
|
|
assistantBridgeHostSetting,
|
|
assistantBridgePortSetting,
|
|
assistantBridgeTokenSetting,
|
|
assistantModelSetting,
|
|
assistantOpenAiCompatibleKeySetting,
|
|
assistantOpenAiCompatibleModelSetting,
|
|
assistantOpenAiCompatibleUrlSetting,
|
|
assistantSkipConfirmationSetting,
|
|
veniceWebSearchSetting,
|
|
batteryDisplayModeSetting,
|
|
brightnessSetting,
|
|
autoBrightnessMinSetting,
|
|
autoBrightnessMaxSetting,
|
|
autoBrightnessCurveSetting,
|
|
dataCollectionSetting,
|
|
distanceUnitSetting,
|
|
glassesBatteryVisibilitySetting,
|
|
glassesModelName,
|
|
phoneBatteryVisibilitySetting,
|
|
ringBatteryVisibilitySetting,
|
|
watchBatteryVisibilitySetting,
|
|
displayLayoutSetting,
|
|
elevenLabsApiKeySetting,
|
|
mapboxApiKeySetting,
|
|
mirrorTouchSetting,
|
|
openAiApiKeySetting,
|
|
previewColorSetting,
|
|
previewScalingSetting,
|
|
phoneInputStyleSetting,
|
|
phoneRotationSetting,
|
|
ringConnectionModeSetting,
|
|
glassesTypeSetting,
|
|
sonioxApiKeySetting,
|
|
whisperServerApiKeySetting,
|
|
whisperServerLanguageSetting,
|
|
whisperServerModelSetting,
|
|
whisperServerUrlSetting,
|
|
screenFadeSetting,
|
|
enumSettingMenuItem,
|
|
firmwareDebugFlagsSetting,
|
|
lockScreenEnabledSetting,
|
|
menuAnimationSetting,
|
|
newNotificationDisplaySetting,
|
|
showBleBandwidthSetting,
|
|
suspendEvenHubWhenScreenOffSetting,
|
|
temperatureUnitSetting,
|
|
textSettingMenuItem,
|
|
timeFormatSetting,
|
|
toggleSettingMenuItem,
|
|
useMicControlSetting,
|
|
voiceProviderSetting,
|
|
screenTimeoutSetting,
|
|
wakeToLastAppSetting,
|
|
wakeWordActionSetting,
|
|
watchCanUnlockSetting,
|
|
watchCrownClockwiseNextSetting,
|
|
watchMirrorAssistantSetting,
|
|
watchRemoteEnabledSetting,
|
|
watchSoundEffectsSetting,
|
|
watchVibrateOnInputSetting,
|
|
} from "../dashboard-settings";
|
|
import { wearBridge } from "../../native/wear-bridge";
|
|
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
|
|
import { uiFontPickerMenuItem } from "../font-picker";
|
|
import { NotificationFilterLayer } from "../notification-filter";
|
|
import { compatibleModelDiscoveryMenuItem } from "../openai-compatible-model-picker";
|
|
import { keyboardSettingsMenuItem } from "../keyboard-settings";
|
|
import { isVeniceApiBaseUrl } from "../../native/openai-chat";
|
|
|
|
/** The Settings section the Notifications app's "Settings" menu item opens. */
|
|
export const NOTIFICATIONS_SETTINGS_SECTION = "Notifications";
|
|
|
|
/** 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),
|
|
toggleSettingMenuItem(wakeToLastAppSetting),
|
|
// A band (at one of five heights) / Tall / Full Screen; the
|
|
// dashboard controller moves or reflows windows on change.
|
|
enumSettingMenuItem(displayLayoutSetting),
|
|
],
|
|
},
|
|
{
|
|
label: "Customization",
|
|
// Depth, the status bar's place and the border only apply (and only
|
|
// show) with the app switcher at the bottom or a popup; the panel
|
|
// re-reads the rows each paint.
|
|
get items() {
|
|
return customizationItems();
|
|
},
|
|
},
|
|
{
|
|
// Also opened from the Notifications app's menu (deep link by label).
|
|
label: NOTIFICATIONS_SETTINGS_SECTION,
|
|
items: [
|
|
enumSettingMenuItem(newNotificationDisplaySetting),
|
|
notificationFilterMenuItem(),
|
|
],
|
|
},
|
|
{
|
|
label: "Voice",
|
|
items: [
|
|
enumSettingMenuItem(wakeWordActionSetting),
|
|
enumSettingMenuItem(voiceProviderSetting),
|
|
...whisperServerMenuItems(),
|
|
asrModelMenuItem("moonshine"),
|
|
asrModelMenuItem("whisper-base-en"),
|
|
],
|
|
},
|
|
{
|
|
label: "Assistant",
|
|
// Re-read on every paint: provider-specific rows follow the selected
|
|
// model (and, for Venice, the compatible URL).
|
|
get items() {
|
|
const selectedModel = assistantModelSetting.get();
|
|
return [
|
|
// iOS's on-phone model is Apple Intelligence; Android downloads one. Only Android has the bridge.
|
|
enumSettingMenuItem(assistantBackendSetting),
|
|
enumSettingMenuItem(assistantModelSetting),
|
|
...(selectedModel === "hermes" ? [
|
|
textSettingMenuItem(assistantHermesUrlSetting),
|
|
textSettingMenuItem(assistantHermesKeySetting),
|
|
] : []),
|
|
...(selectedModel === "openai-compatible" ? [
|
|
textSettingMenuItem(assistantOpenAiCompatibleUrlSetting),
|
|
textSettingMenuItem(assistantOpenAiCompatibleKeySetting),
|
|
compatibleModelDiscoveryMenuItem({
|
|
getBaseUrl: () => assistantOpenAiCompatibleUrlSetting.get(),
|
|
getApiKey: () => assistantOpenAiCompatibleKeySetting.get(),
|
|
getModel: () => assistantOpenAiCompatibleModelSetting.get(),
|
|
setModel: (model) => assistantOpenAiCompatibleModelSetting.set(model),
|
|
}, assistantOpenAiCompatibleModelSetting),
|
|
textSettingMenuItem(assistantOpenAiCompatibleModelSetting),
|
|
...(isVeniceApiBaseUrl(assistantOpenAiCompatibleUrlSetting.get())
|
|
? [toggleSettingMenuItem(veniceWebSearchSetting)] : []),
|
|
] : []),
|
|
global.isIOS ? systemModelMenuItem() : localModelMenuItem(),
|
|
toggleSettingMenuItem(assistantSkipConfirmationSetting),
|
|
// iOS has no 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),
|
|
enumSettingMenuItem(previewScalingSetting),
|
|
toggleSettingMenuItem(mirrorTouchSetting),
|
|
// Watch or Ring: which touchpad the main page shows under the mirror.
|
|
enumSettingMenuItem(phoneInputStyleSetting),
|
|
],
|
|
},
|
|
{
|
|
label: "Watch",
|
|
// Watch remote (wear/, apple-watch/); the status line above the items says
|
|
// whether a watch running the companion app is currently reachable.
|
|
items: [
|
|
toggleSettingMenuItem(watchRemoteEnabledSetting),
|
|
...(global.isIOS ? [
|
|
toggleSettingMenuItem(watchVibrateOnInputSetting),
|
|
toggleSettingMenuItem(watchSoundEffectsSetting),
|
|
] : [
|
|
toggleSettingMenuItem(watchCrownClockwiseNextSetting),
|
|
]),
|
|
toggleSettingMenuItem(watchCanUnlockSetting),
|
|
toggleSettingMenuItem(watchMirrorAssistantSetting),
|
|
],
|
|
renderDetail: renderWatchStatus,
|
|
},
|
|
// A Bluetooth keyboard paired with the glasses themselves (the G2's
|
|
// custom firmware hosts it; app/g2/keyboard/). Hidden rather than left
|
|
// out: the Settings window can be open across a change of glasses.
|
|
{
|
|
label: "Keyboard",
|
|
items: [keyboardSettingsMenuItem()],
|
|
hidden: () => glassesTypeSetting.get() !== "g2",
|
|
},
|
|
{
|
|
label: "Developer",
|
|
items: [
|
|
// Whether and how the phone opens its own BLE link to the R1 ring.
|
|
// Applied at connect time.
|
|
ringConnectionMenuItem(),
|
|
toggleSettingMenuItem(firmwareDebugFlagsSetting),
|
|
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),
|
|
toggleSettingMenuItem(useMicControlSetting),
|
|
toggleSettingMenuItem(showBleBandwidthSetting),
|
|
],
|
|
},
|
|
{
|
|
label: "Privacy",
|
|
items: [
|
|
// First chosen in the on-glasses onboarding (app/apps/onboarding/).
|
|
enumSettingMenuItem(dataCollectionSetting),
|
|
bundledDocMenuItem("PRIVACY", "Privacy policy"),
|
|
],
|
|
},
|
|
{
|
|
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;
|
|
return sections.map(section => {
|
|
if (section.label === "Developer") return { ...section, items: [enumSettingMenuItem(ringConnectionModeSetting),
|
|
toggleSettingMenuItem(showBleBandwidthSetting)] };
|
|
// No downloadable on-device models: iOS's on-device option is Apple's recognizer.
|
|
if (section.label === "Voice") return { label: "Voice", items: [enumSettingMenuItem(wakeWordActionSetting),
|
|
enumSettingMenuItem(voiceProviderSetting), ...whisperServerMenuItems()] };
|
|
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).
|
|
const statusBarVisibility = enumSettingMenuItem(statusBarVisibilitySetting);
|
|
// The lines round the foreground window: a rounded border all around, only
|
|
// the line between it and the status bar, or none; the dashboard
|
|
// controller resizes windows when the border's rows come or go.
|
|
const windowBorder = enumSettingMenuItem(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),
|
|
// Fahrenheit or Celsius, wherever weather temperatures show.
|
|
enumSettingMenuItem(temperatureUnitSetting),
|
|
// Miles or kilometers: Weather's wind speed and Navigate's distances.
|
|
enumSettingMenuItem(distanceUnitSetting),
|
|
];
|
|
const bottomRows = [font, position, depth, statusBar, windowBorder, ...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;
|
|
}
|
|
};
|
|
}
|
|
|
|
/** Notifications > Notification filter: per-app toggles for which notifications pop up. */
|
|
function notificationFilterMenuItem(): MenuItem {
|
|
return submenuItem(
|
|
"Notification filter",
|
|
(ctx) => {
|
|
ctx.stack.push(new NotificationFilterLayer());
|
|
},
|
|
{ description: "Choose which apps' new notifications pop up on the glasses. All of them still appear in the Notifications app." },
|
|
);
|
|
}
|
|
|
|
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, 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),
|
|
// Named as the top bar names this indicator.
|
|
enumSettingMenuItem(glassesBatteryVisibilitySetting, { label: glassesModelName() }),
|
|
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 speeds. */
|
|
function animationsMenuItem(): MenuItem {
|
|
return submenuItem(
|
|
"Animations",
|
|
(ctx) => {
|
|
openSettingsSubMenu(ctx, "Animations", [
|
|
enumSettingMenuItem(menuAnimationSetting),
|
|
enumSettingMenuItem(screenFadeSetting),
|
|
]);
|
|
},
|
|
{ description: "Speed up, slow down, or turn off menu and icon-grid motion and 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";
|
|
}
|
|
|
|
/**
|
|
* iOS: the on-phone model is the Apple Intelligence system model, which iOS
|
|
* installs and manages; the row only reports whether it can be used.
|
|
*/
|
|
function systemModelMenuItem(): MenuItem {
|
|
const statusText = (): string => {
|
|
const state = localModelState();
|
|
return state.status === "ready" ? "ready" : state.detail ?? "unavailable";
|
|
};
|
|
return {
|
|
label: "On-phone model",
|
|
description:
|
|
"Apple Intelligence's on-device model answers assistant queries on the phone itself, with no API key or cloud service. " +
|
|
"Needs iOS 26 and an iPhone that supports Apple Intelligence, with Apple Intelligence turned on in iOS Settings. " +
|
|
"Faster and more private than the cloud models, but simpler, with a short memory. " +
|
|
"Used automatically when no API key is set.",
|
|
onSelect: () => {},
|
|
render: ({ image, x, y, width }) => {
|
|
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, "On-phone model", statusText());
|
|
},
|
|
};
|
|
}
|
|
|
|
/** 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";
|
|
}
|
|
|
|
/**
|
|
* The self-hosted Whisper server's settings. Always listed: the provider
|
|
* option stays disabled until the URL is set.
|
|
*/
|
|
function whisperServerMenuItems(): MenuItem[] {
|
|
return [
|
|
textSettingMenuItem(whisperServerUrlSetting),
|
|
textSettingMenuItem(whisperServerModelSetting),
|
|
textSettingMenuItem(whisperServerLanguageSetting),
|
|
textSettingMenuItem(whisperServerApiKeySetting),
|
|
];
|
|
}
|
|
|
|
/** 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)`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Developer > Ring connection: the setting, except with a RayNeo iO, which
|
|
* always takes the ring directly (effectiveRingConnectionMode): then a fixed,
|
|
* disabled "Direct" row, the stored choice kept for G2 glasses.
|
|
*/
|
|
function ringConnectionMenuItem(): MenuItem {
|
|
const item = enumSettingMenuItem(ringConnectionModeSetting);
|
|
const io = () => glassesTypeSetting.get() !== "g2";
|
|
return {
|
|
...item,
|
|
disabled: io,
|
|
render: (args) => {
|
|
if (!io()) return item.render?.(args);
|
|
drawRightValueMenuItem(args.image, getDefaultSmallFont(), args.x, args.y, args.width, item.label, glassesTypeSetting.get() === "g1" ? "Direct (Even G1)" : "Direct (RayNeo iO)");
|
|
},
|
|
};
|
|
}
|
|
|
|
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 = global.isIOS
|
|
? "This device can't pair with an Apple Watch."
|
|
: "Google Play services is unavailable on this phone, so no watch can connect.";
|
|
} else {
|
|
const connection = wearBridge.getWatchConnection();
|
|
if (global.isIOS) {
|
|
// iOS only says whether the app is installed; it may not be running.
|
|
status = connection.reachable
|
|
? "The Faceclaw app is installed on your Apple Watch."
|
|
: "No watch connected. Install the Faceclaw watch app (apple-watch/ in the source tree) on an Apple Watch paired with this iPhone.";
|
|
} else {
|
|
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;
|
|
}
|