forked from Blendman974/faceclaw
[verified] fix(evenhub): preserve app hold gestures without forcing host menu
This commit is contained in:
1 parent
bd630845b6
commit
7c71729d83
4 files changed
+130
-25
No files matched your search
@@ -0,0 +1,107 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
function fixture() {
|
||||
let items = [];
|
||||
const gestures = [], submitted = [], selected = [];
|
||||
class Menu {
|
||||
constructor(_title, entries) { this.items = entries; }
|
||||
handleInput() {}
|
||||
}
|
||||
class Stack {
|
||||
constructor(base) { this.layers = [base]; }
|
||||
isAtBase() { return this.layers.length === 1; }
|
||||
topMatches(fn) { return fn(this.layers.at(-1)); }
|
||||
push(layer) { this.layers.push(layer); }
|
||||
pop() { this.layers.pop(); }
|
||||
popIfTop(fn) { if (!this.isAtBase() && this.topMatches(fn)) { this.pop(); return true; } return false; }
|
||||
async handleInput(event) { await this.layers.at(-1).handleInput(event); }
|
||||
paint() { return []; }
|
||||
}
|
||||
const session = {
|
||||
manifest: { name: 'Test', packageId: 'test.app' },
|
||||
contextMenuItems: () => items,
|
||||
handleGesture(event) { gestures.push(event); },
|
||||
selectContextMenuItem(id) { selected.push(id); },
|
||||
attachWindow() {},
|
||||
};
|
||||
const load = loader({}, {
|
||||
'../../graphics/image': {}, './compositor': {}, './session': {},
|
||||
'../../ui/gestures': { isDirectionalInput: () => false },
|
||||
'../../ui/shell/shell': { shell: {} }, './shell': { shell: {} },
|
||||
'../../ui/shell/chrome-layer': { windowIcon: () => () => null, makeImageWindowIcon: () => () => null },
|
||||
'./chrome-layer': { windowIcon: () => () => null },
|
||||
'./installed-apps': {}, './glasses-compat': { needsDisplayWarning: () => false },
|
||||
'./display-warning-dialog': {}, '../layers': { LayerStack: Stack },
|
||||
'../window-menu': { WindowMenuLayer: Menu },
|
||||
'./geometry': { appViewport: () => ({}), setAppImmersive() {} },
|
||||
'../../native/frame-timings': { annotateFrame() {}, span: (_id, _name, fn) => fn(),
|
||||
runWithFrame: (_id, fn) => fn(), spanAsync: (_id, _name, fn) => fn() },
|
||||
'../../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false },
|
||||
});
|
||||
const created = load('app/apps/evenhub/evenhub-window.ts').createEvenHubWindow('test', 'test', session,
|
||||
{ actions: {}, submitFrame: async (_planes, _ms, id) => submitted.push(id) }, () => {}, () => {});
|
||||
return { ...created, gestures, submitted, selected, setItems(value) { items = value; },
|
||||
input: type => created.window.handleInput({ type, source: 'ring', timestampMs: 42 }, 17) };
|
||||
}
|
||||
|
||||
for (const swap of [false, true]) {
|
||||
test(`shell routes EvenHub holds without a host menu, inversion ${swap}`, async () => {
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
const f = fixture();
|
||||
const source = ts.createSourceFile('shell.ts', fs.readFileSync('app/ui/shell/shell.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'Shell');
|
||||
const route = cls.members.find(n => n.name?.getText(source) === 'routeInput');
|
||||
const context = { exports: {}, isWatchInput: () => false,
|
||||
swapMenuGesturesSetting: { get: () => swap } };
|
||||
vm.runInNewContext(ts.transpileModule(`export class Shell { ${route.getText(source)} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
let systemMenu = false;
|
||||
const shell = new context.exports.Shell();
|
||||
Object.assign(shell, { focus: 'window', screenOn: true, lastInput: null,
|
||||
foregroundWindow: () => f.window, cancelEscapeMenuTimer() {},
|
||||
stack: { isAtBase: () => !systemMenu, popIfTop: () => false },
|
||||
openEscapeMenu() { systemMenu = true; } });
|
||||
const input = type => shell.routeInput({ type, source: 'ring', timestampMs: 42 }, 17);
|
||||
await input(swap ? 'long-press' : 'short-then-long-press');
|
||||
await input('long-press-release');
|
||||
assert.equal(f.stack.isAtBase(), true);
|
||||
assert.equal(systemMenu, false);
|
||||
assert.deepEqual(f.gestures.map(e => e.type), ['short-then-long-press', 'long-press-release']);
|
||||
await input(swap ? 'short-then-long-press' : 'long-press');
|
||||
assert.equal(systemMenu, true);
|
||||
await input('long-press-release');
|
||||
assert.equal(f.gestures.length, 2, 'system-menu gesture and release must not leak to the app');
|
||||
});
|
||||
}
|
||||
|
||||
test('EvenHub owns the app-menu gesture without a forced host menu or duplicate release', async () => {
|
||||
const f = fixture();
|
||||
// The shell canonicalizes long-press to this event when inversion is enabled.
|
||||
await f.input('short-then-long-press');
|
||||
assert.equal(f.stack.isAtBase(), true, 'must not open Show phone UI over the app');
|
||||
await f.input('long-press-release');
|
||||
assert.deepEqual(f.gestures.map(e => e.type), ['short-then-long-press', 'long-press-release']);
|
||||
assert.equal(f.gestures[0].source, 'ring');
|
||||
assert.equal(f.gestures[0].timestampMs, 42);
|
||||
assert.deepEqual(f.submitted, [17, 17]);
|
||||
});
|
||||
|
||||
test('EvenHub registered menus still open, receive release once, and stop opening when cleared', async () => {
|
||||
const f = fixture();
|
||||
f.setItems([{ itemName: 'App action', itemID: 7 }]);
|
||||
await f.input('short-then-long-press');
|
||||
assert.equal(f.stack.isAtBase(), false);
|
||||
assert.deepEqual(Array.from(f.stack.layers.at(-1).items, item => item.label), ['App action', 'Show phone UI']);
|
||||
await f.input('long-press-release');
|
||||
assert.deepEqual(f.gestures.map(e => e.type), ['short-then-long-press', 'long-press-release']);
|
||||
f.stack.layers.at(-1).items[0].onSelect({ stack: f.stack });
|
||||
assert.deepEqual(f.selected, [7]);
|
||||
f.setItems([]);
|
||||
await f.input('short-then-long-press');
|
||||
assert.equal(f.stack.isAtBase(), true);
|
||||
});
|
||||
Reference in new issue
Block a user