mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
EvenHub UI improvements
Handle left/right swipes on the tab bar, not just up/down Update All button on the Updates page main list Scroll by pages rather than lines on the permissions list
This commit is contained in:
1 parent
d1f9f76abb
commit
3a0908fde2
4 files changed
+373
-27
No files matched your search
@@ -20,11 +20,11 @@ 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: scroll events move
|
||||
* through the content row by row, and only once the bottom is fully visible do
|
||||
* further scrolls move the action selection. The actions are inert until then
|
||||
* (a click just scrolls), so the user can't Allow without having had the whole
|
||||
* list on screen.
|
||||
* 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.
|
||||
*/
|
||||
export class EvenHubPermissionDialogLayer implements Layer {
|
||||
/** Floats in front of the window content, like the context menus. */
|
||||
@@ -35,6 +35,9 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
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(
|
||||
@@ -125,6 +128,8 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
}
|
||||
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);
|
||||
@@ -159,19 +164,19 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
if (this.atBottom() && this.selectedIndex > 0) {
|
||||
this.selectedIndex -= 1;
|
||||
} else if (this.firstRow > 0) {
|
||||
this.firstRow -= 1;
|
||||
this.pageUp();
|
||||
}
|
||||
return;
|
||||
case "scroll-down":
|
||||
if (!this.atBottom()) {
|
||||
this.firstRow += 1;
|
||||
this.pageDown();
|
||||
} else {
|
||||
this.selectedIndex = Math.min(actions.length - 1, this.selectedIndex + 1);
|
||||
}
|
||||
return;
|
||||
case "click":
|
||||
if (!this.atBottom()) {
|
||||
this.firstRow += 1;
|
||||
this.pageDown();
|
||||
return;
|
||||
}
|
||||
if (actions[this.selectedIndex] === "Privacy policy") {
|
||||
@@ -188,6 +193,29 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
|
||||
import { directionalFallback, GESTURE_CLICK, isDirectionalInput, type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerActions, type LayerContext, type LayerStack } from "../../ui/layers";
|
||||
import { drawSelectionHighlight, type MenuItem } from "../../ui/menu";
|
||||
import { Menu } from "../../ui/menu-core";
|
||||
@@ -55,7 +55,32 @@ type StoreRow =
|
||||
/** The Search tab's first row: shows the query and opens the phone editor. */
|
||||
| { kind: "search-query" }
|
||||
/** A registry entry whose package is gone and which the store no longer lists. */
|
||||
| { kind: "orphan"; update: EvenHubAppUpdate };
|
||||
| { kind: "orphan"; update: EvenHubAppUpdate }
|
||||
/** The Updates tab's first row while any update is installable; `busy` while Update All runs. */
|
||||
| { kind: "update-all"; count: number; busy: boolean };
|
||||
|
||||
type AppRow = Extract<StoreRow, { kind: "app" }>;
|
||||
|
||||
/** An Updates row that installing the store's version would satisfy. */
|
||||
function isUpdatableRow(row: StoreRow): row is AppRow {
|
||||
return row.kind === "app" && row.update !== undefined;
|
||||
}
|
||||
|
||||
/** An Updates row for one installed app (not the Update All row). */
|
||||
function isInstalledAppRow(row: StoreRow): boolean {
|
||||
return row.kind === "app" || row.kind === "orphan";
|
||||
}
|
||||
|
||||
function rowPackageId(row: StoreRow): string | undefined {
|
||||
switch (row.kind) {
|
||||
case "app":
|
||||
return row.app.packageId;
|
||||
case "orphan":
|
||||
return row.update.installed.packageId;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
type TabState = {
|
||||
rows: StoreRow[];
|
||||
@@ -118,10 +143,13 @@ export type EvenHubStoreLayerOptions = {
|
||||
* The EvenHub storefront: Top (leaderboard), New (by first publication),
|
||||
* Search, and Updates (installed apps that are stale or whose package is
|
||||
* missing). The tab row is its own focus level above the list: double-click
|
||||
* in the list focuses the tabs, scrolling there switches tabs, and a click
|
||||
* returns to the list.
|
||||
* in the list focuses the tabs, scrolling (or a watch swipe in any direction)
|
||||
* there switches tabs, and a click returns to the list.
|
||||
*/
|
||||
export class EvenHubStoreLayer implements Layer {
|
||||
/** Swipes left/right switch tabs on the tab strip; elsewhere they get the usual fallback. */
|
||||
readonly acceptsDirectional = true;
|
||||
|
||||
private readonly tabs: Record<StoreTab, TabState> = {
|
||||
top: emptyTab(),
|
||||
new: emptyTab(),
|
||||
@@ -229,7 +257,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
const label = TABS.find((entry) => entry.id === tab)!.label;
|
||||
if (tab !== "updates") return label;
|
||||
const updates = this.tabs.updates;
|
||||
const count = updates.rows.filter((row) => row.kind !== "search-query").length;
|
||||
const count = updates.rows.filter(isInstalledAppRow).length;
|
||||
return updates.loaded && count > 0 ? `${label} (${count})` : label;
|
||||
}
|
||||
|
||||
@@ -245,9 +273,11 @@ export class EvenHubStoreLayer implements Layer {
|
||||
if (!state.query) return "Search public apps";
|
||||
return results === 1 ? `1 result for "${state.query}"` : `${results} results for "${state.query}"`;
|
||||
}
|
||||
case "updates":
|
||||
case "updates": {
|
||||
if (!state.loaded) return "Installed apps with newer versions";
|
||||
return count === 0 ? "All installed apps are up to date" : count === 1 ? "1 app needs attention" : `${count} apps need attention`;
|
||||
const apps = state.rows.filter(isInstalledAppRow).length;
|
||||
return apps === 0 ? "All installed apps are up to date" : apps === 1 ? "1 app needs attention" : `${apps} apps need attention`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +293,10 @@ export class EvenHubStoreLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
async handleInput(rawEvent: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
const tabSwipe = !this.showingLogin && this.focus === "tabs"
|
||||
&& (rawEvent.type === "swipe-left" || rawEvent.type === "swipe-right");
|
||||
const event = isDirectionalInput(rawEvent) && !tabSwipe ? directionalFallback(rawEvent) : rawEvent;
|
||||
if (this.showingLogin) {
|
||||
if (event.type === "click" && !this.loginBusy) {
|
||||
this.openCredentialEditor(ctx);
|
||||
@@ -301,9 +334,11 @@ export class EvenHubStoreLayer implements Layer {
|
||||
const index = TABS.findIndex((tab) => tab.id === this.activeTab);
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
case "swipe-left":
|
||||
this.switchTab(ctx, TABS[Math.max(0, index - 1)]!.id);
|
||||
return;
|
||||
case "scroll-down":
|
||||
case "swipe-right":
|
||||
this.switchTab(ctx, TABS[Math.min(TABS.length - 1, index + 1)]!.id);
|
||||
return;
|
||||
case "click":
|
||||
@@ -333,6 +368,9 @@ export class EvenHubStoreLayer implements Layer {
|
||||
case "search-query":
|
||||
this.openSearchEditor(ctx);
|
||||
return;
|
||||
case "update-all":
|
||||
void this.updateAll(ctx);
|
||||
return;
|
||||
case "orphan": {
|
||||
// Nothing can be reinstalled; the only useful action is to drop the
|
||||
// dead registry entry so the launcher stops offering it.
|
||||
@@ -532,8 +570,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
const rows: StoreRow[] = updates.map((update) =>
|
||||
update.latest ? { kind: "app", app: update.latest, update } : { kind: "orphan", update },
|
||||
);
|
||||
state.rows = rows;
|
||||
state.menu.setItems(rows, 0);
|
||||
this.setUpdateRows(state, rows, 0);
|
||||
state.menu.scrollTop = 0;
|
||||
state.status = "";
|
||||
state.exhausted = true;
|
||||
@@ -548,10 +585,20 @@ export class EvenHubStoreLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
private updatableRows(): Extract<StoreRow, { kind: "app" }>[] {
|
||||
return this.tabs.updates.rows.filter(
|
||||
(row): row is Extract<StoreRow, { kind: "app" }> => row.kind === "app" && row.update !== undefined,
|
||||
);
|
||||
private updatableRows(): AppRow[] {
|
||||
return this.tabs.updates.rows.filter(isUpdatableRow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the Updates rows, putting an Update All row on top while any of
|
||||
* them can be installed (and dropping it once none can).
|
||||
*/
|
||||
private setUpdateRows(state: TabState, entries: readonly StoreRow[], selectedIndex?: number): void {
|
||||
const rows = entries.filter(isInstalledAppRow);
|
||||
const count = rows.filter(isUpdatableRow).length;
|
||||
if (count > 0) rows.unshift({ kind: "update-all", count, busy: this.updatingAll });
|
||||
state.rows = rows;
|
||||
state.menu.setItems(rows, selectedIndex);
|
||||
}
|
||||
|
||||
/** Install every pending update in turn; a declined permission dialog skips that app. */
|
||||
@@ -559,6 +606,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
if (this.updatingAll) return;
|
||||
this.updatingAll = true;
|
||||
const state = this.tabs.updates;
|
||||
this.setUpdateRows(state, state.rows);
|
||||
const pending = this.updatableRows();
|
||||
let installed = 0;
|
||||
const failures: string[] = [];
|
||||
@@ -593,6 +641,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
: installed === 1 ? "Updated 1 app." : `Updated ${installed} apps.`;
|
||||
} finally {
|
||||
this.updatingAll = false;
|
||||
this.setUpdateRows(this.tabs.updates, this.tabs.updates.rows);
|
||||
if (!this.closed) ctx.actions.requestRender();
|
||||
}
|
||||
}
|
||||
@@ -609,10 +658,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
|
||||
private removeUpdateRow(packageId: string): void {
|
||||
const state = this.tabs.updates;
|
||||
state.rows = state.rows.filter((row) =>
|
||||
row.kind === "search-query" ? true : row.kind === "app" ? row.app.packageId !== packageId : row.update.installed.packageId !== packageId,
|
||||
);
|
||||
state.menu.setItems(state.rows);
|
||||
this.setUpdateRows(state, state.rows.filter((row) => rowPackageId(row) !== packageId));
|
||||
}
|
||||
|
||||
// ---- login and phone editors --------------------------------------------
|
||||
@@ -751,6 +797,14 @@ function rowText(row: StoreRow): { title: string; detail: string; titleValue: nu
|
||||
titleValue: 200,
|
||||
};
|
||||
}
|
||||
case "update-all":
|
||||
return {
|
||||
title: row.busy ? "Updating..." : "Update All",
|
||||
detail: row.busy
|
||||
? "Installing updates; progress is shown above."
|
||||
: row.count === 1 ? "Install the 1 available update" : `Install all ${row.count} available updates`,
|
||||
titleValue: row.busy ? 150 : 230,
|
||||
};
|
||||
case "orphan":
|
||||
return {
|
||||
title: row.update.installed.name,
|
||||
|
||||
@@ -17,6 +17,8 @@ const setting = (initial = '') => {
|
||||
|
||||
class AuthError extends Error {}
|
||||
|
||||
const gestures = loader({}, {})('app/ui/gestures.ts');
|
||||
|
||||
/**
|
||||
* Load the store layer, by default with a signed-out account and no stored
|
||||
* credentials. `api` overrides evenHubApi methods; text the layer paints is
|
||||
@@ -34,7 +36,7 @@ const loadStoreLayer = ({ configured = false, api = {} } = {}) => {
|
||||
'../../graphics/image': { GrayImage: class { drawText(_f, _x, _y, text) { drawn.push(text); } fillRect() {} } },
|
||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] },
|
||||
'../../util/numeric-util': { clamp: (v, lo, hi) => Math.min(hi, Math.max(lo, v)) },
|
||||
'../../ui/gestures': { GESTURE_CLICK: 'click' },
|
||||
'../../ui/gestures': { ...gestures, GESTURE_CLICK: 'click' },
|
||||
'../../ui/menu': { drawSelectionHighlight() {} },
|
||||
'../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'),
|
||||
'../../ui/shell/shell': { shell: { yieldFocusToSidebar() {} } },
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
// EvenHub store navigation: watch swipes on the tab strip, the Updates tab's
|
||||
// Update All row, and page-at-a-time scrolling in the permission dialog.
|
||||
//
|
||||
// The real layers run with their dependencies mocked; what they paint is
|
||||
// collected as text, so these assert what the user would see.
|
||||
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() {}
|
||||
};
|
||||
|
||||
/** Stand-in for ui/menu-core's Menu: draws every row in order, scrolls the selection by one. */
|
||||
class FakeMenu {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.items = options.items;
|
||||
this.selectedIndex = 0;
|
||||
this.scrollTop = 0;
|
||||
}
|
||||
setItems(items, selectedIndex) {
|
||||
this.items = items;
|
||||
if (selectedIndex !== undefined) this.selectedIndex = selectedIndex;
|
||||
this.selectedIndex = Math.max(0, Math.min(this.selectedIndex, items.length - 1));
|
||||
}
|
||||
get selectedItem() { return this.items[this.selectedIndex] ?? null; }
|
||||
handleInput(event) {
|
||||
if (event.type === 'scroll-down') this.selectedIndex = Math.min(this.items.length - 1, this.selectedIndex + 1);
|
||||
if (event.type === 'scroll-up') this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
||||
}
|
||||
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 storeApp = (packageId, name, version) => ({
|
||||
id: 1, packageId, name, version, creatorName: '', tagline: '', description: '', categories: [],
|
||||
installCount: 0, likeCount: 0, firstPublishedAt: '', iconPath: '', changelog: '', fileSize: 0,
|
||||
});
|
||||
|
||||
const emptyPage = { apps: [], total: 0, page: 1, pageSize: 20 };
|
||||
|
||||
/** A signed-in store layer; `updates` is what the update check reports. */
|
||||
const loadStore = ({ updates = [] } = {}) => {
|
||||
const drawn = [];
|
||||
const installs = [];
|
||||
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() {} } },
|
||||
'../../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 () => 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: () => updates.map((update) => update.installed), uninstallEvenHubPackage: () => true },
|
||||
'./store-detail-layer': { EvenHubStoreDetailLayer: class {} },
|
||||
'./store-install': {
|
||||
cleanError: (error) => String(error?.message ?? error),
|
||||
installStoreApp: async (_ctx, app) => { installs.push(app.packageId); return { packageId: app.packageId }; },
|
||||
},
|
||||
'./updates': {
|
||||
checkForEvenHubUpdates: async () => updates,
|
||||
describeUpdate: () => ({ updateAvailable: false, packageMissing: false }),
|
||||
},
|
||||
});
|
||||
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
||||
const layer = new EvenHubStoreLayer({ launchApp: async () => {}, appendLog: () => {} });
|
||||
return { layer, drawn, installs };
|
||||
};
|
||||
|
||||
const makeCtx = () => ({
|
||||
stack: {
|
||||
getBaseSize: () => ({ width: 576, height: 288 }),
|
||||
isFocused: () => true,
|
||||
clearToBase() {},
|
||||
push() {},
|
||||
pop() {},
|
||||
},
|
||||
actions: { requestRender() {}, endTextSettingEdit() {}, startTextSettingsEdit() {} },
|
||||
});
|
||||
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
/** Repaint and return the drawn text. */
|
||||
const repaint = (layer, drawn, ctx) => {
|
||||
drawn.length = 0;
|
||||
layer.paint(ctx);
|
||||
return [...drawn];
|
||||
};
|
||||
|
||||
const watch = (type) => ({ type, source: 'watch', timestampMs: 0 });
|
||||
|
||||
test('watch swipes left and right switch tabs while the tab strip is focused', async () => {
|
||||
const { layer, drawn } = loadStore();
|
||||
const ctx = makeCtx();
|
||||
layer.paint(ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Public apps by popularity'));
|
||||
|
||||
// In the list, a right swipe is "select" and must not change tabs.
|
||||
await layer.handleInput(watch('swipe-right'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Public apps by popularity'), 'still on Top');
|
||||
|
||||
// A left swipe in the list is "back", which focuses the tab strip.
|
||||
await layer.handleInput(watch('swipe-left'), ctx);
|
||||
await layer.handleInput(watch('swipe-right'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Recently published apps'), 'right moved to New');
|
||||
|
||||
await layer.handleInput(watch('swipe-left'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Public apps by popularity'), 'left moved back to Top');
|
||||
|
||||
// Up/down still switch tabs too.
|
||||
await layer.handleInput(watch('swipe-down'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Recently published apps'), 'down moved to New');
|
||||
});
|
||||
|
||||
/** Open the store and move to the Updates tab, with focus back in its list. */
|
||||
const openUpdatesTab = async (layer, ctx) => {
|
||||
layer.paint(ctx);
|
||||
await settle();
|
||||
await layer.handleInput({ type: 'double-click', source: 'ring' }, ctx);
|
||||
for (let i = 0; i < 3; i++) await layer.handleInput({ type: 'scroll-down' }, ctx);
|
||||
await settle();
|
||||
await layer.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
};
|
||||
|
||||
test('the Updates tab lists Update All first and it installs every update', async () => {
|
||||
const updates = [
|
||||
{ installed: { packageId: 'a', name: 'Alpha', version: '1' }, latest: storeApp('a', 'Alpha', '2'), packageMissing: false },
|
||||
{ installed: { packageId: 'b', name: 'Beta', version: '1' }, latest: storeApp('b', 'Beta', '3'), packageMissing: false },
|
||||
{ installed: { packageId: 'c', name: 'Gamma', version: '1' } },
|
||||
];
|
||||
const { layer, drawn, installs } = loadStore({ updates });
|
||||
const ctx = makeCtx();
|
||||
await openUpdatesTab(layer, ctx);
|
||||
|
||||
const painted = repaint(layer, drawn, ctx);
|
||||
assert.ok(painted.includes('Updates (3)'), `the tab count is apps, not rows: ${JSON.stringify(painted)}`);
|
||||
assert.ok(painted.includes('3 apps need attention'));
|
||||
const updateAll = painted.indexOf('Update All');
|
||||
assert.ok(updateAll >= 0, `painted: ${JSON.stringify(painted)}`);
|
||||
assert.ok(painted.includes('Install all 2 available updates'), 'the orphan is not counted');
|
||||
assert.ok(updateAll < painted.indexOf('Alpha') && updateAll < painted.indexOf('Gamma'), 'Update All is the first row');
|
||||
|
||||
// The list opens on Update All; clicking it installs both updatable apps.
|
||||
await layer.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
await settle();
|
||||
assert.deepEqual(installs, ['a', 'b']);
|
||||
const after = repaint(layer, drawn, ctx);
|
||||
assert.ok(!after.includes('Update All'), 'nothing left to update, so the row goes');
|
||||
assert.ok(after.includes('Gamma'), 'the missing package stays listed');
|
||||
assert.ok(after.includes('Updated 2 apps.'));
|
||||
});
|
||||
|
||||
test('the Updates tab has no Update All row when nothing can be installed', async () => {
|
||||
const updates = [{ installed: { packageId: 'c', name: 'Gamma', version: '1' } }];
|
||||
const { layer, drawn } = loadStore({ updates });
|
||||
const ctx = makeCtx();
|
||||
await openUpdatesTab(layer, ctx);
|
||||
const painted = repaint(layer, drawn, ctx);
|
||||
assert.ok(painted.includes('Gamma'));
|
||||
assert.ok(!painted.includes('Update All'));
|
||||
});
|
||||
|
||||
// ---- permission dialog ---------------------------------------------------
|
||||
|
||||
const loadDialog = (detailLines) => {
|
||||
const drawn = [];
|
||||
const load = loader({}, {
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../../graphics/image': { GrayImage: makeImageClass(drawn) },
|
||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => text.split('|') },
|
||||
'../../ui/gestures': gestures,
|
||||
'../../ui/layers': {},
|
||||
'../../ui/menu': { drawListScrollbar() {}, drawSelectionHighlight() {} },
|
||||
'./permissions': { permissionDetail: (permission) => permission.detail, permissionLabel: (name) => name },
|
||||
'./privacy-policy': { openPrivacyPolicyOnPhone() {} },
|
||||
'../../ui/metrics': { lineStep: () => 12, listRowHeight: () => 20 },
|
||||
});
|
||||
const { EvenHubPermissionDialogLayer } = load('app/apps/evenhub/permission-dialog.ts');
|
||||
const ImageClass = makeImageClass(drawn);
|
||||
const outcome = { confirmed: null };
|
||||
const dialog = new EvenHubPermissionDialogLayer(
|
||||
'Demo',
|
||||
[{ name: 'network', detail: detailLines.join('|') }],
|
||||
'',
|
||||
() => { outcome.confirmed = true; },
|
||||
() => { outcome.confirmed = false; },
|
||||
);
|
||||
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 136 }), isFocused: () => true, pop() {} } };
|
||||
const paint = () => {
|
||||
drawn.length = 0;
|
||||
dialog.paint(ctx, () => new ImageClass());
|
||||
return [...drawn];
|
||||
};
|
||||
return { dialog, ctx, paint, outcome };
|
||||
};
|
||||
|
||||
test('the permission dialog scrolls a page at a time with one line of overlap', () => {
|
||||
const lines = Array.from({ length: 30 }, (_, i) => `line ${i + 1}`);
|
||||
const { dialog, ctx, paint, outcome } = loadDialog(lines);
|
||||
|
||||
const pages = [paint()];
|
||||
while (!pages[pages.length - 1].includes('Allow')) {
|
||||
assert.ok(pages.length < 20, 'paging reaches the actions');
|
||||
dialog.handleInput({ type: 'scroll-down' }, ctx);
|
||||
pages.push(paint());
|
||||
}
|
||||
assert.ok(pages.length >= 3, `the list is long enough to need several pages (${pages.length})`);
|
||||
// Every page but the last (which stops at the bottom) starts on the line the previous one ended on.
|
||||
for (let page = 1; page < pages.length - 1; page++) {
|
||||
const previous = pages[page - 1];
|
||||
assert.equal(pages[page][0], previous[previous.length - 1], `page ${page + 1} overlaps page ${page} by one line`);
|
||||
assert.ok(pages[page].length > 2, 'a page moves by more than one line');
|
||||
}
|
||||
// Every line was on screen on some page.
|
||||
for (const line of lines) assert.ok(pages.some((page) => page.includes(line)), `${line} was shown`);
|
||||
|
||||
// Paging up from the bottom: the old first line becomes the new last one.
|
||||
const bottom = pages[pages.length - 1];
|
||||
dialog.handleInput({ type: 'scroll-up' }, ctx);
|
||||
const up = paint();
|
||||
assert.equal(up[up.length - 1], bottom[0], 'one line of overlap going up');
|
||||
assert.ok(up.length > 2);
|
||||
for (let i = 0; i < pages.length; i++) dialog.handleInput({ type: 'scroll-up' }, ctx);
|
||||
assert.deepEqual(paint(), pages[0], 'back at the top');
|
||||
|
||||
// A click before the bottom pages down rather than allowing; scrolling up returns.
|
||||
dialog.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
assert.deepEqual(paint(), pages[1]);
|
||||
assert.equal(outcome.confirmed, null);
|
||||
dialog.handleInput({ type: 'scroll-up' }, ctx);
|
||||
assert.deepEqual(paint(), pages[0]);
|
||||
});
|
||||
Reference in new issue
Block a user