EvenHub app uses logo; move login from the Settings app into the EvenHub app

This commit is contained in:
James Babcock committed 2026-08-19 00:49:18 -07:00
1 parent 83e0fa919f
commit deac81f98f
15 files changed
+443 -90

No files matched your search

+3
View File
@@ -1,3 +1,4 @@
import { type GrayImage } from "../graphics/image";
import { type Plane } from "../graphics/plane";
import { type IconName } from "../graphics/icons";
import { type LayerActions } from "../ui/layers";
@@ -18,6 +19,8 @@ export type AppDefinition = {
title: string;
/** Launcher-grid icon. */
icon: IconName;
/** App-supplied launcher icon renderer; icon remains the fallback. */
renderIcon?: (size: number) => GrayImage | null;
/** Open the app's window (or focus it if already open). */
launch: (ctx: AppContext, params?: AppLaunchParams) => Promise<void>;
/**
+36
View File
@@ -0,0 +1,36 @@
import { ConfigSettingString } from "../../ui/dashboard-settings";
/**
* EvenHub owns its account configuration. The storage keys intentionally
* match the former Settings-app entries so existing users stay signed in.
*/
export const evenHubEmailSetting = new ConfigSettingString({
id: "evenhub-email",
label: "Email",
storageKey: "integrations.evenhub.email",
defaultValue: "",
editorTitle: "Email",
glassesEditTitle: "Edit Even email",
inputKind: "email",
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
});
export const evenHubPasswordSetting = new ConfigSettingString({
id: "evenhub-password",
label: "Password",
storageKey: "integrations.evenhub.password",
defaultValue: "",
editorTitle: "Password",
glassesEditTitle: "Edit Even password",
inputKind: "password",
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, ""),
formatValue: (value) => (value ? "(set)" : "(not set)"),
});
export function hasEvenHubCredentials(): boolean {
return Boolean(evenHubEmailSetting.get().trim() && evenHubPasswordSetting.get());
}
export function clearEvenHubPassword(): void {
evenHubPasswordSetting.set("");
}
+25 -13
View File
@@ -6,7 +6,7 @@
* the same signed-header scheme used by the firmware API.
*/
import { Application } from "@nativescript/core";
import { evenHubEmailSetting, evenHubPasswordSetting } from "../../ui/dashboard-settings";
import { evenHubEmailSetting, evenHubPasswordSetting, hasEvenHubCredentials } from "./credentials";
declare const android: any;
@@ -60,7 +60,14 @@ export type EvenHubAppDownload = {
};
export function isEvenHubStoreConfigured(): boolean {
return Boolean(evenHubEmailSetting.get().trim() && evenHubPasswordSetting.get());
return hasEvenHubCredentials();
}
export class EvenHubAuthenticationError extends Error {
constructor(message: string) {
super(message);
this.name = "EvenHubAuthenticationError";
}
}
export class EvenHubApiClient {
@@ -162,7 +169,7 @@ export class EvenHubApiClient {
private ensureLogin(): Promise<string> {
if (this.token) return Promise.resolve(this.token);
if (!isEvenHubStoreConfigured()) {
return Promise.reject(new Error("Set the EvenHub email and password in Settings > EvenHub."));
return Promise.reject(new EvenHubAuthenticationError("Enter your Even account email and password."));
}
if (!this.loginPromise) {
this.loginPromise = this.login().finally(() => {
@@ -173,15 +180,20 @@ export class EvenHubApiClient {
}
private async login(): Promise<string> {
const response = await this.request("POST", "/v2/g/login", {
commonVersion: 1,
body: { email: evenHubEmailSetting.get().trim(), passwd: evenHubPasswordSetting.get() },
});
const data = asRecord(unwrap(response.envelope, response.httpStatus, "/v2/g/login"));
const token = typeof data.token === "string" ? data.token : "";
if (!token) throw new Error("Even login succeeded without returning a session token.");
this.token = token;
return token;
try {
const response = await this.request("POST", "/v2/g/login", {
commonVersion: 1,
body: { email: evenHubEmailSetting.get().trim(), passwd: evenHubPasswordSetting.get() },
});
const data = asRecord(unwrap(response.envelope, response.httpStatus, "/v2/g/login"));
const token = typeof data.token === "string" ? data.token : "";
if (!token) throw new Error("Even login succeeded without returning a session token.");
this.token = token;
return token;
} catch (error) {
if (error instanceof EvenHubAuthenticationError) throw error;
throw new EvenHubAuthenticationError(String((error as Error)?.message ?? error));
}
}
private async request(
@@ -321,7 +333,7 @@ async function fetchWithTimeout(url: string, init: RequestInit, timeoutMs = REQU
function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknown {
if (httpStatus === 401) {
throw new Error("Even rejected the login session. Check Settings > EvenHub.");
throw new EvenHubAuthenticationError("Even rejected the login session.");
}
if (httpStatus < 200 || httpStatus >= 300) {
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
+8 -2
View File
@@ -12,6 +12,8 @@ import { shell } from "../../ui/shell/shell";
import { EvenHubStoreLayer } from "./store-layer";
import { launchPackage } from "./manager";
import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-process-window";
import { renderEvenRealitiesLogo } from "../../graphics/even-realities-logo";
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
const EVENHUB_STORE_WINDOW_ID = "evenhub:store";
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
@@ -28,6 +30,7 @@ const evenhubApp: AppDefinition = {
appId: "evenhub",
title: "EvenHub",
icon: "package",
renderIcon: renderEvenRealitiesLogo,
launch: async (ctx) => {
const existing = shell.getWindows().find((window) => window.windowId === EVENHUB_STORE_WINDOW_ID);
if (existing) {
@@ -38,7 +41,6 @@ const evenhubApp: AppDefinition = {
let created: InProcessWindow | null = null;
const store = new EvenHubStoreLayer({
launchApp: (appId) => ctx.launchApp(appId),
openSettings: () => ctx.launchApp("settings", { section: "EvenHub" }),
appendLog: ctx.appendLog,
});
await ctx.launchInProcessApp(EVENHUB_STORE_WINDOW_ID, EVENHUB_STORE_SURFACE_ID, (options) => {
@@ -48,6 +50,7 @@ const evenhubApp: AppDefinition = {
title: "EvenHub",
iconLetter: "EH",
icon: "package",
drawIcon: makeImageWindowIcon(renderEvenRealitiesLogo, windowIcon("package", "EH")),
closeable: true,
menuItems: () => (created?.stack.isAtBase() ? store.buildMenuItems() : []),
actions: options.actions,
@@ -55,7 +58,10 @@ const evenhubApp: AppDefinition = {
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
onClosed: () => {
store.closeCredentialEditor(options.actions);
options.onClosed();
},
});
return created;
});
+99 -20
View File
@@ -1,9 +1,9 @@
import { getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage } from "../../graphics/image";
import { truncateText } from "../../graphics/textwrap";
import { truncateText, wrapText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
import { type DashboardInputEvent, type Layer, type LayerActions, type LayerContext } from "../../ui/layers";
import {
drawListScrollbar,
drawSelectionHighlight,
@@ -11,7 +11,17 @@ import {
type MenuItem,
} from "../../ui/menu";
import { shell } from "../../ui/shell/shell";
import { evenHubApi, isEvenHubStoreConfigured, type EvenHubStoreApp } from "./even-api";
import {
evenHubApi,
EvenHubAuthenticationError,
isEvenHubStoreConfigured,
type EvenHubStoreApp,
} from "./even-api";
import {
clearEvenHubPassword,
evenHubEmailSetting,
evenHubPasswordSetting,
} from "./credentials";
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
const HEADER_HEIGHT = 34;
@@ -21,7 +31,6 @@ const LIST_X = 18;
export type EvenHubStoreLayerOptions = {
launchApp: (appId: string) => Promise<void> | void;
openSettings: () => Promise<void> | void;
appendLog: (message: string) => void;
};
@@ -34,14 +43,20 @@ export class EvenHubStoreLayer implements Layer {
private nextPage = 1;
private started = false;
private loading = false;
private status = "";
private showingLogin = !isEvenHubStoreConfigured();
private status = this.showingLogin ? "Sign in to browse public apps." : "";
private credentialEditorOpen = false;
constructor(private readonly options: EvenHubStoreLayerOptions) {}
paint(ctx: LayerContext): GrayImage {
if (!this.started) {
this.started = true;
void this.reload(ctx);
if (this.showingLogin) {
this.openCredentialEditor(ctx);
} else {
void this.reload(ctx);
}
}
const font = getDefaultSmallFont();
@@ -49,11 +64,26 @@ export class EvenHubStoreLayer implements Layer {
const image = new GrayImage(width, height, 0);
image.drawText(font, LIST_X, 8, "EvenHub", 220);
const subtitle = !isEvenHubStoreConfigured()
? "Set account details in Settings > EvenHub"
: this.status || (this.total ? `${this.apps.length} of ${this.total} public apps` : "Public apps");
const subtitle = this.status || (this.total ? `${this.apps.length} of ${this.total} public apps` : "Public apps");
image.drawText(font, LIST_X, 22, truncateText(font, subtitle, width - LIST_X * 2), 125);
if (this.showingLogin) {
const message = this.loading
? "Signing in..."
: "Enter your Even account email and password in the phone app.";
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) {
image.drawText(font, LIST_X, HEADER_HEIGHT + 22 + index * 15, line, 190);
}
image.drawText(
font,
LIST_X,
height - 16,
truncateText(font, `${GESTURE_CLICK} edit credentials ${GESTURE_DOUBLE_CLICK} back`, width - LIST_X * 2),
105,
);
return image;
}
if (this.apps.length === 0) {
const message = this.loading ? "Loading apps..." : this.status || "No apps returned.";
image.drawText(font, LIST_X, HEADER_HEIGHT + 28, truncateText(font, message, width - LIST_X * 2), 190);
@@ -83,14 +113,20 @@ export class EvenHubStoreLayer implements Layer {
}
}
const hint = !isEvenHubStoreConfigured()
? `${GESTURE_CLICK} settings ${GESTURE_DOUBLE_CLICK} back`
: `${GESTURE_SCROLL} select ${GESTURE_CLICK} details ${GESTURE_DOUBLE_CLICK} back`;
const hint = `${GESTURE_SCROLL} select ${GESTURE_CLICK} details ${GESTURE_DOUBLE_CLICK} back`;
image.drawText(font, LIST_X, height - 16, truncateText(font, hint, width - LIST_X * 2), 105);
return image;
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (this.showingLogin) {
if (event.type === "click" && !this.loading) {
this.openCredentialEditor(ctx);
} else if (event.type === "double-click") {
shell.yieldFocusToSidebar();
}
return;
}
switch (event.type) {
case "scroll-up":
this.selectedIndex = Math.max(0, this.selectedIndex - 1);
@@ -102,10 +138,6 @@ export class EvenHubStoreLayer implements Layer {
}
return;
case "click":
if (!isEvenHubStoreConfigured()) {
await this.options.openSettings();
return;
}
if (!this.loading) {
const app = this.apps[this.selectedIndex];
if (app) {
@@ -127,6 +159,7 @@ export class EvenHubStoreLayer implements Layer {
}
buildMenuItems(): MenuItem[] {
if (this.showingLogin) return [];
return [
{
label: "Refresh",
@@ -136,15 +169,23 @@ export class EvenHubStoreLayer implements Layer {
},
},
{
label: "EvenHub settings",
label: "Log Out",
onSelect: (ctx) => {
ctx.stack.pop();
void this.options.openSettings();
clearEvenHubPassword();
evenHubApi.clearSession();
this.enterLogin(ctx, "Signed out.");
},
},
];
}
closeCredentialEditor(actions: Pick<LayerActions, "endTextSettingEdit">): void {
if (!this.credentialEditorOpen) return;
this.credentialEditorOpen = false;
void actions.endTextSettingEdit();
}
private async reload(ctx: LayerContext): Promise<void> {
if (this.loading) return;
evenHubApi.clearSession();
@@ -155,7 +196,7 @@ export class EvenHubStoreLayer implements Layer {
this.scrollRow = 0;
this.status = "";
if (!isEvenHubStoreConfigured()) {
ctx.actions.requestRender();
this.enterLogin(ctx);
return;
}
await this.loadNextPage(ctx);
@@ -174,7 +215,13 @@ export class EvenHubStoreLayer implements Layer {
this.nextPage = page.page + 1;
this.status = "";
} catch (error) {
this.status = cleanError(error);
const message = cleanError(error);
if (error instanceof EvenHubAuthenticationError) {
this.options.appendLog(`evenhub store login failed: ${message}`);
this.enterLogin(ctx, `Login failed: ${message}`);
return;
}
this.status = message;
this.options.appendLog(`evenhub store: ${this.status}`);
} finally {
this.loading = false;
@@ -182,6 +229,38 @@ export class EvenHubStoreLayer implements Layer {
}
}
private enterLogin(ctx: LayerContext, status = "Sign in to browse public apps."): void {
this.showingLogin = true;
this.loading = false;
this.apps = [];
this.total = 0;
this.status = status;
this.openCredentialEditor(ctx);
ctx.actions.requestRender();
}
private openCredentialEditor(ctx: LayerContext): void {
if (this.credentialEditorOpen) return;
this.credentialEditorOpen = true;
void ctx.actions.startTextSettingsEdit(
[evenHubEmailSetting, evenHubPasswordSetting],
"Sign in to EvenHub",
() => {
this.credentialEditorOpen = false;
void this.submitCredentials(ctx);
},
);
}
private async submitCredentials(ctx: LayerContext): Promise<void> {
if (!isEvenHubStoreConfigured()) {
this.enterLogin(ctx, "Email and password are required.");
return;
}
this.showingLogin = false;
await this.reload(ctx);
}
}
function cleanError(error: unknown): string {
+6 -1
View File
@@ -25,7 +25,12 @@ const launcherApp: AppDefinition = {
apps: () => [
...ctx.apps
.filter((app) => app.showInLauncher !== false)
.map((app) => ({ appId: app.appId, label: app.title, icon: app.icon })),
.map((app) => ({
appId: app.appId,
label: app.title,
icon: app.icon,
renderIcon: app.renderIcon,
})),
...getInstalledEvenHubApps().map((app) => ({
appId: installedEvenHubAppId(app.packageId),
label: app.name,
+50 -12
View File
@@ -57,8 +57,14 @@ export type DashboardSnapshot = {
*/
displayPreviewMessage: string;
activeTextSettingId: string | null;
activeTextEditorTitle: string;
activeTextSettingTitle: string;
activeTextSettingValue: string;
activeTextSettingInputKind: "text" | "email" | "password";
secondaryTextSettingId: string | null;
secondaryTextSettingTitle: string;
secondaryTextSettingValue: string;
secondaryTextSettingInputKind: "text" | "email" | "password";
evenAppConflictMessage: string;
evenAppConflictWarningVisible: boolean;
firmwareWarningMessage: string;
@@ -142,7 +148,9 @@ class DashboardController {
private phase: ConnectionPhase = "disconnected";
private status = "Disconnected.";
private log = "";
private activeTextSetting: ConfigSettingString | null = null;
private activeTextSettings: ConfigSettingString[] = [];
private activeTextEditorTitle = "";
private activeTextEditorOnFinish: (() => void) | null = null;
private evenNotificationActive = false;
private evenAppConflictMessage = "";
private firmwareWarningMessage = "";
@@ -212,6 +220,11 @@ class DashboardController {
const sharedActions = {
disconnect: () => this.disconnect(),
startTextSettingEdit: (setting: ConfigSettingString) => this.startTextSettingEdit(setting),
startTextSettingsEdit: (
settings: readonly ConfigSettingString[],
title: string,
onFinish?: () => void,
) => this.startTextSettingsEdit(settings, title, onFinish),
endTextSettingEdit: () => this.endTextSettingEdit(),
startVoiceCapture: () => this.startVoiceCapture(),
stopVoiceCapture: () => this.stopVoiceCapture(),
@@ -683,15 +696,23 @@ class DashboardController {
}
snapshot(): DashboardSnapshot {
const primaryTextSetting = this.activeTextSettings[0] ?? null;
const secondaryTextSetting = this.activeTextSettings[1] ?? null;
return {
phase: this.phase,
status: this.status,
log: this.log,
displayPreview: this.displayPreview,
displayPreviewMessage: this.displayPreviewMessage(),
activeTextSettingId: this.activeTextSetting?.id ?? null,
activeTextSettingTitle: this.activeTextSetting?.editorTitle ?? "",
activeTextSettingValue: this.activeTextSetting?.get() ?? "",
activeTextSettingId: primaryTextSetting?.id ?? null,
activeTextEditorTitle: this.activeTextEditorTitle,
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
activeTextSettingValue: primaryTextSetting?.get() ?? "",
activeTextSettingInputKind: primaryTextSetting?.inputKind ?? "text",
secondaryTextSettingId: secondaryTextSetting?.id ?? null,
secondaryTextSettingTitle: secondaryTextSetting?.editorTitle ?? "",
secondaryTextSettingValue: secondaryTextSetting?.get() ?? "",
secondaryTextSettingInputKind: secondaryTextSetting?.inputKind ?? "text",
evenAppConflictMessage: this.evenAppConflictMessage,
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
firmwareWarningMessage: this.firmwareWarningMessage,
@@ -771,9 +792,11 @@ class DashboardController {
openEvenAppSettings();
}
setActiveTextSettingValue(value: string): void {
setActiveTextSettingValue(value: string, settingId?: string): void {
shell.noteUserActivity();
const setting = this.activeTextSetting;
const setting = settingId
? this.activeTextSettings.find((candidate) => candidate.id === settingId) ?? null
: this.activeTextSettings[0] ?? null;
if (!setting) return;
if (setting.get() === value) return;
setting.set(value);
@@ -1182,7 +1205,17 @@ class DashboardController {
}
private startTextSettingEdit(setting: ConfigSettingString): void {
this.activeTextSetting = setting;
this.startTextSettingsEdit([setting], setting.editorTitle);
}
private startTextSettingsEdit(
settings: readonly ConfigSettingString[],
title: string,
onFinish?: () => void,
): void {
this.activeTextSettings = Array.from(settings.slice(0, 2));
this.activeTextEditorTitle = title;
this.activeTextEditorOnFinish = onFinish ?? null;
this.emit();
}
@@ -1236,10 +1269,12 @@ class DashboardController {
}
private endTextSettingEdit(): void {
const finishedSetting = this.activeTextSetting;
this.activeTextSetting = null;
const finishedSettings = this.activeTextSettings;
this.activeTextSettings = [];
this.activeTextEditorTitle = "";
this.activeTextEditorOnFinish = null;
this.emit();
if (finishedSetting === nightscoutSiteUrlSetting || finishedSetting === nightscoutApiTokenSetting) {
if (finishedSettings.includes(nightscoutSiteUrlSetting) || finishedSettings.includes(nightscoutApiTokenSetting)) {
void this.refreshNightscoutAfterSettingsChange();
}
}
@@ -1250,11 +1285,14 @@ class DashboardController {
* out of the edit page.
*/
finishActiveTextSettingEdit(): void {
if (!this.activeTextSetting) return;
if (!this.activeTextSettings.length) return;
const onFinish = this.activeTextEditorOnFinish;
const closesGlassesEditor = this.activeTextSettings.length === 1;
this.endTextSettingEdit();
if (this.textEditorHost?.closeTextEditor()) {
if (closesGlassesEditor && this.textEditorHost?.closeTextEditor()) {
this.textEditorHost.requestRender();
}
onFinish?.();
}
private updateTextSetting(setting: ConfigSettingString, value: string): void {
+45
View File
@@ -0,0 +1,45 @@
import { GrayImage } from "./image";
import { loadPngAsGrayImage } from "./imagefile";
const LOGO_PATH = "images/EvenRealitiesLogo.png";
let sourceLogo: GrayImage | null | undefined;
const scaledLogos = new Map<number, GrayImage>();
/** Render the bundled Even Realities logo at launcher/sidebar icon size. */
export function renderEvenRealitiesLogo(size: number): GrayImage | null {
const targetSize = Math.max(1, Math.round(size));
const cached = scaledLogos.get(targetSize);
if (cached) return cached;
if (sourceLogo === undefined) {
try {
sourceLogo = loadPngAsGrayImage(LOGO_PATH);
} catch (error) {
console.warn(`Could not load ${LOGO_PATH}: ${error}`);
sourceLogo = null;
}
}
if (!sourceLogo) return null;
const scaled = scaleToFit(sourceLogo, targetSize, targetSize);
scaledLogos.set(targetSize, scaled);
return scaled;
}
function scaleToFit(source: GrayImage, maxWidth: number, maxHeight: number): GrayImage {
const scale = Math.min(maxWidth / source.width, maxHeight / source.height, 1);
const width = Math.max(1, Math.round(source.width * scale));
const height = Math.max(1, Math.round(source.height * scale));
if (width === source.width && height === source.height) return source;
const output = new GrayImage(width, height, 0);
for (let y = 0; y < height; y++) {
const sourceY = Math.min(source.height - 1, Math.floor(((y + 0.5) * source.height) / height));
for (let x = 0; x < width; x++) {
const sourceX = Math.min(source.width - 1, Math.floor(((x + 0.5) * source.width) / width));
output.pixels[y * width + x] = source.pixels[sourceY * source.width + sourceX]!;
}
}
return output;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

+7 -3
View File
@@ -79,12 +79,16 @@ function applySettingsTextFieldContrast(textField: TextField): void {
nativeTextField.setSelectAllOnFocus(true)
}
function focusSystemNameField(page: Page): void {
function focusTextEditor(page: Page): void {
setTimeout(() => {
const textField = page.getViewById<TextField>('settingsTextField')
const secondaryTextField = page.getViewById<TextField>('secondarySettingsTextField')
if (textField) {
applySettingsTextFieldContrast(textField)
}
if (secondaryTextField) {
applySettingsTextFieldContrast(secondaryTextField)
}
textField?.focus()
}, 0)
}
@@ -139,7 +143,7 @@ export function loaded(args: EventData) {
}
if (propertyArgs.propertyName === 'activeTextSettingId') {
if (model.isTextSettingEditorActive) {
focusSystemNameField(page)
focusTextEditor(page)
}
return
}
@@ -160,7 +164,7 @@ export function loaded(args: EventData) {
setPageState(page, state)
scrollLogsToBottom(scrollViews)
if (model.isTextSettingEditorActive) {
focusSystemNameField(page)
focusTextEditor(page)
}
}
+18 -2
View File
@@ -105,15 +105,31 @@
visibility="{{ textSettingEditorVisibility }}"
horizontalAlignment="stretch"
verticalAlignment="top">
<Label text="{{ activeTextEditorTitle }}" class="h2" />
<Label text="{{ activeTextSettingTitle }}" />
<TextField
id="settingsTextField"
text="{{ activeTextSettingValue }}"
textChange="{{ onTextSettingTextChange }}"
returnPress="{{ onTextSettingReturnPress }}"
returnPress="{{ onPrimaryTextSettingReturnPress }}"
autocorrect="false"
autocapitalizationType="none"
returnKeyType="done" />
keyboardType="{{ activeTextSettingKeyboardType }}"
secure="{{ activeTextSettingSecure }}"
returnKeyType="{{ primaryTextSettingReturnKeyType }}" />
<StackLayout visibility="{{ secondaryTextSettingVisibility }}">
<Label text="{{ secondaryTextSettingTitle }}" />
<TextField
id="secondarySettingsTextField"
text="{{ secondaryTextSettingValue }}"
textChange="{{ onSecondaryTextSettingTextChange }}"
returnPress="{{ onSecondaryTextSettingReturnPress }}"
autocorrect="false"
autocapitalizationType="none"
keyboardType="{{ secondaryTextSettingKeyboardType }}"
secure="{{ secondaryTextSettingSecure }}"
returnKeyType="done" />
</StackLayout>
</StackLayout>
</GridLayout>
</Page>
+136 -3
View File
@@ -14,8 +14,14 @@ export class MainViewModel extends Observable {
private _displayPreviewMessage = "";
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
private _activeTextSettingId: string | null = null;
private _activeTextEditorTitle = "";
private _activeTextSettingTitle = "";
private _activeTextSettingValue = "";
private _activeTextSettingInputKind: "text" | "email" | "password" = "text";
private _secondaryTextSettingId: string | null = null;
private _secondaryTextSettingTitle = "";
private _secondaryTextSettingValue = "";
private _secondaryTextSettingInputKind: "text" | "email" | "password" = "text";
private _evenAppConflictMessage = "";
private _evenAppConflictWarningVisible = false;
private _firmwareWarningMessage = "";
@@ -34,8 +40,14 @@ export class MainViewModel extends Observable {
this.displayPreviewMessage = snapshot.displayPreviewMessage;
this.phase = snapshot.phase;
this.activeTextSettingId = snapshot.activeTextSettingId;
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
this.activeTextSettingValue = snapshot.activeTextSettingValue;
this.activeTextSettingInputKind = snapshot.activeTextSettingInputKind;
this.secondaryTextSettingId = snapshot.secondaryTextSettingId;
this.secondaryTextSettingTitle = snapshot.secondaryTextSettingTitle;
this.secondaryTextSettingValue = snapshot.secondaryTextSettingValue;
this.secondaryTextSettingInputKind = snapshot.secondaryTextSettingInputKind;
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
@@ -185,6 +197,17 @@ export class MainViewModel extends Observable {
return this._activeTextSettingTitle;
}
get activeTextEditorTitle(): string {
return this._activeTextEditorTitle;
}
set activeTextEditorTitle(value: string) {
if (this._activeTextEditorTitle !== value) {
this._activeTextEditorTitle = value;
this.notifyPropertyChange("activeTextEditorTitle", value);
}
}
set activeTextSettingTitle(value: string) {
if (this._activeTextSettingTitle !== value) {
this._activeTextSettingTitle = value;
@@ -203,6 +226,94 @@ export class MainViewModel extends Observable {
}
}
get activeTextSettingInputKind(): "text" | "email" | "password" {
return this._activeTextSettingInputKind;
}
set activeTextSettingInputKind(value: "text" | "email" | "password") {
if (this._activeTextSettingInputKind !== value) {
this._activeTextSettingInputKind = value;
this.notifyPropertyChange("activeTextSettingKeyboardType", this.activeTextSettingKeyboardType);
this.notifyPropertyChange("activeTextSettingSecure", this.activeTextSettingSecure);
}
}
get activeTextSettingKeyboardType(): "email" | "text" {
return this._activeTextSettingInputKind === "email" ? "email" : "text";
}
get activeTextSettingSecure(): boolean {
return this._activeTextSettingInputKind === "password";
}
get secondaryTextSettingId(): string | null {
return this._secondaryTextSettingId;
}
set secondaryTextSettingId(value: string | null) {
if (this._secondaryTextSettingId !== value) {
this._secondaryTextSettingId = value;
this.notifyPropertyChange("secondaryTextSettingId", value);
this.notifyPropertyChange("secondaryTextSettingVisibility", this.secondaryTextSettingVisibility);
this.notifyPropertyChange("hasSecondaryTextSetting", this.hasSecondaryTextSetting);
this.notifyPropertyChange("primaryTextSettingReturnKeyType", this.primaryTextSettingReturnKeyType);
}
}
get secondaryTextSettingTitle(): string {
return this._secondaryTextSettingTitle;
}
set secondaryTextSettingTitle(value: string) {
if (this._secondaryTextSettingTitle !== value) {
this._secondaryTextSettingTitle = value;
this.notifyPropertyChange("secondaryTextSettingTitle", value);
}
}
get secondaryTextSettingValue(): string {
return this._secondaryTextSettingValue;
}
set secondaryTextSettingValue(value: string) {
if (this._secondaryTextSettingValue !== value) {
this._secondaryTextSettingValue = value;
this.notifyPropertyChange("secondaryTextSettingValue", value);
}
}
get secondaryTextSettingInputKind(): "text" | "email" | "password" {
return this._secondaryTextSettingInputKind;
}
set secondaryTextSettingInputKind(value: "text" | "email" | "password") {
if (this._secondaryTextSettingInputKind !== value) {
this._secondaryTextSettingInputKind = value;
this.notifyPropertyChange("secondaryTextSettingKeyboardType", this.secondaryTextSettingKeyboardType);
this.notifyPropertyChange("secondaryTextSettingSecure", this.secondaryTextSettingSecure);
}
}
get secondaryTextSettingKeyboardType(): "email" | "text" {
return this._secondaryTextSettingInputKind === "email" ? "email" : "text";
}
get secondaryTextSettingSecure(): boolean {
return this._secondaryTextSettingInputKind === "password";
}
get hasSecondaryTextSetting(): boolean {
return this._secondaryTextSettingId !== null;
}
get secondaryTextSettingVisibility(): "visible" | "collapse" {
return this.hasSecondaryTextSetting ? "visible" : "collapse";
}
get primaryTextSettingReturnKeyType(): "next" | "done" {
return this.hasSecondaryTextSetting ? "next" : "done";
}
get isTextSettingEditorActive(): boolean {
return this._activeTextSettingId !== null;
}
@@ -423,15 +534,37 @@ export class MainViewModel extends Observable {
}
onTextSettingTextChange(args: { value?: string; object?: { text?: string } }): void {
dashboardController.setActiveTextSettingValue(args.object?.text ?? args.value ?? "");
dashboardController.setActiveTextSettingValue(
args.object?.text ?? args.value ?? "",
this.activeTextSettingId ?? undefined,
);
}
onTextSettingReturnPress(args: { object?: { text?: string } }): void {
onPrimaryTextSettingReturnPress(args: { object?: { text?: string; page?: { getViewById?: (id: string) => { focus?: () => void } | null } } }): void {
// Commit the field's actual text at done-time, in case the final
// keystroke's textChange hadn't landed yet.
const text = args?.object?.text;
if (typeof text === "string") {
dashboardController.setActiveTextSettingValue(text);
dashboardController.setActiveTextSettingValue(text, this.activeTextSettingId ?? undefined);
}
if (this.hasSecondaryTextSetting) {
args.object?.page?.getViewById?.("secondarySettingsTextField")?.focus?.();
return;
}
dashboardController.finishActiveTextSettingEdit();
}
onSecondaryTextSettingTextChange(args: { value?: string; object?: { text?: string } }): void {
dashboardController.setActiveTextSettingValue(
args.object?.text ?? args.value ?? "",
this.secondaryTextSettingId ?? undefined,
);
}
onSecondaryTextSettingReturnPress(args: { object?: { text?: string } }): void {
const text = args?.object?.text;
if (typeof text === "string") {
dashboardController.setActiveTextSettingValue(text, this.secondaryTextSettingId ?? undefined);
}
dashboardController.finishActiveTextSettingEdit();
}
+3 -25
View File
@@ -167,6 +167,7 @@ export class ConfigSettingEnum<TValue extends string, TId extends string = strin
type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<string, TId> & {
editorTitle?: string;
glassesEditTitle?: string;
inputKind?: "text" | "email" | "password";
normalize?: (value: string | null | undefined) => string;
};
@@ -182,12 +183,14 @@ export function getStringSettingById(id: string): ConfigSettingString | null {
export class ConfigSettingString<TId extends string = string> extends ConfigSetting<string, TId> {
readonly editorTitle: string;
readonly glassesEditTitle: string;
readonly inputKind: "text" | "email" | "password";
private readonly normalizer: (value: string | null | undefined) => string;
constructor(options: ConfigSettingStringOptions<TId>) {
super(options);
this.editorTitle = options.editorTitle ?? options.label;
this.glassesEditTitle = options.glassesEditTitle ?? `Edit ${options.label}`;
this.inputKind = options.inputKind ?? "text";
this.normalizer = options.normalize ?? ((value) => value ?? "");
stringSettingsById.set(this.id, this);
}
@@ -497,31 +500,6 @@ export const mapboxApiKeySetting = new ConfigSettingString({
description: "Mapbox public token (pk. prefix), used by the Navigate app for maps, geocoding, and directions.",
});
export const evenHubEmailSetting = new ConfigSettingString({
id: "evenhub-email",
label: "Even account email",
storageKey: "integrations.evenhub.email",
defaultValue: "",
editorTitle: "Even Realities account email",
glassesEditTitle: "Edit Even email",
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
formatValue: emptySettingDisplay,
description: "Email for the Even account used to browse and download public EvenHub apps.",
});
export const evenHubPasswordSetting = new ConfigSettingString({
id: "evenhub-password",
label: "Even account password",
storageKey: "integrations.evenhub.password",
defaultValue: "",
editorTitle: "Even Realities account password",
glassesEditTitle: "Edit Even password",
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, ""),
formatValue: (value) => (value ? "(set)" : "(not set)"),
description:
"Password used to mint a short-lived Even API session. Faceclaw stores it in the same private settings store as other API credentials and never logs it.",
});
/**
* Staging buffer for the Terminal app's "Add connection" flow: the worker
* asks the shell to open the phone text editor on this setting, the user
-9
View File
@@ -27,8 +27,6 @@ import {
assistantSkipConfirmationSetting,
batteryDisplayModeSetting,
brightnessSetting,
evenHubEmailSetting,
evenHubPasswordSetting,
elevenLabsApiKeySetting,
mapboxApiKeySetting,
openAiApiKeySetting,
@@ -134,13 +132,6 @@ function settingsSections(): SettingsSection[] {
textSettingMenuItem(roamApiTokenSetting),
],
},
{
label: "EvenHub",
items: [
textSettingMenuItem(evenHubEmailSetting),
textSettingMenuItem(evenHubPasswordSetting),
],
},
{
label: "Developer",
items: [
+7
View File
@@ -29,6 +29,12 @@ export type LayerActions = {
requestRender: () => void;
disconnect: () => Promise<void> | void;
startTextSettingEdit: (setting: ConfigSettingString) => Promise<void> | void;
/** Open one phone form for multiple related settings (for example email + password). */
startTextSettingsEdit: (
settings: readonly ConfigSettingString[],
title: string,
onFinish?: () => void,
) => Promise<void> | void;
endTextSettingEdit: () => Promise<void> | void;
/**
* Start push-to-talk voice capture with the provider chosen in settings.
@@ -50,6 +56,7 @@ export const noopLayerActions: LayerActions = {
requestRender: () => {},
disconnect: () => {},
startTextSettingEdit: () => {},
startTextSettingsEdit: () => {},
endTextSettingEdit: () => {},
startVoiceCapture: () => {},
stopVoiceCapture: () => {},