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

+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