Don't show EvenHub store, and show compatibility warning on sideloaded apps, when using RayNeo iO
This commit is contained in:
1 parent
43738b181d
commit
b866224909
10 files changed
+701
-183
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { wrapText } from "../../graphics/textwrap";
|
||||
import { type LayerContext } from "../../ui/layers";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
import { ScrollingDialogLayer, type DialogBody, type DialogRow } from "./scrolling-dialog";
|
||||
|
||||
/** Wider than the permission dialog: the RayNeo iO's window is short, so fewer, longer lines fit better. */
|
||||
const DIALOG_WIDTH = 420;
|
||||
|
||||
/**
|
||||
* Shown over an EvenHub app the first time it runs with a RayNeo iO paired
|
||||
* (see glasses-compat.ts): the app is made for Even Realities glasses and
|
||||
* won't display correctly on the iO's screen. The app starts underneath.
|
||||
* Continue (or double-click) dismisses the warning; Close app closes the
|
||||
* app's window. Either answer counts as having seen it; a window closed with
|
||||
* the warning still up shows it again next time.
|
||||
*/
|
||||
export class EvenHubDisplayWarningLayer extends ScrollingDialogLayer {
|
||||
constructor(
|
||||
private readonly appName: string,
|
||||
private readonly onAnswered: () => void,
|
||||
private readonly closeApp: () => void,
|
||||
) {
|
||||
super(DIALOG_WIDTH);
|
||||
}
|
||||
|
||||
protected bodyRows({ image, font, left, textWidth }: DialogBody): DialogRow[] {
|
||||
const step = lineStep(font);
|
||||
const rows: DialogRow[] = [];
|
||||
for (const line of wrapText(font, "Compatibility warning", textWidth)) {
|
||||
rows.push({ height: step + 2, draw: (top) => image.drawText(font, left, top, line, 235) });
|
||||
}
|
||||
rows[rows.length - 1]!.height += 6;
|
||||
const message =
|
||||
`${this.appName} is an EvenHub app, made for Even Realities glasses. It will not display correctly ` +
|
||||
"on the RayNeo iO, because the iO's screen has a different resolution.";
|
||||
// One row per wrapped line, so a large font scrolls line by line.
|
||||
const lines = wrapText(font, message, textWidth);
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
rows.push({
|
||||
height: step + (index === lines.length - 1 ? 8 : 0),
|
||||
draw: (top) => image.drawText(font, left, top, lines[index]!, 190),
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
protected actions(): string[] {
|
||||
return ["Continue", "Close app"];
|
||||
}
|
||||
|
||||
protected activate(action: string, ctx: LayerContext): void {
|
||||
this.close(ctx, () => {
|
||||
this.onAnswered();
|
||||
if (action === "Close app") this.closeApp();
|
||||
});
|
||||
}
|
||||
|
||||
protected backedOut(): void {
|
||||
this.onAnswered();
|
||||
}
|
||||
|
||||
protected abandoned(): void {
|
||||
// Not answered: the next launch shows it again.
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import { shell } from "../../ui/shell/shell";
|
||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||
import { EvenHubSession } from "./session";
|
||||
import { renderInstalledEvenHubIcon } from "./installed-apps";
|
||||
import { markDisplayWarningShown, needsDisplayWarning } from "./glasses-compat";
|
||||
import { EvenHubDisplayWarningLayer } from "./display-warning-dialog";
|
||||
|
||||
class EvenHubAppLayer implements Layer {
|
||||
/**
|
||||
@@ -149,5 +151,16 @@ export function createEvenHubWindow(
|
||||
session.setScreenOn(on);
|
||||
};
|
||||
|
||||
// The app's first run with a RayNeo iO paired: warn, over the app itself,
|
||||
// that it won't display correctly there.
|
||||
const packageId = session.manifest.packageId;
|
||||
if (needsDisplayWarning(packageId)) {
|
||||
created.stack.push(new EvenHubDisplayWarningLayer(
|
||||
session.manifest.name,
|
||||
() => markDisplayWarningShown(packageId),
|
||||
() => shell.closeWindow(windowId),
|
||||
));
|
||||
}
|
||||
|
||||
return created;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* EvenHub with glasses that aren't Even Realities': with a RayNeo iO paired,
|
||||
* the store is off (it is Even's, and its apps are made for their glasses),
|
||||
* while apps sideloaded through Files or the Developer app still run, after a
|
||||
* warning the first time each one launches that it won't display correctly
|
||||
* (EvenHub apps lay out for the G2's 576x288 display; the iO's is 540x220).
|
||||
*/
|
||||
import { glassesTypeSetting } from "../../ui/dashboard-settings";
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
|
||||
/** The package IDs whose RayNeo iO display warning has been answered, as a JSON array. */
|
||||
const DISPLAY_WARNED_KEY = "evenhub.rayneoDisplayWarned";
|
||||
|
||||
/** Whether the EvenHub store can be used: with Even Realities glasses paired, not a RayNeo iO. */
|
||||
export function isEvenHubStoreAvailable(): boolean {
|
||||
return glassesTypeSetting.get() !== "rayneo-io";
|
||||
}
|
||||
|
||||
/** Whether launching this package should warn that it won't display correctly on these glasses. */
|
||||
export function needsDisplayWarning(packageId: string): boolean {
|
||||
return glassesTypeSetting.get() === "rayneo-io" && !displayWarnedPackages().includes(packageId);
|
||||
}
|
||||
|
||||
/** The user answered the package's display warning: don't show it again. */
|
||||
export function markDisplayWarningShown(packageId: string): void {
|
||||
const warned = displayWarnedPackages();
|
||||
if (warned.includes(packageId)) return;
|
||||
setStringSetting(DISPLAY_WARNED_KEY, JSON.stringify([...warned, packageId]));
|
||||
}
|
||||
|
||||
function displayWarnedPackages(): string[] {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(getStringSetting(DISPLAY_WARNED_KEY, "[]"));
|
||||
return Array.isArray(parsed) ? parsed.filter((id): id is string => typeof id === "string") : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
* a phone WebView (its runtime + phone UI) and a 576x288 glasses window
|
||||
* composited by Faceclaw instead of the stock firmware.
|
||||
*
|
||||
* With a RayNeo iO paired the store is unavailable and sideloaded apps warn
|
||||
* on first run that they won't display correctly; see glasses-compat.ts.
|
||||
*
|
||||
* Design notes: notes/evenhub_compatibility.txt.
|
||||
*/
|
||||
import { type AppContext, type AppDefinition } from "../app-definition";
|
||||
@@ -15,6 +18,7 @@ import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-p
|
||||
import { renderEvenRealitiesLogo } from "../../graphics/even-realities-logo";
|
||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||
import { type InstalledEvenHubApp } from "./installed-apps";
|
||||
import { isEvenHubStoreAvailable } from "./glasses-compat";
|
||||
|
||||
const EVENHUB_STORE_WINDOW_ID = "evenhub:store";
|
||||
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
|
||||
@@ -104,8 +108,17 @@ const evenhubApp: AppDefinition = {
|
||||
title: "EvenHub",
|
||||
icon: "package",
|
||||
renderIcon: renderEvenRealitiesLogo,
|
||||
// Off the launcher with a RayNeo iO paired. A store window that opens
|
||||
// anyway (restored from before a re-pair, or the launcher's route for an
|
||||
// installed app whose package is missing) says why instead of loading.
|
||||
isSupported: isEvenHubStoreAvailable,
|
||||
launch: async (ctx) => {
|
||||
await ensureStoreWindow(ctx);
|
||||
const { window } = await ensureStoreWindow(ctx);
|
||||
if (!isEvenHubStoreAvailable()) {
|
||||
// Store pages opened while Even glasses were paired would cover the notice.
|
||||
window.stack.clearToBase();
|
||||
window.requestRender();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
|
||||
import { type LayerContext } from "../../ui/layers";
|
||||
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
||||
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
||||
import { lineStep, listRowHeight } from "../../ui/metrics";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
import { ScrollingDialogLayer, type DialogBody, type DialogRow } from "./scrolling-dialog";
|
||||
|
||||
/** Minimum gap between the dialog and the edges of the window it's centered in. */
|
||||
const DIALOG_MARGIN = 8;
|
||||
const DIALOG_WIDTH = 320;
|
||||
const PADDING = 10;
|
||||
const PERM_GAP = 4;
|
||||
|
||||
/**
|
||||
@@ -20,59 +14,26 @@ const PERM_GAP = 4;
|
||||
* Cancel (or double-click) backs out. A privacy-policy-only app still reaches
|
||||
* this dialog so the user can review the policy before allowing first run.
|
||||
*
|
||||
* When the list overflows the viewport the dialog scrolls a page at a time,
|
||||
* keeping one line of overlap (the last line of one page is the first of the
|
||||
* next), and only once the bottom is fully visible do further scrolls move the
|
||||
* action selection. The actions are inert until then (a click just pages
|
||||
* down), so the user can't Allow without having had the whole list on screen.
|
||||
* A long list scrolls a page at a time, and Allow stays inert until the
|
||||
* bottom has been reached (see ScrollingDialogLayer), so the user can't
|
||||
* Allow without having had the whole list on screen.
|
||||
*/
|
||||
export class EvenHubPermissionDialogLayer implements Layer {
|
||||
/** Floats in front of the window content, like the context menus. */
|
||||
readonly depth = 2;
|
||||
/** Starts on Allow; the optional privacy-policy action is inserted after it. */
|
||||
private selectedIndex = 0;
|
||||
/** First content row drawn; rows above it are scrolled off. */
|
||||
private firstRow = 0;
|
||||
/** Scroll position at which the last row is fully visible; set by paint. */
|
||||
private maxFirstRow = 0;
|
||||
/** Heights of the content rows and of the viewport they scroll in, as last painted (for paging). */
|
||||
private rowHeights: number[] = [];
|
||||
private visibleHeight = 0;
|
||||
private resolved = false;
|
||||
|
||||
export class EvenHubPermissionDialogLayer extends ScrollingDialogLayer {
|
||||
constructor(
|
||||
private readonly appName: string,
|
||||
private readonly permissions: EvenHubPermission[],
|
||||
private readonly privacyPolicyUrl: string,
|
||||
private readonly onConfirm: () => void,
|
||||
private readonly onCancel: () => void,
|
||||
) {}
|
||||
|
||||
/** Whether the dialog is scrolled to the bottom, making the actions live. */
|
||||
private atBottom(): boolean {
|
||||
return this.firstRow >= this.maxFirstRow;
|
||||
) {
|
||||
super(DIALOG_WIDTH);
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width: viewportWidth, height: viewportHeight } = ctx.stack.getBaseSize();
|
||||
const image = paintBelow();
|
||||
const dialogWidth = Math.min(DIALOG_WIDTH, viewportWidth - 2 * DIALOG_MARGIN);
|
||||
const dialogX = ((viewportWidth - dialogWidth) / 2) | 0;
|
||||
const textWidth = dialogWidth - 2 * PADDING - 4;
|
||||
const left = dialogX + PADDING + 2;
|
||||
|
||||
protected bodyRows({ image, font, left, textWidth }: DialogBody): DialogRow[] {
|
||||
const headerStep = lineStep(font) + 2;
|
||||
const permLabelStep = lineStep(font) + 1;
|
||||
const permDetailStep = lineStep(font) - 1;
|
||||
const actionRowH = listRowHeight(font);
|
||||
const actions = this.actions();
|
||||
const focused = ctx.stack.isFocused();
|
||||
|
||||
// The dialog body as scrollable rows; each row's height includes the gap
|
||||
// below it, so scrolling and visibility checks work on whole rows.
|
||||
type Row = { height: number; draw: (top: number) => void };
|
||||
const rows: Row[] = [];
|
||||
const rows: DialogRow[] = [];
|
||||
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
||||
rows.push({
|
||||
height: headerStep + 6,
|
||||
@@ -101,138 +62,28 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
});
|
||||
}
|
||||
}
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
rows.push({
|
||||
height: actionRowH,
|
||||
draw: (top) => {
|
||||
const selected = this.atBottom() && index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, dialogX + 12, top, dialogWidth - 24, actionRowH - 1, focused, 8);
|
||||
}
|
||||
image.drawText(font, dialogX + 22, top + 3, actions[index]!, selected ? 255 : 200);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const contentHeight = rows.reduce((sum, row) => sum + row.height, 0);
|
||||
const height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_MARGIN);
|
||||
const dialogY = ((viewportHeight - height) / 2) | 0;
|
||||
const visibleHeight = height - 2 * PADDING;
|
||||
|
||||
// The bottommost scroll position: the largest suffix of rows that fits.
|
||||
let maxFirstRow = rows.length;
|
||||
for (let suffixHeight = 0; maxFirstRow > 0; maxFirstRow--) {
|
||||
const rowHeight = rows[maxFirstRow - 1]!.height;
|
||||
if (suffixHeight + rowHeight > visibleHeight) break;
|
||||
suffixHeight += rowHeight;
|
||||
}
|
||||
this.maxFirstRow = maxFirstRow;
|
||||
this.firstRow = Math.max(0, Math.min(this.firstRow, maxFirstRow));
|
||||
this.rowHeights = rows.map((row) => row.height);
|
||||
this.visibleHeight = visibleHeight;
|
||||
|
||||
// Fill 1 (transparent color key is 0), outline for the dialog edge.
|
||||
image.fillRoundedRect(dialogX, dialogY, dialogWidth, height, 1);
|
||||
image.drawRoundedRect(dialogX, dialogY, dialogWidth, height, 72);
|
||||
|
||||
let y = dialogY + PADDING;
|
||||
for (let index = this.firstRow; index < rows.length; index++) {
|
||||
const row = rows[index]!;
|
||||
if (y + row.height > dialogY + PADDING + visibleHeight) break;
|
||||
row.draw(y);
|
||||
y += row.height;
|
||||
}
|
||||
|
||||
if (maxFirstRow > 0) {
|
||||
drawListScrollbar(
|
||||
image,
|
||||
dialogX + dialogWidth - 7,
|
||||
dialogY + PADDING,
|
||||
visibleHeight,
|
||||
this.firstRow,
|
||||
rows.length - maxFirstRow,
|
||||
rows.length,
|
||||
);
|
||||
}
|
||||
return image;
|
||||
return rows;
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent, ctx: LayerContext): void {
|
||||
const actions = this.actions();
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
if (this.atBottom() && this.selectedIndex > 0) {
|
||||
this.selectedIndex -= 1;
|
||||
} else if (this.firstRow > 0) {
|
||||
this.pageUp();
|
||||
}
|
||||
return;
|
||||
case "scroll-down":
|
||||
if (!this.atBottom()) {
|
||||
this.pageDown();
|
||||
} else {
|
||||
this.selectedIndex = Math.min(actions.length - 1, this.selectedIndex + 1);
|
||||
}
|
||||
return;
|
||||
case "click":
|
||||
if (!this.atBottom()) {
|
||||
this.pageDown();
|
||||
return;
|
||||
}
|
||||
if (actions[this.selectedIndex] === "Privacy policy") {
|
||||
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
|
||||
} else {
|
||||
this.resolve(ctx, actions[this.selectedIndex] === "Allow");
|
||||
}
|
||||
return;
|
||||
case "double-click":
|
||||
this.resolve(ctx, false);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** Scroll so the last fully visible row becomes the first (one row of overlap). */
|
||||
private pageDown(): void {
|
||||
let y = 0;
|
||||
let lastVisible = this.firstRow;
|
||||
for (let index = this.firstRow; index < this.rowHeights.length; index++) {
|
||||
y += this.rowHeights[index]!;
|
||||
if (y > this.visibleHeight) break;
|
||||
lastVisible = index;
|
||||
}
|
||||
this.firstRow = Math.min(this.maxFirstRow, Math.max(this.firstRow + 1, lastVisible));
|
||||
}
|
||||
|
||||
/** Scroll so the current first row becomes the last fully visible one (one row of overlap). */
|
||||
private pageUp(): void {
|
||||
let first = this.firstRow;
|
||||
let y = this.rowHeights[first] ?? 0;
|
||||
while (first > 0 && y + this.rowHeights[first - 1]! <= this.visibleHeight) {
|
||||
first -= 1;
|
||||
y += this.rowHeights[first]!;
|
||||
}
|
||||
this.firstRow = Math.max(0, Math.min(this.firstRow - 1, first));
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
// Dismissed some other way (window closed, back button): treat as cancel.
|
||||
if (!this.resolved) {
|
||||
this.resolved = true;
|
||||
this.onCancel();
|
||||
}
|
||||
}
|
||||
|
||||
private resolve(ctx: LayerContext, confirmed: boolean): void {
|
||||
if (this.resolved) return;
|
||||
this.resolved = true;
|
||||
ctx.stack.pop();
|
||||
if (confirmed) this.onConfirm();
|
||||
else this.onCancel();
|
||||
}
|
||||
|
||||
private actions(): string[] {
|
||||
protected actions(): string[] {
|
||||
return this.privacyPolicyUrl ? ["Allow", "Privacy policy", "Cancel"] : ["Allow", "Cancel"];
|
||||
}
|
||||
|
||||
protected activate(action: string, ctx: LayerContext): void {
|
||||
if (action === "Privacy policy") {
|
||||
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
|
||||
} else if (action === "Allow") {
|
||||
this.close(ctx, () => this.onConfirm());
|
||||
} else {
|
||||
this.close(ctx, () => this.onCancel());
|
||||
}
|
||||
}
|
||||
|
||||
protected backedOut(): void {
|
||||
this.onCancel();
|
||||
}
|
||||
|
||||
protected abandoned(): void {
|
||||
this.onCancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { type GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
|
||||
import { listRowHeight } from "../../ui/metrics";
|
||||
|
||||
/** Minimum gap between the dialog and the edges of the window it's centered in. */
|
||||
const DIALOG_MARGIN = 8;
|
||||
const PADDING = 10;
|
||||
|
||||
/** One row of a dialog's content. Its height includes the gap below it, so scrolling works on whole rows. */
|
||||
export type DialogRow = { height: number; draw: (top: number) => void };
|
||||
|
||||
/** What a dialog's body rows draw with: the canvas, the font, and the text column. */
|
||||
export type DialogBody = { image: GrayImage; font: UiFont; left: number; textWidth: number };
|
||||
|
||||
/**
|
||||
* A dialog box centered over the window it opens in: body rows, then a
|
||||
* column of actions, starting on the first. EvenHub's confirmations and
|
||||
* warnings (permissions, the RayNeo iO display warning) are built on it.
|
||||
*
|
||||
* When the content overflows the viewport the dialog scrolls a page at a
|
||||
* time, keeping one line of overlap (the last line of one page is the first
|
||||
* of the next), and only once the bottom is fully visible do further scrolls
|
||||
* move the action selection. The actions are inert until then (a click just
|
||||
* pages down), so nothing can be chosen without the whole dialog having been
|
||||
* on screen. Double-click backs out.
|
||||
*/
|
||||
export abstract class ScrollingDialogLayer implements Layer {
|
||||
/** Floats in front of the window content, like the context menus. */
|
||||
readonly depth = 2;
|
||||
private selectedIndex = 0;
|
||||
/** First content row drawn; rows above it are scrolled off. */
|
||||
private firstRow = 0;
|
||||
/** Scroll position at which the last row is fully visible; set by paint. */
|
||||
private maxFirstRow = 0;
|
||||
/** Heights of the content rows and of the viewport they scroll in, as last painted (for paging). */
|
||||
private rowHeights: number[] = [];
|
||||
private visibleHeight = 0;
|
||||
private resolved = false;
|
||||
|
||||
constructor(private readonly maxWidth: number) {}
|
||||
|
||||
/** The rows above the actions. */
|
||||
protected abstract bodyRows(body: DialogBody): DialogRow[];
|
||||
/** The action labels, top to bottom. */
|
||||
protected abstract actions(): string[];
|
||||
/** A click on an action once the actions are live; close() dismisses the dialog with it. */
|
||||
protected abstract activate(action: string, ctx: LayerContext): void;
|
||||
/** Double-click: the user backed out of the dialog. */
|
||||
protected abstract backedOut(): void;
|
||||
/** The dialog left the stack unanswered (its window closed). */
|
||||
protected abstract abandoned(): void;
|
||||
|
||||
/** Whether the dialog is scrolled to the bottom, making the actions live. */
|
||||
private atBottom(): boolean {
|
||||
return this.firstRow >= this.maxFirstRow;
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width: viewportWidth, height: viewportHeight } = ctx.stack.getBaseSize();
|
||||
const image = paintBelow();
|
||||
const dialogWidth = Math.min(this.maxWidth, viewportWidth - 2 * DIALOG_MARGIN);
|
||||
const dialogX = ((viewportWidth - dialogWidth) / 2) | 0;
|
||||
const textWidth = dialogWidth - 2 * PADDING - 4;
|
||||
const left = dialogX + PADDING + 2;
|
||||
|
||||
const actionRowH = listRowHeight(font);
|
||||
const actions = this.actions();
|
||||
const focused = ctx.stack.isFocused();
|
||||
|
||||
const rows = this.bodyRows({ image, font, left, textWidth });
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
rows.push({
|
||||
height: actionRowH,
|
||||
draw: (top) => {
|
||||
const selected = this.atBottom() && index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, dialogX + 12, top, dialogWidth - 24, actionRowH - 1, focused, 8);
|
||||
}
|
||||
image.drawText(font, dialogX + 22, top + 3, actions[index]!, selected ? 255 : 200);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const contentHeight = rows.reduce((sum, row) => sum + row.height, 0);
|
||||
const height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_MARGIN);
|
||||
const dialogY = ((viewportHeight - height) / 2) | 0;
|
||||
const visibleHeight = height - 2 * PADDING;
|
||||
|
||||
// The bottommost scroll position: the largest suffix of rows that fits.
|
||||
let maxFirstRow = rows.length;
|
||||
for (let suffixHeight = 0; maxFirstRow > 0; maxFirstRow--) {
|
||||
const rowHeight = rows[maxFirstRow - 1]!.height;
|
||||
if (suffixHeight + rowHeight > visibleHeight) break;
|
||||
suffixHeight += rowHeight;
|
||||
}
|
||||
this.maxFirstRow = maxFirstRow;
|
||||
this.firstRow = Math.max(0, Math.min(this.firstRow, maxFirstRow));
|
||||
this.rowHeights = rows.map((row) => row.height);
|
||||
this.visibleHeight = visibleHeight;
|
||||
|
||||
// Fill 1 (transparent color key is 0), outline for the dialog edge.
|
||||
image.fillRoundedRect(dialogX, dialogY, dialogWidth, height, 1);
|
||||
image.drawRoundedRect(dialogX, dialogY, dialogWidth, height, 72);
|
||||
|
||||
let y = dialogY + PADDING;
|
||||
for (let index = this.firstRow; index < rows.length; index++) {
|
||||
const row = rows[index]!;
|
||||
if (y + row.height > dialogY + PADDING + visibleHeight) break;
|
||||
row.draw(y);
|
||||
y += row.height;
|
||||
}
|
||||
|
||||
if (maxFirstRow > 0) {
|
||||
drawListScrollbar(
|
||||
image,
|
||||
dialogX + dialogWidth - 7,
|
||||
dialogY + PADDING,
|
||||
visibleHeight,
|
||||
this.firstRow,
|
||||
rows.length - maxFirstRow,
|
||||
rows.length,
|
||||
);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent, ctx: LayerContext): void {
|
||||
const actions = this.actions();
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
if (this.atBottom() && this.selectedIndex > 0) {
|
||||
this.selectedIndex -= 1;
|
||||
} else if (this.firstRow > 0) {
|
||||
this.pageUp();
|
||||
}
|
||||
return;
|
||||
case "scroll-down":
|
||||
if (!this.atBottom()) {
|
||||
this.pageDown();
|
||||
} else {
|
||||
this.selectedIndex = Math.min(actions.length - 1, this.selectedIndex + 1);
|
||||
}
|
||||
return;
|
||||
case "click":
|
||||
if (!this.atBottom()) {
|
||||
this.pageDown();
|
||||
return;
|
||||
}
|
||||
this.activate(actions[this.selectedIndex]!, ctx);
|
||||
return;
|
||||
case "double-click":
|
||||
this.close(ctx, () => this.backedOut());
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** Scroll so the last fully visible row becomes the first (one row of overlap). */
|
||||
private pageDown(): void {
|
||||
let y = 0;
|
||||
let lastVisible = this.firstRow;
|
||||
for (let index = this.firstRow; index < this.rowHeights.length; index++) {
|
||||
y += this.rowHeights[index]!;
|
||||
if (y > this.visibleHeight) break;
|
||||
lastVisible = index;
|
||||
}
|
||||
this.firstRow = Math.min(this.maxFirstRow, Math.max(this.firstRow + 1, lastVisible));
|
||||
}
|
||||
|
||||
/** Scroll so the current first row becomes the last fully visible one (one row of overlap). */
|
||||
private pageUp(): void {
|
||||
let first = this.firstRow;
|
||||
let y = this.rowHeights[first] ?? 0;
|
||||
while (first > 0 && y + this.rowHeights[first - 1]! <= this.visibleHeight) {
|
||||
first -= 1;
|
||||
y += this.rowHeights[first]!;
|
||||
}
|
||||
this.firstRow = Math.max(0, Math.min(this.firstRow - 1, first));
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
// Dismissed some other way (window closed, back button).
|
||||
if (!this.resolved) {
|
||||
this.resolved = true;
|
||||
this.abandoned();
|
||||
}
|
||||
}
|
||||
|
||||
/** Take the dialog down, then run the answer's effect (once, however it was answered). */
|
||||
protected close(ctx: LayerContext, then: () => void): void {
|
||||
if (this.resolved) return;
|
||||
this.resolved = true;
|
||||
ctx.stack.pop();
|
||||
then();
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { EvenHubStoreDetailLayer, type EvenHubStoreDetailOptions } from "./store
|
||||
import { cleanError, installStoreApp } from "./store-install";
|
||||
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
import { isEvenHubStoreAvailable } from "./glasses-compat";
|
||||
|
||||
const LIST_X = 18;
|
||||
/** Horizontal gap between tab labels. */
|
||||
@@ -145,6 +146,11 @@ export type EvenHubStoreLayerOptions = {
|
||||
* missing). The tab row is its own focus level above the list: double-click
|
||||
* in the list focuses the tabs, scrolling (or a watch swipe in any direction)
|
||||
* there switches tabs, and a click returns to the list.
|
||||
*
|
||||
* With glasses that can't use the store (a RayNeo iO; see glasses-compat.ts)
|
||||
* it shows only a notice saying so, and loads nothing. That is checked on
|
||||
* every paint and input, so a window open across a re-pair follows the
|
||||
* glasses either way.
|
||||
*/
|
||||
export class EvenHubStoreLayer implements Layer {
|
||||
/** Swipes left/right switch tabs on the tab strip; elsewhere they get the usual fallback. */
|
||||
@@ -168,12 +174,15 @@ export class EvenHubStoreLayer implements Layer {
|
||||
private updatingAll = false;
|
||||
/** An app page requested while the login form was up; opened once signed in. */
|
||||
private pendingPackage: InstalledEvenHubApp | null = null;
|
||||
/** An app page requested while the store was unavailable, named on its notice. */
|
||||
private unavailablePackageName: string | null = null;
|
||||
|
||||
constructor(private readonly options: EvenHubStoreLayerOptions) {
|
||||
if (this.showingLogin) resetEvenHubLoginForm();
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
if (!isEvenHubStoreAvailable()) return this.paintUnavailable(ctx);
|
||||
if (!this.started) {
|
||||
this.started = true;
|
||||
// Do NOT open the phone credential editor here. This runs on the first
|
||||
@@ -233,6 +242,23 @@ export class EvenHubStoreLayer implements Layer {
|
||||
return image;
|
||||
}
|
||||
|
||||
/** The notice that replaces the store when the paired glasses can't use it. */
|
||||
private paintUnavailable(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
image.drawText(font, LIST_X, 8, "EvenHub", 220);
|
||||
if (this.unavailablePackageName) {
|
||||
const status = `${this.unavailablePackageName}'s package is missing.`;
|
||||
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, status, width - LIST_X * 2), 125);
|
||||
}
|
||||
const message = "Using the Even Realities app store requires Even Realities glasses.";
|
||||
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) {
|
||||
image.drawText(font, LIST_X, headerHeight(font) + 16 + index * lineStep(font), line, 190);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/** Tab labels to the right of the title; the active one is bright and underlined. */
|
||||
private paintTabs(image: GrayImage, font: UiFont, ctx: LayerContext): void {
|
||||
const tabsFocused = ctx.stack.isFocused() && this.focus === "tabs";
|
||||
@@ -294,6 +320,10 @@ export class EvenHubStoreLayer implements Layer {
|
||||
}
|
||||
|
||||
async handleInput(rawEvent: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (!isEvenHubStoreAvailable()) {
|
||||
if (directionalFallback(rawEvent).type === "double-click") shell.yieldFocusToSidebar();
|
||||
return;
|
||||
}
|
||||
const tabSwipe = !this.showingLogin && this.focus === "tabs"
|
||||
&& (rawEvent.type === "swipe-left" || rawEvent.type === "swipe-right");
|
||||
const event = isDirectionalInput(rawEvent) && !tabSwipe ? directionalFallback(rawEvent) : rawEvent;
|
||||
@@ -396,6 +426,12 @@ export class EvenHubStoreLayer implements Layer {
|
||||
* placeholder built from the registry entry stands in.
|
||||
*/
|
||||
showInstalledPackage(stack: LayerStack, installed: InstalledEvenHubApp): void {
|
||||
if (!isEvenHubStoreAvailable()) {
|
||||
this.unavailablePackageName = installed.name;
|
||||
stack.clearToBase();
|
||||
return;
|
||||
}
|
||||
this.unavailablePackageName = null;
|
||||
if (this.showingLogin) {
|
||||
this.pendingPackage = installed;
|
||||
return;
|
||||
@@ -407,7 +443,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
|
||||
/** Dictated text becomes a search (the shell's "Type Into App" / voice input). */
|
||||
receiveTextInput(text: string, ctx: LayerContext): void {
|
||||
if (this.showingLogin) return;
|
||||
if (this.showingLogin || !isEvenHubStoreAvailable()) return;
|
||||
const query = evenHubSearchQuerySetting.set(text);
|
||||
if (!query) return;
|
||||
this.closePhoneEditor(ctx.actions, "search");
|
||||
@@ -417,7 +453,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
}
|
||||
|
||||
buildMenuItems(): MenuItem[] {
|
||||
if (this.showingLogin) return [];
|
||||
if (this.showingLogin || !isEvenHubStoreAvailable()) return [];
|
||||
const items: MenuItem[] = [];
|
||||
if (this.activeTab === "search") {
|
||||
items.push({
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
// EvenHub with a RayNeo iO paired: the store shows only a notice (and loads
|
||||
// nothing), and each sideloaded app warns once that it won't display
|
||||
// correctly. The real layers run with their dependencies mocked; what they
|
||||
// paint is collected as text.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
const gestures = loader({}, {})('app/ui/gestures.ts');
|
||||
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
|
||||
|
||||
/** Records drawn text; every other drawing call is a no-op. */
|
||||
const makeImageClass = (drawn) => class {
|
||||
drawText(_font, _x, _y, text) { drawn.push(text); }
|
||||
fillRect() {}
|
||||
fillRoundedRect() {}
|
||||
drawRoundedRect() {}
|
||||
};
|
||||
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
// ---- the store -----------------------------------------------------------
|
||||
|
||||
const emptyPage = { apps: [], total: 0, page: 1, pageSize: 20 };
|
||||
|
||||
class FakeMenu {
|
||||
constructor(options) { this.options = options; this.items = options.items; this.selectedIndex = 0; }
|
||||
setItems(items) { this.items = items; }
|
||||
get selectedItem() { return this.items[this.selectedIndex] ?? null; }
|
||||
handleInput() {}
|
||||
paint(image, box) { this.items.forEach((item, index) => this.options.draw({ image, item, index, x: box.x, y: box.y, width: box.width })); }
|
||||
drawScrollbar() {}
|
||||
}
|
||||
|
||||
const loadStore = () => {
|
||||
const drawn = [];
|
||||
const glasses = { available: false };
|
||||
const calls = { listApps: 0, yields: 0 };
|
||||
const setting = { get: () => '', set() {} };
|
||||
const load = loader({}, {
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../../graphics/image': { GrayImage: makeImageClass(drawn) },
|
||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] },
|
||||
'../../ui/gestures': { ...gestures, GESTURE_CLICK: 'click' },
|
||||
'../../ui/menu': { drawSelectionHighlight() {} },
|
||||
'../../ui/menu-core': { Menu: FakeMenu },
|
||||
'../../ui/shell/shell': { shell: { yieldFocusToSidebar() { calls.yields++; } } },
|
||||
'../../ui/metrics': { lineStep: () => 12 },
|
||||
'../../ui/dashboard-settings': {
|
||||
ConfigSettingString: class { constructor(options) { this.value = options.defaultValue ?? ''; }
|
||||
get() { return this.value; } set(next) { this.value = next; return next; } },
|
||||
},
|
||||
'./even-api': {
|
||||
evenHubApi: {
|
||||
listApps: async () => { calls.listApps++; return emptyPage; },
|
||||
listNewApps: async () => emptyPage,
|
||||
searchApps: async () => emptyPage,
|
||||
},
|
||||
EvenHubAuthenticationError: class extends Error {},
|
||||
isEvenHubStoreConfigured: () => true,
|
||||
},
|
||||
'./credentials': {
|
||||
evenHubLoginEmailSetting: setting, evenHubLoginPasswordSetting: setting, evenHubRememberMeSetting: setting,
|
||||
clearEvenHubLoginForm() {}, resetEvenHubLoginForm() {}, clearEvenHubSession() {}, clearTransientEvenHubSession() {},
|
||||
},
|
||||
'./installed-apps': { getInstalledEvenHubApps: () => [], uninstallEvenHubPackage: () => true },
|
||||
'./store-detail-layer': { EvenHubStoreDetailLayer: class {} },
|
||||
'./store-install': { cleanError: (error) => String(error), installStoreApp: async () => ({}) },
|
||||
'./updates': { checkForEvenHubUpdates: async () => [], describeUpdate: () => ({}) },
|
||||
'./glasses-compat': { isEvenHubStoreAvailable: () => glasses.available },
|
||||
});
|
||||
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
||||
const layer = new EvenHubStoreLayer({ launchApp: async () => {}, appendLog: () => {} });
|
||||
const stackCalls = { push: 0, clearToBase: 0 };
|
||||
const ctx = {
|
||||
stack: {
|
||||
getBaseSize: () => ({ width: 476, height: 180 }),
|
||||
isFocused: () => true,
|
||||
clearToBase() { stackCalls.clearToBase++; },
|
||||
push() { stackCalls.push++; },
|
||||
pop() {},
|
||||
},
|
||||
actions: { requestRender() {}, endTextSettingEdit() {}, startTextSettingsEdit() {} },
|
||||
};
|
||||
const repaint = () => {
|
||||
drawn.length = 0;
|
||||
layer.paint(ctx);
|
||||
return [...drawn];
|
||||
};
|
||||
return { layer, ctx, glasses, calls, stackCalls, repaint };
|
||||
};
|
||||
|
||||
const NOTICE = 'Using the Even Realities app store requires Even Realities glasses.';
|
||||
|
||||
test('with a RayNeo iO the store shows the notice and loads nothing', async () => {
|
||||
const { layer, ctx, calls, repaint } = loadStore();
|
||||
const painted = repaint();
|
||||
assert.ok(painted.includes(NOTICE), JSON.stringify(painted));
|
||||
assert.ok(!painted.includes('Top'), 'no tabs');
|
||||
await settle();
|
||||
assert.equal(calls.listApps, 0, 'no request to the store');
|
||||
assert.equal(layer.buildMenuItems().length, 0, 'no store actions in the window menu');
|
||||
|
||||
await layer.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
await layer.handleInput({ type: 'scroll-down' }, ctx);
|
||||
layer.receiveTextInput('chess', ctx);
|
||||
await settle();
|
||||
assert.equal(calls.listApps, 0, 'input and dictation do nothing');
|
||||
assert.ok(repaint().includes(NOTICE));
|
||||
|
||||
await layer.handleInput({ type: 'double-click', source: 'ring' }, ctx);
|
||||
await layer.handleInput({ type: 'swipe-left', source: 'watch', timestampMs: 0 }, ctx);
|
||||
assert.equal(calls.yields, 2, 'double-click and a back swipe leave the window');
|
||||
});
|
||||
|
||||
test('an installed app\'s store page opens to the notice, naming the app', () => {
|
||||
const { layer, ctx, stackCalls, repaint } = loadStore();
|
||||
layer.showInstalledPackage(ctx.stack, { packageId: 'com.example.alpha', name: 'Alpha', version: '1' });
|
||||
assert.equal(stackCalls.push, 0, 'no store page is opened');
|
||||
assert.equal(stackCalls.clearToBase, 1, 'pages above the notice are closed');
|
||||
const painted = repaint();
|
||||
assert.ok(painted.includes("Alpha's package is missing."), JSON.stringify(painted));
|
||||
assert.ok(painted.includes(NOTICE));
|
||||
});
|
||||
|
||||
test('the store comes back once Even Realities glasses are paired', async () => {
|
||||
const { glasses, calls, repaint } = loadStore();
|
||||
repaint();
|
||||
glasses.available = true;
|
||||
repaint();
|
||||
await settle();
|
||||
assert.equal(calls.listApps, 1, 'the Top tab loads on the first paint it gets');
|
||||
const painted = repaint();
|
||||
assert.ok(!painted.includes(NOTICE));
|
||||
assert.ok(painted.includes('Public apps by popularity'), JSON.stringify(painted));
|
||||
});
|
||||
|
||||
// ---- the display warning ---------------------------------------------------
|
||||
|
||||
const loadWarning = () => {
|
||||
const drawn = [];
|
||||
const load = loader({}, {
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../../graphics/image': { GrayImage: makeImageClass(drawn) },
|
||||
'../../graphics/textwrap': { wrapText: (_f, text) => [text] },
|
||||
'../../ui/gestures': gestures,
|
||||
'../../ui/layers': {},
|
||||
'../../ui/menu': { drawListScrollbar() {}, drawSelectionHighlight() {} },
|
||||
'../../ui/metrics': { lineStep: () => 12, listRowHeight: () => 20 },
|
||||
});
|
||||
const { EvenHubDisplayWarningLayer } = load('app/apps/evenhub/display-warning-dialog.ts');
|
||||
const ImageClass = makeImageClass(drawn);
|
||||
const outcome = { answered: 0, closed: 0, popped: 0 };
|
||||
const dialog = new EvenHubDisplayWarningLayer(
|
||||
'Demo',
|
||||
() => { outcome.answered++; },
|
||||
() => { outcome.closed++; },
|
||||
);
|
||||
// The real stack calls onRemoved as it pops.
|
||||
const ctx = {
|
||||
stack: {
|
||||
getBaseSize: () => ({ width: 476, height: 180 }),
|
||||
isFocused: () => true,
|
||||
pop() { outcome.popped++; dialog.onRemoved(); },
|
||||
},
|
||||
};
|
||||
const paint = () => {
|
||||
drawn.length = 0;
|
||||
dialog.paint(ctx, () => new ImageClass());
|
||||
return [...drawn];
|
||||
};
|
||||
return { dialog, ctx, paint, outcome };
|
||||
};
|
||||
|
||||
test('the display warning names the app and the reason', () => {
|
||||
const { paint } = loadWarning();
|
||||
const painted = paint();
|
||||
assert.ok(painted.includes('Compatibility warning'));
|
||||
const message = painted.find((text) => text.includes('Demo'));
|
||||
assert.ok(message, JSON.stringify(painted));
|
||||
assert.match(message, /will not display correctly on the RayNeo iO/);
|
||||
assert.match(message, /different resolution/);
|
||||
assert.ok(painted.includes('Continue') && painted.includes('Close app'));
|
||||
});
|
||||
|
||||
test('Continue dismisses the warning and leaves the app running', () => {
|
||||
const { dialog, ctx, paint, outcome } = loadWarning();
|
||||
paint();
|
||||
dialog.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
assert.deepEqual(outcome, { answered: 1, closed: 0, popped: 1 });
|
||||
});
|
||||
|
||||
test('Close app dismisses the warning and closes the app', () => {
|
||||
const { dialog, ctx, paint, outcome } = loadWarning();
|
||||
paint();
|
||||
dialog.handleInput({ type: 'scroll-down' }, ctx);
|
||||
dialog.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
assert.deepEqual(outcome, { answered: 1, closed: 1, popped: 1 });
|
||||
});
|
||||
|
||||
test('double-click dismisses the warning; closing the window under it does not count', () => {
|
||||
const backedOut = loadWarning();
|
||||
backedOut.paint();
|
||||
backedOut.dialog.handleInput({ type: 'double-click', source: 'ring' }, backedOut.ctx);
|
||||
assert.deepEqual(backedOut.outcome, { answered: 1, closed: 0, popped: 1 });
|
||||
|
||||
const abandoned = loadWarning();
|
||||
abandoned.paint();
|
||||
abandoned.dialog.onRemoved();
|
||||
assert.deepEqual(abandoned.outcome, { answered: 0, closed: 0, popped: 0 }, 'shown again next launch');
|
||||
});
|
||||
|
||||
// ---- which launches warn -------------------------------------------------
|
||||
|
||||
const loadCompat = (glassesType) => {
|
||||
const store = new Map();
|
||||
const glasses = { type: glassesType };
|
||||
const compat = loader({}, {
|
||||
'../../ui/dashboard-settings': { glassesTypeSetting: { get: () => glasses.type } },
|
||||
'../../native/settings-store': {
|
||||
getStringSetting: (key, fallback) => (store.has(key) ? store.get(key) : fallback),
|
||||
setStringSetting: (key, value) => { store.set(key, value); },
|
||||
},
|
||||
})('app/apps/evenhub/glasses-compat.ts');
|
||||
return { compat, glasses };
|
||||
};
|
||||
|
||||
test('each app warns once with a RayNeo iO paired, and never with Even glasses', () => {
|
||||
const { compat, glasses } = loadCompat('rayneo-io');
|
||||
assert.equal(compat.isEvenHubStoreAvailable(), false);
|
||||
assert.equal(compat.needsDisplayWarning('com.example.a'), true);
|
||||
compat.markDisplayWarningShown('com.example.a');
|
||||
compat.markDisplayWarningShown('com.example.a');
|
||||
assert.equal(compat.needsDisplayWarning('com.example.a'), false, 'answered once');
|
||||
assert.equal(compat.needsDisplayWarning('com.example.b'), true, 'another app still warns');
|
||||
|
||||
glasses.type = 'g2';
|
||||
assert.equal(compat.isEvenHubStoreAvailable(), true);
|
||||
assert.equal(compat.needsDisplayWarning('com.example.b'), false);
|
||||
glasses.type = 'g1';
|
||||
assert.equal(compat.isEvenHubStoreAvailable(), true);
|
||||
assert.equal(compat.needsDisplayWarning('com.example.b'), false);
|
||||
});
|
||||
|
||||
// ---- the app window ------------------------------------------------------
|
||||
|
||||
const loadWindow = (needsWarning) => {
|
||||
const pushed = [];
|
||||
const closed = [];
|
||||
const marked = [];
|
||||
class FakeWarning { constructor(appName, onAnswered, closeApp) { Object.assign(this, { appName, onAnswered, closeApp }); } }
|
||||
const load = loader({}, {
|
||||
'../../graphics/image': { GrayImage: class {} },
|
||||
'./compositor': { EVENHUB_SCREEN_WIDTH: 576 },
|
||||
'../../ui/gestures': gestures,
|
||||
'../../ui/layers': {},
|
||||
'../../ui/shell/in-process-window': {
|
||||
createInProcessWindow: () => ({
|
||||
stack: { push: (layer) => pushed.push(layer) },
|
||||
window: { handleInput: async () => {} },
|
||||
requestRender() {},
|
||||
setHeightMode() {},
|
||||
}),
|
||||
},
|
||||
'../../ui/shell/shell': { shell: { closeWindow: (id) => closed.push(id), foregroundWindow: () => null } },
|
||||
'../../ui/shell/chrome-layer': { makeImageWindowIcon: () => () => {}, windowIcon: () => () => {} },
|
||||
'./session': { EvenHubSession: class {} },
|
||||
'./installed-apps': { renderInstalledEvenHubIcon: () => null },
|
||||
'./glasses-compat': {
|
||||
needsDisplayWarning: () => needsWarning,
|
||||
markDisplayWarningShown: (id) => marked.push(id),
|
||||
},
|
||||
'./display-warning-dialog': { EvenHubDisplayWarningLayer: FakeWarning },
|
||||
});
|
||||
const { createEvenHubWindow } = load('app/apps/evenhub/evenhub-window.ts');
|
||||
const session = {
|
||||
manifest: { packageId: 'com.example.demo', name: 'Demo' },
|
||||
attachWindow() {},
|
||||
};
|
||||
const options = { actions: {}, submitFrame() {}, setSurfaceVisible() {}, removeSurface() {}, onClosed() {} };
|
||||
createEvenHubWindow('evenhub:app:7', 'evenhub', session, options, () => {}, () => {});
|
||||
return { pushed, closed, marked, FakeWarning };
|
||||
};
|
||||
|
||||
test('an EvenHub window opens under the warning when the app needs one', () => {
|
||||
const { pushed, closed, marked, FakeWarning } = loadWindow(true);
|
||||
assert.equal(pushed.length, 1);
|
||||
const warning = pushed[0];
|
||||
assert.ok(warning instanceof FakeWarning);
|
||||
assert.equal(warning.appName, 'Demo');
|
||||
warning.onAnswered();
|
||||
assert.deepEqual(marked, ['com.example.demo']);
|
||||
warning.closeApp();
|
||||
assert.deepEqual(closed, ['evenhub:app:7']);
|
||||
});
|
||||
|
||||
test('an EvenHub window opens straight to the app otherwise', () => {
|
||||
assert.equal(loadWindow(false).pushed.length, 0);
|
||||
});
|
||||
@@ -62,6 +62,7 @@ const loadStoreLayer = ({ configured = false, api = {} } = {}) => {
|
||||
'./store-detail-layer': { EvenHubStoreDetailLayer: class { constructor(_app, options) { detailOptions.push(options); } } },
|
||||
'./store-install': { cleanError: (error) => String(error?.message ?? error), installStoreApp: async () => {} },
|
||||
'./updates': { checkForEvenHubUpdates: async () => [], describeUpdate: () => '' },
|
||||
'./glasses-compat': { isEvenHubStoreAvailable: () => true },
|
||||
});
|
||||
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
||||
return { EvenHubStoreLayer, email, password, drawn, detailOptions };
|
||||
|
||||
@@ -86,6 +86,7 @@ const loadStore = ({ updates = [] } = {}) => {
|
||||
checkForEvenHubUpdates: async () => updates,
|
||||
describeUpdate: () => ({ updateAvailable: false, packageMissing: false }),
|
||||
},
|
||||
'./glasses-compat': { isEvenHubStoreAvailable: () => true },
|
||||
});
|
||||
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
||||
const layer = new EvenHubStoreLayer({ launchApp: async () => {}, appendLog: () => {} });
|
||||
|
||||
Reference in new issue
Block a user