forked from Blendman974/faceclaw
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c71729d83 | ||
|
|
bd630845b6 |
No files matched your search
@@ -49,11 +49,9 @@ class EvenHubAppLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleInput(event: InputEvent): void {
|
handleInput(event: InputEvent): void {
|
||||||
// Everything goes to the app; the menu gestures never reach here (the
|
// The shell reserves the configured system-menu gesture as the way out.
|
||||||
// shell keeps long-press for its system menu and the window's context
|
// Without a registered EvenHub menu, the app-menu gesture belongs to the
|
||||||
// menu intercepts tap-then-hold), which is the guaranteed way out since
|
// app and reaches this layer as the canonical tap-then-hold event.
|
||||||
// EvenHub apps own double-click. Tap-then-hold is still reported to the
|
|
||||||
// app as LONG_PRESS_EVENT — see the handleInput wrapper below.
|
|
||||||
this.session.handleGesture(isDirectionalInput(event) ? ({ ...directionalFallback(event), source: "watch" } as InputEvent) : event);
|
this.session.handleGesture(isDirectionalInput(event) ? ({ ...directionalFallback(event), source: "watch" } as InputEvent) : event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +84,8 @@ export function createEvenHubWindow(
|
|||||||
// apps register with `menuObject` (SDK 0.0.14): the app's own entries come
|
// apps register with `menuObject` (SDK 0.0.14): the app's own entries come
|
||||||
// first, then the host entries. Evaluated at open time, so a rebuild that
|
// first, then the host entries. Evaluated at open time, so a rebuild that
|
||||||
// changes or clears the menu is reflected on the next press.
|
// changes or clears the menu is reflected on the next press.
|
||||||
|
// A host-only "Show phone UI" entry must not steal the app's hold.
|
||||||
|
openMenuOnAppGesture: () => session.contextMenuItems().length > 0,
|
||||||
menuItems: () => [
|
menuItems: () => [
|
||||||
...session.contextMenuItems().map((item) => ({
|
...session.contextMenuItems().map((item) => ({
|
||||||
label: item.itemName,
|
label: item.itemName,
|
||||||
@@ -133,15 +133,15 @@ export function createEvenHubWindow(
|
|||||||
windowId,
|
windowId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// LONG_PRESS_EVENT / LONG_PRESS_RELEASE_EVENT (SDK 0.0.14): the app hears
|
// Notify the app even when its registered menu or another overlay consumes
|
||||||
// the context-menu gesture (tap-then-hold; a plain long-press is the
|
// the gesture. At base, with no registered menu, the app layer delivers it
|
||||||
// shell's and never arrives) as its long-press. Wrapped at the window
|
// instead; never deliver a press or release twice.
|
||||||
// rather than handled in the base layer because the press opens the window
|
|
||||||
// menu and so never reaches a layer, and because the release lands on that
|
|
||||||
// menu once it is up.
|
|
||||||
const baseHandleInput = created.window.handleInput;
|
const baseHandleInput = created.window.handleInput;
|
||||||
created.window.handleInput = async (event, frameId) => {
|
created.window.handleInput = async (event, frameId) => {
|
||||||
if (event.type === "short-then-long-press" || event.type === "long-press-release") {
|
const opensMenu = event.type === "short-then-long-press" && session.contextMenuItems().length > 0;
|
||||||
|
const overlayOwnsInput = !created.stack.isAtBase();
|
||||||
|
if (opensMenu || (overlayOwnsInput &&
|
||||||
|
(event.type === "short-then-long-press" || event.type === "long-press-release"))) {
|
||||||
session.handleGesture(event);
|
session.handleGesture(event);
|
||||||
}
|
}
|
||||||
await baseHandleInput(event, frameId);
|
await baseHandleInput(event, frameId);
|
||||||
|
|||||||
@@ -603,13 +603,10 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
|
|||||||
case "long-press":
|
case "long-press":
|
||||||
case "short-then-long-press":
|
case "short-then-long-press":
|
||||||
case "long-press-release": {
|
case "long-press-release": {
|
||||||
// SDK 0.0.14 exposes press and release as ordinary events. The app's
|
// SDK 0.0.14 exposes press and release as ordinary events. The shell
|
||||||
// press is the context-menu gesture (tap-then-hold; the shell keeps
|
// canonicalizes the configured app gesture to tap-then-hold. The app
|
||||||
// the plain long-press for its system menu): the window still opens
|
// owns it unless it registered contextual-menu items; the separate
|
||||||
// its menu on it (that menu is where the app's contextual-menu items
|
// system-menu gesture remains available as the way out.
|
||||||
// live, and it is the way out of an app that owns double-click), so
|
|
||||||
// an app hears the press as well as seeing the menu — it cannot be
|
|
||||||
// given exclusive use of the gesture.
|
|
||||||
const eventType = event.type === "long-press-release" ? LONG_PRESS_RELEASE_EVENT : LONG_PRESS_EVENT;
|
const eventType = event.type === "long-press-release" ? LONG_PRESS_RELEASE_EVENT : LONG_PRESS_EVENT;
|
||||||
if (capture?.kind === "list") {
|
if (capture?.kind === "list") {
|
||||||
this.emitListEvent(capture, eventType, inputSource);
|
this.emitListEvent(capture, eventType, inputSource);
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ export type InProcessWindowOptions = {
|
|||||||
* has no menu of its own, and tap-then-hold opens the system menu instead.
|
* has no menu of its own, and tap-then-hold opens the system menu instead.
|
||||||
*/
|
*/
|
||||||
menuItems?: () => MenuItem[];
|
menuItems?: () => MenuItem[];
|
||||||
|
/** False lets the base app handle the canonical app-menu gesture instead. */
|
||||||
|
openMenuOnAppGesture?: () => boolean;
|
||||||
/** Dedicated chat gestures: click menu, hold microphone, tap-hold system menu. */
|
/** Dedicated chat gestures: click menu, hold microphone, tap-hold system menu. */
|
||||||
holdToTalk?: boolean;
|
holdToTalk?: boolean;
|
||||||
isVoiceCapturing?: () => boolean;
|
isVoiceCapturing?: () => boolean;
|
||||||
@@ -201,12 +203,11 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
|||||||
if (closedMenu) requestRender();
|
if (closedMenu) requestRender();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// The default tap-then-hold response: the window menu (or the system
|
// In-process apps normally use the canonical app-menu gesture for the
|
||||||
// menu in its place). Handled here (not per-layer) so it works over
|
// window menu. An app owning that gesture can opt out dynamically and
|
||||||
// submenus and app content alike. A plain long-press never arrives:
|
// receive it through its layer stack instead.
|
||||||
// the shell keeps it for the system menu (no in-process window claims
|
if ((!options.holdToTalk && event.type === "short-then-long-press" &&
|
||||||
// it).
|
(options.openMenuOnAppGesture?.() ?? true)) ||
|
||||||
if ((!options.holdToTalk && event.type === "short-then-long-press") ||
|
|
||||||
(options.holdToTalk && event.type === "click" && stack.isAtBase())) {
|
(options.holdToTalk && event.type === "click" && stack.isAtBase())) {
|
||||||
openWindowMenu();
|
openWindowMenu();
|
||||||
await render(frameId);
|
await render(frameId);
|
||||||
|
|||||||
@@ -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