forked from Blendman974/faceclaw
Merge branch 'case-battery-ui'
This commit is contained in:
commit
c896ce9ac8
31 files changed
+729
-35
No files matched your search
@@ -98,13 +98,21 @@ 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";
|
||||
|
||||
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;
|
||||
/**
|
||||
@@ -340,6 +348,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;
|
||||
@@ -1156,6 +1165,7 @@ class DashboardController {
|
||||
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
||||
previewMode: this.isPreviewDisplayActive(),
|
||||
evenHubPhoneUi: phoneUiButton(),
|
||||
batteries: shell.getBatteryLevels(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1173,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
|
||||
@@ -1205,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(),
|
||||
};
|
||||
@@ -1619,6 +1637,17 @@ class DashboardController {
|
||||
// the watch state, so refresh both consumers on every report.
|
||||
this.emit();
|
||||
});
|
||||
this.offCaseBattery = communicator.onCaseState((state) => {
|
||||
// The level is kept when a reading has none (the glasses left the case)
|
||||
// and across disconnects: the case only reports while the glasses are
|
||||
// docked and only drains while charging them, so the last level holds.
|
||||
// Whether the case is on USB is only known while they are docked.
|
||||
shell.setBatteryLevels({
|
||||
...(state.battery !== null ? { case: state.battery } : {}),
|
||||
caseCharging: state.docked ? state.charging : null,
|
||||
});
|
||||
this.emit();
|
||||
});
|
||||
this.offEvenAppConflict = communicator.onEvenAppConflict((message) => {
|
||||
this.refreshEvenAppStatus();
|
||||
if (!this.evenNotificationActive) {
|
||||
@@ -1739,6 +1768,8 @@ class DashboardController {
|
||||
this.offRing = null;
|
||||
this.offBattery?.();
|
||||
this.offBattery = null;
|
||||
this.offCaseBattery?.();
|
||||
this.offCaseBattery = null;
|
||||
this.offSilentMode?.();
|
||||
this.offSilentMode = null;
|
||||
this.offWearState?.();
|
||||
@@ -1851,6 +1882,8 @@ class DashboardController {
|
||||
this.offRing = null;
|
||||
this.offBattery?.();
|
||||
this.offBattery = null;
|
||||
this.offCaseBattery?.();
|
||||
this.offCaseBattery = null;
|
||||
this.offSilentMode?.();
|
||||
this.offSilentMode = null;
|
||||
this.offWearState?.();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -883,6 +883,13 @@ export class IosPreviewController {
|
||||
if (this.active) this.onConnectionState({ ...this.state })
|
||||
this.requestShellRender()
|
||||
}),
|
||||
communicator.onCaseState(state => {
|
||||
if (this.communicator !== communicator) return
|
||||
// As on Android: keep the last level when a reading has none (out of the case);
|
||||
// the case's own charging is only known while the glasses are docked.
|
||||
shell.setBatteryLevels({ ...(state.battery !== null ? { case: state.battery } : {}),
|
||||
caseCharging: state.docked ? state.charging : null })
|
||||
}),
|
||||
communicator.onFirmwareInfo(info => {
|
||||
if (this.communicator !== communicator) return
|
||||
this.logBluetooth(`Firmware: L=${info.leftVersion || '?'} R=${info.rightVersion || '?'}` +
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
Reference in new issue
Block a user