forked from Blendman974/faceclaw
EvenHub app stores login token instead of password
This commit is contained in:
1 parent
cc4b69fb80
commit
6c46f2f7cc
8 files changed
+302
-49
No files matched your search
+144
-12
@@ -1,24 +1,86 @@
|
|||||||
import { ConfigSettingString } from "../../ui/dashboard-settings";
|
import {
|
||||||
|
ConfigSettingBoolean,
|
||||||
|
ConfigSettingString,
|
||||||
|
} from "../../ui/dashboard-settings";
|
||||||
|
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EvenHub owns its account configuration. The storage keys intentionally
|
* Persistent EvenHub session data. Passwords are deliberately excluded: the
|
||||||
* match the former Settings-app entries so existing users stay signed in.
|
* password entered in the login form lives only in memory until the request
|
||||||
|
* completes, while a successful login may persist the returned token.
|
||||||
*/
|
*/
|
||||||
export const evenHubEmailSetting = new ConfigSettingString({
|
export const evenHubEmailSetting = new ConfigSettingString({
|
||||||
id: "evenhub-email",
|
id: "evenhub-saved-email",
|
||||||
label: "Email",
|
label: "Email",
|
||||||
storageKey: "integrations.evenhub.email",
|
storageKey: "integrations.evenhub.email",
|
||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
|
normalize: normalizeEmail,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const evenHubTokenSetting = new ConfigSettingString({
|
||||||
|
id: "evenhub-token",
|
||||||
|
label: "Login token",
|
||||||
|
storageKey: "integrations.evenhub.token",
|
||||||
|
defaultValue: "",
|
||||||
|
inputKind: "password",
|
||||||
|
normalize: normalizeToken,
|
||||||
|
formatValue: (value) => (value ? "(signed in)" : "(signed out)"),
|
||||||
|
});
|
||||||
|
|
||||||
|
class TransientStringSetting extends ConfigSettingString {
|
||||||
|
private value: string;
|
||||||
|
private readonly normalizeValue: (value: string | null | undefined) => string;
|
||||||
|
|
||||||
|
constructor(options: ConstructorParameters<typeof ConfigSettingString>[0]) {
|
||||||
|
super(options);
|
||||||
|
this.normalizeValue = options.normalize ?? ((value) => value ?? "");
|
||||||
|
this.value = this.normalizeValue(options.defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
override get(): string {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
override set(value: string): string {
|
||||||
|
this.value = this.normalizeValue(value);
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransientBooleanSetting extends ConfigSettingBoolean {
|
||||||
|
private value: boolean;
|
||||||
|
|
||||||
|
constructor(options: ConstructorParameters<typeof ConfigSettingBoolean>[0]) {
|
||||||
|
super(options);
|
||||||
|
this.value = options.defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
override get(): boolean {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
override set(value: boolean): boolean {
|
||||||
|
this.value = value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Phone login-form values. These overrides never touch the settings store. */
|
||||||
|
export const evenHubLoginEmailSetting = new TransientStringSetting({
|
||||||
|
id: "evenhub-login-email",
|
||||||
|
label: "Email",
|
||||||
|
storageKey: "transient.evenhub.email",
|
||||||
|
defaultValue: "",
|
||||||
editorTitle: "Email",
|
editorTitle: "Email",
|
||||||
glassesEditTitle: "Edit Even email",
|
glassesEditTitle: "Edit Even email",
|
||||||
inputKind: "email",
|
inputKind: "email",
|
||||||
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
|
normalize: normalizeEmail,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const evenHubPasswordSetting = new ConfigSettingString({
|
export const evenHubLoginPasswordSetting = new TransientStringSetting({
|
||||||
id: "evenhub-password",
|
id: "evenhub-login-password",
|
||||||
label: "Password",
|
label: "Password",
|
||||||
storageKey: "integrations.evenhub.password",
|
storageKey: "transient.evenhub.password",
|
||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
editorTitle: "Password",
|
editorTitle: "Password",
|
||||||
glassesEditTitle: "Edit Even password",
|
glassesEditTitle: "Edit Even password",
|
||||||
@@ -27,10 +89,80 @@ export const evenHubPasswordSetting = new ConfigSettingString({
|
|||||||
formatValue: (value) => (value ? "(set)" : "(not set)"),
|
formatValue: (value) => (value ? "(set)" : "(not set)"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export function hasEvenHubCredentials(): boolean {
|
export const evenHubRememberMeSetting = new TransientBooleanSetting({
|
||||||
return Boolean(evenHubEmailSetting.get().trim() && evenHubPasswordSetting.get());
|
id: "evenhub-remember-me",
|
||||||
|
label: "Remember me",
|
||||||
|
storageKey: "transient.evenhub.rememberMe",
|
||||||
|
defaultValue: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
let transientToken = "";
|
||||||
|
|
||||||
|
export function getEvenHubToken(): string {
|
||||||
|
return transientToken || evenHubTokenSetting.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearEvenHubPassword(): void {
|
export function hasEvenHubCredentials(): boolean {
|
||||||
evenHubPasswordSetting.set("");
|
return Boolean(getEvenHubToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveEvenHubSession(email: string, token: string, remember: boolean): void {
|
||||||
|
const normalizedEmail = normalizeEmail(email);
|
||||||
|
const normalizedToken = normalizeToken(token);
|
||||||
|
if (remember) {
|
||||||
|
evenHubEmailSetting.set(normalizedEmail);
|
||||||
|
evenHubTokenSetting.set(normalizedToken);
|
||||||
|
transientToken = "";
|
||||||
|
} else {
|
||||||
|
evenHubEmailSetting.set("");
|
||||||
|
evenHubTokenSetting.set("");
|
||||||
|
transientToken = normalizedToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clear a rejected token but retain a remembered email for the next login. */
|
||||||
|
export function invalidateEvenHubToken(): void {
|
||||||
|
transientToken = "";
|
||||||
|
evenHubTokenSetting.set("");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearEvenHubSession(): void {
|
||||||
|
transientToken = "";
|
||||||
|
evenHubEmailSetting.set("");
|
||||||
|
evenHubTokenSetting.set("");
|
||||||
|
clearEvenHubLoginForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetEvenHubLoginForm(): void {
|
||||||
|
evenHubLoginEmailSetting.set(evenHubEmailSetting.get());
|
||||||
|
evenHubLoginPasswordSetting.set("");
|
||||||
|
evenHubRememberMeSetting.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearEvenHubLoginForm(): void {
|
||||||
|
evenHubLoginEmailSetting.set("");
|
||||||
|
evenHubLoginPasswordSetting.set("");
|
||||||
|
evenHubRememberMeSetting.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Discard a window-scoped session; remembered sessions are left intact. */
|
||||||
|
export function clearTransientEvenHubSession(): void {
|
||||||
|
if (transientToken) transientToken = "";
|
||||||
|
clearEvenHubLoginForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeEmail(value: string | null | undefined): string {
|
||||||
|
return (value ?? "").replace(/[\x00-\x1f]+/g, "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeToken(value: string | null | undefined): string {
|
||||||
|
return (value ?? "").replace(/[\x00-\x20\x7f]+/g, "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// One-time security migration from builds that persisted the account password.
|
||||||
|
// Existing users must sign in once more so the password can be exchanged for a
|
||||||
|
// token under the new storage model.
|
||||||
|
const LEGACY_PASSWORD_KEY = "integrations.evenhub.password";
|
||||||
|
if (getStringSetting(LEGACY_PASSWORD_KEY, "")) {
|
||||||
|
setStringSetting(LEGACY_PASSWORD_KEY, "");
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,12 @@
|
|||||||
* 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, hasEvenHubCredentials } from "./credentials";
|
import {
|
||||||
|
getEvenHubToken,
|
||||||
|
hasEvenHubCredentials,
|
||||||
|
invalidateEvenHubToken,
|
||||||
|
saveEvenHubSession,
|
||||||
|
} from "./credentials";
|
||||||
import { fetchWithUserAgent } from "../../util/http";
|
import { fetchWithUserAgent } from "../../util/http";
|
||||||
|
|
||||||
declare const android: any;
|
declare const android: any;
|
||||||
@@ -72,7 +77,6 @@ export class EvenHubAuthenticationError extends Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EvenHubApiClient {
|
export class EvenHubApiClient {
|
||||||
private token = "";
|
|
||||||
private loginPromise: Promise<string> | null = null;
|
private loginPromise: Promise<string> | null = null;
|
||||||
|
|
||||||
async listApps(page = 1, category = ""): Promise<EvenHubStorePage> {
|
async listApps(page = 1, category = ""): Promise<EvenHubStorePage> {
|
||||||
@@ -147,9 +151,13 @@ export class EvenHubApiClient {
|
|||||||
return { bytes, extension: extension === "jpeg" ? "jpg" : extension };
|
return { bytes, extension: extension === "jpeg" ? "jpg" : extension };
|
||||||
}
|
}
|
||||||
|
|
||||||
clearSession(): void {
|
async signIn(email: string, password: string, remember: boolean): Promise<void> {
|
||||||
this.token = "";
|
if (!this.loginPromise) {
|
||||||
this.loginPromise = null;
|
this.loginPromise = this.login(email, password, remember).finally(() => {
|
||||||
|
this.loginPromise = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await this.loginPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async authenticatedRequest(
|
private async authenticatedRequest(
|
||||||
@@ -158,38 +166,30 @@ export class EvenHubApiClient {
|
|||||||
options: { query?: Record<string, string | number>; body?: Record<string, unknown> } = {},
|
options: { query?: Record<string, string | number>; body?: Record<string, unknown> } = {},
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
let token = await this.ensureLogin();
|
let token = await this.ensureLogin();
|
||||||
let response = await this.request(method, path, { ...options, token, commonVersion: 3 });
|
const response = await this.request(method, path, { ...options, token, commonVersion: 3 });
|
||||||
if (response.httpStatus === 401) {
|
if (response.httpStatus === 401) {
|
||||||
this.clearSession();
|
invalidateEvenHubToken();
|
||||||
token = await this.ensureLogin();
|
|
||||||
response = await this.request(method, path, { ...options, token, commonVersion: 3 });
|
|
||||||
}
|
}
|
||||||
return unwrap(response.envelope, response.httpStatus, path);
|
return unwrap(response.envelope, response.httpStatus, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ensureLogin(): Promise<string> {
|
private ensureLogin(): Promise<string> {
|
||||||
if (this.token) return Promise.resolve(this.token);
|
const token = getEvenHubToken();
|
||||||
if (!isEvenHubStoreConfigured()) {
|
return token
|
||||||
return Promise.reject(new EvenHubAuthenticationError("Enter your Even account email and password."));
|
? Promise.resolve(token)
|
||||||
}
|
: Promise.reject(new EvenHubAuthenticationError("Enter your Even account email and password."));
|
||||||
if (!this.loginPromise) {
|
|
||||||
this.loginPromise = this.login().finally(() => {
|
|
||||||
this.loginPromise = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this.loginPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async login(): Promise<string> {
|
private async login(email: string, password: string, remember: boolean): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const response = await this.request("POST", "/v2/g/login", {
|
const response = await this.request("POST", "/v2/g/login", {
|
||||||
commonVersion: 1,
|
commonVersion: 1,
|
||||||
body: { email: evenHubEmailSetting.get().trim(), passwd: evenHubPasswordSetting.get() },
|
body: { email: email.trim(), passwd: password },
|
||||||
});
|
});
|
||||||
const data = asRecord(unwrap(response.envelope, response.httpStatus, "/v2/g/login"));
|
const data = asRecord(unwrap(response.envelope, response.httpStatus, "/v2/g/login"));
|
||||||
const token = typeof data.token === "string" ? data.token : "";
|
const token = typeof data.token === "string" ? data.token : "";
|
||||||
if (!token) throw new Error("Even login succeeded without returning a session token.");
|
if (!token) throw new Error("Even login succeeded without returning a session token.");
|
||||||
this.token = token;
|
saveEvenHubSession(email, token, remember);
|
||||||
return token;
|
return token;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof EvenHubAuthenticationError) throw error;
|
if (error instanceof EvenHubAuthenticationError) throw error;
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ const evenhubApp: AppDefinition = {
|
|||||||
setSurfaceVisible: options.setSurfaceVisible,
|
setSurfaceVisible: options.setSurfaceVisible,
|
||||||
removeSurface: options.removeSurface,
|
removeSurface: options.removeSurface,
|
||||||
onClosed: () => {
|
onClosed: () => {
|
||||||
store.closeCredentialEditor(options.actions);
|
store.onWindowClosed(options.actions);
|
||||||
options.onClosed();
|
options.onClosed();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,9 +18,13 @@ import {
|
|||||||
type EvenHubStoreApp,
|
type EvenHubStoreApp,
|
||||||
} from "./even-api";
|
} from "./even-api";
|
||||||
import {
|
import {
|
||||||
clearEvenHubPassword,
|
clearEvenHubLoginForm,
|
||||||
evenHubEmailSetting,
|
clearEvenHubSession,
|
||||||
evenHubPasswordSetting,
|
clearTransientEvenHubSession,
|
||||||
|
evenHubLoginEmailSetting,
|
||||||
|
evenHubLoginPasswordSetting,
|
||||||
|
evenHubRememberMeSetting,
|
||||||
|
resetEvenHubLoginForm,
|
||||||
} from "./credentials";
|
} from "./credentials";
|
||||||
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
|
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
|
||||||
import { lineStep } from "../../ui/metrics";
|
import { lineStep } from "../../ui/metrics";
|
||||||
@@ -49,8 +53,11 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
private showingLogin = !isEvenHubStoreConfigured();
|
private showingLogin = !isEvenHubStoreConfigured();
|
||||||
private status = this.showingLogin ? "Sign in to browse public apps." : "";
|
private status = this.showingLogin ? "Sign in to browse public apps." : "";
|
||||||
private credentialEditorOpen = false;
|
private credentialEditorOpen = false;
|
||||||
|
private closed = false;
|
||||||
|
|
||||||
constructor(private readonly options: EvenHubStoreLayerOptions) {}
|
constructor(private readonly options: EvenHubStoreLayerOptions) {
|
||||||
|
if (this.showingLogin) resetEvenHubLoginForm();
|
||||||
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
@@ -169,8 +176,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
label: "Log Out",
|
label: "Log Out",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
clearEvenHubPassword();
|
clearEvenHubSession();
|
||||||
evenHubApi.clearSession();
|
|
||||||
this.enterLogin(ctx, "Signed out.");
|
this.enterLogin(ctx, "Signed out.");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -183,9 +189,14 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
void actions.endTextSettingEdit();
|
void actions.endTextSettingEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onWindowClosed(actions: Pick<LayerActions, "endTextSettingEdit">): void {
|
||||||
|
this.closed = true;
|
||||||
|
this.closeCredentialEditor(actions);
|
||||||
|
clearTransientEvenHubSession();
|
||||||
|
}
|
||||||
|
|
||||||
private async reload(ctx: LayerContext): Promise<void> {
|
private async reload(ctx: LayerContext): Promise<void> {
|
||||||
if (this.loading) return;
|
if (this.loading) return;
|
||||||
evenHubApi.clearSession();
|
|
||||||
this.apps = [];
|
this.apps = [];
|
||||||
this.total = 0;
|
this.total = 0;
|
||||||
this.nextPage = 1;
|
this.nextPage = 1;
|
||||||
@@ -227,11 +238,13 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enterLogin(ctx: LayerContext, status = "Sign in to browse public apps."): void {
|
private enterLogin(ctx: LayerContext, status = "Sign in to browse public apps."): void {
|
||||||
|
const wasShowingLogin = this.showingLogin;
|
||||||
this.showingLogin = true;
|
this.showingLogin = true;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.apps = [];
|
this.apps = [];
|
||||||
this.total = 0;
|
this.total = 0;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
if (!wasShowingLogin) resetEvenHubLoginForm();
|
||||||
this.openCredentialEditor(ctx);
|
this.openCredentialEditor(ctx);
|
||||||
ctx.actions.requestRender();
|
ctx.actions.requestRender();
|
||||||
}
|
}
|
||||||
@@ -240,22 +253,48 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
if (this.credentialEditorOpen) return;
|
if (this.credentialEditorOpen) return;
|
||||||
this.credentialEditorOpen = true;
|
this.credentialEditorOpen = true;
|
||||||
void ctx.actions.startTextSettingsEdit(
|
void ctx.actions.startTextSettingsEdit(
|
||||||
[evenHubEmailSetting, evenHubPasswordSetting],
|
[evenHubLoginEmailSetting, evenHubLoginPasswordSetting],
|
||||||
"Sign in to EvenHub",
|
"Sign in to EvenHub",
|
||||||
() => {
|
() => {
|
||||||
this.credentialEditorOpen = false;
|
this.credentialEditorOpen = false;
|
||||||
void this.submitCredentials(ctx);
|
void this.submitCredentials(ctx);
|
||||||
},
|
},
|
||||||
|
{ setting: evenHubRememberMeSetting, label: "Remember me" },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async submitCredentials(ctx: LayerContext): Promise<void> {
|
private async submitCredentials(ctx: LayerContext): Promise<void> {
|
||||||
if (!isEvenHubStoreConfigured()) {
|
const email = evenHubLoginEmailSetting.get();
|
||||||
|
const password = evenHubLoginPasswordSetting.get();
|
||||||
|
if (!email.trim() || !password) {
|
||||||
this.enterLogin(ctx, "Email and password are required.");
|
this.enterLogin(ctx, "Email and password are required.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.showingLogin = false;
|
this.loading = true;
|
||||||
await this.reload(ctx);
|
this.status = "Signing in...";
|
||||||
|
ctx.actions.requestRender();
|
||||||
|
try {
|
||||||
|
await evenHubApi.signIn(email, password, evenHubRememberMeSetting.get());
|
||||||
|
if (this.closed) {
|
||||||
|
clearTransientEvenHubSession();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.showingLogin = false;
|
||||||
|
clearEvenHubLoginForm();
|
||||||
|
this.loading = false;
|
||||||
|
await this.reload(ctx);
|
||||||
|
} catch (error) {
|
||||||
|
if (this.closed) return;
|
||||||
|
const message = cleanError(error);
|
||||||
|
this.options.appendLog(`evenhub store login failed: ${message}`);
|
||||||
|
this.status = `Login failed: ${message}`;
|
||||||
|
evenHubLoginPasswordSetting.set("");
|
||||||
|
this.openCredentialEditor(ctx);
|
||||||
|
} finally {
|
||||||
|
evenHubLoginPasswordSetting.set("");
|
||||||
|
this.loading = false;
|
||||||
|
if (!this.closed) ctx.actions.requestRender();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import { type AppContext, type AppDefinition, type AppLaunchParams, type TextEdi
|
|||||||
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
|
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
|
||||||
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
|
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
|
||||||
import { appViewportRect, type WindowHeightMode } from "../ui/shell/geometry";
|
import { appViewportRect, type WindowHeightMode } from "../ui/shell/geometry";
|
||||||
import { type LayerActions } from "../ui/layers";
|
import { type LayerActions, type TextSettingsEditToggle } from "../ui/layers";
|
||||||
import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||||
import {
|
import {
|
||||||
@@ -66,6 +66,9 @@ export type DashboardSnapshot = {
|
|||||||
secondaryTextSettingTitle: string;
|
secondaryTextSettingTitle: string;
|
||||||
secondaryTextSettingValue: string;
|
secondaryTextSettingValue: string;
|
||||||
secondaryTextSettingInputKind: "text" | "email" | "password";
|
secondaryTextSettingInputKind: "text" | "email" | "password";
|
||||||
|
activeTextEditorToggleLabel: string;
|
||||||
|
activeTextEditorToggleValue: boolean;
|
||||||
|
activeTextEditorToggleVisible: boolean;
|
||||||
evenAppConflictMessage: string;
|
evenAppConflictMessage: string;
|
||||||
evenAppConflictWarningVisible: boolean;
|
evenAppConflictWarningVisible: boolean;
|
||||||
firmwareWarningMessage: string;
|
firmwareWarningMessage: string;
|
||||||
@@ -152,6 +155,7 @@ class DashboardController {
|
|||||||
private activeTextSettings: ConfigSettingString[] = [];
|
private activeTextSettings: ConfigSettingString[] = [];
|
||||||
private activeTextEditorTitle = "";
|
private activeTextEditorTitle = "";
|
||||||
private activeTextEditorOnFinish: (() => void) | null = null;
|
private activeTextEditorOnFinish: (() => void) | null = null;
|
||||||
|
private activeTextEditorToggle: TextSettingsEditToggle | null = null;
|
||||||
private evenNotificationActive = false;
|
private evenNotificationActive = false;
|
||||||
private evenAppConflictMessage = "";
|
private evenAppConflictMessage = "";
|
||||||
private firmwareWarningMessage = "";
|
private firmwareWarningMessage = "";
|
||||||
@@ -232,7 +236,8 @@ class DashboardController {
|
|||||||
settings: readonly ConfigSettingString[],
|
settings: readonly ConfigSettingString[],
|
||||||
title: string,
|
title: string,
|
||||||
onFinish?: () => void,
|
onFinish?: () => void,
|
||||||
) => this.startTextSettingsEdit(settings, title, onFinish),
|
toggle?: TextSettingsEditToggle,
|
||||||
|
) => this.startTextSettingsEdit(settings, title, onFinish, toggle),
|
||||||
endTextSettingEdit: () => this.endTextSettingEdit(),
|
endTextSettingEdit: () => this.endTextSettingEdit(),
|
||||||
startVoiceCapture: () => this.startVoiceCapture(),
|
startVoiceCapture: () => this.startVoiceCapture(),
|
||||||
stopVoiceCapture: () => this.stopVoiceCapture(),
|
stopVoiceCapture: () => this.stopVoiceCapture(),
|
||||||
@@ -733,6 +738,9 @@ class DashboardController {
|
|||||||
secondaryTextSettingTitle: secondaryTextSetting?.editorTitle ?? "",
|
secondaryTextSettingTitle: secondaryTextSetting?.editorTitle ?? "",
|
||||||
secondaryTextSettingValue: secondaryTextSetting?.get() ?? "",
|
secondaryTextSettingValue: secondaryTextSetting?.get() ?? "",
|
||||||
secondaryTextSettingInputKind: secondaryTextSetting?.inputKind ?? "text",
|
secondaryTextSettingInputKind: secondaryTextSetting?.inputKind ?? "text",
|
||||||
|
activeTextEditorToggleLabel: this.activeTextEditorToggle?.label ?? "",
|
||||||
|
activeTextEditorToggleValue: this.activeTextEditorToggle?.setting.get() ?? false,
|
||||||
|
activeTextEditorToggleVisible: this.activeTextEditorToggle !== null,
|
||||||
evenAppConflictMessage: this.evenAppConflictMessage,
|
evenAppConflictMessage: this.evenAppConflictMessage,
|
||||||
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
||||||
firmwareWarningMessage: this.firmwareWarningMessage,
|
firmwareWarningMessage: this.firmwareWarningMessage,
|
||||||
@@ -827,6 +835,12 @@ class DashboardController {
|
|||||||
this.previewOrRenderAfterTextSettingChange();
|
this.previewOrRenderAfterTextSettingChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setActiveTextEditorToggleValue(value: boolean): void {
|
||||||
|
if (!this.activeTextEditorToggle || this.activeTextEditorToggle.setting.get() === value) return;
|
||||||
|
this.activeTextEditorToggle.setting.set(value);
|
||||||
|
this.emit();
|
||||||
|
}
|
||||||
|
|
||||||
async connect(): Promise<void> {
|
async connect(): Promise<void> {
|
||||||
if (this.phase !== "disconnected") return;
|
if (this.phase !== "disconnected") return;
|
||||||
// Connecting is the explicit way out of the manual-disconnected state.
|
// Connecting is the explicit way out of the manual-disconnected state.
|
||||||
@@ -1291,10 +1305,12 @@ class DashboardController {
|
|||||||
settings: readonly ConfigSettingString[],
|
settings: readonly ConfigSettingString[],
|
||||||
title: string,
|
title: string,
|
||||||
onFinish?: () => void,
|
onFinish?: () => void,
|
||||||
|
toggle?: TextSettingsEditToggle,
|
||||||
): void {
|
): void {
|
||||||
this.activeTextSettings = Array.from(settings.slice(0, 2));
|
this.activeTextSettings = Array.from(settings.slice(0, 2));
|
||||||
this.activeTextEditorTitle = title;
|
this.activeTextEditorTitle = title;
|
||||||
this.activeTextEditorOnFinish = onFinish ?? null;
|
this.activeTextEditorOnFinish = onFinish ?? null;
|
||||||
|
this.activeTextEditorToggle = toggle ?? null;
|
||||||
this.emit();
|
this.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1352,6 +1368,7 @@ class DashboardController {
|
|||||||
this.activeTextSettings = [];
|
this.activeTextSettings = [];
|
||||||
this.activeTextEditorTitle = "";
|
this.activeTextEditorTitle = "";
|
||||||
this.activeTextEditorOnFinish = null;
|
this.activeTextEditorOnFinish = null;
|
||||||
|
this.activeTextEditorToggle = null;
|
||||||
this.emit();
|
this.emit();
|
||||||
if (finishedSettings.includes(nightscoutSiteUrlSetting) || finishedSettings.includes(nightscoutApiTokenSetting)) {
|
if (finishedSettings.includes(nightscoutSiteUrlSetting) || finishedSettings.includes(nightscoutApiTokenSetting)) {
|
||||||
void this.refreshNightscoutAfterSettingsChange();
|
void this.refreshNightscoutAfterSettingsChange();
|
||||||
|
|||||||
@@ -130,6 +130,16 @@
|
|||||||
secure="{{ secondaryTextSettingSecure }}"
|
secure="{{ secondaryTextSettingSecure }}"
|
||||||
returnKeyType="done" />
|
returnKeyType="done" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
<GridLayout
|
||||||
|
columns="*,auto"
|
||||||
|
visibility="{{ activeTextEditorToggleVisibility }}"
|
||||||
|
class="m-t-8">
|
||||||
|
<Label col="0" text="{{ activeTextEditorToggleLabel }}" verticalAlignment="center" />
|
||||||
|
<Switch
|
||||||
|
col="1"
|
||||||
|
checked="{{ activeTextEditorToggleValue }}"
|
||||||
|
checkedChange="{{ onTextSettingToggleChange }}" />
|
||||||
|
</GridLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
</Page>
|
</Page>
|
||||||
@@ -23,6 +23,9 @@ export class MainViewModel extends Observable {
|
|||||||
private _secondaryTextSettingTitle = "";
|
private _secondaryTextSettingTitle = "";
|
||||||
private _secondaryTextSettingValue = "";
|
private _secondaryTextSettingValue = "";
|
||||||
private _secondaryTextSettingInputKind: "text" | "email" | "password" = "text";
|
private _secondaryTextSettingInputKind: "text" | "email" | "password" = "text";
|
||||||
|
private _activeTextEditorToggleLabel = "";
|
||||||
|
private _activeTextEditorToggleValue = false;
|
||||||
|
private _activeTextEditorToggleVisible = false;
|
||||||
private _evenAppConflictMessage = "";
|
private _evenAppConflictMessage = "";
|
||||||
private _evenAppConflictWarningVisible = false;
|
private _evenAppConflictWarningVisible = false;
|
||||||
private _firmwareWarningMessage = "";
|
private _firmwareWarningMessage = "";
|
||||||
@@ -49,6 +52,9 @@ export class MainViewModel extends Observable {
|
|||||||
this.secondaryTextSettingTitle = snapshot.secondaryTextSettingTitle;
|
this.secondaryTextSettingTitle = snapshot.secondaryTextSettingTitle;
|
||||||
this.secondaryTextSettingValue = snapshot.secondaryTextSettingValue;
|
this.secondaryTextSettingValue = snapshot.secondaryTextSettingValue;
|
||||||
this.secondaryTextSettingInputKind = snapshot.secondaryTextSettingInputKind;
|
this.secondaryTextSettingInputKind = snapshot.secondaryTextSettingInputKind;
|
||||||
|
this.activeTextEditorToggleLabel = snapshot.activeTextEditorToggleLabel;
|
||||||
|
this.activeTextEditorToggleValue = snapshot.activeTextEditorToggleValue;
|
||||||
|
this.activeTextEditorToggleVisible = snapshot.activeTextEditorToggleVisible;
|
||||||
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||||
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
||||||
@@ -315,6 +321,43 @@ export class MainViewModel extends Observable {
|
|||||||
return this.hasSecondaryTextSetting ? "next" : "done";
|
return this.hasSecondaryTextSetting ? "next" : "done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get activeTextEditorToggleLabel(): string {
|
||||||
|
return this._activeTextEditorToggleLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
set activeTextEditorToggleLabel(value: string) {
|
||||||
|
if (this._activeTextEditorToggleLabel !== value) {
|
||||||
|
this._activeTextEditorToggleLabel = value;
|
||||||
|
this.notifyPropertyChange("activeTextEditorToggleLabel", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get activeTextEditorToggleValue(): boolean {
|
||||||
|
return this._activeTextEditorToggleValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
set activeTextEditorToggleValue(value: boolean) {
|
||||||
|
if (this._activeTextEditorToggleValue !== value) {
|
||||||
|
this._activeTextEditorToggleValue = value;
|
||||||
|
this.notifyPropertyChange("activeTextEditorToggleValue", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get activeTextEditorToggleVisible(): boolean {
|
||||||
|
return this._activeTextEditorToggleVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
set activeTextEditorToggleVisible(value: boolean) {
|
||||||
|
if (this._activeTextEditorToggleVisible !== value) {
|
||||||
|
this._activeTextEditorToggleVisible = value;
|
||||||
|
this.notifyPropertyChange("activeTextEditorToggleVisibility", this.activeTextEditorToggleVisibility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get activeTextEditorToggleVisibility(): "visible" | "collapse" {
|
||||||
|
return this._activeTextEditorToggleVisible ? "visible" : "collapse";
|
||||||
|
}
|
||||||
|
|
||||||
get isTextSettingEditorActive(): boolean {
|
get isTextSettingEditorActive(): boolean {
|
||||||
return this._activeTextSettingId !== null;
|
return this._activeTextSettingId !== null;
|
||||||
}
|
}
|
||||||
@@ -573,6 +616,12 @@ export class MainViewModel extends Observable {
|
|||||||
dashboardController.finishActiveTextSettingEdit();
|
dashboardController.finishActiveTextSettingEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTextSettingToggleChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
|
||||||
|
dashboardController.setActiveTextEditorToggleValue(
|
||||||
|
args.object?.checked ?? args.value ?? false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onOpenEvenAppSettingsTap(): void {
|
onOpenEvenAppSettingsTap(): void {
|
||||||
dashboardController.openEvenAppSettings();
|
dashboardController.openEvenAppSettings();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -1,7 +1,12 @@
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||||
import { type Plane } from "../graphics/plane";
|
import { type Plane } from "../graphics/plane";
|
||||||
import { spanCurrent } from "../native/frame-timings";
|
import { spanCurrent } from "../native/frame-timings";
|
||||||
import { type ConfigSettingString } from "./dashboard-settings";
|
import { type ConfigSettingBoolean, type ConfigSettingString } from "./dashboard-settings";
|
||||||
|
|
||||||
|
export type TextSettingsEditToggle = {
|
||||||
|
setting: ConfigSettingBoolean;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type DashboardInputEvent =
|
export type DashboardInputEvent =
|
||||||
| { type: "click"; source: "ring" | "left-arm" | "right-arm" }
|
| { type: "click"; source: "ring" | "left-arm" | "right-arm" }
|
||||||
@@ -34,6 +39,7 @@ export type LayerActions = {
|
|||||||
settings: readonly ConfigSettingString[],
|
settings: readonly ConfigSettingString[],
|
||||||
title: string,
|
title: string,
|
||||||
onFinish?: () => void,
|
onFinish?: () => void,
|
||||||
|
toggle?: TextSettingsEditToggle,
|
||||||
) => Promise<void> | void;
|
) => Promise<void> | void;
|
||||||
endTextSettingEdit: () => Promise<void> | void;
|
endTextSettingEdit: () => Promise<void> | void;
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user