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

-7
View File
@@ -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;
+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) => ({
+11 -2
View File
@@ -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<typeof setTimeout> | 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<TextView>('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
+5 -7
View File
@@ -19,7 +19,7 @@
</ActionBar>
<GridLayout>
<GridLayout rows="auto,auto,*" visibility="{{ portraitLayoutVisibility }}">
<GridLayout rows="auto,*" visibility="{{ portraitLayoutVisibility }}">
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}"
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
@@ -31,10 +31,9 @@
visibility="{{ displayPreviewMessageVisibility }}">
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
</GridLayout>
<Label row="1" text="{{ batteryLine }}" visibility="{{ batteryLineVisibility }}" class="battery-line" />
<!-- The controls get the whole star row so the active tab's
content can center in the leftover height. -->
<GridLayout row="2" rows="*,auto" class="p-20">
<GridLayout row="1" rows="*,auto" class="p-20">
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
</GridLayout>
@@ -61,10 +60,9 @@
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
</GridLayout>
</GridLayout>
<GridLayout col="1" rows="auto,*,auto">
<Label row="0" text="{{ batteryLine }}" visibility="{{ batteryLineVisibility }}" class="battery-line" />
<rc:remote-controls row="1" visibility="{{ controlsVisibility }}" />
<Button row="2" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
<GridLayout col="1" rows="*,auto">
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
</GridLayout>
</GridLayout>
</GridLayout>
+12 -39
View File
@@ -14,7 +14,8 @@ import {
type TouchGestureEventData,
type View,
} from "@nativescript/core";
import { dashboardController, type DashboardSnapshot, type MirrorTouchKind } from "../g2/dashboard-controller";
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
import { formatBatteryLine } from "../g2/glasses-display-state";
import {
mirrorTouchSetting,
onAnySettingChanged,
@@ -32,30 +33,8 @@ const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
type LayoutOrientation = "portrait" | "landscape";
/**
* The line under the mirror: each device whose level is known, e.g.
* "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging). Levels are the last known
* ones (the case only reports while the glasses are docked), so ⚡ appears only
* while it is live: with a link to the glasses, and for the case only while
* they are docked (caseCharging is null otherwise).
*/
function formatBatteryLine(snapshot: Pick<DashboardSnapshot, "batteries" | "phase">): string {
const levels = snapshot.batteries;
const live = snapshot.phase === "connected" || snapshot.phase === "charging";
const devices: Array<[string, number | null, boolean | null]> = [
["G2", levels.headset, live && levels.headsetCharging],
["Case", levels.case, live && levels.caseCharging],
["R1", levels.ring, levels.ringCharging],
];
return devices
.filter(([, level]) => level !== null)
.map(([label, level, charging]) => `${label} ${level}%${charging ? " ⚡" : ""}`)
.join(" · ");
}
export class MainViewModel extends RemoteControlsViewModel {
private _status = "Disconnected.";
private _batteryLine = "";
private _displayPreview: ImageSource | null = null;
private _displayPreviewMessage = "";
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
@@ -112,7 +91,10 @@ export class MainViewModel extends RemoteControlsViewModel {
this.displayPreview = snapshot.displayPreview;
this.displayPreviewMessage = snapshot.displayPreviewMessage;
this.phase = snapshot.phase;
this.batteryLine = formatBatteryLine(snapshot);
this.batteryLine = formatBatteryLine(
snapshot.batteries,
snapshot.phase === "connected" || snapshot.phase === "charging",
);
this.activeTextSettingId = snapshot.activeTextSettingId;
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
@@ -167,21 +149,6 @@ export class MainViewModel extends RemoteControlsViewModel {
}
}
get batteryLine(): string {
return this._batteryLine;
}
set batteryLine(value: string) {
if (this._batteryLine === value) return;
this._batteryLine = value;
this.notifyPropertyChange("batteryLine", value);
this.notifyPropertyChange("batteryLineVisibility", this.batteryLineVisibility);
}
get batteryLineVisibility(): "visible" | "collapse" {
return this._batteryLine ? "visible" : "collapse";
}
/**
* Short connection indicator for the action bar. The full status string
* (which can be a sentence, e.g. a failure reason) stays available by
@@ -1106,10 +1073,16 @@ export class MainViewModel extends RemoteControlsViewModel {
return dashboardController.glassesDisplayAsleep();
}
override get padDetailLine(): string {
return dashboardController.glassesDisplayDetail();
}
private refreshPadFocusLine(): void {
this.notifyPropertyChange("padFocusLine", this.padFocusLine);
this.notifyPropertyChange("padFocusClass", this.padFocusClass);
this.notifyPropertyChange("padWakeHintVisibility", this.padWakeHintVisibility);
this.notifyPropertyChange("padDetailLine", this.padDetailLine);
this.notifyPropertyChange("padDetailVisibility", this.padDetailVisibility);
}
async onPadTap(): Promise<void> {
+31 -1
View File
@@ -8,6 +8,7 @@ let lastControlsTab: ControlsTab = 'watch';
/** Shared state and actions for remote-controls.xml; transport stays in the host. */
export class RemoteControlsViewModel extends Observable {
private _controlsTab: ControlsTab = lastControlsTab;
private _batteryLine = "";
get settingsTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "settings" ? "visible" : "collapse";
@@ -50,6 +51,19 @@ export class RemoteControlsViewModel extends Observable {
return this.padDisplayAsleep ? "visible" : "collapse";
}
/**
* A smaller line under the watch face's status line, or "" to hide it: the
* charging case's level while the glasses charge in it. The host overrides
* this and notifies padDetailLine and padDetailVisibility when it changes.
*/
get padDetailLine(): string {
return "";
}
get padDetailVisibility(): "visible" | "collapse" {
return this.padDetailLine ? "visible" : "collapse";
}
onSettingsTabTap(): void {
this.setControlsTab("settings");
}
@@ -76,7 +90,23 @@ export class RemoteControlsViewModel extends Observable {
this.notifyPropertyChange("ringTabClass", this.ringTabClass);
}
// ---- display mode and brightness, on the Settings tab ----
// ---- display mode, brightness and battery levels, on the Settings tab ----
/** The Settings tab's battery row (formatBatteryLine), or "" to hide it; set by the host. */
get batteryLine(): string {
return this._batteryLine;
}
set batteryLine(value: string) {
if (this._batteryLine === value) return;
this._batteryLine = value;
this.notifyPropertyChange("batteryLine", value);
this.notifyPropertyChange("batteryLineVisibility", this.batteryLineVisibility);
}
get batteryLineVisibility(): "visible" | "collapse" {
return this._batteryLine ? "visible" : "collapse";
}
get displayModeLabel(): string {
return displayLayoutSetting.displayValue() + " ▾";
+9
View File
@@ -91,6 +91,9 @@
font-size: 13;
margin-right: 2;
}
.settings-battery-line {
font-size: 14;
}
.touchpad {
height: 230;
background-color: #1f1f1f;
@@ -113,6 +116,12 @@
color: #6a6a6a;
margin-top: 4;
}
/* The charging case's level under "Charging · G2 n%". */
.pad-detail {
font-size: 15;
color: #b0b0b0;
margin-top: 4;
}
.action-row {
margin-top: 6;
}
+16 -7
View File
@@ -1,10 +1,10 @@
<!--
The phone's controller for the glasses, as a three-tab area below the mirror:
Settings (screen size + brightness), Watch (the simulated watch face: same
scheme as the watch pad - tap = select, double-tap or two fingers = back,
hold = menu, swipes navigate), and Ring (a touchpad on the ring's own
scheme: vertical swipes scroll, tap/double-tap/hold = click/double-click/
long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The
Settings (display mode, brightness and battery levels), Watch (the
simulated watch face: same scheme as the watch pad - tap = select,
double-tap or two fingers = back, hold = menu, swipes navigate), and Ring
(a touchpad on the ring's own scheme: vertical swipes scroll,
tap/double-tap/hold = click/double-click/long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The
narrow mic and keyboard buttons at the tab bar's right edge fire the
wakeword / open the keyboard dialog without changing the selected tab. Used
by main-page.xml in both orientations; binds to the page's MainViewModel,
@@ -49,15 +49,24 @@
<Switch checked="{{ brightnessAuto }}" checkedChange="{{ onBrightnessAutoChange }}" />
</StackLayout>
</GridLayout>
<!-- Last-known levels of the glasses, their charging case and the R1;
collapsed until one is known. Last so its appearing doesn't move
the controls above. -->
<GridLayout rows="auto" columns="auto,*" class="settings-row" visibility="{{ batteryLineVisibility }}">
<Label col="0" text="Battery" class="settings-row-label" verticalAlignment="center" />
<Label col="1" text="{{ batteryLine }}" textWrap="true" class="settings-battery-line" verticalAlignment="center" />
</GridLayout>
</StackLayout>
<!-- Watch tab: centered in the leftover height, capped at the 1.5:1 face
aspect (watchFaceWidth = min(available, 1.5 x face height). The star
rows center the status line, plus the wake hint under it while the
display is off (a double-tap is the only gesture that wakes it). -->
<GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" rows="*,auto,auto,*" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
display is off (a double-tap is the only gesture that wakes it), or
the charging case's level while the glasses charge in it. -->
<GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" rows="*,auto,auto,auto,*" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
<Label row="1" isUserInteractionEnabled="false" text="{{ padFocusLine }}" class="{{ padFocusClass }}" horizontalAlignment="center" />
<Label row="2" isUserInteractionEnabled="false" text="●● wake" visibility="{{ padWakeHintVisibility }}" class="pad-wake-hint" horizontalAlignment="center" />
<Label row="3" isUserInteractionEnabled="false" text="{{ padDetailLine }}" visibility="{{ padDetailVisibility }}" class="pad-detail" horizontalAlignment="center" />
</GridLayout>
<!-- Ring tab: a touchpad on the ring's own scheme. Vertical swipes only
+40 -1
View File
@@ -1,13 +1,22 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { chargingDisplayLabel, glassesDisplayAsleep, glassesDisplayLabel } = require("../.test-build/app/g2/glasses-display-state.js");
const {
chargingDisplayLabel,
chargingPreviewMessage,
formatBatteryLine,
glassesDisplayAsleep,
glassesDisplayDetail,
glassesDisplayLabel,
} = require("../.test-build/app/g2/glasses-display-state.js");
const connected = {
phase: "connected",
silentMode: false,
screenOn: true,
battery: 72,
caseBattery: null,
caseCharging: null,
foregroundTitle: "Music",
previewMode: false,
};
@@ -37,3 +46,33 @@ test("charging takes precedence and includes the last-known G2 battery", () => {
assert.equal(chargingDisplayLabel(-1), "Charging");
assert.equal(chargingDisplayLabel(101), "Charging");
});
test("while charging, the case level is the watch face's second line and joins the mirror's message", () => {
const charging = { ...connected, phase: "charging", caseBattery: 64, caseCharging: false };
assert.equal(glassesDisplayLabel(charging), "Charging · G2 72%");
assert.equal(glassesDisplayDetail(charging), "Case 64%");
assert.equal(glassesDisplayDetail({ ...charging, caseCharging: true }), "Case 64% ⚡");
assert.equal(chargingPreviewMessage(charging), "Charging · G2 72% · Case 64%");
// No case level yet: the label alone.
assert.equal(glassesDisplayDetail({ ...charging, caseBattery: null }), "");
assert.equal(chargingPreviewMessage({ ...charging, caseBattery: null, battery: null }), "Charging");
// Out of the case the level is stale, so it is not shown.
assert.equal(glassesDisplayDetail({ ...connected, caseBattery: 64 }), "");
});
const levels = {
headset: 87, headsetCharging: true, case: 64, caseCharging: true, ring: 72, ringCharging: false,
};
test("the Settings battery line lists each known level, with ⚡ only while the reading is live", () => {
assert.equal(formatBatteryLine(levels, true), "G2 87% ⚡ · Case 64% ⚡ · R1 72%");
// Without a link to the glasses their charging state and the case's are stale.
assert.equal(formatBatteryLine({ ...levels, ringCharging: true }, false), "G2 87% · Case 64% · R1 72% ⚡");
// caseCharging is null while the glasses are out of the case.
assert.equal(formatBatteryLine({ ...levels, caseCharging: null }, true), "G2 87% ⚡ · Case 64% · R1 72%");
assert.equal(formatBatteryLine({ ...levels, case: null, ring: null }, true), "G2 87% ⚡");
assert.equal(
formatBatteryLine({ headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }, true),
"",
);
});
+3
View File
@@ -218,6 +218,9 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
'./onboarding-state': { isPreviewOnlyMode: () => false },
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
'../g2/glasses-display-state': require('../.test-build/app/g2/glasses-display-state.js'),
'../ui/shell/shell': { shell: { onBatteryLevelsChanged: () => () => {}, getBatteryLevels: () => ({
headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }) } },
};
modules['./keyboard-input-view-model'] = load('app/phone-ui/keyboard-input-view-model.ts', { require: id => modules[id] });
modules['./remote-controls-view-model'] = load('app/phone-ui/remote-controls-view-model.ts', { require: id => modules[id] });
+7
View File
@@ -58,6 +58,7 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
"phase": "connected", "status": "…", "connected": true,
"screenOn": true, "locked": false, "worn": true, "listening": false,
"battery": 78, "charging": false, "silentMode": false,
"caseBattery": 64, "caseCharging": true,
"foreground": {"appId": "music", "title": "Music"},
"windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}],
"apps": [{"appId": "timer", "title": "Timer"}],
@@ -71,6 +72,12 @@ dashboard state, re-sent whenever it changes (and at least every 30 s):
`silentMode` identify the two states in which the glasses display is not
visible even though the BLE session remains available.
`caseBattery` is the last-known charging-case percentage, or null until the
glasses have reported one; the case only reports while the glasses are docked,
so outside charging it can be stale. `caseCharging` is whether the case is on
USB, or null while the glasses are out of the case (they can't see it then).
The watch shows the case level under the charging line.
`protocol` is reserved for incompatible revisions of this format (nothing
checks it yet). `crownClockwiseNext` mirrors the
on-glasses Settings > Watch toggle; when false (the default), clockwise crown
@@ -95,6 +95,10 @@ data class PhoneState(
/** Current or last-known G2 charge percentage. */
val battery: Int?,
val charging: Boolean,
/** Last-known charging-case percentage; live only while the glasses are docked. */
val caseBattery: Int?,
/** The case is on USB; null while the glasses are out of the case. */
val caseCharging: Boolean?,
val silentMode: Boolean,
val foreground: AppEntry?,
val windows: List<WindowEntry>,
@@ -123,6 +127,8 @@ data class PhoneState(
listening = o.optBoolean("listening", false),
battery = if (o.isNull("battery")) null else o.optInt("battery", -1).takeIf { it in 0..100 },
charging = o.optBoolean("charging", false),
caseBattery = if (o.isNull("caseBattery")) null else o.optInt("caseBattery", -1).takeIf { it in 0..100 },
caseCharging = if (o.isNull("caseCharging")) null else o.optBoolean("caseCharging"),
silentMode = o.optBoolean("silentMode", false),
foreground = foreground?.let {
AppEntry(it.optString("appId", ""), it.optString("title", ""))
@@ -12,7 +12,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -64,13 +63,10 @@ fun AmbientScreen(link: PhoneLink, ambient: AmbientMode) {
maxLines = 1,
modifier = Modifier.align(Alignment.Center),
)
Text(
text = padLine(state, linkStatus).text,
style = MaterialTheme.typography.title3,
PadStatusText(
pad = padLine(state, linkStatus),
color = statusColor,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
detailColor = statusColor,
modifier = Modifier
.align(Alignment.Center)
.offset(y = 46.dp)
@@ -14,6 +14,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
@@ -59,8 +60,11 @@ fun NoticeOverlay(notice: Notice?) {
}
}
/** The pad's single indicator line, with a tone that picks its colour. */
data class StatusLine(val text: String, val tone: StatusTone)
/**
* The pad's indicator line, with a tone that picks its colour, and an
* optional smaller line under it (the charging case's level while charging).
*/
data class StatusLine(val text: String, val tone: StatusTone, val detail: String? = null)
enum class StatusTone { GOOD, BUSY, OFF, PROBLEM }
@@ -76,7 +80,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.charging || state.phase == "charging" ->
StatusLine(chargingLine(state.battery), StatusTone.BUSY, caseLine(state))
state.silentMode -> StatusLine("Silent mode", StatusTone.OFF)
state.locked -> StatusLine("Locked", StatusTone.OFF)
!state.screenOn -> StatusLine("●● Wake", StatusTone.OFF)
@@ -91,6 +96,56 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when {
private fun chargingLine(battery: Int?): String =
if (battery != null) "Charging · G2 $battery%" else "Charging"
/**
* "Case 64%", with ⚡ while the case is on USB; null when the level is
* unknown. Matches the phone's watch face (glassesDisplayDetail). The case is
* only reported while the glasses are docked, so the line is only drawn while
* they charge.
*/
private fun caseLine(state: PhoneState): String? =
state.caseBattery?.let { "Case $it%" + if (state.caseCharging == true) " ⚡" else "" }
/**
* [pad]'s status line, with its detail (if any) drawn under it. Only the
* status line counts toward the measured height, so a caller that centres
* this keeps the status line in the same place whether or not a detail shows.
*/
@Composable
fun PadStatusText(pad: StatusLine, color: Color, detailColor: Color, modifier: Modifier = Modifier) {
Layout(
modifier = modifier,
content = {
Text(
text = pad.text,
style = MaterialTheme.typography.title3,
color = color,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
pad.detail?.let { detail ->
Text(
text = detail,
style = MaterialTheme.typography.caption1,
color = detailColor,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
},
) { measurables, constraints ->
val placeables = measurables.map { it.measure(constraints.copy(minWidth = 0, minHeight = 0)) }
val status = placeables.first()
val width = placeables.maxOf { it.width }.coerceIn(constraints.minWidth, constraints.maxWidth)
val height = status.height.coerceIn(constraints.minHeight, constraints.maxHeight)
layout(width, height) {
status.placeRelative((width - status.width) / 2, 0)
placeables.getOrNull(1)?.let { it.placeRelative((width - it.width) / 2, status.height) }
}
}
}
fun StatusTone.color(): Color = when (this) {
StatusTone.GOOD -> Color(0xFF7BD88F)
StatusTone.BUSY -> Color(0xFFF2C14E)
@@ -36,7 +36,6 @@ import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
@@ -307,13 +306,10 @@ fun RemoteScreen(
modifier = Modifier.align(Alignment.Center).offset(y = 46.dp),
) {
val pad = padLine(state, linkStatus)
Text(
text = pad.text,
style = MaterialTheme.typography.title3,
PadStatusText(
pad = pad,
color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(),
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
detailColor = MaterialTheme.colors.onSurfaceVariant,
modifier = Modifier.padding(horizontal = 42.dp),
)
}