From 09a59b98211ad5b87bcfdcfdc69a0798b6715aae Mon Sep 17 00:00:00 2001 From: James Babcock Date: Fri, 25 Sep 2026 01:56:52 -0700 Subject: [PATCH] Fix the EvenHub login form sizing and missing cancel button --- CHANGELOG | 3 +- app/apps/evenhub/even-api.ts | 24 ++++-- app/apps/evenhub/store-detail-layer.ts | 5 ++ app/apps/evenhub/store-layer.ts | 68 ++++++++------- app/g2/dashboard-controller.ts | 32 +++++++ app/phone-ui/main-page.xml | 114 +++++++++++++++---------- app/phone-ui/main-view-model.ts | 21 +++++ tests/evenhub-signin.test.cjs | 98 ++++++++++++++++++--- 8 files changed, 269 insertions(+), 96 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 88cae117..e78d956e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,11 +12,12 @@ * Depth effects for the window switcher, top bar, and modals * Glanceboard has configurable distance -### Other Features +### Other Features and Bugfixes * Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses * Navigate app: Add map-without-destination mode * Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space +* EvenHub: Fix login form being stuck open without a cancel button ### iOS port: diff --git a/app/apps/evenhub/even-api.ts b/app/apps/evenhub/even-api.ts index 932e008c..051568f9 100644 --- a/app/apps/evenhub/even-api.ts +++ b/app/apps/evenhub/even-api.ts @@ -181,12 +181,18 @@ export class EvenHubApiClient { path: string, options: { query?: Record; body?: Record } = {}, ): Promise { - let token = await this.ensureLogin(); + const token = await this.ensureLogin(); const response = await this.request(method, path, { ...options, token, commonVersion: 3 }); - if (response.httpStatus === 401) { - invalidateEvenHubToken(); + try { + return unwrap(response.envelope, response.httpStatus, path); + } catch (error) { + // A rejected session fails every later request too, so drop the token + // (unless a fresh sign-in replaced it while this request was in flight). + if (error instanceof EvenHubAuthenticationError && getEvenHubToken() === token) { + invalidateEvenHubToken(); + } + throw error; } - return unwrap(response.envelope, response.httpStatus, path); } private ensureLogin(): Promise { @@ -350,15 +356,17 @@ async function fetchWithTimeout(url: string, init: RequestInit, timeoutMs = REQU } function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknown { - if (httpStatus === 401) { - throw new EvenHubAuthenticationError("Even rejected the login session."); + const message = typeof envelope.msg === "string" ? envelope.msg.trim() : ""; + // An expired session can come back as HTTP 401, or as HTTP 200 with code + // 401 in the envelope ("Your login is expired"). + if (httpStatus === 401 || Number(envelope.code) === 401) { + throw new EvenHubAuthenticationError(message || "Even rejected the login session."); } if (httpStatus < 200 || httpStatus >= 300) { throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`); } if (envelope.code !== 0) { - const detail = typeof envelope.msg === "string" && envelope.msg ? `: ${envelope.msg}` : ""; - throw new Error(`EvenHub API error ${envelope.code ?? "unknown"}${detail}`); + throw new Error(`EvenHub API error ${envelope.code ?? "unknown"}${message ? `: ${message}` : ""}`); } return envelope.data; } diff --git a/app/apps/evenhub/store-detail-layer.ts b/app/apps/evenhub/store-detail-layer.ts index e7bd52f8..ba179d86 100644 --- a/app/apps/evenhub/store-detail-layer.ts +++ b/app/apps/evenhub/store-detail-layer.ts @@ -26,6 +26,8 @@ export type EvenHubStoreDetailOptions = { appendLog: (message: string) => void; /** A package was installed, updated, or reinstalled from this page. */ onInstalled?: (app: InstalledEvenHubApp) => void; + /** Offered every failure first; returns true if it was a rejected session (and was dealt with). */ + onAuthError?: (ctx: LayerContext, error: unknown) => boolean; }; /** Storefront metadata and the Install/Launch action for one public app. */ @@ -170,6 +172,7 @@ export class EvenHubStoreDetailLayer implements Layer { await this.install(ctx); } catch (error) { + if (this.options.onAuthError?.(ctx, error)) return; this.status = cleanError(error); this.options.appendLog(`evenhub store: ${this.status}`); } finally { this.working = false; ctx.actions.requestRender(); } @@ -203,6 +206,7 @@ export class EvenHubStoreDetailLayer implements Layer { ctx.actions.requestRender(); await this.options.launchApp(installedEvenHubAppId(result.packageId)); } catch (error) { + if (this.options.onAuthError?.(ctx, error)) return; this.status = cleanError(error); this.options.appendLog(`evenhub store: ${this.status}`); } finally { @@ -226,6 +230,7 @@ export class EvenHubStoreDetailLayer implements Layer { return undefined; }) .catch((error) => { + if (this.options.onAuthError?.(ctx, error)) return; this.options.appendLog(`evenhub store: app details unavailable: ${cleanError(error)}`); }) .finally(() => ctx.actions.requestRender()); diff --git a/app/apps/evenhub/store-layer.ts b/app/apps/evenhub/store-layer.ts index 765593a0..966fc279 100644 --- a/app/apps/evenhub/store-layer.ts +++ b/app/apps/evenhub/store-layer.ts @@ -10,7 +10,7 @@ import { ConfigSettingString } from "../../ui/dashboard-settings"; import { evenHubApi, EvenHubAuthenticationError, isEvenHubStoreConfigured, type EvenHubStoreApp, type EvenHubStorePage } from "./even-api"; import { clearEvenHubLoginForm, clearEvenHubSession, clearTransientEvenHubSession, evenHubLoginEmailSetting, evenHubLoginPasswordSetting, evenHubRememberMeSetting, resetEvenHubLoginForm } from "./credentials"; import { getInstalledEvenHubApps, uninstallEvenHubPackage, type InstalledEvenHubApp } from "./installed-apps"; -import { EvenHubStoreDetailLayer } from "./store-detail-layer"; +import { EvenHubStoreDetailLayer, type EvenHubStoreDetailOptions } from "./store-detail-layer"; import { cleanError, installStoreApp } from "./store-install"; import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates"; import { lineStep } from "../../ui/metrics"; @@ -150,13 +150,11 @@ export class EvenHubStoreLayer implements Layer { this.started = true; // Do NOT open the phone credential editor here. This runs on the first // paint, which includes the restore of a still-open EvenHub at app - // startup -- so an unfinished sign-in re-opened the form on every launch, - // and the form has no way out: it has no Cancel control, its onCancel is - // dropped before it reaches the controller, and Back leaves the app - // rather than closing it. The login pane already says "Enter your Even - // account email and password in the phone app" and already opens the - // editor on click (handleInput), so the editor is still one tap away for - // someone who actually wants it. + // startup -- so an unfinished sign-in re-opened the form on every + // launch, unasked. The login pane already says "Enter your Even account + // email and password in the phone app" and already opens the editor on + // click (handleInput), so the editor is still one tap away for someone + // who actually wants it. if (!this.showingLogin) { void this.ensureTabLoaded(ctx, this.activeTab); } @@ -348,13 +346,7 @@ export class EvenHubStoreLayer implements Layer { } case "app": if (this.updatingAll) return; - ctx.stack.push( - new EvenHubStoreDetailLayer(row.app, { - launchApp: this.options.launchApp, - appendLog: this.options.appendLog, - onInstalled: (installed) => this.onInstalled(installed), - }), - ); + ctx.stack.push(new EvenHubStoreDetailLayer(row.app, this.detailOptions())); return; } } @@ -372,13 +364,7 @@ export class EvenHubStoreLayer implements Layer { } this.pendingPackage = null; stack.clearToBase(); - stack.push( - new EvenHubStoreDetailLayer(placeholderStoreApp(installed), { - launchApp: this.options.launchApp, - appendLog: this.options.appendLog, - onInstalled: (result) => this.onInstalled(result), - }), - ); + stack.push(new EvenHubStoreDetailLayer(placeholderStoreApp(installed), this.detailOptions())); } /** Dictated text becomes a search (the shell's "Type Into App" / voice input). */ @@ -595,6 +581,8 @@ export class EvenHubStoreLayer implements Layer { failures.push(`${row.app.name} (declined)`); } } catch (error) { + // An expired session fails every remaining update the same way. + if (this.handleAuthError(ctx, error)) return; const message = cleanError(error); this.options.appendLog(`evenhub store: update of ${row.app.packageId} failed: ${message}`); failures.push(row.app.name); @@ -629,15 +617,33 @@ export class EvenHubStoreLayer implements Layer { // ---- login and phone editors -------------------------------------------- - /** Route a rejected session back to the login form; true if it was one. */ + /** + * Drop back to the logged-out pane when Even rejects the session (an + * expired login); true if the error was one. Anything open above the list + * (an app page, a permission dialog) needed the session too, so it goes. + * The phone form is not opened: this can happen on the first load of a + * store window restored at startup (see paint), and the pane's click + * opens it. + */ private handleAuthError(ctx: LayerContext, error: unknown): boolean { if (!(error instanceof EvenHubAuthenticationError)) return false; const message = cleanError(error); - this.options.appendLog(`evenhub store login failed: ${message}`); - this.enterLogin(ctx, `Login failed: ${message}`); + this.options.appendLog(`evenhub store: session rejected: ${message}`); + if (this.closed) return true; + ctx.stack.clearToBase(); + this.enterLogin(ctx, `Signed out: ${message}`, false); return true; } + private detailOptions(): EvenHubStoreDetailOptions { + return { + launchApp: this.options.launchApp, + appendLog: this.options.appendLog, + onInstalled: (installed) => this.onInstalled(installed), + onAuthError: (ctx, error) => this.handleAuthError(ctx, error), + }; + } + private enterLogin( ctx: LayerContext, status = "Sign in to browse public apps.", @@ -691,13 +697,11 @@ export class EvenHubStoreLayer implements Layer { const email = evenHubLoginEmailSetting.get(); const password = evenHubLoginPasswordSetting.get(); if (!email.trim() || !password) { - // The phone editor has no Cancel control, so submitting an untouched form - // with the keyboard's Done key is the only way someone can back out of - // it. Reopening the editor there makes that a loop with no exit, so a - // wholly empty submission is treated as a cancel and leaves the editor - // closed -- the login pane still says how to get back in, and a click - // reopens the editor. A half-filled form is a real mistake, so that - // still reopens with the message. + // A wholly empty submission (the keyboard's Done key on an untouched + // form) is treated as a cancel and leaves the editor closed -- the login + // pane still says how to get back in, and a click reopens the editor. + // A half-filled form is a real mistake, so that still reopens with the + // message. const cancelled = !email.trim() && !password; this.enterLogin( ctx, diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index d0643fb1..de643e1f 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -213,6 +213,13 @@ class DashboardController { */ private activeTextEditorOnCancel: (() => void) | null = null; private activeTextEditorToggle: TextSettingsEditToggle | null = null; + /** + * The active settings' values (and the toggle's) when the edit began. The + * phone fields write through on every keystroke, so this is what the + * editor's Cancel button puts back. + */ + private activeTextSettingOriginalValues: string[] = []; + private activeTextEditorToggleOriginalValue = false; private evenNotificationActive = false; private evenAppConflictMessage = ""; private firmwareWarningMessage = ""; @@ -1897,9 +1904,11 @@ class DashboardController { onCancel?: () => void, ): void { this.activeTextSettings = Array.from(settings.slice(0, 2)); + this.activeTextSettingOriginalValues = this.activeTextSettings.map((setting) => setting.get()); this.activeTextEditorTitle = title; this.activeTextEditorOnFinish = onFinish ?? null; this.activeTextEditorToggle = toggle ?? null; + this.activeTextEditorToggleOriginalValue = toggle?.setting.get() ?? false; this.activeTextEditorOnCancel = onCancel ?? null; this.emit(); } @@ -2021,6 +2030,7 @@ class DashboardController { // finishTextSettingEdit clears this first, so a completed edit never fires it. const onCancel = this.activeTextEditorOnCancel; this.activeTextSettings = []; + this.activeTextSettingOriginalValues = []; this.activeTextEditorTitle = ""; this.activeTextEditorOnFinish = null; this.activeTextEditorToggle = null; @@ -2056,6 +2066,28 @@ class DashboardController { onFinish?.(); } + /** + * The phone editor's Cancel button: put back the values the edit started + * with, end the edit as a cancel (the caller's onCancel fires), and + * navigate the Settings app's glasses editor out of the edit page. + */ + cancelActiveTextSettingEdit(): void { + if (!this.activeTextSettings.length) return; + this.activeTextSettings.forEach((setting, index) => { + const original = this.activeTextSettingOriginalValues[index] ?? ""; + if (setting.get() !== original) setting.set(original); + }); + const toggle = this.activeTextEditorToggle; + if (toggle && toggle.setting.get() !== this.activeTextEditorToggleOriginalValue) { + toggle.setting.set(this.activeTextEditorToggleOriginalValue); + } + const closesGlassesEditor = this.activeTextSettings.length === 1; + this.endTextSettingEdit(); + if (closesGlassesEditor && this.textEditorHost?.closeTextEditor()) { + this.textEditorHost.requestRender(); + } + } + private updateTextSetting(setting: ConfigSettingString, value: string): void { if (setting.get() !== value) { setting.set(value); diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index c1bfbff0..e80b711b 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -106,50 +106,76 @@ - - + room. The tabbed controls are collapsed while it is up. + + NativeScript has no maxHeight, so the transparent outer grid's + fixed height is the cap: it shrinks to the page when the keyboard + leaves less room than that, and the bottom-aligned modal inside + sizes to its content within it. Past the cap the fields scroll + and the buttons stay put. + + Any GridLayout in here needs an explicit rows="auto": the implicit + single star row stretches to fill all the height offered (Stack- + and DockLayout offer it AT_MOST the remaining height), which is + what made the form balloon with the keyboard minimized. --> + + +