Compare commits

..
17 changed files with 176 additions and 167 deletions

No files matched your search

+47 -3
View File
@@ -121,6 +121,7 @@ export type DashboardSnapshot = {
* glasses, and this says which harmless thing is actually going on. * glasses, and this says which harmless thing is actually going on.
*/ */
displayPreviewMessage: string; displayPreviewMessage: string;
silentModeFeedback: string;
activeTextSettingId: string | null; activeTextSettingId: string | null;
activeTextEditorTitle: string; activeTextEditorTitle: string;
activeTextSettingTitle: string; activeTextSettingTitle: string;
@@ -294,6 +295,9 @@ class DashboardController {
/** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */ /** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */
private displayPreviewCrop: ScreenRect | null = null; private displayPreviewCrop: ScreenRect | null = null;
private silentMode = false; private silentMode = false;
private silentModeFeedback = "";
private silentModeFeedbackGeneration = 0;
private silentModeFeedbackTimer: ReturnType<typeof setTimeout> | null = null;
// Brightness value last pushed to the glasses; see pushBrightness. // Brightness value last pushed to the glasses; see pushBrightness.
private lastPushedBrightness: string | null = null; private lastPushedBrightness: string | null = null;
// Last battery level the glasses reported, kept across disconnects so a // Last battery level the glasses reported, kept across disconnects so a
@@ -1142,6 +1146,7 @@ class DashboardController {
status: this.status, status: this.status,
displayPreview: this.displayPreview, displayPreview: this.displayPreview,
displayPreviewMessage: this.displayPreviewMessage(), displayPreviewMessage: this.displayPreviewMessage(),
silentModeFeedback: this.silentModeFeedback,
activeTextSettingId: primaryTextSetting?.id ?? null, activeTextSettingId: primaryTextSetting?.id ?? null,
activeTextEditorTitle: this.activeTextEditorTitle, activeTextEditorTitle: this.activeTextEditorTitle,
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "", activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
@@ -1181,6 +1186,43 @@ class DashboardController {
* charging and silent mode both make the display unavailable while BLE stays * charging and silent mode both make the display unavailable while BLE stays
* up, and a battery that just ran out simply stops answering. * 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 { private displayPreviewMessage(): string {
if (this.phase === "charging") { if (this.phase === "charging") {
return chargingPreviewMessage(this.glassesDisplayState()); return chargingPreviewMessage(this.glassesDisplayState());
@@ -1604,9 +1646,7 @@ class DashboardController {
}); });
}); });
this.offSilentMode = communicator.onSilentMode((silent) => { this.offSilentMode = communicator.onSilentMode((silent) => {
if (this.silentMode === silent) return; this.handleSilentMode(silent);
this.silentMode = silent;
this.emit();
}); });
this.offWearState = communicator.onWearState((wearing) => { this.offWearState = communicator.onWearState((wearing) => {
this.handleWearState(wearing); this.handleWearState(wearing);
@@ -2984,6 +3024,10 @@ class DashboardController {
// Kept across "connecting": silent mode blocks app launches, so it can // Kept across "connecting": silent mode blocks app launches, so it can
// itself cause the reconnect churn, and Java re-reports it either way. // itself cause the reconnect churn, and Java re-reports it either way.
this.silentMode = false; this.silentMode = false;
this.silentModeFeedbackGeneration++;
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
this.silentModeFeedbackTimer = null;
this.silentModeFeedback = "";
} }
this.emit(); this.emit();
} }
+3
View File
@@ -74,6 +74,9 @@
class="ble-bandwidth-indicator" class="ble-bandwidth-indicator"
horizontalAlignment="center" horizontalAlignment="center"
verticalAlignment="bottom" /> verticalAlignment="bottom" />
<Label text="{{ silentModeFeedback }}" visibility="{{ silentModeFeedbackVisibility }}"
textWrap="true" horizontalAlignment="center" verticalAlignment="top"
margin="12" padding="12" backgroundColor="#333333" color="white" borderRadius="8" />
<ScrollView <ScrollView
class="warnings-modal" class="warnings-modal"
visibility="{{ warningsModalVisibility }}" visibility="{{ warningsModalVisibility }}"
+13
View File
@@ -37,6 +37,7 @@ export class MainViewModel extends RemoteControlsViewModel {
private _status = "Disconnected."; private _status = "Disconnected.";
private _displayPreview: ImageSource | null = null; private _displayPreview: ImageSource | null = null;
private _displayPreviewMessage = ""; private _displayPreviewMessage = "";
private _silentModeFeedback = "";
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation(); private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
private _landscapePreviewWidth = 0; private _landscapePreviewWidth = 0;
private _landscapePreviewHeight = 0; private _landscapePreviewHeight = 0;
@@ -90,6 +91,7 @@ export class MainViewModel extends RemoteControlsViewModel {
this.previewMode = snapshot.previewMode; this.previewMode = snapshot.previewMode;
this.displayPreview = snapshot.displayPreview; this.displayPreview = snapshot.displayPreview;
this.displayPreviewMessage = snapshot.displayPreviewMessage; this.displayPreviewMessage = snapshot.displayPreviewMessage;
this.silentModeFeedback = snapshot.silentModeFeedback ?? "";
this.phase = snapshot.phase; this.phase = snapshot.phase;
this.batteryLine = formatBatteryLine( this.batteryLine = formatBatteryLine(
snapshot.batteries, snapshot.batteries,
@@ -216,6 +218,17 @@ 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 { get hasDisplayPreview(): boolean {
return this._displayPreview !== null; return this._displayPreview !== null;
} }
-8
View File
@@ -601,14 +601,6 @@ export function getBrightnessPreferences() {
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) }; curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) };
} }
export const swapMenuGesturesSetting = new ConfigSettingBoolean({
id: "swap-menu-gestures",
label: "Long press for app menu",
storageKey: "input.swapMenuGestures",
defaultValue: false,
description: "Use long press for the app menu and tap then hold for the system menu. Apps using long press for a game action or voice capture keep their gestures. The app switcher keeps its system menu gestures.",
});
export const wakeToLastAppSetting = new ConfigSettingBoolean({ export const wakeToLastAppSetting = new ConfigSettingBoolean({
id: "wake-to-last-app", id: "wake-to-last-app",
label: "Wake into last app", label: "Wake into last app",
-2
View File
@@ -89,7 +89,6 @@ import {
voiceProviderSetting, voiceProviderSetting,
screenTimeoutSetting, screenTimeoutSetting,
wakeToLastAppSetting, wakeToLastAppSetting,
swapMenuGesturesSetting,
wakeWordActionSetting, wakeWordActionSetting,
watchCanUnlockSetting, watchCanUnlockSetting,
watchCrownClockwiseNextSetting, watchCrownClockwiseNextSetting,
@@ -126,7 +125,6 @@ function settingsSections(): SettingsSection[] {
}), }),
toggleSettingMenuItem(lockScreenEnabledSetting), toggleSettingMenuItem(lockScreenEnabledSetting),
toggleSettingMenuItem(wakeToLastAppSetting), toggleSettingMenuItem(wakeToLastAppSetting),
toggleSettingMenuItem(swapMenuGesturesSetting),
// A band (at one of five heights) / Tall / Full Screen; the // A band (at one of five heights) / Tall / Full Screen; the
// dashboard controller moves or reflows windows on change. // dashboard controller moves or reflows windows on change.
enumSettingMenuItem(displayLayoutSetting), enumSettingMenuItem(displayLayoutSetting),
+6 -17
View File
@@ -9,7 +9,6 @@ import {
directionalFallback, directionalFallback,
type DirectionalInputEvent, type DirectionalInputEvent,
GESTURE_SHORT_THEN_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS,
GESTURE_LONG_PRESS,
gestureHints, gestureHints,
InputEvent, InputEvent,
type InputEventPayload, type InputEventPayload,
@@ -53,7 +52,6 @@ import {
timeFormatSetting, timeFormatSetting,
wakeWordActionSetting, wakeWordActionSetting,
wakeToLastAppSetting, wakeToLastAppSetting,
swapMenuGesturesSetting,
windowBorderSetting, windowBorderSetting,
} from "../dashboard-settings"; } from "../dashboard-settings";
import { onAmbientCardsChanged } from "./ambient-cards"; import { onAmbientCardsChanged } from "./ambient-cards";
@@ -1063,15 +1061,7 @@ class Shell {
return { shell: false, window: false }; return { shell: false, window: false };
} }
// Remap menu intent only. Apps still receive the canonical context-menu // Long-press is the shell's own gesture: it opens the system menu
// event, while owned holds (games / voice) retain their raw input.
const menuWindow = this.foregroundWindow();
const swapMenus = this.focus === "window" && swapMenuGesturesSetting.get() &&
!menuWindow?.holdToTalk && !menuWindow?.claimsLongPress?.();
const systemMenuGesture = swapMenus ? "short-then-long-press" : "long-press";
const appMenuGesture = swapMenus ? "long-press" : "short-then-long-press";
// The resolved system gesture opens the shell's own menu
// directly, never reaching the app — over the app's own context menu // directly, never reaching the app — over the app's own context menu
// too (the window closes that on system-menu-opened), while an already // too (the window closes that on system-menu-opened), while an already
// open system menu just stays. Its later generic release is consumed // open system menu just stays. Its later generic release is consumed
@@ -1079,7 +1069,7 @@ class Shell {
// app. The exception is a window that claims long-press for a move of // app. The exception is a window that claims long-press for a move of
// its own: it gets the press forwarded, with the escape timer running // its own: it gets the press forwarded, with the escape timer running
// so that holding the press long enough still opens the system menu. // so that holding the press long enough still opens the system menu.
if (event.type === systemMenuGesture) { if (event.type === "long-press") {
if (this.activeVoiceLayer || !this.stack.isAtBase()) { if (this.activeVoiceLayer || !this.stack.isAtBase()) {
return { shell: true, window: false }; return { shell: true, window: false };
} }
@@ -1101,11 +1091,11 @@ class Shell {
return { shell: true, window: true }; return { shell: true, window: true };
} }
// The resolved app-menu gesture is delivered as tap-then-hold: it // The 2.2.9 tap-then-hold gesture is the app's context-menu gesture: it
// goes to the foreground window (from the sidebar it focuses the window // goes to the foreground window (from the sidebar it focuses the window
// first), which answers with its own menu or asks for the system menu // first), which answers with its own menu or asks for the system menu
// when it has none. // when it has none.
if (event.type === appMenuGesture) { if (event.type === "short-then-long-press") {
const window = this.foregroundWindow(); const window = this.foregroundWindow();
if (window?.holdToTalk) { if (window?.holdToTalk) {
this.openEscapeMenu(); this.openEscapeMenu();
@@ -1133,7 +1123,7 @@ class Shell {
window.onFocus?.(this.lastInput); window.onFocus?.(this.lastInput);
} }
// The window owns frameId from here (render or explicit finish). // The window owns frameId from here (render or explicit finish).
await window.handleInput(swapMenus ? { ...event, type: "short-then-long-press" } : event, frameId); await window.handleInput(event, frameId);
return { shell: true, window: true }; return { shell: true, window: true };
} }
if (event.type === "long-press-release") { if (event.type === "long-press-release") {
@@ -1990,8 +1980,7 @@ class Shell {
// when the app has one (otherwise it opens this very menu, not worth a // when the app has one (otherwise it opens this very menu, not worth a
// hint). // hint).
const footer = foreground.hasAppMenu?.() const footer = foreground.hasAppMenu?.()
? (foreground.holdToTalk ? undefined : gestureHints([[this.focus === "window" && swapMenuGesturesSetting.get() && !foreground.claimsLongPress?.() ? (foreground.holdToTalk ? undefined : gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
? GESTURE_LONG_PRESS : GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
: undefined; : undefined;
const layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar()); const layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar());
layer.selectItem(initialSelection); layer.selectItem(initialSelection);
+5 -7
View File
@@ -1,4 +1,3 @@
import { swapMenuGesturesSetting } from "./dashboard-settings";
import { GrayImage } from "../graphics/image"; import { GrayImage } from "../graphics/image";
import { singlePlane, type Plane } from "../graphics/plane"; import { singlePlane, type Plane } from "../graphics/plane";
import { GESTURE_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures"; import { GESTURE_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
@@ -7,9 +6,8 @@ import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem, type MenuLayout } from "./m
import type { WorkerAppReply } from "./shell/worker-window"; import type { WorkerAppReply } from "./shell/worker-window";
/** /**
* The window context menu, opened by tap-then-hold by default: an app's own menu, * The window context menu, opened by tap-then-hold: an app's own menu,
* holding its app-specific actions. The menu gesture preference can swap * holding its app-specific actions. The shell's system menu (long-press)
* these bindings unless the app owns long-press. The shell's system menu
* carries the entries every window shares — Focus app switcher, Voice input, * carries the entries every window shares — Focus app switcher, Voice input,
* Close window — so an app with nothing of its own to offer has no menu of * Close window — so an app with nothing of its own to offer has no menu of
* its own: tap-then-hold then opens the system menu in its place, so both * its own: tap-then-hold then opens the system menu in its place, so both
@@ -30,8 +28,8 @@ export const WINDOW_MENU_LAYOUT: MenuLayout = {
}; };
export class WindowMenuLayer extends MenuLayer { export class WindowMenuLayer extends MenuLayer {
constructor(title: string | null, items: MenuItem[], holdToTalk = false, claimsLongPress = false) { constructor(title: string | null, items: MenuItem[], holdToTalk = false) {
super(title, items, (holdToTalk || (swapMenuGesturesSetting.get() && !claimsLongPress)) super(title, items, holdToTalk
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) } ? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
: WINDOW_MENU_LAYOUT); : WINDOW_MENU_LAYOUT);
} }
@@ -125,7 +123,7 @@ export class WindowMenu {
handleInput: () => {}, handleInput: () => {},
}; };
const stack = new LayerStack(base, this.layerActions(), this.options.size, this.options.isFocused); const stack = new LayerStack(base, this.layerActions(), this.options.size, this.options.isFocused);
const layer = new WindowMenuLayer(title, items, false, this.options.claimsLongPress?.() ?? false); const layer = new WindowMenuLayer(title, items);
if (selectedIndex !== undefined) layer.selectItem(selectedIndex); if (selectedIndex !== undefined) layer.selectItem(selectedIndex);
stack.push(layer); stack.push(layer);
this.stack = stack; this.stack = stack;
-9
View File
@@ -1,9 +0,0 @@
# Configurable menu gestures
Settings > Display > Long press for app menu is off by default, preserving existing installations. When enabled with an app focused, long press opens its context menu and tap then hold opens the system menu. The preference uses the existing ConfigSettingBoolean/settings store and takes effect on subsequent input without restarting.
Windows claiming long press retain that input, their existing tap-then-hold app menu and the extended-hold system escape. Hold-to-talk windows retain voice capture and tap-then-hold for the system menu. The app switcher retains its existing bindings. Empty app menus continue to fall back to the system menu. The shell delivers the canonical tap-then-hold context-menu event to apps, so worker and EvenHub input contracts do not change. Menu gesture hints follow the preference and exceptions.
Software validation: TypeScript and changed-source lint; full JavaScript suite (1072 passed, 2 skipped on the independent branch). Routing tests cover both mappings, overlay switching, input metadata, dynamic hold ownership, switcher behavior and screen-off input. Persistence tests cover default, enabled and disabled values after store reload. App-menu hint tests cover owned holds and voice capture.
Hardware validation remains pending: test both bindings on the glasses/ring, app-specific holds, voice release, extended-hold escape, switching menus, app switcher, and restart. No firmware was flashed.
+11
View File
@@ -0,0 +1,11 @@
# 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.
Independent JavaScript suite: 1065 passed, 2 skipped. 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.
@@ -37,6 +37,8 @@ class ConnectionOptions {
const val HEARTBEAT_FAILURE_DEADLINE_MS = 10_000 const val HEARTBEAT_FAILURE_DEADLINE_MS = 10_000
const val HEARTBEAT_READY_MS = 4_000 const val HEARTBEAT_READY_MS = 4_000
const val HEARTBEAT_URGENT_MS = 6_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_REFRESH_INTERVAL_MS = 5 * 60_000
const val BATTERY_INPUT_QUIET_MS = 5_000 const val BATTERY_INPUT_QUIET_MS = 5_000
// Poll cadence while in charging mode; also bounds how quickly we notice // Poll cadence while in charging mode; also bounds how quickly we notice
@@ -1041,8 +1041,9 @@ internal fun GlassesSessionCore.shouldPollBatteryLocked(now: Long): Boolean {
&& sessionReady && sessionReady
&& pendingMessages.isEmpty() && pendingMessages.isEmpty()
&& inFlightMessages.isEmpty() && inFlightMessages.isEmpty()
&& now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS && (silentMode == 1 || now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS)
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS) && (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >=
if (silentMode == 1) ConnectionOptions.SILENT_MODE_POLL_MS else ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
} }
internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage { internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage {
+1 -1
View File
@@ -266,7 +266,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
handleInput(event, ctx) { if (event.type === 'double-click') ctx.stack.pop(); } handleInput(event, ctx) { if (event.type === 'double-click') ctx.stack.pop(); }
} }
const voiceDialogs = []; const voiceDialogs = [];
const settings = { swapMenuGesturesSetting: { get: () => false }, wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' }, const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
assistantSkipConfirmationSetting: { get: () => skipConfirmation } }; assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', { const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) }, '../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
-11
View File
@@ -59,14 +59,3 @@ test('curve drafts preview exactly while brightness keeps the previous valid sav
assert.equal(curve.validationError(), null); assert.equal(curve.validationError(), null);
assert.equal(api.getBrightnessPreferences().curve, '0:0,2:50,6:100'); assert.equal(api.getBrightnessPreferences().curve, '0:0,2:50,6:100');
}); });
test('menu gesture preference preserves defaults and survives restart in either state', () => {
const store = new Map();
let api = settingsFixture(store);
assert.equal(api.swapMenuGesturesSetting.get(), false);
api.swapMenuGesturesSetting.set(true);
api = settingsFixture(store);
assert.equal(api.swapMenuGesturesSetting.get(), true);
api.swapMenuGesturesSetting.set(false);
assert.equal(settingsFixture(store).swapMenuGesturesSetting.get(), false);
});
-1
View File
@@ -39,7 +39,6 @@ const menu = load('app/ui/menu.ts', {
function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) { function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) {
let value = initial, writes = 0, closed = 0; let value = initial, writes = 0, closed = 0;
const settings = { const settings = {
swapMenuGesturesSetting: { get: () => false },
brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } }, brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } },
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value), brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
}; };
@@ -316,6 +316,24 @@ private class Session {
} }
class GlassesSessionCoreTest { class GlassesSessionCoreTest {
@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() { @Test fun brightnessConfigPrecedesFirstFrameAndSleepWakeFollowsComposites() {
val s = Session() val s = Session()
s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280) s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280)
-106
View File
@@ -1,106 +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(swap = false, app = {}) {
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');
class Overlay {}
const context = { exports: {}, ShellOverlayMenuLayer: Overlay,
swapMenuGesturesSetting: { get: () => swap }, isWatchInput: () => false };
vm.runInNewContext(ts.transpileModule(`export class Shell { ${route.getText(source)} }`, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
const s = new context.exports.Shell();
const delivered = [];
const window = { handleInput: async e => delivered.push(e), hasAppMenu: () => true, ...app };
let overlay = false, escapes = 0;
Object.assign(s, { focus: 'window', screenOn: true, lastInput: null,
foregroundWindow: () => window, cancelEscapeMenuTimer() {},
startEscapeMenuTimer() { escapes++; }, config: { requestShellRender() {} },
openEscapeMenu() { overlay = true; },
stack: { isAtBase: () => !overlay, popIfTop(fn) { if (overlay && fn(new Overlay())) { overlay = false; return true; } return false; } },
});
return { s, delivered, setSwap: value => { swap = value; }, overlay: () => overlay, escapes: () => escapes,
input: type => s.routeInput({ type, source: 'ring', timestampMs: 42 }, 17) };
}
for (const swap of [false, true]) {
test(`menu routing, overlay switching and metadata with inversion ${swap}`, async () => {
const h = fixture(swap);
const system = swap ? 'short-then-long-press' : 'long-press';
const app = swap ? 'long-press' : 'short-then-long-press';
await h.input(app);
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
assert.equal(h.delivered.at(-1).source, 'ring');
assert.equal(h.delivered.at(-1).timestampMs, 42);
await h.input(system);
assert.equal(h.overlay(), true);
await h.input(app);
assert.equal(h.overlay(), false);
assert.equal(h.delivered.length, 2);
});
for (const app of [{ claimsLongPress: () => true }, { holdToTalk: true }]) {
test(`owned long press remains intact with inversion ${swap}: ${JSON.stringify(Object.keys(app))}`, async () => {
const h = fixture(swap, app);
await h.input('long-press');
assert.equal(h.delivered[0].type, 'long-press');
assert.equal(h.escapes(), app.holdToTalk ? 0 : 1);
await h.input('short-then-long-press');
if (app.holdToTalk) assert.equal(h.overlay(), true);
else assert.equal(h.delivered[1].type, 'short-then-long-press');
});
}
}
test('gesture inversion never wakes a sleeping screen', async () => {
const h = fixture(true); h.s.screenOn = false;
await h.input('long-press'); await h.input('short-then-long-press');
assert.equal(h.delivered.length, 0); assert.equal(h.overlay(), false);
});
test('the switcher retains its existing gestures when inversion is enabled', async () => {
for (const type of ['long-press', 'short-then-long-press']) {
const snapshots = [];
for (const swap of [false, true]) {
const h = fixture(swap); h.s.focus = 'sidebar';
await h.input(type);
snapshots.push({ overlay: h.overlay(), delivered: h.delivered.map(e => e.type) });
}
assert.deepEqual(snapshots[0], snapshots[1]);
}
});
test('the setting applies immediately and follows changing app hold ownership', async () => {
let claims = false;
const h = fixture(false, { claimsLongPress: () => claims });
h.setSwap(true);
await h.input('long-press');
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
claims = true;
await h.input('long-press');
assert.equal(h.delivered.at(-1).type, 'long-press');
claims = false;
await h.input('long-press');
assert.equal(h.delivered.at(-1).type, 'short-then-long-press');
});
test('app menu hints reflect inversion, voice capture and owned holds', () => {
const source = ts.createSourceFile('window-menu.ts', fs.readFileSync('app/ui/window-menu.ts', 'utf8'), ts.ScriptTarget.Latest, true);
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'WindowMenuLayer');
let swap = false;
const context = { exports: {}, MenuLayer: class { constructor(_title, _items, layout) { this.layout = layout; } },
WINDOW_MENU_LAYOUT: { footer: 'long-press' }, GESTURE_SHORT_THEN_LONG_PRESS: 'tap-hold',
swapMenuGesturesSetting: { get: () => swap }, gestureHints: hints => hints[0][0] };
vm.runInNewContext(ts.transpileModule(cls.getText(source), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
const hint = (voice = false, claims = false) => new context.exports.WindowMenuLayer('App', [], voice, claims).layout.footer;
assert.equal(hint(), 'long-press');
swap = true;
assert.equal(hint(), 'tap-hold');
assert.equal(hint(false, true), 'long-press');
assert.equal(hint(true), 'tap-hold');
});
+67
View File
@@ -0,0 +1,67 @@
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, '');
});