forked from Blendman974/faceclaw
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:
1 parent
acfcf79787
commit
9c0535014a
6 files changed
+70
-6
No files matched your search
@@ -136,6 +136,13 @@ Button.-primary {
|
|||||||
text-align: center;
|
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 {
|
.system-name-modal {
|
||||||
margin: 16;
|
margin: 16;
|
||||||
padding: 16;
|
padding: 16;
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging"
|
|||||||
|
|
||||||
export type DashboardSnapshot = {
|
export type DashboardSnapshot = {
|
||||||
phase: ConnectionPhase;
|
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;
|
status: string;
|
||||||
displayPreview: ImageSource | null;
|
displayPreview: ImageSource | null;
|
||||||
/**
|
/**
|
||||||
@@ -333,6 +335,7 @@ class DashboardController {
|
|||||||
private offState: (() => void) | null = null;
|
private offState: (() => void) | null = null;
|
||||||
private offRing: (() => void) | null = null;
|
private offRing: (() => void) | null = null;
|
||||||
private offBattery: (() => void) | null = null;
|
private offBattery: (() => void) | null = null;
|
||||||
|
private offCaseBattery: (() => void) | null = null;
|
||||||
private offSilentMode: (() => void) | null = null;
|
private offSilentMode: (() => void) | null = null;
|
||||||
private offWearState: (() => void) | null = null;
|
private offWearState: (() => void) | null = null;
|
||||||
private offPhoneLockState: (() => void) | null = null;
|
private offPhoneLockState: (() => void) | null = null;
|
||||||
@@ -1130,6 +1133,7 @@ class DashboardController {
|
|||||||
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
||||||
previewMode: this.isPreviewDisplayActive(),
|
previewMode: this.isPreviewDisplayActive(),
|
||||||
evenHubPhoneUi: phoneUiButton(),
|
evenHubPhoneUi: phoneUiButton(),
|
||||||
|
batteries: shell.getBatteryLevels(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1584,6 +1588,12 @@ class DashboardController {
|
|||||||
// the watch state, so refresh both consumers on every report.
|
// the watch state, so refresh both consumers on every report.
|
||||||
this.emit();
|
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.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
|
||||||
this.refreshEvenAppStatus();
|
this.refreshEvenAppStatus();
|
||||||
if (!this.evenNotificationActive) {
|
if (!this.evenNotificationActive) {
|
||||||
@@ -1704,6 +1714,8 @@ class DashboardController {
|
|||||||
this.offRing = null;
|
this.offRing = null;
|
||||||
this.offBattery?.();
|
this.offBattery?.();
|
||||||
this.offBattery = null;
|
this.offBattery = null;
|
||||||
|
this.offCaseBattery?.();
|
||||||
|
this.offCaseBattery = null;
|
||||||
this.offSilentMode?.();
|
this.offSilentMode?.();
|
||||||
this.offSilentMode = null;
|
this.offSilentMode = null;
|
||||||
this.offWearState?.();
|
this.offWearState?.();
|
||||||
@@ -1816,6 +1828,8 @@ class DashboardController {
|
|||||||
this.offRing = null;
|
this.offRing = null;
|
||||||
this.offBattery?.();
|
this.offBattery?.();
|
||||||
this.offBattery = null;
|
this.offBattery = null;
|
||||||
|
this.offCaseBattery?.();
|
||||||
|
this.offCaseBattery = null;
|
||||||
this.offSilentMode?.();
|
this.offSilentMode?.();
|
||||||
this.offSilentMode = null;
|
this.offSilentMode = null;
|
||||||
this.offWearState?.();
|
this.offWearState?.();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</ActionBar>
|
</ActionBar>
|
||||||
|
|
||||||
<GridLayout>
|
<GridLayout>
|
||||||
<GridLayout rows="auto,*" visibility="{{ portraitLayoutVisibility }}">
|
<GridLayout rows="auto,auto,*" visibility="{{ portraitLayoutVisibility }}">
|
||||||
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
|
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
|
||||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}"
|
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}"
|
||||||
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
|
tap="{{ onMirrorTap }}" doubleTap="{{ onMirrorDoubleTap }}" longPress="{{ onMirrorLongPress }}" swipe="{{ onMirrorSwipe }}" />
|
||||||
@@ -31,9 +31,10 @@
|
|||||||
visibility="{{ displayPreviewMessageVisibility }}">
|
visibility="{{ displayPreviewMessageVisibility }}">
|
||||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
<Label row="1" text="{{ batteryLine }}" visibility="{{ batteryLineVisibility }}" class="battery-line" />
|
||||||
<!-- The controls get the whole star row so the active tab's
|
<!-- The controls get the whole star row so the active tab's
|
||||||
content can center in the leftover height. -->
|
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 }}" />
|
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
|
||||||
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
@@ -60,9 +61,10 @@
|
|||||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
<GridLayout col="1" rows="*,auto">
|
<GridLayout col="1" rows="auto,*,auto">
|
||||||
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
|
<Label row="0" text="{{ batteryLine }}" visibility="{{ batteryLineVisibility }}" class="battery-line" />
|
||||||
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
<rc:remote-controls row="1" visibility="{{ controlsVisibility }}" />
|
||||||
|
<Button row="2" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
type TouchGestureEventData,
|
type TouchGestureEventData,
|
||||||
type View,
|
type View,
|
||||||
} from "@nativescript/core";
|
} from "@nativescript/core";
|
||||||
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
|
import { dashboardController, type DashboardSnapshot, type MirrorTouchKind } from "../g2/dashboard-controller";
|
||||||
import {
|
import {
|
||||||
mirrorTouchSetting,
|
mirrorTouchSetting,
|
||||||
onAnySettingChanged,
|
onAnySettingChanged,
|
||||||
@@ -32,8 +32,26 @@ const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
|
|||||||
|
|
||||||
type LayoutOrientation = "portrait" | "landscape";
|
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 {
|
export class MainViewModel extends RemoteControlsViewModel {
|
||||||
private _status = "Disconnected.";
|
private _status = "Disconnected.";
|
||||||
|
private _batteryLine = "";
|
||||||
private _displayPreview: ImageSource | null = null;
|
private _displayPreview: ImageSource | null = null;
|
||||||
private _displayPreviewMessage = "";
|
private _displayPreviewMessage = "";
|
||||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||||
@@ -90,6 +108,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
|||||||
this.displayPreview = snapshot.displayPreview;
|
this.displayPreview = snapshot.displayPreview;
|
||||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||||
this.phase = snapshot.phase;
|
this.phase = snapshot.phase;
|
||||||
|
this.batteryLine = formatBatteryLine(snapshot.batteries);
|
||||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
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
|
* (which can be a sentence, e.g. a failure reason) stays available by
|
||||||
* tapping the indicator.
|
* 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 {
|
get connectionStatusLabel(): string {
|
||||||
switch (this._phase) {
|
switch (this._phase) {
|
||||||
case "connected":
|
case "connected":
|
||||||
|
|||||||
@@ -486,6 +486,12 @@ export type ShellChromeState = {
|
|||||||
/** The Wear OS watch (app/g2/wear-remote.ts); null when no watch is reachable. */
|
/** The Wear OS watch (app/g2/wear-remote.ts); null when no watch is reachable. */
|
||||||
watch: number | null;
|
watch: number | null;
|
||||||
watchCharging: boolean | 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. */
|
/** App-provided tray images, drawn between notification icons and batteries. */
|
||||||
trayIcons: ShellChromeTrayIcon[];
|
trayIcons: ShellChromeTrayIcon[];
|
||||||
|
|||||||
@@ -452,6 +452,7 @@ class Shell {
|
|||||||
private lastInput: InputEvent | null = null;
|
private lastInput: InputEvent | null = null;
|
||||||
private battery: ShellChromeState["battery"] = {
|
private battery: ShellChromeState["battery"] = {
|
||||||
headset: null, headsetCharging: null, ring: null, ringCharging: null, watch: null, watchCharging: null,
|
headset: null, headsetCharging: null, ring: null, ringCharging: null, watch: null, watchCharging: null,
|
||||||
|
case: null, caseCharging: null,
|
||||||
};
|
};
|
||||||
private readonly batteryListeners = new Set<() => void>();
|
private readonly batteryListeners = new Set<() => void>();
|
||||||
private attention = new Map<string, boolean>();
|
private attention = new Map<string, boolean>();
|
||||||
|
|||||||
Reference in new issue
Block a user