forked from Blendman974/faceclaw
Add silent-mode and low-battery indicators to Android preview form
This commit is contained in:
1 parent
bbd3bbcf13
commit
a5c6f18795
8 files changed
+216
-3
No files matched your search
+17
@@ -29,6 +29,23 @@ Button.-primary {
|
||||
font-size: 18;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stands in for the lens preview when showing it would be misleading (silent
|
||||
* mode, or a disconnect explained by a flat battery). Sized by the view model
|
||||
* to the preview's own box so the form doesn't reflow, and kept dark so it
|
||||
* reads as "where the preview goes" rather than as a page-level banner.
|
||||
*/
|
||||
.display-preview-message {
|
||||
background-color: #222222;
|
||||
color: #ffffff;
|
||||
padding: 16;
|
||||
}
|
||||
|
||||
.display-preview-message Label {
|
||||
font-size: 18;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.system-name-modal {
|
||||
margin: 16;
|
||||
padding: 16;
|
||||
|
||||
@@ -90,6 +90,12 @@ export type DashboardSnapshot = {
|
||||
status: string;
|
||||
log: string;
|
||||
displayPreview: ImageSource | null;
|
||||
/**
|
||||
* When non-empty, the phone UI shows this instead of the display preview:
|
||||
* the preview would be a black rectangle indistinguishable from dead
|
||||
* glasses, and this says which harmless thing is actually going on.
|
||||
*/
|
||||
displayPreviewMessage: string;
|
||||
activeTextSettingId: string | null;
|
||||
activeTextSettingTitle: string;
|
||||
activeTextSettingValue: string;
|
||||
@@ -114,6 +120,8 @@ const SCREEN_TIMEOUT_CHECK_MS = 1_000;
|
||||
const FOREGROUND_NOTIFICATION_MIN_UPDATE_MS = 30_000;
|
||||
const FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS = 6_000;
|
||||
const CONNECTED_PREVIEW_MIN_UPDATE_MS = 1_000;
|
||||
// Below this, a disconnect is more likely a flat battery than a BLE problem.
|
||||
const LOW_BATTERY_PERCENT = 5;
|
||||
const EVEN_APP_DETECTED_MESSAGE =
|
||||
"The Even Realities app appears to be running. If Faceclaw has trouble connecting, open its app settings and force stop it.";
|
||||
|
||||
@@ -155,6 +163,10 @@ class DashboardController {
|
||||
private firmwareWarningMessage = "";
|
||||
private batteryOptimizationWarningVisible = false;
|
||||
private displayPreview: ImageSource | null = createInitialDisplayPreview();
|
||||
private silentMode = false;
|
||||
// Last battery level the glasses reported, kept across disconnects so a
|
||||
// drop-off right after a low reading can be explained as a flat battery.
|
||||
private lastHeadsetBattery: number | null = null;
|
||||
private readonly listeners = new Set<DashboardListener>();
|
||||
// Set at connect time from the persisted flag; the one-time post-onboarding
|
||||
// welcome sound plays on the first rendered frame (proof the session is warm).
|
||||
@@ -168,6 +180,7 @@ class DashboardController {
|
||||
private offLog: (() => void) | null = null;
|
||||
private offRing: (() => void) | null = null;
|
||||
private offBattery: (() => void) | null = null;
|
||||
private offSilentMode: (() => void) | null = null;
|
||||
private offEvenAppConflict: (() => void) | null = null;
|
||||
private offFrameMetrics: (() => void) | null = null;
|
||||
private offFirmwareInfo: (() => void) | null = null;
|
||||
@@ -299,6 +312,7 @@ class DashboardController {
|
||||
status: this.status,
|
||||
log: this.log,
|
||||
displayPreview: this.displayPreview,
|
||||
displayPreviewMessage: this.displayPreviewMessage(),
|
||||
activeTextSettingId: this.activeTextSetting?.id ?? null,
|
||||
activeTextSettingTitle: this.activeTextSetting?.editorTitle ?? "",
|
||||
activeTextSettingValue: this.activeTextSetting?.get() ?? "",
|
||||
@@ -311,6 +325,28 @@ class DashboardController {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Message to show in place of the display preview, or "" to show the preview.
|
||||
*
|
||||
* Both cases look identical to a dead pair of glasses from the phone side:
|
||||
* silent mode blanks the display and swallows input while the BLE session
|
||||
* stays up, and a battery that just ran out simply stops answering.
|
||||
*/
|
||||
private displayPreviewMessage(): string {
|
||||
if (this.silentMode && (this.phase === "connected" || this.phase === "charging")) {
|
||||
return "Connected (Silent mode enabled)";
|
||||
}
|
||||
const connectionFailing = this.phase === "disconnected" || this.phase === "connecting";
|
||||
if (
|
||||
connectionFailing &&
|
||||
this.lastHeadsetBattery !== null &&
|
||||
this.lastHeadsetBattery < LOW_BATTERY_PERCENT
|
||||
) {
|
||||
return "Disconnected (low battery)";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-check the Doze exemption (cheap system call, but cached so snapshot()
|
||||
* stays trivial). Called on connect, page load, and after the user answers
|
||||
@@ -444,7 +480,13 @@ class DashboardController {
|
||||
this.appendLog(`input handler failed: ${message}`);
|
||||
});
|
||||
});
|
||||
this.offSilentMode = communicator.onSilentMode((silent) => {
|
||||
if (this.silentMode === silent) return;
|
||||
this.silentMode = silent;
|
||||
this.emit();
|
||||
});
|
||||
this.offBattery = communicator.onBatteryState((state) => {
|
||||
this.lastHeadsetBattery = state.battery >= 0 ? state.battery : null;
|
||||
shell.setBatteryLevels({
|
||||
headset: state.battery,
|
||||
headsetCharging: state.chargingStatus > 0,
|
||||
@@ -545,6 +587,8 @@ class DashboardController {
|
||||
this.offRing = null;
|
||||
this.offBattery?.();
|
||||
this.offBattery = null;
|
||||
this.offSilentMode?.();
|
||||
this.offSilentMode = null;
|
||||
this.offEvenAppConflict?.();
|
||||
this.offEvenAppConflict = null;
|
||||
this.offFrameMetrics?.();
|
||||
@@ -585,6 +629,8 @@ class DashboardController {
|
||||
this.offRing = null;
|
||||
this.offBattery?.();
|
||||
this.offBattery = null;
|
||||
this.offSilentMode?.();
|
||||
this.offSilentMode = null;
|
||||
this.offEvenAppConflict?.();
|
||||
this.offEvenAppConflict = null;
|
||||
this.offFrameMetrics?.();
|
||||
@@ -1146,6 +1192,11 @@ class DashboardController {
|
||||
private setPhase(phase: ConnectionPhase): void {
|
||||
if (this.phase === phase) return;
|
||||
this.phase = phase;
|
||||
if (phase === "disconnected") {
|
||||
// Kept across "connecting": silent mode blocks app launches, so it can
|
||||
// itself cause the reconnect churn, and Java re-reports it either way.
|
||||
this.silentMode = false;
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ export class FaceclawCommunicatorBridge {
|
||||
private readonly stateListeners = new Set<(state: CommunicatorState) => void>();
|
||||
private readonly ringListeners = new Set<(event: RawInputEvent) => void>();
|
||||
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
|
||||
private readonly silentModeListeners = new Set<(silent: boolean) => void>();
|
||||
private readonly evenAppConflictListeners = new Set<(message: string) => void>();
|
||||
private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>();
|
||||
private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>();
|
||||
@@ -159,6 +160,9 @@ export class FaceclawCommunicatorBridge {
|
||||
};
|
||||
this.emitAsync(this.batteryListeners, state);
|
||||
},
|
||||
onSilentMode: (silent: boolean) => {
|
||||
this.emitAsync(this.silentModeListeners, Boolean(silent));
|
||||
},
|
||||
onEvenAppConflict: (message: string) => {
|
||||
this.emitAsync(this.evenAppConflictListeners, String(message));
|
||||
},
|
||||
@@ -239,6 +243,15 @@ export class FaceclawCommunicatorBridge {
|
||||
return () => this.batteryListeners.delete(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Silent mode, toggled on the glasses by long-pressing both touchpads. While
|
||||
* it is on the firmware ignores all input and blanks the display.
|
||||
*/
|
||||
onSilentMode(listener: (silent: boolean) => void): () => void {
|
||||
this.silentModeListeners.add(listener);
|
||||
return () => this.silentModeListeners.delete(listener);
|
||||
}
|
||||
|
||||
onEvenAppConflict(listener: (message: string) => void): () => void {
|
||||
this.evenAppConflictListeners.add(listener);
|
||||
return () => this.evenAppConflictListeners.delete(listener);
|
||||
|
||||
@@ -11,6 +11,13 @@
|
||||
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
|
||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout
|
||||
row="0"
|
||||
class="display-preview-message"
|
||||
height="{{ displayPreviewHeight }}"
|
||||
visibility="{{ displayPreviewMessageVisibility }}">
|
||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
|
||||
<StackLayout row="0" class="m-b-8">
|
||||
<StackLayout visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
@@ -62,6 +69,16 @@
|
||||
width="{{ landscapeDisplayPreviewWidth }}"
|
||||
height="{{ landscapeDisplayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout
|
||||
row="0"
|
||||
col="0"
|
||||
class="display-preview-message"
|
||||
horizontalAlignment="left"
|
||||
width="{{ landscapeDisplayPreviewWidth }}"
|
||||
height="{{ landscapeDisplayPreviewHeight }}"
|
||||
visibility="{{ displayPreviewMessageVisibility }}">
|
||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
<StackLayout row="0" col="1" class="m-l-16">
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*">
|
||||
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
|
||||
|
||||
@@ -8,6 +8,7 @@ export class MainViewModel extends Observable {
|
||||
private _status = "Disconnected.";
|
||||
private _log = "";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _displayPreviewMessage = "";
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
private _activeTextSettingId: string | null = null;
|
||||
private _activeTextSettingTitle = "";
|
||||
@@ -27,6 +28,7 @@ export class MainViewModel extends Observable {
|
||||
this.status = snapshot.status;
|
||||
this.log = snapshot.log;
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.phase = snapshot.phase;
|
||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
||||
@@ -75,12 +77,33 @@ export class MainViewModel extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
get displayPreviewMessage(): string {
|
||||
return this._displayPreviewMessage;
|
||||
}
|
||||
|
||||
set displayPreviewMessage(value: string) {
|
||||
if (this._displayPreviewMessage !== value) {
|
||||
this._displayPreviewMessage = value;
|
||||
this.notifyPropertyChange("displayPreviewMessage", value);
|
||||
this.notifyPropertyChange("displayPreviewMessageVisibility", this.displayPreviewMessageVisibility);
|
||||
this.notifyPropertyChange("displayPreviewVisibility", this.displayPreviewVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
get hasDisplayPreview(): boolean {
|
||||
return this._displayPreview !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The preview and its stand-in message are mutually exclusive and occupy the
|
||||
* same box, so the form doesn't reflow when one replaces the other.
|
||||
*/
|
||||
get displayPreviewVisibility(): "visible" | "collapse" {
|
||||
return this.hasDisplayPreview ? "visible" : "collapse";
|
||||
return this.hasDisplayPreview && !this._displayPreviewMessage ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get displayPreviewMessageVisibility(): "visible" | "collapse" {
|
||||
return this._displayPreviewMessage ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get displayPreviewHeight(): number {
|
||||
|
||||
Reference in new issue
Block a user