forked from Blendman974/faceclaw
EvenHub app uses logo; move login from the Settings app into the EvenHub app
This commit is contained in:
1 parent
83e0fa919f
commit
deac81f98f
15 files changed
+443
-90
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
import { type GrayImage } from "../graphics/image";
|
||||||
import { type Plane } from "../graphics/plane";
|
import { type Plane } from "../graphics/plane";
|
||||||
import { type IconName } from "../graphics/icons";
|
import { type IconName } from "../graphics/icons";
|
||||||
import { type LayerActions } from "../ui/layers";
|
import { type LayerActions } from "../ui/layers";
|
||||||
@@ -18,6 +19,8 @@ export type AppDefinition = {
|
|||||||
title: string;
|
title: string;
|
||||||
/** Launcher-grid icon. */
|
/** Launcher-grid icon. */
|
||||||
icon: IconName;
|
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). */
|
/** Open the app's window (or focus it if already open). */
|
||||||
launch: (ctx: AppContext, params?: AppLaunchParams) => Promise<void>;
|
launch: (ctx: AppContext, params?: AppLaunchParams) => Promise<void>;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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("");
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* the same signed-header scheme used by the firmware API.
|
* the same signed-header scheme used by the firmware API.
|
||||||
*/
|
*/
|
||||||
import { Application } from "@nativescript/core";
|
import { Application } from "@nativescript/core";
|
||||||
import { evenHubEmailSetting, evenHubPasswordSetting } from "../../ui/dashboard-settings";
|
import { evenHubEmailSetting, evenHubPasswordSetting, hasEvenHubCredentials } from "./credentials";
|
||||||
|
|
||||||
declare const android: any;
|
declare const android: any;
|
||||||
|
|
||||||
@@ -60,7 +60,14 @@ export type EvenHubAppDownload = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function isEvenHubStoreConfigured(): boolean {
|
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 {
|
export class EvenHubApiClient {
|
||||||
@@ -162,7 +169,7 @@ export class EvenHubApiClient {
|
|||||||
private ensureLogin(): Promise<string> {
|
private ensureLogin(): Promise<string> {
|
||||||
if (this.token) return Promise.resolve(this.token);
|
if (this.token) return Promise.resolve(this.token);
|
||||||
if (!isEvenHubStoreConfigured()) {
|
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) {
|
if (!this.loginPromise) {
|
||||||
this.loginPromise = this.login().finally(() => {
|
this.loginPromise = this.login().finally(() => {
|
||||||
@@ -173,15 +180,20 @@ export class EvenHubApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async login(): Promise<string> {
|
private async login(): Promise<string> {
|
||||||
const response = await this.request("POST", "/v2/g/login", {
|
try {
|
||||||
commonVersion: 1,
|
const response = await this.request("POST", "/v2/g/login", {
|
||||||
body: { email: evenHubEmailSetting.get().trim(), passwd: evenHubPasswordSetting.get() },
|
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 : "";
|
const data = asRecord(unwrap(response.envelope, response.httpStatus, "/v2/g/login"));
|
||||||
if (!token) throw new Error("Even login succeeded without returning a session token.");
|
const token = typeof data.token === "string" ? data.token : "";
|
||||||
this.token = token;
|
if (!token) throw new Error("Even login succeeded without returning a session token.");
|
||||||
return 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(
|
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 {
|
function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknown {
|
||||||
if (httpStatus === 401) {
|
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) {
|
if (httpStatus < 200 || httpStatus >= 300) {
|
||||||
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
|
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import { shell } from "../../ui/shell/shell";
|
|||||||
import { EvenHubStoreLayer } from "./store-layer";
|
import { EvenHubStoreLayer } from "./store-layer";
|
||||||
import { launchPackage } from "./manager";
|
import { launchPackage } from "./manager";
|
||||||
import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-process-window";
|
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_WINDOW_ID = "evenhub:store";
|
||||||
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
|
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
|
||||||
@@ -28,6 +30,7 @@ const evenhubApp: AppDefinition = {
|
|||||||
appId: "evenhub",
|
appId: "evenhub",
|
||||||
title: "EvenHub",
|
title: "EvenHub",
|
||||||
icon: "package",
|
icon: "package",
|
||||||
|
renderIcon: renderEvenRealitiesLogo,
|
||||||
launch: async (ctx) => {
|
launch: async (ctx) => {
|
||||||
const existing = shell.getWindows().find((window) => window.windowId === EVENHUB_STORE_WINDOW_ID);
|
const existing = shell.getWindows().find((window) => window.windowId === EVENHUB_STORE_WINDOW_ID);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
@@ -38,7 +41,6 @@ const evenhubApp: AppDefinition = {
|
|||||||
let created: InProcessWindow | null = null;
|
let created: InProcessWindow | null = null;
|
||||||
const store = new EvenHubStoreLayer({
|
const store = new EvenHubStoreLayer({
|
||||||
launchApp: (appId) => ctx.launchApp(appId),
|
launchApp: (appId) => ctx.launchApp(appId),
|
||||||
openSettings: () => ctx.launchApp("settings", { section: "EvenHub" }),
|
|
||||||
appendLog: ctx.appendLog,
|
appendLog: ctx.appendLog,
|
||||||
});
|
});
|
||||||
await ctx.launchInProcessApp(EVENHUB_STORE_WINDOW_ID, EVENHUB_STORE_SURFACE_ID, (options) => {
|
await ctx.launchInProcessApp(EVENHUB_STORE_WINDOW_ID, EVENHUB_STORE_SURFACE_ID, (options) => {
|
||||||
@@ -48,6 +50,7 @@ const evenhubApp: AppDefinition = {
|
|||||||
title: "EvenHub",
|
title: "EvenHub",
|
||||||
iconLetter: "EH",
|
iconLetter: "EH",
|
||||||
icon: "package",
|
icon: "package",
|
||||||
|
drawIcon: makeImageWindowIcon(renderEvenRealitiesLogo, windowIcon("package", "EH")),
|
||||||
closeable: true,
|
closeable: true,
|
||||||
menuItems: () => (created?.stack.isAtBase() ? store.buildMenuItems() : []),
|
menuItems: () => (created?.stack.isAtBase() ? store.buildMenuItems() : []),
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
@@ -55,7 +58,10 @@ const evenhubApp: AppDefinition = {
|
|||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
setSurfaceVisible: options.setSurfaceVisible,
|
setSurfaceVisible: options.setSurfaceVisible,
|
||||||
removeSurface: options.removeSurface,
|
removeSurface: options.removeSurface,
|
||||||
onClosed: options.onClosed,
|
onClosed: () => {
|
||||||
|
store.closeCredentialEditor(options.actions);
|
||||||
|
options.onClosed();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return created;
|
return created;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
import { truncateText } from "../../graphics/textwrap";
|
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||||
import { clamp } from "../../util/numeric-util";
|
import { clamp } from "../../util/numeric-util";
|
||||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
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 {
|
import {
|
||||||
drawListScrollbar,
|
drawListScrollbar,
|
||||||
drawSelectionHighlight,
|
drawSelectionHighlight,
|
||||||
@@ -11,7 +11,17 @@ import {
|
|||||||
type MenuItem,
|
type MenuItem,
|
||||||
} from "../../ui/menu";
|
} from "../../ui/menu";
|
||||||
import { shell } from "../../ui/shell/shell";
|
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";
|
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
|
||||||
|
|
||||||
const HEADER_HEIGHT = 34;
|
const HEADER_HEIGHT = 34;
|
||||||
@@ -21,7 +31,6 @@ const LIST_X = 18;
|
|||||||
|
|
||||||
export type EvenHubStoreLayerOptions = {
|
export type EvenHubStoreLayerOptions = {
|
||||||
launchApp: (appId: string) => Promise<void> | void;
|
launchApp: (appId: string) => Promise<void> | void;
|
||||||
openSettings: () => Promise<void> | void;
|
|
||||||
appendLog: (message: string) => void;
|
appendLog: (message: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,14 +43,20 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
private nextPage = 1;
|
private nextPage = 1;
|
||||||
private started = false;
|
private started = false;
|
||||||
private loading = 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) {}
|
constructor(private readonly options: EvenHubStoreLayerOptions) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
this.started = true;
|
this.started = true;
|
||||||
void this.reload(ctx);
|
if (this.showingLogin) {
|
||||||
|
this.openCredentialEditor(ctx);
|
||||||
|
} else {
|
||||||
|
void this.reload(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const font = getDefaultSmallFont();
|
const font = getDefaultSmallFont();
|
||||||
@@ -49,11 +64,26 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
const image = new GrayImage(width, height, 0);
|
const image = new GrayImage(width, height, 0);
|
||||||
image.drawText(font, LIST_X, 8, "EvenHub", 220);
|
image.drawText(font, LIST_X, 8, "EvenHub", 220);
|
||||||
|
|
||||||
const subtitle = !isEvenHubStoreConfigured()
|
const subtitle = this.status || (this.total ? `${this.apps.length} of ${this.total} public apps` : "Public apps");
|
||||||
? "Set account details in Settings > EvenHub"
|
|
||||||
: 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);
|
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) {
|
if (this.apps.length === 0) {
|
||||||
const message = this.loading ? "Loading apps..." : this.status || "No apps returned.";
|
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);
|
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()
|
const hint = `${GESTURE_SCROLL} select ${GESTURE_CLICK} details ${GESTURE_DOUBLE_CLICK} back`;
|
||||||
? `${GESTURE_CLICK} settings ${GESTURE_DOUBLE_CLICK} back`
|
|
||||||
: `${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);
|
image.drawText(font, LIST_X, height - 16, truncateText(font, hint, width - LIST_X * 2), 105);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
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) {
|
switch (event.type) {
|
||||||
case "scroll-up":
|
case "scroll-up":
|
||||||
this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
||||||
@@ -102,10 +138,6 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case "click":
|
case "click":
|
||||||
if (!isEvenHubStoreConfigured()) {
|
|
||||||
await this.options.openSettings();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.loading) {
|
if (!this.loading) {
|
||||||
const app = this.apps[this.selectedIndex];
|
const app = this.apps[this.selectedIndex];
|
||||||
if (app) {
|
if (app) {
|
||||||
@@ -127,6 +159,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildMenuItems(): MenuItem[] {
|
buildMenuItems(): MenuItem[] {
|
||||||
|
if (this.showingLogin) return [];
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: "Refresh",
|
label: "Refresh",
|
||||||
@@ -136,15 +169,23 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "EvenHub settings",
|
label: "Log Out",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
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> {
|
private async reload(ctx: LayerContext): Promise<void> {
|
||||||
if (this.loading) return;
|
if (this.loading) return;
|
||||||
evenHubApi.clearSession();
|
evenHubApi.clearSession();
|
||||||
@@ -155,7 +196,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
this.scrollRow = 0;
|
this.scrollRow = 0;
|
||||||
this.status = "";
|
this.status = "";
|
||||||
if (!isEvenHubStoreConfigured()) {
|
if (!isEvenHubStoreConfigured()) {
|
||||||
ctx.actions.requestRender();
|
this.enterLogin(ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.loadNextPage(ctx);
|
await this.loadNextPage(ctx);
|
||||||
@@ -174,7 +215,13 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
this.nextPage = page.page + 1;
|
this.nextPage = page.page + 1;
|
||||||
this.status = "";
|
this.status = "";
|
||||||
} catch (error) {
|
} 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}`);
|
this.options.appendLog(`evenhub store: ${this.status}`);
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
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 {
|
function cleanError(error: unknown): string {
|
||||||
|
|||||||
@@ -25,7 +25,12 @@ const launcherApp: AppDefinition = {
|
|||||||
apps: () => [
|
apps: () => [
|
||||||
...ctx.apps
|
...ctx.apps
|
||||||
.filter((app) => app.showInLauncher !== false)
|
.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) => ({
|
...getInstalledEvenHubApps().map((app) => ({
|
||||||
appId: installedEvenHubAppId(app.packageId),
|
appId: installedEvenHubAppId(app.packageId),
|
||||||
label: app.name,
|
label: app.name,
|
||||||
|
|||||||
@@ -57,8 +57,14 @@ export type DashboardSnapshot = {
|
|||||||
*/
|
*/
|
||||||
displayPreviewMessage: string;
|
displayPreviewMessage: string;
|
||||||
activeTextSettingId: string | null;
|
activeTextSettingId: string | null;
|
||||||
|
activeTextEditorTitle: string;
|
||||||
activeTextSettingTitle: string;
|
activeTextSettingTitle: string;
|
||||||
activeTextSettingValue: string;
|
activeTextSettingValue: string;
|
||||||
|
activeTextSettingInputKind: "text" | "email" | "password";
|
||||||
|
secondaryTextSettingId: string | null;
|
||||||
|
secondaryTextSettingTitle: string;
|
||||||
|
secondaryTextSettingValue: string;
|
||||||
|
secondaryTextSettingInputKind: "text" | "email" | "password";
|
||||||
evenAppConflictMessage: string;
|
evenAppConflictMessage: string;
|
||||||
evenAppConflictWarningVisible: boolean;
|
evenAppConflictWarningVisible: boolean;
|
||||||
firmwareWarningMessage: string;
|
firmwareWarningMessage: string;
|
||||||
@@ -142,7 +148,9 @@ class DashboardController {
|
|||||||
private phase: ConnectionPhase = "disconnected";
|
private phase: ConnectionPhase = "disconnected";
|
||||||
private status = "Disconnected.";
|
private status = "Disconnected.";
|
||||||
private log = "";
|
private log = "";
|
||||||
private activeTextSetting: ConfigSettingString | null = null;
|
private activeTextSettings: ConfigSettingString[] = [];
|
||||||
|
private activeTextEditorTitle = "";
|
||||||
|
private activeTextEditorOnFinish: (() => void) | null = null;
|
||||||
private evenNotificationActive = false;
|
private evenNotificationActive = false;
|
||||||
private evenAppConflictMessage = "";
|
private evenAppConflictMessage = "";
|
||||||
private firmwareWarningMessage = "";
|
private firmwareWarningMessage = "";
|
||||||
@@ -212,6 +220,11 @@ class DashboardController {
|
|||||||
const sharedActions = {
|
const sharedActions = {
|
||||||
disconnect: () => this.disconnect(),
|
disconnect: () => this.disconnect(),
|
||||||
startTextSettingEdit: (setting: ConfigSettingString) => this.startTextSettingEdit(setting),
|
startTextSettingEdit: (setting: ConfigSettingString) => this.startTextSettingEdit(setting),
|
||||||
|
startTextSettingsEdit: (
|
||||||
|
settings: readonly ConfigSettingString[],
|
||||||
|
title: string,
|
||||||
|
onFinish?: () => void,
|
||||||
|
) => this.startTextSettingsEdit(settings, title, onFinish),
|
||||||
endTextSettingEdit: () => this.endTextSettingEdit(),
|
endTextSettingEdit: () => this.endTextSettingEdit(),
|
||||||
startVoiceCapture: () => this.startVoiceCapture(),
|
startVoiceCapture: () => this.startVoiceCapture(),
|
||||||
stopVoiceCapture: () => this.stopVoiceCapture(),
|
stopVoiceCapture: () => this.stopVoiceCapture(),
|
||||||
@@ -683,15 +696,23 @@ class DashboardController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
snapshot(): DashboardSnapshot {
|
snapshot(): DashboardSnapshot {
|
||||||
|
const primaryTextSetting = this.activeTextSettings[0] ?? null;
|
||||||
|
const secondaryTextSetting = this.activeTextSettings[1] ?? null;
|
||||||
return {
|
return {
|
||||||
phase: this.phase,
|
phase: this.phase,
|
||||||
status: this.status,
|
status: this.status,
|
||||||
log: this.log,
|
log: this.log,
|
||||||
displayPreview: this.displayPreview,
|
displayPreview: this.displayPreview,
|
||||||
displayPreviewMessage: this.displayPreviewMessage(),
|
displayPreviewMessage: this.displayPreviewMessage(),
|
||||||
activeTextSettingId: this.activeTextSetting?.id ?? null,
|
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||||
activeTextSettingTitle: this.activeTextSetting?.editorTitle ?? "",
|
activeTextEditorTitle: this.activeTextEditorTitle,
|
||||||
activeTextSettingValue: this.activeTextSetting?.get() ?? "",
|
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,
|
evenAppConflictMessage: this.evenAppConflictMessage,
|
||||||
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
||||||
firmwareWarningMessage: this.firmwareWarningMessage,
|
firmwareWarningMessage: this.firmwareWarningMessage,
|
||||||
@@ -771,9 +792,11 @@ class DashboardController {
|
|||||||
openEvenAppSettings();
|
openEvenAppSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
setActiveTextSettingValue(value: string): void {
|
setActiveTextSettingValue(value: string, settingId?: string): void {
|
||||||
shell.noteUserActivity();
|
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) return;
|
||||||
if (setting.get() === value) return;
|
if (setting.get() === value) return;
|
||||||
setting.set(value);
|
setting.set(value);
|
||||||
@@ -1182,7 +1205,17 @@ class DashboardController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private startTextSettingEdit(setting: ConfigSettingString): void {
|
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();
|
this.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1236,10 +1269,12 @@ class DashboardController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private endTextSettingEdit(): void {
|
private endTextSettingEdit(): void {
|
||||||
const finishedSetting = this.activeTextSetting;
|
const finishedSettings = this.activeTextSettings;
|
||||||
this.activeTextSetting = null;
|
this.activeTextSettings = [];
|
||||||
|
this.activeTextEditorTitle = "";
|
||||||
|
this.activeTextEditorOnFinish = null;
|
||||||
this.emit();
|
this.emit();
|
||||||
if (finishedSetting === nightscoutSiteUrlSetting || finishedSetting === nightscoutApiTokenSetting) {
|
if (finishedSettings.includes(nightscoutSiteUrlSetting) || finishedSettings.includes(nightscoutApiTokenSetting)) {
|
||||||
void this.refreshNightscoutAfterSettingsChange();
|
void this.refreshNightscoutAfterSettingsChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1250,11 +1285,14 @@ class DashboardController {
|
|||||||
* out of the edit page.
|
* out of the edit page.
|
||||||
*/
|
*/
|
||||||
finishActiveTextSettingEdit(): void {
|
finishActiveTextSettingEdit(): void {
|
||||||
if (!this.activeTextSetting) return;
|
if (!this.activeTextSettings.length) return;
|
||||||
|
const onFinish = this.activeTextEditorOnFinish;
|
||||||
|
const closesGlassesEditor = this.activeTextSettings.length === 1;
|
||||||
this.endTextSettingEdit();
|
this.endTextSettingEdit();
|
||||||
if (this.textEditorHost?.closeTextEditor()) {
|
if (closesGlassesEditor && this.textEditorHost?.closeTextEditor()) {
|
||||||
this.textEditorHost.requestRender();
|
this.textEditorHost.requestRender();
|
||||||
}
|
}
|
||||||
|
onFinish?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateTextSetting(setting: ConfigSettingString, value: string): void {
|
private updateTextSetting(setting: ConfigSettingString, value: string): void {
|
||||||
|
|||||||
@@ -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 |
@@ -79,12 +79,16 @@ function applySettingsTextFieldContrast(textField: TextField): void {
|
|||||||
nativeTextField.setSelectAllOnFocus(true)
|
nativeTextField.setSelectAllOnFocus(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function focusSystemNameField(page: Page): void {
|
function focusTextEditor(page: Page): void {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const textField = page.getViewById<TextField>('settingsTextField')
|
const textField = page.getViewById<TextField>('settingsTextField')
|
||||||
|
const secondaryTextField = page.getViewById<TextField>('secondarySettingsTextField')
|
||||||
if (textField) {
|
if (textField) {
|
||||||
applySettingsTextFieldContrast(textField)
|
applySettingsTextFieldContrast(textField)
|
||||||
}
|
}
|
||||||
|
if (secondaryTextField) {
|
||||||
|
applySettingsTextFieldContrast(secondaryTextField)
|
||||||
|
}
|
||||||
textField?.focus()
|
textField?.focus()
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
@@ -139,7 +143,7 @@ export function loaded(args: EventData) {
|
|||||||
}
|
}
|
||||||
if (propertyArgs.propertyName === 'activeTextSettingId') {
|
if (propertyArgs.propertyName === 'activeTextSettingId') {
|
||||||
if (model.isTextSettingEditorActive) {
|
if (model.isTextSettingEditorActive) {
|
||||||
focusSystemNameField(page)
|
focusTextEditor(page)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -160,7 +164,7 @@ export function loaded(args: EventData) {
|
|||||||
setPageState(page, state)
|
setPageState(page, state)
|
||||||
scrollLogsToBottom(scrollViews)
|
scrollLogsToBottom(scrollViews)
|
||||||
if (model.isTextSettingEditorActive) {
|
if (model.isTextSettingEditorActive) {
|
||||||
focusSystemNameField(page)
|
focusTextEditor(page)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,15 +105,31 @@
|
|||||||
visibility="{{ textSettingEditorVisibility }}"
|
visibility="{{ textSettingEditorVisibility }}"
|
||||||
horizontalAlignment="stretch"
|
horizontalAlignment="stretch"
|
||||||
verticalAlignment="top">
|
verticalAlignment="top">
|
||||||
|
<Label text="{{ activeTextEditorTitle }}" class="h2" />
|
||||||
<Label text="{{ activeTextSettingTitle }}" />
|
<Label text="{{ activeTextSettingTitle }}" />
|
||||||
<TextField
|
<TextField
|
||||||
id="settingsTextField"
|
id="settingsTextField"
|
||||||
text="{{ activeTextSettingValue }}"
|
text="{{ activeTextSettingValue }}"
|
||||||
textChange="{{ onTextSettingTextChange }}"
|
textChange="{{ onTextSettingTextChange }}"
|
||||||
returnPress="{{ onTextSettingReturnPress }}"
|
returnPress="{{ onPrimaryTextSettingReturnPress }}"
|
||||||
autocorrect="false"
|
autocorrect="false"
|
||||||
autocapitalizationType="none"
|
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>
|
</StackLayout>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
</Page>
|
</Page>
|
||||||
@@ -14,8 +14,14 @@ export class MainViewModel extends Observable {
|
|||||||
private _displayPreviewMessage = "";
|
private _displayPreviewMessage = "";
|
||||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||||
private _activeTextSettingId: string | null = null;
|
private _activeTextSettingId: string | null = null;
|
||||||
|
private _activeTextEditorTitle = "";
|
||||||
private _activeTextSettingTitle = "";
|
private _activeTextSettingTitle = "";
|
||||||
private _activeTextSettingValue = "";
|
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 _evenAppConflictMessage = "";
|
||||||
private _evenAppConflictWarningVisible = false;
|
private _evenAppConflictWarningVisible = false;
|
||||||
private _firmwareWarningMessage = "";
|
private _firmwareWarningMessage = "";
|
||||||
@@ -34,8 +40,14 @@ export class MainViewModel extends Observable {
|
|||||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||||
this.phase = snapshot.phase;
|
this.phase = snapshot.phase;
|
||||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||||
|
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
||||||
this.activeTextSettingValue = snapshot.activeTextSettingValue;
|
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.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||||
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
||||||
@@ -185,6 +197,17 @@ export class MainViewModel extends Observable {
|
|||||||
return this._activeTextSettingTitle;
|
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) {
|
set activeTextSettingTitle(value: string) {
|
||||||
if (this._activeTextSettingTitle !== value) {
|
if (this._activeTextSettingTitle !== value) {
|
||||||
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 {
|
get isTextSettingEditorActive(): boolean {
|
||||||
return this._activeTextSettingId !== null;
|
return this._activeTextSettingId !== null;
|
||||||
}
|
}
|
||||||
@@ -423,15 +534,37 @@ export class MainViewModel extends Observable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTextSettingTextChange(args: { value?: string; object?: { text?: string } }): void {
|
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
|
// Commit the field's actual text at done-time, in case the final
|
||||||
// keystroke's textChange hadn't landed yet.
|
// keystroke's textChange hadn't landed yet.
|
||||||
const text = args?.object?.text;
|
const text = args?.object?.text;
|
||||||
if (typeof text === "string") {
|
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();
|
dashboardController.finishActiveTextSettingEdit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ export class ConfigSettingEnum<TValue extends string, TId extends string = strin
|
|||||||
type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<string, TId> & {
|
type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<string, TId> & {
|
||||||
editorTitle?: string;
|
editorTitle?: string;
|
||||||
glassesEditTitle?: string;
|
glassesEditTitle?: string;
|
||||||
|
inputKind?: "text" | "email" | "password";
|
||||||
normalize?: (value: string | null | undefined) => string;
|
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> {
|
export class ConfigSettingString<TId extends string = string> extends ConfigSetting<string, TId> {
|
||||||
readonly editorTitle: string;
|
readonly editorTitle: string;
|
||||||
readonly glassesEditTitle: string;
|
readonly glassesEditTitle: string;
|
||||||
|
readonly inputKind: "text" | "email" | "password";
|
||||||
private readonly normalizer: (value: string | null | undefined) => string;
|
private readonly normalizer: (value: string | null | undefined) => string;
|
||||||
|
|
||||||
constructor(options: ConfigSettingStringOptions<TId>) {
|
constructor(options: ConfigSettingStringOptions<TId>) {
|
||||||
super(options);
|
super(options);
|
||||||
this.editorTitle = options.editorTitle ?? options.label;
|
this.editorTitle = options.editorTitle ?? options.label;
|
||||||
this.glassesEditTitle = options.glassesEditTitle ?? `Edit ${options.label}`;
|
this.glassesEditTitle = options.glassesEditTitle ?? `Edit ${options.label}`;
|
||||||
|
this.inputKind = options.inputKind ?? "text";
|
||||||
this.normalizer = options.normalize ?? ((value) => value ?? "");
|
this.normalizer = options.normalize ?? ((value) => value ?? "");
|
||||||
stringSettingsById.set(this.id, this);
|
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.",
|
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
|
* 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
|
* asks the shell to open the phone text editor on this setting, the user
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import {
|
|||||||
assistantSkipConfirmationSetting,
|
assistantSkipConfirmationSetting,
|
||||||
batteryDisplayModeSetting,
|
batteryDisplayModeSetting,
|
||||||
brightnessSetting,
|
brightnessSetting,
|
||||||
evenHubEmailSetting,
|
|
||||||
evenHubPasswordSetting,
|
|
||||||
elevenLabsApiKeySetting,
|
elevenLabsApiKeySetting,
|
||||||
mapboxApiKeySetting,
|
mapboxApiKeySetting,
|
||||||
openAiApiKeySetting,
|
openAiApiKeySetting,
|
||||||
@@ -134,13 +132,6 @@ function settingsSections(): SettingsSection[] {
|
|||||||
textSettingMenuItem(roamApiTokenSetting),
|
textSettingMenuItem(roamApiTokenSetting),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: "EvenHub",
|
|
||||||
items: [
|
|
||||||
textSettingMenuItem(evenHubEmailSetting),
|
|
||||||
textSettingMenuItem(evenHubPasswordSetting),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: "Developer",
|
label: "Developer",
|
||||||
items: [
|
items: [
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ export type LayerActions = {
|
|||||||
requestRender: () => void;
|
requestRender: () => void;
|
||||||
disconnect: () => Promise<void> | void;
|
disconnect: () => Promise<void> | void;
|
||||||
startTextSettingEdit: (setting: ConfigSettingString) => 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;
|
endTextSettingEdit: () => Promise<void> | void;
|
||||||
/**
|
/**
|
||||||
* Start push-to-talk voice capture with the provider chosen in settings.
|
* Start push-to-talk voice capture with the provider chosen in settings.
|
||||||
@@ -50,6 +56,7 @@ export const noopLayerActions: LayerActions = {
|
|||||||
requestRender: () => {},
|
requestRender: () => {},
|
||||||
disconnect: () => {},
|
disconnect: () => {},
|
||||||
startTextSettingEdit: () => {},
|
startTextSettingEdit: () => {},
|
||||||
|
startTextSettingsEdit: () => {},
|
||||||
endTextSettingEdit: () => {},
|
endTextSettingEdit: () => {},
|
||||||
startVoiceCapture: () => {},
|
startVoiceCapture: () => {},
|
||||||
stopVoiceCapture: () => {},
|
stopVoiceCapture: () => {},
|
||||||
|
|||||||
Reference in new issue
Block a user