From 27756913d0612b964e61d69dd5d03bd8c081c8fa Mon Sep 17 00:00:00 2001 From: James Babcock Date: Mon, 2 Nov 2026 00:30:21 -0800 Subject: [PATCH] Show G2 charging case on Settings tab and charging view rather than main activity --- app/app.css | 7 --- app/g2/dashboard-controller.ts | 18 +++++- app/g2/glasses-display-state.ts | 55 +++++++++++++++++ app/g2/wear-remote.ts | 2 + app/phone-ui/main-page.ios.ts | 13 +++- app/phone-ui/main-page.xml | 12 ++-- app/phone-ui/main-view-model.ts | 51 ++++------------ app/phone-ui/remote-controls-view-model.ts | 32 +++++++++- app/phone-ui/remote-controls.css | 9 +++ app/phone-ui/remote-controls.xml | 23 ++++--- tests/glasses-display-state.test.cjs | 41 ++++++++++++- tests/ios-app-host.test.cjs | 3 + wear/PROTOCOL.md | 7 +++ .../main/kotlin/com/faceclaw/wear/Protocol.kt | 6 ++ .../com/faceclaw/wear/ui/AmbientScreen.kt | 10 +-- .../kotlin/com/faceclaw/wear/ui/Common.kt | 61 ++++++++++++++++++- .../com/faceclaw/wear/ui/RemoteScreen.kt | 10 +-- 17 files changed, 277 insertions(+), 83 deletions(-) diff --git a/app/app.css b/app/app.css index 0eb26377..b59200cd 100644 --- a/app/app.css +++ b/app/app.css @@ -136,13 +136,6 @@ Button.-primary { text-align: center; } -/* Battery levels under the mirror (main-page.xml). */ -.battery-line { - font-size: 14; - text-align: center; - padding: 12 16 0 16; -} - .system-name-modal { margin: 16; padding: 16; diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 6da48736..43ce0f71 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -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(), }; diff --git a/app/g2/glasses-display-state.ts b/app/g2/glasses-display-state.ts index c9e51e4b..20a7a736 100644 --- a/app/g2/glasses-display-state.ts +++ b/app/g2/glasses-display-state.ts @@ -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; } diff --git a/app/g2/wear-remote.ts b/app/g2/wear-remote.ts index 9ce66457..92a62902 100644 --- a/app/g2/wear-remote.ts +++ b/app/g2/wear-remote.ts @@ -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) => ({ diff --git a/app/phone-ui/main-page.ios.ts b/app/phone-ui/main-page.ios.ts index 5ce75e5d..5f647c99 100644 --- a/app/phone-ui/main-page.ios.ts +++ b/app/phone-ui/main-page.ios.ts @@ -10,6 +10,8 @@ import { sampleBleTraffic } from '../native/ble-traffic' import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings' import { loadDeviceAddresses } from '../g2/device-addresses' import { deviceAddressError } from '../g2/ios-peripheral-identity' +import { formatBatteryLine } from '../g2/glasses-display-state' +import { shell } from '../ui/shell/shell' export function createMainPage(): Page { const page = new Page() @@ -70,6 +72,10 @@ export function createMainPage(): Page { keyboardPanel.bindingContext = keyboardModel GridLayout.setRow(keyboardPanel, 1); root.addChild(keyboardPanel) let focusTimer: ReturnType | null = null + // The Settings tab's battery row. iOS reports charging sessions as + // connected, so "connected" is the whole live-link condition here. + let glassesLinked = false + const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked) } const keyboardField = () => keyboardPanel.getViewById('keyboardInputField') const controller = new IosPreviewController((image, label) => { mirror.imageSource = image; model.set('padFocusLine', label) @@ -79,6 +85,7 @@ export function createMainPage(): Page { state.text = ({ connected: 'Connected', disconnected: 'Preview', connecting: 'Connecting', retrying: 'Reconnecting', disconnecting: 'Disconnecting', error: 'Failed' })[connection.phase] warning.visibility = connection.firmwareWarning ? 'visible' : 'collapse' + glassesLinked = connection.phase === 'connected'; refreshBatteryLine() }, session => { keyboardModel.setSession(session) controls.visibility = session ? 'collapse' : 'visible' @@ -256,6 +263,7 @@ export function createMainPage(): Page { const resume = () => { foreground = true; controller.resume(); syncBandwidth() } let keyboardObserver: any = null let offSettings: (() => void) | null = null + let offBattery: (() => void) | null = null page.on('loaded', () => { if (!keyboardObserver) keyboardObserver = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock( UIKeyboardWillChangeFrameNotification, null, NSOperationQueue.mainQueue, notification => { @@ -266,14 +274,15 @@ export function createMainPage(): Page { }) Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume) offSettings?.(); offSettings = onAnySettingChanged(() => { model.refreshDisplayControls(); syncBandwidth() }) - model.refreshDisplayControls(); resume() + offBattery?.(); offBattery = shell.onBatteryLevelsChanged(refreshBatteryLine) + model.refreshDisplayControls(); refreshBatteryLine(); resume() if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect() }) page.on('unloaded', () => { if (keyboardObserver) NSNotificationCenter.defaultCenter.removeObserver(keyboardObserver) keyboardObserver = null root.paddingBottom = 0 - pause(); offSettings?.(); offSettings = null + pause(); offSettings?.(); offSettings = null; offBattery?.(); offBattery = null Application.off(Application.suspendEvent, pause); Application.off(Application.resumeEvent, resume) }) return page diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index 880b9032..846fa253 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -19,7 +19,7 @@ - + @@ -31,10 +31,9 @@ visibility="{{ displayPreviewMessageVisibility }}"> -