Watch display shows if glasses are charging or silent mode

This commit is contained in:
James Babcock committed 2026-08-28 18:36:35 -07:00
1 parent ed8302bc6b
commit 6cd7d5fff9
10 files changed
+122 -20

No files matched your search

+32 -9
View File
@@ -66,6 +66,7 @@ import {
uninstallEvenHubPackage,
} from "../apps/evenhub/installed-apps";
import { closeRunningPackage, launchInstalledPackage } from "../apps/evenhub/manager";
import { glassesDisplayLabel } from "./glasses-display-state";
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting";
@@ -300,12 +301,13 @@ class DashboardController {
requestShellRender: () => this.requestShellRender(),
onWindowsChanged: () => {
this.persistOpenApps();
this.wearRemote?.schedulePublish();
// The foreground title is mirrored on both remote-control faces.
this.emit();
},
onScreenStateChanged: (on) => {
this.handleScreenStateChanged(on);
if (on) this.requestShellRender();
this.wearRemote?.schedulePublish();
this.emit();
},
});
// Boot hooks register windows that exist from startup (the launcher,
@@ -353,6 +355,8 @@ class DashboardController {
status: this.status,
glassesLocked: this.glassesLocked,
glassesWorn: this.glassesWorn,
silentMode: this.silentMode,
lastHeadsetBattery: this.lastHeadsetBattery,
}),
appendLog: (line) => this.appendLog(line),
});
@@ -847,12 +851,15 @@ class DashboardController {
/**
* Message to show in place of the display preview, or "" to show the preview.
*
* Both cases look identical to a dead pair of glasses from the phone side:
* silent mode blanks the display and swallows input while the BLE session
* stays up, and a battery that just ran out simply stops answering.
* These states look identical to a dead pair of glasses from the phone side:
* charging and silent mode both make the display unavailable while BLE stays
* up, and a battery that just ran out simply stops answering.
*/
private displayPreviewMessage(): string {
if (this.silentMode && (this.phase === "connected" || this.phase === "charging")) {
if (this.phase === "charging") {
return this.glassesDisplayLabel();
}
if (this.silentMode && this.phase === "connected") {
return "Connected (Silent mode enabled)";
}
const connectionFailing = this.phase === "disconnected" || this.phase === "connecting";
@@ -866,6 +873,17 @@ class DashboardController {
return "";
}
/** What occupies the foreground-title line on the watch-style controls. */
glassesDisplayLabel(): string {
return glassesDisplayLabel({
phase: this.phase,
silentMode: this.silentMode,
screenOn: shell.isScreenOn(),
battery: this.lastHeadsetBattery,
foregroundTitle: shell.getForegroundApp()?.title ?? null,
});
}
/**
* Re-check the Doze exemption (cheap system call, but cached so snapshot()
* stays trivial). Called on connect, page load, and after the user answers
@@ -1047,16 +1065,21 @@ class DashboardController {
this.handlePhoneLockState(locked);
});
this.offBattery = communicator.onBatteryState((state) => {
this.lastHeadsetBattery = state.battery >= 0 ? state.battery : null;
// An unavailable reading must not erase the useful last-known value,
// especially while the glasses remain reachable in their case.
const hasBatteryLevel = Number.isInteger(state.battery) && state.battery >= 0 && state.battery <= 100;
if (hasBatteryLevel) this.lastHeadsetBattery = state.battery;
shell.setBatteryLevels({
headset: state.battery,
headset: hasBatteryLevel ? state.battery : this.lastHeadsetBattery,
headsetCharging: state.chargingStatus > 0,
});
if ((this.phase === "connected" || this.phase === "charging") && this.communicator) {
// Repaint the top bar (battery indicators live in the shell chrome).
this.requestShellRender();
}
this.wearRemote?.schedulePublish();
// Battery belongs in the charging stand-in on the phone as well as in
// the watch state, so refresh both consumers on every report.
this.emit();
});
this.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
this.refreshEvenAppStatus();
+34
View File
@@ -0,0 +1,34 @@
export type GlassesDisplayState = {
phase: string;
silentMode: boolean;
screenOn: boolean;
battery: number | null;
foregroundTitle: string | null;
};
/** Compact status shown where the foreground-window title normally lives. */
export function glassesDisplayLabel(state: GlassesDisplayState): string {
// Charging wins over every session-local state: the glasses are in their
// case, so neither the lock screen nor the foreground window is visible.
if (state.phase === "charging") {
return chargingDisplayLabel(state.battery);
}
if (state.phase !== "connected") {
return "Glasses disconnected";
}
if (state.silentMode) {
return "Silent mode";
}
if (!state.screenOn) {
return "Display off";
}
return state.foregroundTitle || "Launcher";
}
export function chargingDisplayLabel(battery: number | null): string {
return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging";
}
function validBatteryLevel(battery: number | null): battery is number {
return battery !== null && Number.isInteger(battery) && battery >= 0 && battery <= 100;
}
+5 -2
View File
@@ -102,6 +102,8 @@ export type WearRemoteHost = {
status: string;
glassesLocked: boolean;
glassesWorn: boolean | null;
silentMode: boolean;
lastHeadsetBattery: number | null;
};
appendLog: (line: string) => void;
};
@@ -196,8 +198,9 @@ export class WearRemote {
locked: state.glassesLocked,
worn: state.glassesWorn,
listening: voiceActivity.isActive(),
battery: battery.headset,
charging: battery.headsetCharging === true,
battery: state.lastHeadsetBattery,
charging: state.phase === "charging" || battery.headsetCharging === true,
silentMode: state.silentMode,
foreground: foreground ? { appId: foreground.appId, title: foreground.title } : null,
windows: shell.getWindows().map((window) => ({
windowId: window.windowId,
+1 -4
View File
@@ -766,10 +766,7 @@ export class MainViewModel extends Observable {
/** What the next gesture lands on, as the watch pad shows it. */
get padFocusLine(): string {
if (this.phase !== "connected" && this.phase !== "charging") return "Glasses disconnected";
if (!shell.isScreenOn()) return "Display off";
const foreground = shell.getForegroundApp();
return foreground ? foreground.title : "Launcher";
return dashboardController.glassesDisplayLabel();
}
private refreshPadFocusLine(): void {
+29
View File
@@ -0,0 +1,29 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { chargingDisplayLabel, glassesDisplayLabel } = require("../.test-build/app/g2/glasses-display-state.js");
const connected = {
phase: "connected",
silentMode: false,
screenOn: true,
battery: 72,
foregroundTitle: "Music",
};
test("the foreground-title line covers visible, dark, and silent displays", () => {
assert.equal(glassesDisplayLabel(connected), "Music");
assert.equal(glassesDisplayLabel({ ...connected, foregroundTitle: null }), "Launcher");
assert.equal(glassesDisplayLabel({ ...connected, screenOn: false }), "Display off");
assert.equal(glassesDisplayLabel({ ...connected, screenOn: false, silentMode: true }), "Silent mode");
});
test("charging takes precedence and includes the last-known G2 battery", () => {
assert.equal(
glassesDisplayLabel({ ...connected, phase: "charging", silentMode: true, screenOn: false }),
"Charging · G2 72%",
);
assert.equal(chargingDisplayLabel(null), "Charging");
assert.equal(chargingDisplayLabel(-1), "Charging");
assert.equal(chargingDisplayLabel(101), "Charging");
});
+1
View File
@@ -15,6 +15,7 @@
"../app/g2/ble-proximity.ts",
"../app/g2/even-advertisement.ts",
"../app/g2/glasses-artwork.ts",
"../app/g2/glasses-display-state.ts",
"../app/g2/pairing-candidates.ts"
]
}
+5 -1
View File
@@ -49,7 +49,7 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
"protocol": 1, "version": "…",
"phase": "connected", "status": "…", "connected": true,
"screenOn": true, "locked": false, "worn": true, "listening": false,
"battery": 78, "charging": false,
"battery": 78, "charging": false, "silentMode": false,
"foreground": {"appId": "music", "title": "Music"},
"windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}],
"apps": [{"appId": "timer", "title": "Timer"}],
@@ -60,6 +60,10 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
}
```
`battery` is the current or last-known G2 percentage. `charging` and
`silentMode` identify the two states in which the glasses display is not
visible even though the BLE session remains available.
`protocol` is reserved for incompatible revisions of this format (nothing
checks it yet); `displayMode` mirrors the phone's Display > Display mode and
is what the `display-mode` command changes. `crownClockwiseNext` mirrors the
@@ -100,9 +100,10 @@ data class PhoneState(
val listening: Boolean,
/** Display mode wire value ("576x288" | "576x480" | "640x480"). */
val displayMode: String,
// The state item also carries "battery"; the watch doesn't show it (the
// glasses' own top bar does), so it is left unparsed.
/** Current or last-known G2 charge percentage. */
val battery: Int?,
val charging: Boolean,
val silentMode: Boolean,
val foreground: AppEntry?,
val windows: List<WindowEntry>,
val apps: List<AppEntry>,
@@ -129,7 +130,9 @@ data class PhoneState(
worn = if (o.isNull("worn")) null else o.optBoolean("worn"),
listening = o.optBoolean("listening", false),
displayMode = o.optString("displayMode", "576x288"),
battery = if (o.isNull("battery")) null else o.optInt("battery", -1).takeIf { it in 0..100 },
charging = o.optBoolean("charging", false),
silentMode = o.optBoolean("silentMode", false),
foreground = foreground?.let {
AppEntry(it.optString("appId", ""), it.optString("title", ""))
},
@@ -63,6 +63,8 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
state == null -> StatusLine("Waiting for phone", StatusTone.BUSY)
state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM)
state.connected -> when {
state.charging || state.phase == "charging" -> StatusLine(chargingLine(state.battery), StatusTone.BUSY)
state.silentMode -> StatusLine("Silent mode", StatusTone.OFF)
state.locked -> StatusLine("Locked", StatusTone.OFF)
!state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
state.listening -> StatusLine("Listening…", StatusTone.BUSY)
@@ -73,6 +75,9 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
else -> StatusLine("Glasses disconnected", StatusTone.OFF)
}
private fun chargingLine(battery: Int?): String =
if (battery != null) "Charging · G2 $battery%" else "Charging"
fun StatusTone.color(): Color = when (this) {
StatusTone.GOOD -> Color(0xFF7BD88F)
StatusTone.BUSY -> Color(0xFFF2C14E)
@@ -42,10 +42,13 @@ fun StatusScreen(link: PhoneLink, haptics: Haptics, onOpenSettings: () -> Unit)
ScalingLazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
item { ListHeader { Text("Glasses") } }
item {
// No battery figure here: the glasses' own top bar shows it.
// Ordinarily the glasses' own top bar shows battery. While
// charging that screen is inside the case, so show it here.
val phaseLabel = when {
state == null -> "No status yet"
connected -> "Connected" + if (state?.charging == true) " · charging" else ""
state?.charging == true || state?.phase == "charging" ->
state?.battery?.let { "Charging · G2 $it%" } ?: "Charging"
connected -> "Connected"
state?.phase == "connecting" -> "Connecting…"
state?.phase == "disconnecting" -> "Disconnecting…"
else -> "Disconnected"