Phone UI: show the glasses, charging case and R1 battery levels

A line under the mirror lists each device whose level is known, e.g.
"G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging), in portrait and
landscape. The case level joins the shell's battery state beside the
glasses and R1 (it is not drawn in the glasses' top bar) and reaches the
page through the dashboard snapshot. Like the glasses level it is kept
across disconnects: the case only reports while the glasses are docked
and only drains while charging them.
This commit is contained in:
Om Alve committed 2026-11-01 21:29:32 +05:30
1 parent acfcf79787
commit 9c0535014a
6 files changed
+70 -6

No files matched your search

+7
View File
@@ -136,6 +136,13 @@ 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;
+14
View File
@@ -103,6 +103,8 @@ type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging"
export type DashboardSnapshot = {
phase: ConnectionPhase;
/** Last-known battery levels: the glasses, their charging case, the R1 ring and a Wear OS watch. */
batteries: ReturnType<typeof shell.getBatteryLevels>;
status: string;
displayPreview: ImageSource | null;
/**
@@ -333,6 +335,7 @@ class DashboardController {
private offState: (() => void) | null = null;
private offRing: (() => void) | null = null;
private offBattery: (() => void) | null = null;
private offCaseBattery: (() => void) | null = null;
private offSilentMode: (() => void) | null = null;
private offWearState: (() => void) | null = null;
private offPhoneLockState: (() => void) | null = null;
@@ -1130,6 +1133,7 @@ class DashboardController {
alarmReliabilityMessage: this.alarmReliabilityMessage,
previewMode: this.isPreviewDisplayActive(),
evenHubPhoneUi: phoneUiButton(),
batteries: shell.getBatteryLevels(),
};
}
@@ -1584,6 +1588,12 @@ class DashboardController {
// the watch state, so refresh both consumers on every report.
this.emit();
});
this.offCaseBattery = communicator.onCaseState((state) => {
// Kept across disconnects: the case only reports while the glasses are
// docked and only drains while charging them, so the last level holds.
shell.setBatteryLevels({ case: state.battery, caseCharging: state.charging });
this.emit();
});
this.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
this.refreshEvenAppStatus();
if (!this.evenNotificationActive) {
@@ -1704,6 +1714,8 @@ class DashboardController {
this.offRing = null;
this.offBattery?.();
this.offBattery = null;
this.offCaseBattery?.();
this.offCaseBattery = null;
this.offSilentMode?.();
this.offSilentMode = null;
this.offWearState?.();
@@ -1816,6 +1828,8 @@ class DashboardController {
this.offRing = null;
this.offBattery?.();
this.offBattery = null;
this.offCaseBattery?.();
this.offCaseBattery = null;
this.offSilentMode?.();
this.offSilentMode = null;
this.offWearState?.();
+7 -5
View File
@@ -19,7 +19,7 @@
</ActionBar>
<GridLayout>
<GridLayout rows="auto,*" visibility="{{ portraitLayoutVisibility }}">
<GridLayout rows="auto,auto,*" visibility="{{ portraitLayoutVisibility }}">
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}"
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
@@ -31,9 +31,10 @@
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="1" rows="*,auto" class="p-20">
<GridLayout row="2" rows="*,auto" class="p-20">
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
</GridLayout>
@@ -60,9 +61,10 @@
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
</GridLayout>
</GridLayout>
<GridLayout col="1" rows="*,auto">
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
<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>
</GridLayout>
</GridLayout>
+35 -1
View File
@@ -14,7 +14,7 @@ import {
type TouchGestureEventData,
type View,
} from "@nativescript/core";
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
import { dashboardController, type DashboardSnapshot, type MirrorTouchKind } from "../g2/dashboard-controller";
import {
mirrorTouchSetting,
onAnySettingChanged,
@@ -32,8 +32,26 @@ 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). The case level is the last
* one the glasses relayed; it only reports while they are docked.
*/
function formatBatteryLine(levels: DashboardSnapshot["batteries"]): string {
const devices: Array<[string, number | null, boolean | null]> = [
["G2", levels.headset, levels.headsetCharging],
["Case", levels.case, 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();
@@ -90,6 +108,7 @@ export class MainViewModel extends RemoteControlsViewModel {
this.displayPreview = snapshot.displayPreview;
this.displayPreviewMessage = snapshot.displayPreviewMessage;
this.phase = snapshot.phase;
this.batteryLine = formatBatteryLine(snapshot.batteries);
this.activeTextSettingId = snapshot.activeTextSettingId;
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
@@ -149,6 +168,21 @@ export class MainViewModel extends RemoteControlsViewModel {
* (which can be a sentence, e.g. a failure reason) stays available by
* tapping the indicator.
*/
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 connectionStatusLabel(): string {
switch (this._phase) {
case "connected":
+6
View File
@@ -486,6 +486,12 @@ export type ShellChromeState = {
/** The Wear OS watch (app/g2/wear-remote.ts); null when no watch is reachable. */
watch: number | null;
watchCharging: boolean | null;
/**
* The glasses' charging case, last known (it only reports while the
* glasses are docked); null until it does. Shown on the phone, not here.
*/
case: number | null;
caseCharging: boolean | null;
};
/** App-provided tray images, drawn between notification icons and batteries. */
trayIcons: ShellChromeTrayIcon[];
+1
View File
@@ -452,6 +452,7 @@ class Shell {
private lastInput: InputEvent | null = null;
private battery: ShellChromeState["battery"] = {
headset: null, headsetCharging: null, ring: null, ringCharging: null, watch: null, watchCharging: null,
case: null, caseCharging: null,
};
private readonly batteryListeners = new Set<() => void>();
private attention = new Map<string, boolean>();