[verified] fix(evenhub): preserve app hold gestures without forcing host menu

This commit is contained in:
MasterControl committed 2026-11-16 14:36:11 +00:00
1 parent bd630845b6
commit 7c71729d83
4 files changed
+130 -25

No files matched your search

+12 -12
View File
@@ -49,11 +49,9 @@ class EvenHubAppLayer implements Layer {
}
handleInput(event: InputEvent): void {
// Everything goes to the app; the menu gestures never reach here (the
// shell keeps long-press for its system menu and the window's context
// menu intercepts tap-then-hold), which is the guaranteed way out since
// EvenHub apps own double-click. Tap-then-hold is still reported to the
// app as LONG_PRESS_EVENT — see the handleInput wrapper below.
// The shell reserves the configured system-menu gesture as the way out.
// Without a registered EvenHub menu, the app-menu gesture belongs to the
// app and reaches this layer as the canonical tap-then-hold 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
// first, then the host entries. Evaluated at open time, so a rebuild that
// 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: () => [
...session.contextMenuItems().map((item) => ({
label: item.itemName,
@@ -133,15 +133,15 @@ export function createEvenHubWindow(
windowId,
});
// LONG_PRESS_EVENT / LONG_PRESS_RELEASE_EVENT (SDK 0.0.14): the app hears
// the context-menu gesture (tap-then-hold; a plain long-press is the
// shell's and never arrives) as its long-press. Wrapped at the window
// 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.
// Notify the app even when its registered menu or another overlay consumes
// the gesture. At base, with no registered menu, the app layer delivers it
// instead; never deliver a press or release twice.
const baseHandleInput = created.window.handleInput;
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);
}
await baseHandleInput(event, frameId);
+4 -7
View File
@@ -603,13 +603,10 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
case "long-press":
case "short-then-long-press":
case "long-press-release": {
// SDK 0.0.14 exposes press and release as ordinary events. The app's
// press is the context-menu gesture (tap-then-hold; the shell keeps
// the plain long-press for its system menu): the window still opens
// its menu on it (that menu is where the app's contextual-menu items
// 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.
// SDK 0.0.14 exposes press and release as ordinary events. The shell
// canonicalizes the configured app gesture to tap-then-hold. The app
// owns it unless it registered contextual-menu items; the separate
// system-menu gesture remains available as the way out.
const eventType = event.type === "long-press-release" ? LONG_PRESS_RELEASE_EVENT : LONG_PRESS_EVENT;
if (capture?.kind === "list") {
this.emitListEvent(capture, eventType, inputSource);
+7 -6
View File
@@ -40,6 +40,8 @@ export type InProcessWindowOptions = {
* has no menu of its own, and tap-then-hold opens the system menu instead.
*/
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. */
holdToTalk?: boolean;
isVoiceCapturing?: () => boolean;
@@ -201,12 +203,11 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
if (closedMenu) requestRender();
return;
}
// The default tap-then-hold response: the window menu (or the system
// menu in its place). Handled here (not per-layer) so it works over
// submenus and app content alike. A plain long-press never arrives:
// the shell keeps it for the system menu (no in-process window claims
// it).
if ((!options.holdToTalk && event.type === "short-then-long-press") ||
// In-process apps normally use the canonical app-menu gesture for the
// window menu. An app owning that gesture can opt out dynamically and
// receive it through its layer stack instead.
if ((!options.holdToTalk && event.type === "short-then-long-press" &&
(options.openMenuOnAppGesture?.() ?? true)) ||
(options.holdToTalk && event.type === "click" && stack.isAtBase())) {
openWindowMenu();
await render(frameId);