Merge silent-mode feedback

# Conflicts:
#	tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlassesSessionCoreTest.kt
This commit is contained in:
Blendman974 committed 2026-11-06 21:48:38 +01:00
commit 3aeed72f5d
8 files changed
+128 -5

No files matched your search

+31 -3
View File
@@ -121,6 +121,7 @@ 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;
@@ -294,6 +295,8 @@ 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 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;
@@ -1160,6 +1163,7 @@ class DashboardController {
status: this.status,
displayPreview: this.displayPreview,
displayPreviewMessage: this.displayPreviewMessage(),
silentModeFeedback: this.silentModeFeedback,
activeTextSettingId: primaryTextSetting?.id ?? null,
activeTextEditorTitle: this.activeTextEditorTitle,
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
@@ -1199,6 +1203,29 @@ 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;
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) {
// Do not wake a sleeping/locked display merely to announce a state change.
if (this.phase === "connected" && shell.isScreenOn() && !this.glassesLocked) {
shell.showAlert("Silent mode disabled");
shell.foregroundWindow()?.requestRender();
}
this.silentModeFeedbackTimer = setTimeout(() => {
this.silentModeFeedbackTimer = null;
this.silentModeFeedback = "";
this.emit();
}, 5000);
}
this.emit();
}
private displayPreviewMessage(): string {
if (this.phase === "charging") {
return chargingPreviewMessage(this.glassesDisplayState());
@@ -1624,9 +1651,7 @@ class DashboardController {
});
});
this.offSilentMode = communicator.onSilentMode((silent) => {
if (this.silentMode === silent) return;
this.silentMode = silent;
this.emit();
this.handleSilentMode(silent);
});
this.offWearState = communicator.onWearState((wearing) => {
this.handleWearState(wearing);
@@ -3004,6 +3029,9 @@ 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;
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
this.silentModeFeedbackTimer = null;
this.silentModeFeedback = "";
}
this.emit();
}
+3
View File
@@ -74,6 +74,9 @@
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 }}"
+13
View File
@@ -37,6 +37,7 @@ 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;
@@ -90,6 +91,7 @@ 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.batteryLine = formatBatteryLine(
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 {
return this._displayPreview !== null;
}
+9
View File
@@ -0,0 +1,9 @@
# 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. Awake, unlocked glasses also show the existing alert popup on exit; no display is woken solely for feedback. 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/locked displays. 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.
@@ -37,6 +37,8 @@ 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
@@ -1042,8 +1042,9 @@ internal fun GlassesSessionCore.shouldPollBatteryLocked(now: Long): Boolean {
&& sessionReady
&& pendingMessages.isEmpty()
&& inFlightMessages.isEmpty()
&& now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS
&& (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS)
&& (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)
}
internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage {
@@ -343,6 +343,24 @@ 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)
+49
View File
@@ -0,0 +1,49 @@
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', 'setPhase'].includes(n.name?.getText(source)));
const alerts = [], timers = new Map(); let next = 0, on = true;
const context = { exports: {}, setTimeout: fn => { timers.set(++next, fn); return next; }, clearTimeout: id => timers.delete(id),
updateGlassesPresence() {}, shell: { isScreenOn: () => on, 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, phase: 'connected', emit() {} });
return { c, alerts, timers, dark: () => { on = false; }, expire() { const callbacks = [...timers.values()]; timers.clear(); callbacks.forEach(fn => fn()); } };
}
test('silent activation remains visible on phone; exit is visible on phone and awake glasses', () => {
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');
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', () => {
const h = fixture(); h.c.handleSilentMode(true); h.c.handleSilentMode(false);
h.c.handleSilentMode(false); assert.equal(h.alerts.length, 1);
h.c.handleSilentMode(true); h.expire();
assert.match(h.c.silentModeFeedback, /enabled/);
});
test('silent exit never wakes a sleeping or locked display for its announcement', () => {
for (const locked of [false, true]) {
const h = fixture(); if (locked) h.c.glassesLocked = true; else h.dark();
h.c.handleSilentMode(true); h.c.handleSilentMode(false);
assert.equal(h.alerts.length, 0); assert.equal(h.c.silentModeFeedback, 'Silent mode disabled');
}
});
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, '');
});