forked from Blendman974/faceclaw
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
386a10775d | ||
|
|
d08a218810 | ||
|
|
c1ca1acf3b | ||
|
|
e49c5641c5 | ||
|
|
bf3fc49f7e | ||
|
|
7c71729d83 | ||
|
|
bd630845b6 | ||
|
|
4b4ab1b02c | ||
|
|
4d9c2bac76 |
No files matched your search
@@ -231,16 +231,17 @@ class FaceclawBleManager(context: Context) {
|
||||
fun connect(address: String?, timeoutMs: Int): Boolean = connect(address, timeoutMs, false)
|
||||
|
||||
/**
|
||||
* autoConnect=true is used for the ring and both glasses arms. The ring specifically
|
||||
* needs it (Even's own vendor app connects the ring with Android's autoConnect flag
|
||||
* set, confirmed via its own BLE debug log, "connect() - device: ...,
|
||||
* auto: true"). A live test showed a ring-only direct connection dying almost
|
||||
* exactly 5 seconds in, repeatedly, with nothing else competing for it, and the
|
||||
* glasses arms showed the same "less patiently supervised" direct-connect drop.
|
||||
* Direct connect (false) is faster to establish but Android supervises it less
|
||||
* patiently. autoConnect=true can take much longer to actually complete (Android
|
||||
* manages it as a background reconnect, not an immediate attempt), so it needs its
|
||||
* own longer timeout. Like [connect], waits on an attempt already pending.
|
||||
* EXPERIMENTAL (2026-09-11): the ring specifically needs autoConnect=true.
|
||||
* Even's own vendor app connects the ring with Android's autoConnect flag
|
||||
* set (confirmed via its own BLE debug log, "connect() - device: ...,
|
||||
* auto: true"), while every other faceclaw connection (both glasses arms)
|
||||
* uses autoConnect=false. Direct connect (false) is faster to establish
|
||||
* but Android supervises it less patiently; a live test showed the
|
||||
* ring-only direct connection dying almost exactly 5 seconds in,
|
||||
* repeatedly, with nothing else competing for it. autoConnect=true can
|
||||
* take much longer to actually complete (Android manages it as a
|
||||
* background reconnect, not an immediate attempt), so this needs its own
|
||||
* longer timeout. Like [connect], waits on an attempt already pending.
|
||||
*/
|
||||
fun connect(address: String?, timeoutMs: Int, autoConnect: Boolean): Boolean {
|
||||
val key = requireAddress(address)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -120,7 +120,6 @@ export type DashboardSnapshot = {
|
||||
* glasses, and this says which harmless thing is actually going on.
|
||||
*/
|
||||
displayPreviewMessage: string;
|
||||
silentModeFeedback: string;
|
||||
activeTextSettingId: string | null;
|
||||
activeTextEditorTitle: string;
|
||||
activeTextSettingTitle: string;
|
||||
@@ -296,9 +295,6 @@ class DashboardController {
|
||||
/** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */
|
||||
private displayPreviewCrop: ScreenRect | null = null;
|
||||
private silentMode = false;
|
||||
private silentModeFeedback = "";
|
||||
private silentModeFeedbackGeneration = 0;
|
||||
private silentModeFeedbackTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
// Brightness value last pushed to the glasses; see pushBrightness.
|
||||
private lastPushedBrightness: string | null = null;
|
||||
private lastPushedHeadUp: string | null = null;
|
||||
@@ -1221,7 +1217,6 @@ class DashboardController {
|
||||
status: this.status,
|
||||
displayPreview: this.displayPreview,
|
||||
displayPreviewMessage: this.displayPreviewMessage(),
|
||||
silentModeFeedback: this.silentModeFeedback,
|
||||
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||
activeTextEditorTitle: this.activeTextEditorTitle,
|
||||
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
|
||||
@@ -1260,43 +1255,6 @@ class DashboardController {
|
||||
* charging and silent mode both make the display unavailable while BLE stays
|
||||
* up, and a battery that just ran out simply stops answering.
|
||||
*/
|
||||
private handleSilentMode(silent: boolean): void {
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
const generation = ++this.silentModeFeedbackGeneration;
|
||||
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = silent
|
||||
? "Silent mode enabled — hold both touchpads to exit"
|
||||
: "Silent mode disabled";
|
||||
if (!silent) {
|
||||
void this.showSilentModeExit(generation).catch(error => {
|
||||
this.appendLog(`silent-mode exit feedback failed: ${this.formatError(error)}`);
|
||||
});
|
||||
this.silentModeFeedbackTimer = setTimeout(() => {
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = "";
|
||||
this.emit();
|
||||
}, 5000);
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
private async showSilentModeExit(generation: number): Promise<void> {
|
||||
if (this.phase !== "connected" || this.silentMode || this.glassesLocked) return;
|
||||
// The firmware powered the lenses down, and Faceclaw may have gone to
|
||||
// sleep/suspended EvenHub meanwhile. Reusing the ordinary wake barrier is
|
||||
// essential: rendering an alert into the retained surface alone is invisible.
|
||||
this.cancelEvenHubSuspendTimer();
|
||||
shell.wake("sidebar");
|
||||
const ready = await this.ensureEvenHubSessionActive();
|
||||
if (!ready || generation !== this.silentModeFeedbackGeneration || this.silentMode ||
|
||||
this.phase !== "connected" || this.glassesLocked) return;
|
||||
shell.showAlert("Silent mode disabled");
|
||||
shell.foregroundWindow()?.requestRender();
|
||||
this.requestShellRender();
|
||||
}
|
||||
|
||||
private displayPreviewMessage(): string {
|
||||
if (this.phase === "charging") {
|
||||
return chargingPreviewMessage(this.glassesDisplayState());
|
||||
@@ -1731,7 +1689,9 @@ class DashboardController {
|
||||
});
|
||||
});
|
||||
this.offSilentMode = communicator.onSilentMode((silent) => {
|
||||
this.handleSilentMode(silent);
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
this.emit();
|
||||
});
|
||||
this.offWearState = communicator.onWearState((wearing) => {
|
||||
this.handleWearState(wearing);
|
||||
@@ -3129,10 +3089,6 @@ class DashboardController {
|
||||
// Kept across "connecting": silent mode blocks app launches, so it can
|
||||
// itself cause the reconnect churn, and Java re-reports it either way.
|
||||
this.silentMode = false;
|
||||
this.silentModeFeedbackGeneration++;
|
||||
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||
this.silentModeFeedbackTimer = null;
|
||||
this.silentModeFeedback = "";
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
@@ -74,9 +74,6 @@
|
||||
class="ble-bandwidth-indicator"
|
||||
horizontalAlignment="center"
|
||||
verticalAlignment="bottom" />
|
||||
<Label text="{{ silentModeFeedback }}" visibility="{{ silentModeFeedbackVisibility }}"
|
||||
textWrap="true" horizontalAlignment="center" verticalAlignment="top"
|
||||
margin="12" padding="12" backgroundColor="#333333" color="white" borderRadius="8" />
|
||||
<ScrollView
|
||||
class="warnings-modal"
|
||||
visibility="{{ warningsModalVisibility }}"
|
||||
|
||||
@@ -38,7 +38,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _status = "Disconnected.";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _displayPreviewMessage = "";
|
||||
private _silentModeFeedback = "";
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
private _landscapePreviewWidth = 0;
|
||||
private _landscapePreviewHeight = 0;
|
||||
@@ -92,7 +91,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.previewMode = snapshot.previewMode;
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.silentModeFeedback = snapshot.silentModeFeedback ?? "";
|
||||
this.phase = snapshot.phase;
|
||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||
@@ -217,17 +215,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
get silentModeFeedback(): string { return this._silentModeFeedback; }
|
||||
set silentModeFeedback(value: string) {
|
||||
if (this._silentModeFeedback === value) return;
|
||||
this._silentModeFeedback = value;
|
||||
this.notifyPropertyChange("silentModeFeedback", value);
|
||||
this.notifyPropertyChange("silentModeFeedbackVisibility", this.silentModeFeedbackVisibility);
|
||||
}
|
||||
get silentModeFeedbackVisibility(): "visible" | "collapse" {
|
||||
return this._silentModeFeedback ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get hasDisplayPreview(): boolean {
|
||||
return this._displayPreview !== null;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# Silent-mode feedback
|
||||
|
||||
The firmware blanks the lenses and stops ordinary input while silent mode is active. App code cannot display an activation popup on lenses that the firmware has switched off. The phone now shows a persistent enabled banner with the exit gesture, and a five-second disabled banner on exit. On exit, unlocked glasses wake through the normal screen/EvenHub barrier before the alert popup is rendered. This also handles the shell falling asleep during a long silent period. Locked glasses keep the phone feedback without being woken. A generation check suppresses stale notices after re-entry or disconnect. Duplicate state reports do not repeat feedback, stale timers are cancelled, and disconnect clears the notice.
|
||||
|
||||
Silent-off firmware pushes are not reliable. The existing fallback read used the five-minute battery cadence. While silent mode is known to be on, settings are now polled every two seconds when the session is ready and the message queues are idle. Normal battery cadence and shutdown guards are retained. This bounds ordinary missing-push recovery without assuming a touch gesture always means silent mode ended.
|
||||
|
||||
Initial independent JavaScript suite: 1065 passed, 2 skipped. The wake-barrier follow-up passes 5 focused tests and the combined suite. TypeScript and changed-source lint passed. Controller tests cover enabled/disabled notices, duplicates, timer cancellation, disconnect and sleeping-display recovery, locked displays, wake-barrier failure and stale async completion. A Kotlin session test checks the two-second silent cadence, normal cadence and shutdown guard. Kotlin compilation and hardware checks are tracked with the combined integration validation.
|
||||
|
||||
Hardware validation remains pending: both transitions via the temple gesture, missing exit push, phone background/foreground, lenses that are awake/asleep/locked, reconnect and charging. No firmware was flashed.
|
||||
|
||||
Follow-up after device-log inspection: both silent transitions arrived, but the exit could occur after the normal idle timeout. Exit now cancels pending suspension, wakes the shell, awaits the existing EvenHub/screen wake barrier and only then shows the notice. It resets idle activity through the ordinary wake path. Re-entry, disconnect, locking or a failed resume suppress stale asynchronous notices. Activation still turns the lenses off in firmware; phone feedback does not claim a lens-side activation popup.
|
||||
|
||||
Current combined validation after removing tilt-down/current-angle measurement: 1129 JavaScript tests passed, 2 skipped; 273 Kotlin Android host tests passed. TypeScript and changed-source lint passed. Android release build, signature and ELF/ZIP 16 KiB alignment checks passed. The rebuilt APK has not been installed during this follow-up; physical display confirmation remains pending.
|
||||
-8
@@ -12,12 +12,6 @@ class ConnectionOptions {
|
||||
// giving up. Both are dialed at once, so a slow or missing arm gets the whole
|
||||
// window (it stays under Android's own ~30 s direct-connect timeout).
|
||||
const val ARM_CONNECT_WINDOW_MS = 20_000
|
||||
// When autoConnect (background reconnect) fails to reach an arm, a direct connect
|
||||
// is retried: its aggressive scan can catch an arm that advertises only briefly,
|
||||
// and the cached bond can sometimes recover a half-open link that stopped
|
||||
// advertising after a dropped link. This is the direct retry's own window,
|
||||
// independent of ARM_CONNECT_WINDOW_MS (already spent on the autoConnect attempt).
|
||||
const val DIRECT_CONNECT_FALLBACK_TIMEOUT_MS = 15_000
|
||||
const val SERVICES_TIMEOUT_MS = 5_000
|
||||
const val DESCRIPTOR_TIMEOUT_MS = 5_000
|
||||
const val RING_DESIRED_MTU = 247
|
||||
@@ -43,8 +37,6 @@ class ConnectionOptions {
|
||||
const val HEARTBEAT_FAILURE_DEADLINE_MS = 10_000
|
||||
const val HEARTBEAT_READY_MS = 4_000
|
||||
const val HEARTBEAT_URGENT_MS = 6_000
|
||||
// Silent-off pushes are not reliable; promptly re-read the state while silent.
|
||||
const val SILENT_MODE_POLL_MS = 2_000
|
||||
const val BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000
|
||||
const val BATTERY_INPUT_QUIET_MS = 5_000
|
||||
// Poll cadence while in charging mode; also bounds how quickly we notice
|
||||
|
||||
+7
-18
@@ -2339,12 +2339,9 @@ class GlassesSessionCore(
|
||||
try {
|
||||
// Dial both arms at once, so the left arm's attempt is already pending (and
|
||||
// can land) while the right arm is being set up; they share one window.
|
||||
// autoConnect=true for both arms: a direct connection is supervised less
|
||||
// patiently by Android's stack and was observed dropping the link shortly
|
||||
// after it came up (the same failure that made the ring require autoConnect).
|
||||
val deadlineMs = now() + ConnectionOptions.ARM_CONNECT_WINDOW_MS
|
||||
link.beginConnect(rightAddress, true)
|
||||
link.beginConnect(leftAddress, true)
|
||||
link.beginConnect(rightAddress, false)
|
||||
link.beginConnect(leftAddress, false)
|
||||
connectArm(rightAddress, true, deadlineMs)
|
||||
connectArm(leftAddress, true, deadlineMs)
|
||||
if (!sleepDuringConnectSettling(800)) {
|
||||
@@ -2453,16 +2450,8 @@ class GlassesSessionCore(
|
||||
|
||||
internal fun connectArm(address: String, enableRenderNotify: Boolean, deadlineMs: Long) {
|
||||
val timeoutMs = maxOf(deadlineMs - now(), ConnectionOptions.CONNECT_TIMEOUT_MS.toLong())
|
||||
if (!link.connect(address, timeoutMs.toInt(), true)) {
|
||||
// autoConnect only connects on a fresh advertisement; an arm stuck in a
|
||||
// half-open state (it stopped advertising after a dropped link) never
|
||||
// produces one. Retry direct: the aggressive scan plus the cached bond
|
||||
// can recover it. Still unreachable after that is a real failure.
|
||||
logLine("autoConnect timed out for " + address + "; retrying direct connect")
|
||||
ConnectionCounters.increment("g2.connect-fallback-direct")
|
||||
if (!link.connect(address, ConnectionOptions.DIRECT_CONNECT_FALLBACK_TIMEOUT_MS, false)) {
|
||||
throw ArmUnreachableException(if (address.equals(leftAddress, ignoreCase = true)) "left" else "right", address)
|
||||
}
|
||||
if (!link.connect(address, timeoutMs.toInt())) {
|
||||
throw ArmUnreachableException(if (address.equals(leftAddress, ignoreCase = true)) "left" else "right", address)
|
||||
}
|
||||
// requestConnectionPriority has no callback in this Android compile target, so there is
|
||||
// no reliable completion point to keep it in the global GATT operation pipeline. But it's
|
||||
@@ -2549,9 +2538,9 @@ class GlassesSessionCore(
|
||||
logLine("connecting direct ring $ringAddress")
|
||||
// autoConnect=true (see SessionLink.connect's 3-arg overload) -
|
||||
// matches what Even's own app does for this device specifically.
|
||||
// Direct connect (false) was measured dying ~5s into an
|
||||
// otherwise-idle ring connection, repeatedly, with nothing else
|
||||
// competing for it.
|
||||
// Direct connect (false, the default used for the glasses) was
|
||||
// measured dying ~5s into an otherwise-idle ring connection,
|
||||
// repeatedly, with nothing else competing for it.
|
||||
if (!link.connect(ringAddress, ConnectionOptions.RING_CONNECT_TIMEOUT_MS, true)) {
|
||||
throw IllegalStateException("connect failed: $ringAddress")
|
||||
}
|
||||
|
||||
+2
-3
@@ -1075,9 +1075,8 @@ internal fun GlassesSessionCore.shouldPollBatteryLocked(now: Long): Boolean {
|
||||
&& sessionReady
|
||||
&& pendingMessages.isEmpty()
|
||||
&& inFlightMessages.isEmpty()
|
||||
&& (silentMode == 1 || now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS)
|
||||
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >=
|
||||
if (silentMode == 1) ConnectionOptions.SILENT_MODE_POLL_MS else ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
|
||||
&& now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS
|
||||
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
|
||||
}
|
||||
|
||||
internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage {
|
||||
|
||||
+1
-2
@@ -18,8 +18,7 @@ interface SessionLink {
|
||||
|
||||
/**
|
||||
* [connect] with the platform's background-reconnect mode (Android's autoConnect) when
|
||||
* [autoConnect] is set. The R1 ring and the G2 glasses arms both need it; platforms
|
||||
* without the distinction ignore it.
|
||||
* [autoConnect] is set. The R1 ring needs it; platforms without the distinction ignore it.
|
||||
*/
|
||||
fun connect(address: String, timeoutMs: Int, autoConnect: Boolean): Boolean = connect(address, timeoutMs)
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -361,24 +361,6 @@ class GlassesSessionCoreTest {
|
||||
} finally { s.core.close() }
|
||||
}
|
||||
|
||||
@Test fun silentModePollsPromptlyWithoutChangingNormalBatteryCadence() {
|
||||
val s = Session()
|
||||
val core = s.core
|
||||
core.monitor.withLock {
|
||||
core.sessionReady = true
|
||||
core.silentMode = 1
|
||||
core.lastBatteryRefreshAtMs = 8_000L
|
||||
core.lastConnectionOrInputAtMs = 10_000L
|
||||
assertFalse(core.shouldPollBatteryLocked(9_999L))
|
||||
assertTrue(core.shouldPollBatteryLocked(10_000L))
|
||||
core.silentMode = 0
|
||||
assertFalse(core.shouldPollBatteryLocked(10_000L))
|
||||
assertTrue(core.shouldPollBatteryLocked(308_000L))
|
||||
core.shutdownRequested = true
|
||||
assertFalse(core.shouldPollBatteryLocked(608_000L))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun brightnessConfigPrecedesFirstFrameAndSleepWakeFollowsComposites() {
|
||||
val s = Session()
|
||||
s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280)
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
function fixture() {
|
||||
const source = ts.createSourceFile('controller.ts', fs.readFileSync('app/g2/dashboard-controller.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name?.text === 'DashboardController');
|
||||
const methods = cls.members.filter(n => ['handleSilentMode', 'showSilentModeExit', 'setPhase'].includes(n.name?.getText(source)));
|
||||
const alerts = [], timers = new Map(); let next = 0, on = true, wakes = 0;
|
||||
const context = { exports: {}, setTimeout: fn => { timers.set(++next, fn); return next; }, clearTimeout: id => timers.delete(id),
|
||||
updateGlassesPresence() {}, shell: { isScreenOn: () => on, wake: () => { on = true; wakes++; }, showAlert: text => alerts.push(text),
|
||||
foregroundWindow: () => ({ requestRender() {} }), setBatteryLevels() {}, getBatteryLevels: () => ({}) } };
|
||||
vm.runInNewContext(ts.transpileModule(`export class Controller { ${methods.map(n => n.getText(source)).join('\n')} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
const c = new context.exports.Controller();
|
||||
Object.assign(c, { silentMode: false, silentModeFeedback: '', silentModeFeedbackTimer: null, silentModeFeedbackGeneration: 0, phase: 'connected', emit() {},
|
||||
cancelEvenHubSuspendTimer() {}, ensureEvenHubSessionActive: async () => true, requestShellRender() {},
|
||||
appendLog() {}, formatError: error => String(error) });
|
||||
return { c, alerts, timers, wakes: () => wakes, dark: () => { on = false; }, expire() { const callbacks = [...timers.values()]; timers.clear(); callbacks.forEach(fn => fn()); } };
|
||||
}
|
||||
test('silent activation remains visible on phone; exit waits for the display wake barrier', async () => {
|
||||
const h = fixture(); h.c.handleSilentMode(false);
|
||||
assert.equal(h.c.silentModeFeedback, '');
|
||||
h.c.handleSilentMode(true);
|
||||
assert.match(h.c.silentModeFeedback, /enabled/); assert.equal(h.timers.size, 0); assert.equal(h.alerts.length, 0);
|
||||
h.c.handleSilentMode(false);
|
||||
assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
|
||||
await new Promise(setImmediate);
|
||||
assert.deepEqual(h.alerts, ['Silent mode disabled']);
|
||||
h.expire(); assert.equal(h.c.silentModeFeedback, '');
|
||||
});
|
||||
test('repeated state reports do not duplicate feedback; an old timer cannot clear a new activation', async () => {
|
||||
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
h.c.handleSilentMode(false); await new Promise(setImmediate); assert.equal(h.alerts.length, 1);
|
||||
h.c.handleSilentMode(true); h.expire();
|
||||
assert.match(h.c.silentModeFeedback, /enabled/);
|
||||
});
|
||||
test('silent exit wakes a sleeping display before showing feedback but leaves locked glasses alone', async () => {
|
||||
for (const locked of [false, true]) {
|
||||
const h = fixture(); h.c.glassesLocked = locked; h.dark();
|
||||
h.c.handleSilentMode(true); h.c.handleSilentMode(false); await new Promise(setImmediate);
|
||||
assert.equal(h.wakes(), locked ? 0 : 1);
|
||||
assert.equal(h.alerts.length, locked ? 0 : 1);
|
||||
assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
|
||||
}
|
||||
});
|
||||
test('an unavailable session, re-entry into silence or disconnect suppresses a stale exit popup', async () => {
|
||||
for (const state of ['not-ready', 'silent', 'disconnected']) {
|
||||
const h = fixture(); let finish;
|
||||
h.c.ensureEvenHubSessionActive = () => new Promise(resolve => { finish = resolve; });
|
||||
h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
assert.equal(h.alerts.length, 0);
|
||||
if (state === 'silent') h.c.handleSilentMode(true);
|
||||
if (state === 'disconnected') h.c.setPhase('disconnected');
|
||||
finish(state !== 'not-ready'); await new Promise(setImmediate);
|
||||
assert.equal(h.alerts.length, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test('disconnect clears feedback and any pending timer without announcing a silent exit', () => {
|
||||
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
|
||||
h.c.setPhase('disconnected');
|
||||
assert.equal(h.c.silentModeFeedback, ''); assert.equal(h.timers.size, 0);
|
||||
h.expire(); assert.equal(h.c.silentModeFeedback, '');
|
||||
});
|
||||
Reference in new issue
Block a user