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
@@ -181,12 +181,18 @@ export class EvenHubApiClient {
|
||||
path: string,
|
||||
options: { query?: Record<string, string | number>; body?: Record<string, unknown> } = {},
|
||||
): Promise<unknown> {
|
||||
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<string> {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user