Merge upstream main preserving custom feature integrations

This commit is contained in:
MasterControl committed 2026-11-10 17:08:15 +00:00
commit 6150a1ac57
228 files changed
+16844 -1388

No files matched your search

+126 -12
View File
@@ -2,7 +2,7 @@ import { readHealthExportSecret, writeHealthExportSecret } from "../native/healt
import type { OpenAiSttModel } from "../native/openai-stt";
import { normalizeNightscoutThreshold, type NightscoutThresholds } from "../apps/nightscout/nightscout-alerts";
import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures";
import { DEFAULT_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
import { DEFAULT_BRIGHTNESS_CURVE, G1_BRIGHTNESS_CURVE, RAYNEO_IO_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
import {
getBooleanSetting,
getStringSetting,
@@ -19,6 +19,7 @@ import {
type AssistantModel,
} from "~/assistant/models";
import { isLocalModelReady } from "../native/local-llm";
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
import { normalizeWhisperServerUrl } from "../native/whisper-server-stt";
import { TRANSCRIPTION_LANGUAGES, resolveTranscriptionLanguage, type TranscriptionLanguage } from "../native/transcription-language";
import { normalizeOpenAiCompatibleUrl } from "../native/openai-chat";
@@ -43,6 +44,8 @@ export type TimeFormat = "24h" | "12h";
export type TemperatureUnit = "fahrenheit" | "celsius";
export type DistanceUnit = "miles" | "kilometers";
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "3m" | "never";
/** Whether new phone notifications pop up on the glasses, and for how long without interaction. */
export type NewNotificationDisplay = "off" | "until-dismissed" | "5s" | "15s" | "1m";
// Auto runs Faceclaw's light curve. Numeric values use the calibrated firmware
// scale, clamped to 2–100; 2 is also the endpoint for screen fades.
export const BRIGHTNESS_VALUES = ["auto", "2", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
@@ -189,31 +192,40 @@ type ConfigSettingEnumOptions<TValue extends string, TId extends string> = Confi
normalize?: (value: string | null | undefined) => TValue;
/** Dynamic availability check used by enum picker rows. */
isDisabled?: (value: TValue) => boolean;
/** The default while nothing is stored, when it depends on context (else `defaultValue`). */
dynamicDefault?: () => TValue | undefined;
};
export class ConfigSettingEnum<TValue extends string, TId extends string = string> extends ConfigSetting<TValue, TId> {
readonly values: readonly TValue[];
private readonly normalizer: (value: string | null | undefined) => TValue;
private readonly disabledPredicate: (value: TValue) => boolean;
private readonly dynamicDefault: (() => TValue | undefined) | undefined;
constructor(options: ConfigSettingEnumOptions<TValue, TId>) {
super(options);
this.dynamicDefault = options.dynamicDefault;
if (options.reportInAnalytics !== false) fixedChoiceSettings.set(options.storageKey, this);
this.values = options.values;
this.disabledPredicate = options.isDisabled ?? (() => false);
if (options.normalize) {
this.normalizer = (value: string | null | undefined) => {
const normalized = options.normalize(value) as TValue|undefined;
if (normalized === undefined) return this.defaultValue;
if (normalized === undefined) return this.currentDefault();
return normalized;
}
} else {
this.normalizer = (value) => this.values.includes(value as TValue) ? value as TValue : this.defaultValue;
this.normalizer = (value) => this.values.includes(value as TValue) ? value as TValue : this.currentDefault();
}
}
/** What an unset (or invalid) value reads as now. */
protected currentDefault(): TValue {
return this.dynamicDefault?.() ?? this.defaultValue;
}
get(): TValue {
return this.normalizer(getStringSetting(this.storageKey, this.defaultValue));
return this.normalizer(getStringSetting(this.storageKey, this.currentDefault()));
}
set(value: TValue): TValue {
@@ -249,6 +261,8 @@ type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<strin
inputKind?: "text" | "email" | "password";
normalize?: (value: string | null | undefined) => string;
validate?: (value: string) => string | null;
/** The default while nothing is stored, when it depends on context (else `defaultValue`). */
dynamicDefault?: () => string | undefined;
};
// Every string setting by id, so isolates that can only pass an id over a
@@ -266,6 +280,7 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
readonly inputKind: "text" | "email" | "password";
private readonly normalizer: (value: string | null | undefined) => string;
private readonly validator?: (value: string) => string | null;
private readonly dynamicDefault: (() => string | undefined) | undefined;
constructor(options: ConfigSettingStringOptions<TId>) {
super(options);
@@ -274,11 +289,16 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
this.inputKind = options.inputKind ?? "text";
this.normalizer = options.normalize ?? ((value) => value ?? "");
this.validator = options.validate;
this.dynamicDefault = options.dynamicDefault;
stringSettingsById.set(this.id, this);
}
private currentDefault(): string {
return this.dynamicDefault?.() ?? this.defaultValue;
}
get(): string {
return this.normalizer(getStringSetting(this.storageKey, this.defaultValue));
return this.normalizer(getStringSetting(this.storageKey, this.currentDefault()));
}
set(value: string): string {
@@ -297,8 +317,8 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
getValidValue(): string {
const value = this.get();
if (!this.validationError(value)) return value;
const saved = this.normalizer(getStringSetting(this.storageKey + ".valid", this.defaultValue));
return this.validationError(saved) ? this.defaultValue : saved;
const saved = this.normalizer(getStringSetting(this.storageKey + ".valid", this.currentDefault()));
return this.validationError(saved) ? this.currentDefault() : saved;
}
}
@@ -369,7 +389,7 @@ export const phoneBatteryVisibilitySetting = batteryVisibilitySetting(
"phoneBatteryVisibility", "Phone", "display.battery.phoneVisibility",
);
export const glassesBatteryVisibilitySetting = batteryVisibilitySetting(
"glassesBatteryVisibility", "G2", "display.battery.glassesVisibility",
"glassesBatteryVisibility", "Glasses", "display.battery.glassesVisibility",
);
export const ringBatteryVisibilitySetting = batteryVisibilitySetting(
"ringBatteryVisibility", "R1", "display.battery.ringVisibility",
@@ -443,6 +463,34 @@ export const distanceUnitSetting = new ConfigSettingEnum<DistanceUnit>({
*/
export type AppSwitcherPosition = "left" | "right" | "bottom" | "popup";
/** Which glasses the saved addresses belong to (set by pairing; see g2/device-addresses.ts). */
export type GlassesType = "g2" | "rayneo-io" | "g1";
export const glassesTypeSetting = new ConfigSettingEnum<GlassesType>({
id: "glasses-type",
label: "Glasses",
storageKey: "deviceType", // graphics/screen-size.ts GLASSES_TYPE_KEY reads it directly
defaultValue: "g2",
values: ["g2", "rayneo-io", "g1"],
reportInAnalytics: false,
});
/**
* Whether the paired glasses can report a heading. A G1 has an accelerometer
* and a gyroscope but no magnetometer; the RayNeo iO's firmware has no compass
* messages.
*/
export function glassesHaveCompass(): boolean {
return glassesTypeSetting.get() === "g2";
}
const GLASSES_MODEL_NAMES: Record<GlassesType, string> = { g2: "G2", g1: "G1", "rayneo-io": "iO" };
/** The paired glasses' model without the brand, short enough for battery labels and a watch's one-line charging status. */
export function glassesModelName(): string {
return GLASSES_MODEL_NAMES[glassesTypeSetting.get()];
}
const APP_SWITCHER_POSITION_LABELS: Record<AppSwitcherPosition, string> = {
left: "Left",
right: "Right",
@@ -456,6 +504,8 @@ export const appSwitcherPositionSetting = new ConfigSettingEnum<AppSwitcherPosit
storageKey: "display.appSwitcherPosition",
defaultValue: "bottom",
values: ["left", "right", "bottom", "popup"],
// The RayNeo iO's 220 rows can't spare a bottom row: a side strip by default there.
dynamicDefault: () => (glassesTypeSetting.get() === "rayneo-io" ? "left" : undefined),
formatValue: (value) => APP_SWITCHER_POSITION_LABELS[value] ?? value,
description:
"Where the open-app icons go. Left and right take a column beside windows; bottom puts a row beneath the window, which makes full-height windows a little shorter; popup shows them only while you're in the app switcher, in a box over the dimmed window. Bottom and popup leave room at the sides to set the display's depth. Open apps reopen at their new size when a change resizes windows.",
@@ -677,6 +727,10 @@ export const autoBrightnessMaxSetting = new ConfigSettingEnum({
export const autoBrightnessCurveSetting = new ConfigSettingString({
id: "autoBrightnessCurve", label: "Auto light curve", storageKey: "display.autoBrightnessCurve",
defaultValue: DEFAULT_BRIGHTNESS_CURVE, normalize: normalizeBrightnessCurve, validate: brightnessCurveError,
dynamicDefault: () => {
const glasses = glassesTypeSetting.get();
return glasses === "rayneo-io" ? RAYNEO_IO_BRIGHTNESS_CURVE : glasses === "g1" ? G1_BRIGHTNESS_CURVE : undefined;
},
description: "2–16 lux:percent pairs, separated by commas. Percent is within your minimum–maximum range. Start at 0:0, end at 100%, and increase lux without decreasing percent. Incomplete edits stay in the preview; brightness keeps using the last valid curve.",
});
/** The screen on/off fade at Normal speed. */
@@ -735,6 +789,23 @@ export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>(
description: "How long the display stays on after the last input before turning itself off. \"Never\" keeps it on until turned off manually.",
});
export const newNotificationDisplaySetting = new ConfigSettingEnum<NewNotificationDisplay>({
id: "new-notification-display",
label: "Display new notifications",
storageKey: "notifications.newNotificationDisplay",
defaultValue: "15s",
values: ["off", "until-dismissed", "5s", "15s", "1m"],
formatValue: newNotificationDisplayLabel,
description:
"Pop up new phone notifications on the glasses. A timed popup closes once left untouched that long; " +
"the notification stays on the phone and in the status bar.",
});
/** Whether a newly posted phone notification from this app pops up on the glasses (the global setting, then the app's filter toggle). */
export function shouldPopUpNewNotification(packageName: string): boolean {
return newNotificationDisplaySetting.get() !== "off" && shouldShowNotificationOnGlasses(packageName);
}
export const lockScreenEnabledSetting = new ConfigSettingBoolean({
id: "lock-screen-enabled",
label: "Enable lock screen",
@@ -988,9 +1059,18 @@ export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMod
formatValue: (value) =>
value === "direct" ? "Direct to phone" : value === "health" ? "Via glasses + health sync" : "Only via glasses",
description:
"How the R1 ring reaches the phone. Only via glasses: the glasses relay the ring's gestures and the phone never connects to it. Via glasses + health sync: the same, plus the phone connects to the ring to sync health data. Direct to phone (experimental): the phone takes the ring over from the glasses and gets its gestures and battery itself; the glasses lose ring input. Health still syncs, but each sync (on opening Health, and at :01 and :31) pauses ring gestures for up to a minute while the phone briefly reconnects to the ring in its health role. Leaving Direct hands the ring back to the glasses. Takes effect on the next connection to the glasses.",
"How the R1 ring reaches the phone. Only via glasses: the glasses relay the ring's gestures and the phone never connects to it. Via glasses + health sync: the same, plus the phone connects to the ring to sync health data. Direct to phone (experimental): the phone takes the ring over from the glasses and gets its gestures and battery itself; the glasses lose ring input. Health still syncs, but each sync (on opening Health, and at :01 and :31) pauses ring gestures for up to a minute while the phone briefly reconnects to the ring in its health role. Leaving Direct hands the ring back to the glasses. A RayNeo iO has no ring link of its own, so with one the phone always connects to the ring directly. Takes effect on the next connection to the glasses.",
});
/**
* The ring connection in effect: the setting with G2 glasses; Direct with a
* RayNeo iO or Even G1, which cannot relay a ring, so the phone holds the ring's
* glasses role itself (gestures, battery; health in brief phone-role windows).
*/
export function effectiveRingConnectionMode(): RingConnectionMode {
return glassesTypeSetting.get() !== "g2" ? "direct" : ringConnectionModeSetting.get();
}
// "whisper" (no "onboard-" prefix) is OpenAI's CLOUD realtime model
// (gpt-realtime-whisper); "onboard-whisper" is the on-device sherpa-onnx
// Whisper backend. Same underlying model family, two different places it
@@ -1660,6 +1740,34 @@ export function screenTimeoutSettingToMs(value: ScreenTimeoutSetting): number |
}
}
/** How long an untouched new-notification popup stays up; null keeps it until dismissed (and for "off", which never opens one). */
export function newNotificationDisplayTimeoutMs(value: NewNotificationDisplay): number | null {
switch (value) {
case "5s":
return 5_000;
case "15s":
return 15_000;
case "1m":
return 60_000;
case "off":
case "until-dismissed":
return null;
}
}
export function newNotificationDisplayLabel(value: NewNotificationDisplay): string {
switch (value) {
case "off":
return "Off";
case "until-dismissed":
return "Until dismissed";
case "1m":
return "1min";
default:
return value;
}
}
export function brightnessLabel(value: BrightnessSetting): string {
return value === "auto" ? "Auto" : value;
}
@@ -1822,11 +1930,17 @@ export class EditTextSettingLayer implements Layer {
for (let index = 0; index < message.length; index++) {
image.drawText(font, 22, messageTop + index * step, message[index]!, 200);
}
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.inputKind === "password" ? this.setting.displayValue() : this.setting.get(), 52), 220);
const valueY = messageTop + (message.length + 2) * step;
image.drawText(font, 22, valueY, truncateSetting(this.setting.inputKind === "password" ? this.setting.displayValue() : this.setting.get(), 52), 220);
const error = this.setting.validationError();
if (error) wrapText(font, error, width - 48).forEach((line, index) =>
const errorLines = error ? wrapText(font, error, width - 48) : [];
errorLines.forEach((line, index) =>
image.drawText(font, 22, messageTop + (message.length + 4 + index) * step, line, 180));
image.drawText(font, 22, height - 24 - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
// The back hint at the bottom, unless a short window (the RayNeo iO's)
// leaves it no room under the value and error.
const contentBottom = errorLines.length ? messageTop + (message.length + 4 + errorLines.length) * step : valueY + step;
const hintY = height - 24 - font.lineHeight;
if (hintY >= contentBottom) image.drawText(font, 22, hintY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}