Add charging mode

This commit is contained in:
James Babcock committed 2026-07-05 00:35:03 -07:00
1 parent 875956e140
commit 4b73cbff35
5 files changed
+138 -47

No files matched your search

+22 -7
View File
@@ -39,7 +39,7 @@ import {
import { saveRawScreenshot } from "../native/raw-screenshot";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "disconnecting";
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting";
export type DashboardSnapshot = {
phase: ConnectionPhase;
@@ -326,11 +326,18 @@ class DashboardController {
const mappedPhase =
state.phase === "connected"
? "connected"
: state.phase === "disconnecting"
? "disconnecting"
: state.phase === "disconnected"
? "disconnected"
: "connecting";
: state.phase === "charging"
? "charging"
: state.phase === "disconnecting"
? "disconnecting"
: state.phase === "disconnected"
? "disconnected"
: "connecting";
if (mappedPhase === "charging" && this.phase !== "charging") {
// Nobody is wearing the glasses; drop the G2-screen wakelock so the
// phone can sleep normally while they charge.
void this.communicator?.setG2ScreenOn(false).catch(() => {});
}
this.setPhase(mappedPhase);
this.setStatus(state.status);
});
@@ -345,7 +352,7 @@ class DashboardController {
headset: state.battery,
headsetCharging: state.chargingStatus > 0,
});
if (this.phase === "connected" && this.communicator) {
if ((this.phase === "connected" || this.phase === "charging") && this.communicator) {
void this.requestRender("interval").catch((error) => {
const message = this.formatError(error);
this.appendLog(`battery update failed: ${message}`);
@@ -700,6 +707,14 @@ class DashboardController {
if (!updatePreviewAfterTransmit) {
this.updateDisplayPreviewFromImage(image);
}
if (this.communicator && this.phase === "charging") {
// Glasses are in the charging case; keep the phone preview fresh but
// send nothing.
frameTimings.finishFrame(frameId, "discarded: glasses charging");
this.updateConnectedForegroundNotification();
console.log("renderDashbaord finished (charging)");
return;
}
if (this.communicator) {
if (dashboardState.screenOn) {
await this.communicator.setG2ScreenOn(true);
+1
View File
@@ -7,6 +7,7 @@ export type CommunicatorPhase =
| "disconnected"
| "connecting"
| "connected"
| "charging"
| "retrying"
| "disconnecting";
+5 -4
View File
@@ -18,7 +18,7 @@ export class MainViewModel extends Observable {
private _rawScreenshotsEnabled = false;
private _batteryOptimizationWarningVisible = false;
private _showLog = false;
private _phase: "disconnected" | "connecting" | "connected" | "disconnecting" = "disconnected";
private _phase: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" = "disconnected";
constructor() {
super();
@@ -278,11 +278,11 @@ export class MainViewModel extends Observable {
dashboardController.requestBatteryOptimizationExemption();
}
get phase(): "disconnected" | "connecting" | "connected" | "disconnecting" {
get phase(): "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" {
return this._phase;
}
set phase(value: "disconnected" | "connecting" | "connected" | "disconnecting") {
set phase(value: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting") {
if (this._phase !== value) {
this._phase = value;
this.notifyPropertyChange("phase", value);
@@ -296,6 +296,7 @@ export class MainViewModel extends Observable {
case "connecting":
return "Connecting...";
case "connected":
case "charging":
return "Disconnect";
case "disconnecting":
return "Disconnecting...";
@@ -312,7 +313,7 @@ export class MainViewModel extends Observable {
if (!this.canRun) return;
try {
if (this.phase === "connected") {
if (this.phase === "connected" || this.phase === "charging") {
await dashboardController.disconnect();
} else {
await dashboardController.connect();