forked from Blendman974/faceclaw
Fix the EvenHub login form sizing and missing cancel button
This commit is contained in:
1 parent
90d60cee10
commit
09a59b9821
8 files changed
+269
-96
No files matched your search
@@ -12,11 +12,12 @@
|
|||||||
* Depth effects for the window switcher, top bar, and modals
|
* Depth effects for the window switcher, top bar, and modals
|
||||||
* Glanceboard has configurable distance
|
* 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
|
* 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
|
* Navigate app: Add map-without-destination mode
|
||||||
* Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space
|
* 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:
|
### iOS port:
|
||||||
|
|
||||||
|
|||||||
@@ -181,12 +181,18 @@ export class EvenHubApiClient {
|
|||||||
path: string,
|
path: string,
|
||||||
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();
|
const token = await this.ensureLogin();
|
||||||
const 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) {
|
try {
|
||||||
invalidateEvenHubToken();
|
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<string> {
|
private ensureLogin(): Promise<string> {
|
||||||
@@ -350,15 +356,17 @@ 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) {
|
const message = typeof envelope.msg === "string" ? envelope.msg.trim() : "";
|
||||||
throw new EvenHubAuthenticationError("Even rejected the login session.");
|
// 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) {
|
if (httpStatus < 200 || httpStatus >= 300) {
|
||||||
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
|
throw new Error(`EvenHub request failed (HTTP ${httpStatus}, ${path}).`);
|
||||||
}
|
}
|
||||||
if (envelope.code !== 0) {
|
if (envelope.code !== 0) {
|
||||||
const detail = typeof envelope.msg === "string" && envelope.msg ? `: ${envelope.msg}` : "";
|
throw new Error(`EvenHub API error ${envelope.code ?? "unknown"}${message ? `: ${message}` : ""}`);
|
||||||
throw new Error(`EvenHub API error ${envelope.code ?? "unknown"}${detail}`);
|
|
||||||
}
|
}
|
||||||
return envelope.data;
|
return envelope.data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ export type EvenHubStoreDetailOptions = {
|
|||||||
appendLog: (message: string) => void;
|
appendLog: (message: string) => void;
|
||||||
/** A package was installed, updated, or reinstalled from this page. */
|
/** A package was installed, updated, or reinstalled from this page. */
|
||||||
onInstalled?: (app: InstalledEvenHubApp) => void;
|
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. */
|
/** Storefront metadata and the Install/Launch action for one public app. */
|
||||||
@@ -170,6 +172,7 @@ export class EvenHubStoreDetailLayer implements Layer {
|
|||||||
|
|
||||||
await this.install(ctx);
|
await this.install(ctx);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (this.options.onAuthError?.(ctx, error)) return;
|
||||||
this.status = cleanError(error);
|
this.status = cleanError(error);
|
||||||
this.options.appendLog(`evenhub store: ${this.status}`);
|
this.options.appendLog(`evenhub store: ${this.status}`);
|
||||||
} finally { this.working = false; ctx.actions.requestRender(); }
|
} finally { this.working = false; ctx.actions.requestRender(); }
|
||||||
@@ -203,6 +206,7 @@ export class EvenHubStoreDetailLayer implements Layer {
|
|||||||
ctx.actions.requestRender();
|
ctx.actions.requestRender();
|
||||||
await this.options.launchApp(installedEvenHubAppId(result.packageId));
|
await this.options.launchApp(installedEvenHubAppId(result.packageId));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (this.options.onAuthError?.(ctx, error)) return;
|
||||||
this.status = cleanError(error);
|
this.status = cleanError(error);
|
||||||
this.options.appendLog(`evenhub store: ${this.status}`);
|
this.options.appendLog(`evenhub store: ${this.status}`);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -226,6 +230,7 @@ export class EvenHubStoreDetailLayer implements Layer {
|
|||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
if (this.options.onAuthError?.(ctx, error)) return;
|
||||||
this.options.appendLog(`evenhub store: app details unavailable: ${cleanError(error)}`);
|
this.options.appendLog(`evenhub store: app details unavailable: ${cleanError(error)}`);
|
||||||
})
|
})
|
||||||
.finally(() => ctx.actions.requestRender());
|
.finally(() => ctx.actions.requestRender());
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { ConfigSettingString } from "../../ui/dashboard-settings";
|
|||||||
import { evenHubApi, EvenHubAuthenticationError, isEvenHubStoreConfigured, type EvenHubStoreApp, type EvenHubStorePage } from "./even-api";
|
import { evenHubApi, EvenHubAuthenticationError, isEvenHubStoreConfigured, type EvenHubStoreApp, type EvenHubStorePage } from "./even-api";
|
||||||
import { clearEvenHubLoginForm, clearEvenHubSession, clearTransientEvenHubSession, evenHubLoginEmailSetting, evenHubLoginPasswordSetting, evenHubRememberMeSetting, resetEvenHubLoginForm } from "./credentials";
|
import { clearEvenHubLoginForm, clearEvenHubSession, clearTransientEvenHubSession, evenHubLoginEmailSetting, evenHubLoginPasswordSetting, evenHubRememberMeSetting, resetEvenHubLoginForm } from "./credentials";
|
||||||
import { getInstalledEvenHubApps, uninstallEvenHubPackage, type InstalledEvenHubApp } from "./installed-apps";
|
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 { cleanError, installStoreApp } from "./store-install";
|
||||||
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
|
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
|
||||||
import { lineStep } from "../../ui/metrics";
|
import { lineStep } from "../../ui/metrics";
|
||||||
@@ -150,13 +150,11 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
this.started = true;
|
this.started = true;
|
||||||
// Do NOT open the phone credential editor here. This runs on the first
|
// 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
|
// 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,
|
// startup -- so an unfinished sign-in re-opened the form on every
|
||||||
// and the form has no way out: it has no Cancel control, its onCancel is
|
// launch, unasked. The login pane already says "Enter your Even account
|
||||||
// dropped before it reaches the controller, and Back leaves the app
|
// email and password in the phone app" and already opens the editor on
|
||||||
// rather than closing it. The login pane already says "Enter your Even
|
// click (handleInput), so the editor is still one tap away for someone
|
||||||
// account email and password in the phone app" and already opens the
|
// who actually wants it.
|
||||||
// editor on click (handleInput), so the editor is still one tap away for
|
|
||||||
// someone who actually wants it.
|
|
||||||
if (!this.showingLogin) {
|
if (!this.showingLogin) {
|
||||||
void this.ensureTabLoaded(ctx, this.activeTab);
|
void this.ensureTabLoaded(ctx, this.activeTab);
|
||||||
}
|
}
|
||||||
@@ -348,13 +346,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
case "app":
|
case "app":
|
||||||
if (this.updatingAll) return;
|
if (this.updatingAll) return;
|
||||||
ctx.stack.push(
|
ctx.stack.push(new EvenHubStoreDetailLayer(row.app, this.detailOptions()));
|
||||||
new EvenHubStoreDetailLayer(row.app, {
|
|
||||||
launchApp: this.options.launchApp,
|
|
||||||
appendLog: this.options.appendLog,
|
|
||||||
onInstalled: (installed) => this.onInstalled(installed),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,13 +364,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
this.pendingPackage = null;
|
this.pendingPackage = null;
|
||||||
stack.clearToBase();
|
stack.clearToBase();
|
||||||
stack.push(
|
stack.push(new EvenHubStoreDetailLayer(placeholderStoreApp(installed), this.detailOptions()));
|
||||||
new EvenHubStoreDetailLayer(placeholderStoreApp(installed), {
|
|
||||||
launchApp: this.options.launchApp,
|
|
||||||
appendLog: this.options.appendLog,
|
|
||||||
onInstalled: (result) => this.onInstalled(result),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dictated text becomes a search (the shell's "Type Into App" / voice input). */
|
/** 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)`);
|
failures.push(`${row.app.name} (declined)`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// An expired session fails every remaining update the same way.
|
||||||
|
if (this.handleAuthError(ctx, error)) return;
|
||||||
const message = cleanError(error);
|
const message = cleanError(error);
|
||||||
this.options.appendLog(`evenhub store: update of ${row.app.packageId} failed: ${message}`);
|
this.options.appendLog(`evenhub store: update of ${row.app.packageId} failed: ${message}`);
|
||||||
failures.push(row.app.name);
|
failures.push(row.app.name);
|
||||||
@@ -629,15 +617,33 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
|
|
||||||
// ---- login and phone editors --------------------------------------------
|
// ---- 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 {
|
private handleAuthError(ctx: LayerContext, error: unknown): boolean {
|
||||||
if (!(error instanceof EvenHubAuthenticationError)) return false;
|
if (!(error instanceof EvenHubAuthenticationError)) return false;
|
||||||
const message = cleanError(error);
|
const message = cleanError(error);
|
||||||
this.options.appendLog(`evenhub store login failed: ${message}`);
|
this.options.appendLog(`evenhub store: session rejected: ${message}`);
|
||||||
this.enterLogin(ctx, `Login failed: ${message}`);
|
if (this.closed) return true;
|
||||||
|
ctx.stack.clearToBase();
|
||||||
|
this.enterLogin(ctx, `Signed out: ${message}`, false);
|
||||||
return true;
|
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(
|
private enterLogin(
|
||||||
ctx: LayerContext,
|
ctx: LayerContext,
|
||||||
status = "Sign in to browse public apps.",
|
status = "Sign in to browse public apps.",
|
||||||
@@ -691,13 +697,11 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
const email = evenHubLoginEmailSetting.get();
|
const email = evenHubLoginEmailSetting.get();
|
||||||
const password = evenHubLoginPasswordSetting.get();
|
const password = evenHubLoginPasswordSetting.get();
|
||||||
if (!email.trim() || !password) {
|
if (!email.trim() || !password) {
|
||||||
// The phone editor has no Cancel control, so submitting an untouched form
|
// A wholly empty submission (the keyboard's Done key on an untouched
|
||||||
// with the keyboard's Done key is the only way someone can back out of
|
// form) is treated as a cancel and leaves the editor closed -- the login
|
||||||
// it. Reopening the editor there makes that a loop with no exit, so a
|
// pane still says how to get back in, and a click reopens the editor.
|
||||||
// wholly empty submission is treated as a cancel and leaves the editor
|
// A half-filled form is a real mistake, so that still reopens with the
|
||||||
// closed -- the login pane still says how to get back in, and a click
|
// message.
|
||||||
// reopens the editor. A half-filled form is a real mistake, so that
|
|
||||||
// still reopens with the message.
|
|
||||||
const cancelled = !email.trim() && !password;
|
const cancelled = !email.trim() && !password;
|
||||||
this.enterLogin(
|
this.enterLogin(
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
@@ -213,6 +213,13 @@ class DashboardController {
|
|||||||
*/
|
*/
|
||||||
private activeTextEditorOnCancel: (() => void) | null = null;
|
private activeTextEditorOnCancel: (() => void) | null = null;
|
||||||
private activeTextEditorToggle: TextSettingsEditToggle | 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 evenNotificationActive = false;
|
||||||
private evenAppConflictMessage = "";
|
private evenAppConflictMessage = "";
|
||||||
private firmwareWarningMessage = "";
|
private firmwareWarningMessage = "";
|
||||||
@@ -1897,9 +1904,11 @@ class DashboardController {
|
|||||||
onCancel?: () => void,
|
onCancel?: () => void,
|
||||||
): void {
|
): void {
|
||||||
this.activeTextSettings = Array.from(settings.slice(0, 2));
|
this.activeTextSettings = Array.from(settings.slice(0, 2));
|
||||||
|
this.activeTextSettingOriginalValues = this.activeTextSettings.map((setting) => setting.get());
|
||||||
this.activeTextEditorTitle = title;
|
this.activeTextEditorTitle = title;
|
||||||
this.activeTextEditorOnFinish = onFinish ?? null;
|
this.activeTextEditorOnFinish = onFinish ?? null;
|
||||||
this.activeTextEditorToggle = toggle ?? null;
|
this.activeTextEditorToggle = toggle ?? null;
|
||||||
|
this.activeTextEditorToggleOriginalValue = toggle?.setting.get() ?? false;
|
||||||
this.activeTextEditorOnCancel = onCancel ?? null;
|
this.activeTextEditorOnCancel = onCancel ?? null;
|
||||||
this.emit();
|
this.emit();
|
||||||
}
|
}
|
||||||
@@ -2021,6 +2030,7 @@ class DashboardController {
|
|||||||
// finishTextSettingEdit clears this first, so a completed edit never fires it.
|
// finishTextSettingEdit clears this first, so a completed edit never fires it.
|
||||||
const onCancel = this.activeTextEditorOnCancel;
|
const onCancel = this.activeTextEditorOnCancel;
|
||||||
this.activeTextSettings = [];
|
this.activeTextSettings = [];
|
||||||
|
this.activeTextSettingOriginalValues = [];
|
||||||
this.activeTextEditorTitle = "";
|
this.activeTextEditorTitle = "";
|
||||||
this.activeTextEditorOnFinish = null;
|
this.activeTextEditorOnFinish = null;
|
||||||
this.activeTextEditorToggle = null;
|
this.activeTextEditorToggle = null;
|
||||||
@@ -2056,6 +2066,28 @@ class DashboardController {
|
|||||||
onFinish?.();
|
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 {
|
private updateTextSetting(setting: ConfigSettingString, value: string): void {
|
||||||
if (setting.get() !== value) {
|
if (setting.get() !== value) {
|
||||||
setting.set(value);
|
setting.set(value);
|
||||||
|
|||||||
+70
-44
@@ -106,50 +106,76 @@
|
|||||||
<!-- Keyboard-input mode: anchored to the bottom of the (keyboard-
|
<!-- Keyboard-input mode: anchored to the bottom of the (keyboard-
|
||||||
shrunk) page, so it sits in the space below the mirror and only
|
shrunk) page, so it sits in the space below the mirror and only
|
||||||
overlaps the mirror when the open keyboard leaves too little
|
overlaps the mirror when the open keyboard leaves too little
|
||||||
room. The tabbed controls are collapsed while it is up. -->
|
room. The tabbed controls are collapsed while it is up.
|
||||||
<StackLayout
|
|
||||||
class="system-name-modal"
|
NativeScript has no maxHeight, so the transparent outer grid's
|
||||||
visibility="{{ textSettingEditorVisibility }}"
|
fixed height is the cap: it shrinks to the page when the keyboard
|
||||||
horizontalAlignment="stretch"
|
leaves less room than that, and the bottom-aligned modal inside
|
||||||
verticalAlignment="bottom">
|
sizes to its content within it. Past the cap the fields scroll
|
||||||
<Label text="{{ activeTextEditorTitle }}" class="h2" />
|
and the buttons stay put.
|
||||||
<!-- Per-field labels only matter with two fields; a single-field
|
|
||||||
edit's field title is the same string as the editor title. -->
|
Any GridLayout in here needs an explicit rows="auto": the implicit
|
||||||
<Label text="{{ activeTextSettingTitle }}" visibility="{{ secondaryTextSettingVisibility }}" />
|
single star row stretches to fill all the height offered (Stack-
|
||||||
<TextField
|
and DockLayout offer it AT_MOST the remaining height), which is
|
||||||
id="settingsTextField"
|
what made the form balloon with the keyboard minimized. -->
|
||||||
text="{{ activeTextSettingValue }}"
|
<GridLayout
|
||||||
textChange="{{ onTextSettingTextChange }}"
|
height="440"
|
||||||
returnPress="{{ onPrimaryTextSettingReturnPress }}"
|
verticalAlignment="bottom"
|
||||||
autocorrect="false"
|
isPassThroughParentEnabled="true"
|
||||||
autocapitalizationType="none"
|
visibility="{{ textSettingEditorVisibility }}">
|
||||||
keyboardType="{{ activeTextSettingKeyboardType }}"
|
<DockLayout
|
||||||
secure="{{ activeTextSettingSecure }}"
|
class="system-name-modal"
|
||||||
returnKeyType="{{ primaryTextSettingReturnKeyType }}" />
|
stretchLastChild="true"
|
||||||
<StackLayout visibility="{{ secondaryTextSettingVisibility }}">
|
horizontalAlignment="stretch"
|
||||||
<Label text="{{ secondaryTextSettingTitle }}" />
|
verticalAlignment="bottom">
|
||||||
<TextField
|
<Label dock="top" text="{{ activeTextEditorTitle }}" class="h2" />
|
||||||
id="secondarySettingsTextField"
|
<GridLayout dock="bottom" columns="*,*" rows="auto" class="m-t-8">
|
||||||
text="{{ secondaryTextSettingValue }}"
|
<Button col="0" text="Cancel" tap="{{ onTextSettingCancelTap }}" />
|
||||||
textChange="{{ onSecondaryTextSettingTextChange }}"
|
<Button col="1" text="Submit" tap="{{ onTextSettingSubmitTap }}" class="-primary" />
|
||||||
returnPress="{{ onSecondaryTextSettingReturnPress }}"
|
</GridLayout>
|
||||||
autocorrect="false"
|
<ScrollView>
|
||||||
autocapitalizationType="none"
|
<StackLayout>
|
||||||
keyboardType="{{ secondaryTextSettingKeyboardType }}"
|
<!-- Per-field labels only matter with two fields; a single-field
|
||||||
secure="{{ secondaryTextSettingSecure }}"
|
edit's field title is the same string as the editor title. -->
|
||||||
returnKeyType="done" />
|
<Label text="{{ activeTextSettingTitle }}" visibility="{{ secondaryTextSettingVisibility }}" />
|
||||||
</StackLayout>
|
<TextField
|
||||||
<GridLayout
|
id="settingsTextField"
|
||||||
columns="*,auto"
|
text="{{ activeTextSettingValue }}"
|
||||||
visibility="{{ activeTextEditorToggleVisibility }}"
|
textChange="{{ onTextSettingTextChange }}"
|
||||||
class="m-t-8">
|
returnPress="{{ onPrimaryTextSettingReturnPress }}"
|
||||||
<Label col="0" text="{{ activeTextEditorToggleLabel }}" verticalAlignment="center" />
|
autocorrect="false"
|
||||||
<Switch
|
autocapitalizationType="none"
|
||||||
col="1"
|
keyboardType="{{ activeTextSettingKeyboardType }}"
|
||||||
checked="{{ activeTextEditorToggleValue }}"
|
secure="{{ activeTextSettingSecure }}"
|
||||||
checkedChange="{{ onTextSettingToggleChange }}" />
|
returnKeyType="{{ primaryTextSettingReturnKeyType }}" />
|
||||||
</GridLayout>
|
<StackLayout visibility="{{ secondaryTextSettingVisibility }}">
|
||||||
</StackLayout>
|
<Label text="{{ secondaryTextSettingTitle }}" />
|
||||||
|
<TextField
|
||||||
|
id="secondarySettingsTextField"
|
||||||
|
text="{{ secondaryTextSettingValue }}"
|
||||||
|
textChange="{{ onSecondaryTextSettingTextChange }}"
|
||||||
|
returnPress="{{ onSecondaryTextSettingReturnPress }}"
|
||||||
|
autocorrect="false"
|
||||||
|
autocapitalizationType="none"
|
||||||
|
keyboardType="{{ secondaryTextSettingKeyboardType }}"
|
||||||
|
secure="{{ secondaryTextSettingSecure }}"
|
||||||
|
returnKeyType="done" />
|
||||||
|
</StackLayout>
|
||||||
|
<GridLayout
|
||||||
|
columns="*,auto"
|
||||||
|
rows="auto"
|
||||||
|
visibility="{{ activeTextEditorToggleVisibility }}"
|
||||||
|
class="m-t-8">
|
||||||
|
<Label col="0" text="{{ activeTextEditorToggleLabel }}" verticalAlignment="center" />
|
||||||
|
<Switch
|
||||||
|
col="1"
|
||||||
|
checked="{{ activeTextEditorToggleValue }}"
|
||||||
|
checkedChange="{{ onTextSettingToggleChange }}" />
|
||||||
|
</GridLayout>
|
||||||
|
</StackLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</DockLayout>
|
||||||
|
</GridLayout>
|
||||||
<!-- Keyboard-input panel (the keyboard button beside the mic button):
|
<!-- Keyboard-input panel (the keyboard button beside the mic button):
|
||||||
the phone's end of the keyboard dialog on the glasses
|
the phone's end of the keyboard dialog on the glasses
|
||||||
(ui/shell/keyboard-input.ts). Same placement and collapsing rules
|
(ui/shell/keyboard-input.ts). Same placement and collapsing rules
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
Screen,
|
Screen,
|
||||||
SwipeDirection,
|
SwipeDirection,
|
||||||
type GestureEventData,
|
type GestureEventData,
|
||||||
|
type TextField,
|
||||||
type SwipeGestureEventData,
|
type SwipeGestureEventData,
|
||||||
type TouchGestureEventData,
|
type TouchGestureEventData,
|
||||||
type View,
|
type View,
|
||||||
@@ -988,6 +989,26 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
dashboardController.finishActiveTextSettingEdit();
|
dashboardController.finishActiveTextSettingEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The editor's Submit button: the same as the done key on the last field. */
|
||||||
|
onTextSettingSubmitTap(args: { object?: View }): void {
|
||||||
|
// Commit both fields' actual text, in case a final keystroke's textChange
|
||||||
|
// hadn't landed yet (as the return-press handlers do).
|
||||||
|
const page = args?.object?.page;
|
||||||
|
const primaryText = page?.getViewById<TextField>("settingsTextField")?.text;
|
||||||
|
if (typeof primaryText === "string") {
|
||||||
|
dashboardController.setActiveTextSettingValue(primaryText, this.activeTextSettingId ?? undefined);
|
||||||
|
}
|
||||||
|
const secondaryText = page?.getViewById<TextField>("secondarySettingsTextField")?.text;
|
||||||
|
if (this.hasSecondaryTextSetting && typeof secondaryText === "string") {
|
||||||
|
dashboardController.setActiveTextSettingValue(secondaryText, this.secondaryTextSettingId ?? undefined);
|
||||||
|
}
|
||||||
|
dashboardController.finishActiveTextSettingEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
onTextSettingCancelTap(): void {
|
||||||
|
dashboardController.cancelActiveTextSettingEdit();
|
||||||
|
}
|
||||||
|
|
||||||
onTextSettingToggleChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
|
onTextSettingToggleChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
|
||||||
dashboardController.setActiveTextEditorToggleValue(
|
dashboardController.setActiveTextEditorToggleValue(
|
||||||
args.object?.checked ?? args.value ?? false,
|
args.object?.checked ?? args.value ?? false,
|
||||||
|
|||||||
@@ -15,14 +15,23 @@ const setting = (initial = '') => {
|
|||||||
return { get: () => value, set: (next) => { value = next; } };
|
return { get: () => value, set: (next) => { value = next; } };
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Load the store layer with a signed-out account and no stored credentials. */
|
class AuthError extends Error {}
|
||||||
const loadStoreLayer = () => {
|
|
||||||
|
/**
|
||||||
|
* Load the store layer, by default with a signed-out account and no stored
|
||||||
|
* credentials. `api` overrides evenHubApi methods; text the layer paints is
|
||||||
|
* collected in `drawn`, and the options each app page is opened with in
|
||||||
|
* `detailOptions`.
|
||||||
|
*/
|
||||||
|
const loadStoreLayer = ({ configured = false, api = {} } = {}) => {
|
||||||
const email = setting('');
|
const email = setting('');
|
||||||
const password = setting('');
|
const password = setting('');
|
||||||
const font = { lineHeight: 10 };
|
const drawn = [];
|
||||||
|
const detailOptions = [];
|
||||||
|
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
|
||||||
const load = loader({}, {
|
const load = loader({}, {
|
||||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||||
'../../graphics/image': { GrayImage: class { drawText() {} } },
|
'../../graphics/image': { GrayImage: class { drawText(_f, _x, _y, text) { drawn.push(text); } fillRect() {} } },
|
||||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] },
|
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] },
|
||||||
'../../util/numeric-util': { clamp: (v, lo, hi) => Math.min(hi, Math.max(lo, v)) },
|
'../../util/numeric-util': { clamp: (v, lo, hi) => Math.min(hi, Math.max(lo, v)) },
|
||||||
'../../ui/gestures': { GESTURE_CLICK: 'click' },
|
'../../ui/gestures': { GESTURE_CLICK: 'click' },
|
||||||
@@ -35,9 +44,9 @@ const loadStoreLayer = () => {
|
|||||||
get() { return this.value; } set(next) { this.value = next; } },
|
get() { return this.value; } set(next) { this.value = next; } },
|
||||||
},
|
},
|
||||||
'./even-api': {
|
'./even-api': {
|
||||||
evenHubApi: { signIn: async () => {} },
|
evenHubApi: { signIn: async () => {}, ...api },
|
||||||
EvenHubAuthenticationError: class extends Error {},
|
EvenHubAuthenticationError: AuthError,
|
||||||
isEvenHubStoreConfigured: () => false,
|
isEvenHubStoreConfigured: () => configured,
|
||||||
},
|
},
|
||||||
'./credentials': {
|
'./credentials': {
|
||||||
evenHubLoginEmailSetting: email,
|
evenHubLoginEmailSetting: email,
|
||||||
@@ -48,20 +57,28 @@ const loadStoreLayer = () => {
|
|||||||
clearEvenHubSession() {}, clearTransientEvenHubSession() {},
|
clearEvenHubSession() {}, clearTransientEvenHubSession() {},
|
||||||
},
|
},
|
||||||
'./installed-apps': { getInstalledEvenHubApps: () => [], uninstallEvenHubPackage: async () => {} },
|
'./installed-apps': { getInstalledEvenHubApps: () => [], uninstallEvenHubPackage: async () => {} },
|
||||||
'./store-detail-layer': { EvenHubStoreDetailLayer: class {} },
|
'./store-detail-layer': { EvenHubStoreDetailLayer: class { constructor(_app, options) { detailOptions.push(options); } } },
|
||||||
'./store-install': { cleanError: (error) => String(error), installStoreApp: async () => {} },
|
'./store-install': { cleanError: (error) => String(error?.message ?? error), installStoreApp: async () => {} },
|
||||||
'./updates': { checkForEvenHubUpdates: async () => [], describeUpdate: () => '' },
|
'./updates': { checkForEvenHubUpdates: async () => [], describeUpdate: () => '' },
|
||||||
});
|
});
|
||||||
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
||||||
return { EvenHubStoreLayer, email, password };
|
return { EvenHubStoreLayer, email, password, drawn, detailOptions };
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A LayerContext that records every editor the layer asks the phone to open. */
|
/** A LayerContext that records every editor the layer asks the phone to open. */
|
||||||
const makeCtx = () => {
|
const makeCtx = () => {
|
||||||
const opened = [];
|
const opened = [];
|
||||||
|
const stack = {
|
||||||
|
cleared: 0,
|
||||||
|
pushed: [],
|
||||||
|
getBaseSize: () => ({ width: 576, height: 136 }),
|
||||||
|
isFocused: () => true,
|
||||||
|
clearToBase() { stack.cleared++; stack.pushed.length = 0; },
|
||||||
|
push(layer) { stack.pushed.push(layer); },
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
opened,
|
opened,
|
||||||
stack: { getBaseSize: () => ({ width: 576, height: 136 }) },
|
stack,
|
||||||
actions: {
|
actions: {
|
||||||
requestRender() {},
|
requestRender() {},
|
||||||
endTextSettingEdit() {},
|
endTextSettingEdit() {},
|
||||||
@@ -125,3 +142,62 @@ test('cancelling the sign-in form leaves it reopenable', () => {
|
|||||||
layer.handleInput({ type: 'click' }, ctx);
|
layer.handleInput({ type: 'click' }, ctx);
|
||||||
assert.equal(ctx.opened.length, 2, 'a dropped onCancel latches the guard and no later open is allowed');
|
assert.equal(ctx.opened.length, 2, 'a dropped onCancel latches the guard and no later open is allowed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('an expired session drops the store back to the logged-out pane', async () => {
|
||||||
|
const { EvenHubStoreLayer, drawn } = loadStoreLayer({
|
||||||
|
configured: true,
|
||||||
|
api: { listApps: async () => { throw new AuthError('Your login is expired'); } },
|
||||||
|
});
|
||||||
|
const layer = new EvenHubStoreLayer({ launchApp: async () => {}, appendLog: () => {} });
|
||||||
|
const ctx = makeCtx();
|
||||||
|
layer.paint(ctx);
|
||||||
|
await settle();
|
||||||
|
assert.equal(layer.buildMenuItems().length, 0, 'the signed-in menu (Refresh, Log Out) is gone');
|
||||||
|
assert.equal(ctx.stack.cleared, 1, 'pages above the list needed the session too');
|
||||||
|
assert.deepEqual(ctx.opened, [], 'this can happen on a startup restore, so the form must not pop up by itself');
|
||||||
|
drawn.length = 0;
|
||||||
|
layer.paint(ctx);
|
||||||
|
assert.ok(drawn.includes('Signed out: Your login is expired'), `painted: ${JSON.stringify(drawn)}`);
|
||||||
|
layer.handleInput({ type: 'click' }, ctx);
|
||||||
|
assert.equal(ctx.opened.length, 1, 'a click on the pane opens the sign-in form');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an expired session on an app page drops the store back to the logged-out pane', () => {
|
||||||
|
const { EvenHubStoreLayer, detailOptions } = loadStoreLayer({
|
||||||
|
configured: true,
|
||||||
|
api: { listApps: () => new Promise(() => {}) },
|
||||||
|
});
|
||||||
|
const layer = new EvenHubStoreLayer({ launchApp: async () => {}, appendLog: () => {} });
|
||||||
|
const ctx = makeCtx();
|
||||||
|
layer.paint(ctx);
|
||||||
|
layer.showInstalledPackage(ctx.stack, { packageId: 'com.example.app', name: 'Example' });
|
||||||
|
assert.equal(ctx.stack.pushed.length, 1);
|
||||||
|
const { onAuthError } = detailOptions[0];
|
||||||
|
assert.equal(onAuthError(ctx, new Error('network down')), false, 'other failures stay on the page');
|
||||||
|
assert.ok(layer.buildMenuItems().length > 0);
|
||||||
|
assert.equal(onAuthError(ctx, new AuthError('Your login is expired')), true);
|
||||||
|
assert.equal(ctx.stack.pushed.length, 0, 'the app page is closed');
|
||||||
|
assert.equal(layer.buildMenuItems().length, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an API envelope with code 401 is a rejected session and forgets the token', async () => {
|
||||||
|
let token = 'stale-token';
|
||||||
|
let invalidated = 0;
|
||||||
|
const api = loader({ setTimeout, clearTimeout }, {
|
||||||
|
'./even-platform': { getPhoneOpenUdid: () => 'fixture-terminal', hmacSha256Base64: () => 'fixture-signature' },
|
||||||
|
'./credentials': {
|
||||||
|
getEvenHubToken: () => token, hasEvenHubCredentials: () => !!token,
|
||||||
|
saveEvenHubSession() {}, invalidateEvenHubToken() { invalidated++; token = ''; },
|
||||||
|
},
|
||||||
|
'../../util/http': {
|
||||||
|
fetchWithUserAgent: async () => ({ status: 200, json: async () => ({ code: 401, msg: 'Your login is expired' }) }),
|
||||||
|
},
|
||||||
|
})('app/apps/evenhub/even-api.ts');
|
||||||
|
await assert.rejects(api.evenHubApi.listApps(), (error) => {
|
||||||
|
assert.ok(error instanceof api.EvenHubAuthenticationError, `got ${error}`);
|
||||||
|
assert.equal(error.message, 'Your login is expired');
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.equal(invalidated, 1);
|
||||||
|
assert.equal(api.isEvenHubStoreConfigured(), false);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user