Show G2 charging case on Settings tab and charging view rather than main activity

This commit is contained in:
James Babcock committed 2026-11-02 00:30:21 -08:00
1 parent 5e729d1236
commit 27756913d0
17 files changed
+277 -83

No files matched your search

+16 -2
View File
@@ -98,7 +98,13 @@ import { createNotificationsAppWindow, NOTIFICATIONS_SURFACE_ID, NOTIFICATIONS_W
import { isInstalledPackagePresent } from "../apps/evenhub/updates";
import { wearerVerificationOptions } from "../apps/microphones/speakers";
import { micSession } from "../apps/microphones/mic-session";
import { glassesDisplayAsleep, glassesDisplayLabel, type GlassesDisplayState } from "./glasses-display-state";
import {
chargingPreviewMessage,
glassesDisplayAsleep,
glassesDisplayDetail,
glassesDisplayLabel,
type GlassesDisplayState,
} from "./glasses-display-state";
import { PreviewDisplayTarget, type DisplayTarget } from "../native/preview-display";
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting";
@@ -1177,7 +1183,7 @@ class DashboardController {
*/
private displayPreviewMessage(): string {
if (this.phase === "charging") {
return this.glassesDisplayLabel();
return chargingPreviewMessage(this.glassesDisplayState());
}
if (this.silentMode && this.phase === "connected") {
// Say how to leave it. Silent mode is entered and exited only by the
@@ -1209,17 +1215,25 @@ class DashboardController {
return glassesDisplayLabel(this.glassesDisplayState());
}
/** The smaller line the watch face shows under that one, or "" (the case level while charging). */
glassesDisplayDetail(): string {
return glassesDisplayDetail(this.glassesDisplayState());
}
/** Whether that line reads "Display off" (the watch face adds a wake hint under it). */
glassesDisplayAsleep(): boolean {
return glassesDisplayAsleep(this.glassesDisplayState());
}
private glassesDisplayState(): GlassesDisplayState {
const batteries = shell.getBatteryLevels();
return {
phase: this.phase,
silentMode: this.silentMode,
screenOn: shell.isScreenOn(),
battery: this.lastHeadsetBattery,
caseBattery: batteries.case,
caseCharging: batteries.caseCharging,
foregroundTitle: shell.getForegroundApp()?.title ?? null,
previewMode: this.isPreviewDisplayActive(),
};
+55
View File
@@ -3,6 +3,13 @@ export type GlassesDisplayState = {
silentMode: boolean;
screenOn: boolean;
battery: number | null;
/**
* The charging case's last-known level, and whether it is on USB (null
* while the glasses are out of the case). Shown only while charging, when
* the glasses are docked and the case reading is live.
*/
caseBattery: number | null;
caseCharging: boolean | null;
foregroundTitle: string | null;
/** The headless preview display is standing in for a connection (preview-only mode). */
previewMode: boolean;
@@ -29,6 +36,20 @@ export function glassesDisplayLabel(state: GlassesDisplayState): string {
return state.foregroundTitle || "Launcher";
}
/**
* The smaller line under that label on the watch face, or "": the case
* level while the glasses charge in it.
*/
export function glassesDisplayDetail(state: GlassesDisplayState): string {
if (state.phase !== "charging") return "";
return validBatteryLevel(state.caseBattery) ? batteryEntry("Case", state.caseBattery, state.caseCharging) : "";
}
/** The phone mirror's stand-in while charging: the label and its detail on one line. */
export function chargingPreviewMessage(state: GlassesDisplayState): string {
return [glassesDisplayLabel(state), glassesDisplayDetail(state)].filter(Boolean).join(" · ");
}
/**
* True when the label reads "Display off": the screen is dark but the glasses
* (or the preview standing in for them) would light it on a wake gesture.
@@ -46,6 +67,40 @@ export function chargingDisplayLabel(battery: number | null): string {
return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging";
}
/** The shell's last-known battery levels (ShellChromeState["battery"]), as far as the phone shows them. */
export type BatteryLevels = {
headset: number | null;
headsetCharging: boolean | null;
case: number | null;
caseCharging: boolean | null;
ring: number | null;
ringCharging: boolean | null;
};
/**
* The phone Settings tab's battery row: each device whose level is known,
* e.g. "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging), or "" when none
* is. Levels are the last known ones (the case only reports while the glasses
* are docked), so ⚡ appears only while it is live: G2 and Case only with a
* link to the glasses (`glassesLinked`: connected or charging), and Case only
* while they are docked (caseCharging is null otherwise).
*/
export function formatBatteryLine(levels: BatteryLevels, glassesLinked: boolean): string {
const devices: Array<[string, number | null, boolean | null]> = [
["G2", levels.headset, glassesLinked && levels.headsetCharging],
["Case", levels.case, glassesLinked && levels.caseCharging],
["R1", levels.ring, levels.ringCharging],
];
return devices
.filter((device): device is [string, number, boolean | null] => validBatteryLevel(device[1]))
.map(([label, level, charging]) => batteryEntry(label, level, charging))
.join(" · ");
}
function batteryEntry(label: string, level: number, charging: boolean | null): string {
return `${label} ${level}%${charging ? " ⚡" : ""}`;
}
function validBatteryLevel(battery: number | null): battery is number {
return battery !== null && Number.isInteger(battery) && battery >= 0 && battery <= 100;
}
+2
View File
@@ -263,6 +263,8 @@ export class WearRemote {
listening: voiceActivity.isActive(),
battery: state.lastHeadsetBattery,
charging: state.phase === "charging" || battery.headsetCharging === true,
caseBattery: battery.case,
caseCharging: battery.caseCharging,
silentMode: state.silentMode,
foreground: foreground ? { appId: foreground.appId, title: foreground.title } : null,
windows: shell.getWindows().map((window) => ({