forked from Blendman974/faceclaw
Compatibility check; notification icon fixes
* Display a warning if paired glasses do not have a compatible custo firmware * Fix certain notification icons being missing on system card * Rescale large notification icons with proper sampling; don't send unnecessary
This commit is contained in:
1 parent
c9fe92dc1c
commit
3532b1f437
13 files changed
+383
-18
No files matched your search
@@ -10,6 +10,8 @@ import { nightscoutBridge } from "../native/nightscout-bridge";
|
||||
import { onAndroidNotificationPosted } from "../native/notification-icons";
|
||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||
import { grayImageToPreviewSource } from "../native/gray-image-preview";
|
||||
import { firmwareIncompatibilityMessage } from "./firmware-compat";
|
||||
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||
import { voiceControlBridge } from "../native/voice-control";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||
import {
|
||||
@@ -44,6 +46,8 @@ export type DashboardSnapshot = {
|
||||
activeTextSettingValue: string;
|
||||
evenAppConflictMessage: string;
|
||||
evenAppConflictWarningVisible: boolean;
|
||||
firmwareWarningMessage: string;
|
||||
firmwareWarningVisible: boolean;
|
||||
};
|
||||
|
||||
type DashboardListener = (snapshot: DashboardSnapshot) => void;
|
||||
@@ -118,6 +122,7 @@ class DashboardController {
|
||||
private activeTextSetting: ConfigSettingString | null = null;
|
||||
private evenNotificationActive = false;
|
||||
private evenAppConflictMessage = "";
|
||||
private firmwareWarningMessage = "";
|
||||
private displayPreview: ImageSource | null = createInitialDisplayPreview();
|
||||
private readonly listeners = new Set<DashboardListener>();
|
||||
|
||||
@@ -132,6 +137,7 @@ class DashboardController {
|
||||
private offBattery: (() => void) | null = null;
|
||||
private offEvenAppConflict: (() => void) | null = null;
|
||||
private offFrameMetrics: (() => void) | null = null;
|
||||
private offFirmwareInfo: (() => void) | null = null;
|
||||
private offMedia: (() => void) | null = null;
|
||||
private offNightscout: (() => void) | null = null;
|
||||
private offVoiceStatus: (() => void) | null = null;
|
||||
@@ -145,6 +151,9 @@ class DashboardController {
|
||||
private queuedFrameId = 0;
|
||||
private lastForegroundNotificationUpdateAtMs = 0;
|
||||
private lastConnectedPreviewUpdateAtMs = 0;
|
||||
// Consumed by the next renderDashboard: repaint with data sources not
|
||||
// allowed to serve stale caches (set after a frame painted with stale data).
|
||||
private nextRenderWantsFreshData = false;
|
||||
|
||||
constructor() {
|
||||
setDashboardActions({
|
||||
@@ -184,6 +193,8 @@ class DashboardController {
|
||||
activeTextSettingValue: this.activeTextSetting?.get() ?? "",
|
||||
evenAppConflictMessage: this.evenAppConflictMessage,
|
||||
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
||||
firmwareWarningMessage: this.firmwareWarningMessage,
|
||||
firmwareWarningVisible: this.firmwareWarningMessage.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -232,6 +243,7 @@ class DashboardController {
|
||||
this.log = "";
|
||||
this.lastInput = "waiting...";
|
||||
this.lastSys = "none yet";
|
||||
this.firmwareWarningMessage = "";
|
||||
resetDashboardSleepTimerAndWake();
|
||||
this.refreshEvenAppStatus();
|
||||
this.setPhase("connecting");
|
||||
@@ -299,6 +311,20 @@ class DashboardController {
|
||||
this.setStatus(`Connected. Last frame: ${this.formatFrameMetrics(metrics)}.`);
|
||||
}
|
||||
});
|
||||
this.offFirmwareInfo = communicator.onFirmwareInfo((info) => {
|
||||
this.appendLog(
|
||||
`firmware: L=${info.leftVersion || "?"} R=${info.rightVersion || "?"}` +
|
||||
(info.capabilities ? ` caps="${info.capabilities}"` : " (no CFW capability string)"),
|
||||
);
|
||||
const warning = firmwareIncompatibilityMessage(info) ?? "";
|
||||
if (warning !== this.firmwareWarningMessage) {
|
||||
this.firmwareWarningMessage = warning;
|
||||
if (warning) {
|
||||
this.appendLog(`firmware compatibility warning: ${warning}`);
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
});
|
||||
this.offMedia = mediaControllerBridge.onStateChange(() => {
|
||||
if (this.phase === "connected" && this.communicator) {
|
||||
void this.requestRender("interval").catch((error) => {
|
||||
@@ -360,6 +386,8 @@ class DashboardController {
|
||||
this.offEvenAppConflict = null;
|
||||
this.offFrameMetrics?.();
|
||||
this.offFrameMetrics = null;
|
||||
this.offFirmwareInfo?.();
|
||||
this.offFirmwareInfo = null;
|
||||
this.offMedia?.();
|
||||
this.offMedia = null;
|
||||
this.offNightscout?.();
|
||||
@@ -406,6 +434,8 @@ class DashboardController {
|
||||
this.offEvenAppConflict = null;
|
||||
this.offFrameMetrics?.();
|
||||
this.offFrameMetrics = null;
|
||||
this.offFirmwareInfo?.();
|
||||
this.offFirmwareInfo = null;
|
||||
this.offMedia?.();
|
||||
this.offMedia = null;
|
||||
this.offNightscout?.();
|
||||
@@ -580,11 +610,18 @@ class DashboardController {
|
||||
private async renderDashboard(reason: "initial" | "interval", frameId: number): Promise<void> {
|
||||
console.log("renderDashboard", reason);
|
||||
frameTimings.logFrame(frameId, `renderDashboard start (${reason})`);
|
||||
const wantFreshData = this.nextRenderWantsFreshData;
|
||||
this.nextRenderWantsFreshData = false;
|
||||
beginRenderPass(!wantFreshData);
|
||||
const paintStartedAtMs = Date.now();
|
||||
const image = frameTimings.span(frameId, "paint", () =>
|
||||
frameTimings.runWithFrame(frameId, () => drawDashboard()),
|
||||
);
|
||||
const paintMs = Date.now() - paintStartedAtMs;
|
||||
const paintUsedStaleData = endRenderPass();
|
||||
if (paintUsedStaleData) {
|
||||
frameTimings.logFrame(frameId, "painted with stale data; will schedule a fresh-data repaint");
|
||||
}
|
||||
const fingerprint = frameTimings.span(frameId, "fingerprint", () => image.fingerprint());
|
||||
const updatePreviewAfterTransmit = this.phase === "connected";
|
||||
if (!updatePreviewAfterTransmit) {
|
||||
@@ -613,6 +650,13 @@ class DashboardController {
|
||||
frameTimings.finishFrame(frameId, "discarded: no communicator, preview only");
|
||||
}
|
||||
|
||||
if (paintUsedStaleData) {
|
||||
this.nextRenderWantsFreshData = true;
|
||||
void this.requestRender("interval").catch((error) => {
|
||||
this.appendLog(`fresh-data repaint failed: ${this.formatError(error)}`);
|
||||
});
|
||||
}
|
||||
|
||||
this.updateConnectedForegroundNotification();
|
||||
if (reason === "initial") {
|
||||
this.appendLog("initial dashboard image queued");
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Compatibility check for the glasses firmware. Faceclaw requires the custom
|
||||
* firmware: version >= 2.2.4.34 with the "imgz" extension token in the CFW
|
||||
* capability string ("EVENCFW/1 img576 imgz ..."). Stock firmware sends no
|
||||
* capability string at all.
|
||||
*/
|
||||
|
||||
import { type FirmwareInfo } from "../native/faceclaw-communicator";
|
||||
|
||||
const MIN_FIRMWARE_VERSION = [2, 2, 4, 34];
|
||||
const REQUIRED_FIRMWARE_EXTENSION = "imgz";
|
||||
|
||||
function parseDottedVersion(version: string): number[] {
|
||||
return version
|
||||
.trim()
|
||||
.split(".")
|
||||
.map((part) => {
|
||||
const value = parseInt(part, 10);
|
||||
return Number.isFinite(value) ? value : 0;
|
||||
});
|
||||
}
|
||||
|
||||
/** Standard component-wise compare; missing components count as 0. */
|
||||
function compareVersions(a: number[], b: number[]): number {
|
||||
const length = Math.max(a.length, b.length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
const delta = (a[i] ?? 0) - (b[i] ?? 0);
|
||||
if (delta !== 0) return delta;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-readable explanation of why this firmware cannot run Faceclaw, or
|
||||
* null if it is compatible. Returns null when no version was reported at all
|
||||
* (no data is not evidence of incompatibility).
|
||||
*/
|
||||
export function firmwareIncompatibilityMessage(info: FirmwareInfo): string | null {
|
||||
const reportedVersions = [info.leftVersion, info.rightVersion].filter((v) => v.trim().length > 0);
|
||||
if (reportedVersions.length === 0) return null;
|
||||
|
||||
const minVersionText = MIN_FIRMWARE_VERSION.join(".");
|
||||
const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`;
|
||||
|
||||
if (reportedVersions.some((v) => compareVersions(parseDottedVersion(v), MIN_FIRMWARE_VERSION) < 0)) {
|
||||
return (
|
||||
`The glasses report firmware ${versionsText}, but Faceclaw requires the modified firmware, ` +
|
||||
`version ${minVersionText} or newer. Displaying images will not work until the glasses firmware is updated.`
|
||||
);
|
||||
}
|
||||
|
||||
const tokens = info.capabilities.trim().split(/\s+/);
|
||||
if (!tokens.includes(REQUIRED_FIRMWARE_EXTENSION)) {
|
||||
return (
|
||||
`The glasses firmware (${versionsText}) does not advertise the "${REQUIRED_FIRMWARE_EXTENSION}" extension` +
|
||||
`${info.capabilities.trim() ? ` (reported: ${info.capabilities.trim()})` : ", which suggests stock firmware"}. ` +
|
||||
`Faceclaw requires the modified firmware with compressed-image support.`
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -26,6 +26,12 @@ export type FrameMetrics = {
|
||||
tileCount: number;
|
||||
};
|
||||
|
||||
export type FirmwareInfo = {
|
||||
leftVersion: string;
|
||||
rightVersion: string;
|
||||
capabilities: string;
|
||||
};
|
||||
|
||||
export type RawInputEvent =
|
||||
| {
|
||||
kind: "list-click";
|
||||
@@ -72,6 +78,7 @@ export class FaceclawCommunicatorBridge {
|
||||
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => 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>();
|
||||
|
||||
constructor(addresses: { right: string; left: string; ring?: string }) {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
@@ -139,6 +146,14 @@ export class FaceclawCommunicatorBridge {
|
||||
onFrameFinished: (frameId: number, outcome: string) => {
|
||||
this.recordFrameFinished(Number(frameId), String(outcome));
|
||||
},
|
||||
onFirmwareInfo: (leftVersion: string, rightVersion: string, capabilities: string) => {
|
||||
const info = {
|
||||
leftVersion: String(leftVersion),
|
||||
rightVersion: String(rightVersion),
|
||||
capabilities: String(capabilities),
|
||||
};
|
||||
this.emitAsync(this.firmwareInfoListeners, info);
|
||||
},
|
||||
});
|
||||
this.communicator.setListener(this.listenerProxy);
|
||||
}
|
||||
@@ -202,6 +217,11 @@ export class FaceclawCommunicatorBridge {
|
||||
return () => this.frameMetricsListeners.delete(listener);
|
||||
}
|
||||
|
||||
onFirmwareInfo(listener: (info: FirmwareInfo) => void): () => void {
|
||||
this.firmwareInfoListeners.add(listener);
|
||||
return () => this.firmwareInfoListeners.delete(listener);
|
||||
}
|
||||
|
||||
getNativeCommunicator(): any {
|
||||
return this.communicator;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,31 @@ export type AndroidNotification = {
|
||||
actions: AndroidNotificationAction[];
|
||||
};
|
||||
|
||||
export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
|
||||
if (!global.isAndroid || maxIcons <= 0) return [];
|
||||
export type NotificationIconsResult = {
|
||||
icons: GrayImage[];
|
||||
/** True when the icons came from an expired (or empty) cache under allowStale. */
|
||||
stale: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* With allowStale, this always returns immediately: expired cached icons (or
|
||||
* none at all, right after startup or a cache invalidation) come back with
|
||||
* stale=true, and the caller is expected to repaint with allowStale=false
|
||||
* once the current frame is done. Only an allowStale=false call actually
|
||||
* fetches from the notification listener service, which can be slow depending
|
||||
* on what is in the tray.
|
||||
*/
|
||||
export function readActiveNotificationIcons(maxIcons: number, allowStale: boolean): NotificationIconsResult {
|
||||
if (!global.isAndroid || maxIcons <= 0) return { icons: [], stale: false };
|
||||
|
||||
const now = Date.now();
|
||||
if (now - cachedAtMs < ICON_CACHE_MS) {
|
||||
if (cachedAtMs > 0 && now - cachedAtMs < ICON_CACHE_MS) {
|
||||
logCurrent("notification icons served from cache");
|
||||
return cachedIcons.map(icon => icon.clone());
|
||||
return { icons: cachedIcons.map(icon => icon.clone()), stale: false };
|
||||
}
|
||||
if (allowStale) {
|
||||
logCurrent("notification icons served stale");
|
||||
return { icons: cachedIcons.map(icon => icon.clone()), stale: true };
|
||||
}
|
||||
|
||||
const bytes = spanCurrent("fetch-notification-icons", () =>
|
||||
@@ -63,7 +81,7 @@ export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
|
||||
|
||||
cachedIcons = icons;
|
||||
cachedAtMs = now;
|
||||
return icons.map(icon => icon.clone());
|
||||
return { icons: icons.map(icon => icon.clone()), stale: false };
|
||||
}
|
||||
|
||||
export function readActiveNotifications(maxNotifications = 50): AndroidNotification[] {
|
||||
|
||||
@@ -11,9 +11,12 @@
|
||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
|
||||
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
<StackLayout row="0" class="m-b-8">
|
||||
<StackLayout visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
<Label text="{{ firmwareWarningMessage }}" textWrap="true" visibility="{{ firmwareWarningVisibility }}" />
|
||||
</StackLayout>
|
||||
<StackLayout row="1">
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
|
||||
@@ -31,9 +34,12 @@
|
||||
</GridLayout>
|
||||
|
||||
<GridLayout rows="auto,*" class="p-20" visibility="{{ landscapeLayoutVisibility }}">
|
||||
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
<StackLayout row="0" class="m-b-8">
|
||||
<StackLayout visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
<Label text="{{ firmwareWarningMessage }}" textWrap="true" visibility="{{ firmwareWarningVisibility }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,*" columns="*,260">
|
||||
<StackLayout row="0" col="0" visibility="{{ displayPreviewVisibility }}" horizontalAlignment="left">
|
||||
|
||||
@@ -13,6 +13,8 @@ export class MainViewModel extends Observable {
|
||||
private _activeTextSettingValue = "";
|
||||
private _evenAppConflictMessage = "";
|
||||
private _evenAppConflictWarningVisible = false;
|
||||
private _firmwareWarningMessage = "";
|
||||
private _firmwareWarningVisible = false;
|
||||
private _showLog = false;
|
||||
private _phase: "disconnected" | "connecting" | "connected" | "disconnecting" = "disconnected";
|
||||
|
||||
@@ -28,6 +30,8 @@ export class MainViewModel extends Observable {
|
||||
this.activeTextSettingValue = snapshot.activeTextSettingValue;
|
||||
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
||||
this.firmwareWarningVisible = snapshot.firmwareWarningVisible;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -199,6 +203,33 @@ export class MainViewModel extends Observable {
|
||||
return this._evenAppConflictWarningVisible ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get firmwareWarningMessage(): string {
|
||||
return this._firmwareWarningMessage;
|
||||
}
|
||||
|
||||
set firmwareWarningMessage(value: string) {
|
||||
if (this._firmwareWarningMessage !== value) {
|
||||
this._firmwareWarningMessage = value;
|
||||
this.notifyPropertyChange("firmwareWarningMessage", value);
|
||||
}
|
||||
}
|
||||
|
||||
get firmwareWarningVisible(): boolean {
|
||||
return this._firmwareWarningVisible;
|
||||
}
|
||||
|
||||
set firmwareWarningVisible(value: boolean) {
|
||||
if (this._firmwareWarningVisible !== value) {
|
||||
this._firmwareWarningVisible = value;
|
||||
this.notifyPropertyChange("firmwareWarningVisible", value);
|
||||
this.notifyPropertyChange("firmwareWarningVisibility", this.firmwareWarningVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
get firmwareWarningVisibility(): "visible" | "collapse" {
|
||||
return this._firmwareWarningVisible ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get phase(): "disconnected" | "connecting" | "connected" | "disconnecting" {
|
||||
return this._phase;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { spanCurrent } from "../../native/frame-timings";
|
||||
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
|
||||
import { BATTERY_ICON_WIDTH, drawBattery } from "../../graphics/battery";
|
||||
import { readActiveNotificationIcons } from "../../native/notification-icons";
|
||||
import { readPhoneBatteryState } from "../../native/phone-battery";
|
||||
@@ -32,7 +33,11 @@ function drawSystemCardFlowItems(image: GrayImage, bounds: DashboardPluginCardBo
|
||||
const items: SystemCardFlowItem[] = [];
|
||||
if (showAndroidNotificationsSetting.get()) {
|
||||
const maxNotificationIcons = Math.max(0, ((right - left) / Math.max(1, NOTIFICATION_ICON_SIZE + SYSTEM_CARD_ITEM_GAP)) | 0) * 2;
|
||||
for (const icon of readActiveNotificationIcons(maxNotificationIcons)) {
|
||||
const { icons, stale } = readActiveNotificationIcons(maxNotificationIcons, renderPassAllowsStaleData());
|
||||
if (stale) {
|
||||
noteStaleDataUsed();
|
||||
}
|
||||
for (const icon of icons) {
|
||||
items.push({ type: "notification", icon });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Per-render-pass channel for stale-data tracking. JS is single-threaded and
|
||||
* paints are synchronous, so module state set around a paint is visible to
|
||||
* every data source consulted during it, without threading flags through each
|
||||
* paint signature.
|
||||
*
|
||||
* Data sources with a cache (e.g. notification icons) consult
|
||||
* renderPassAllowsStaleData() to decide whether to return expired cached data
|
||||
* immediately instead of blocking the paint on a refetch, and report having
|
||||
* done so via noteStaleDataUsed(). The render loop reads the result from
|
||||
* endRenderPass() and schedules one follow-up repaint with fresh data, so the
|
||||
* first frame out of sleep is never blocked on slow data sources.
|
||||
*/
|
||||
|
||||
let allowStale = true;
|
||||
let staleDataUsed = false;
|
||||
|
||||
export function beginRenderPass(allowStaleData: boolean): void {
|
||||
allowStale = allowStaleData;
|
||||
staleDataUsed = false;
|
||||
}
|
||||
|
||||
export function renderPassAllowsStaleData(): boolean {
|
||||
return allowStale;
|
||||
}
|
||||
|
||||
export function noteStaleDataUsed(): void {
|
||||
staleDataUsed = true;
|
||||
}
|
||||
|
||||
/** End the pass, returning whether any source served stale data. */
|
||||
export function endRenderPass(): boolean {
|
||||
const usedStale = staleDataUsed;
|
||||
allowStale = true;
|
||||
staleDataUsed = false;
|
||||
return usedStale;
|
||||
}
|
||||
Reference in new issue
Block a user