Fix an issue where animations on the phone preview stopped prematurely

This commit is contained in:
James Babcock committed 2026-10-03 15:54:57 -07:00
1 parent eb7f385644
commit 4234d3e9e9
14 files changed
+160 -6

No files matched your search

+13 -1
View File
@@ -331,6 +331,7 @@ class DashboardController {
private offPhoneLockState: (() => void) | null = null;
private offEvenAppConflict: (() => void) | null = null;
private offFrameMetrics: (() => void) | null = null;
private offPreviewAnimation: (() => void) | null = null;
private offFirmwareInfo: (() => void) | null = null;
private offVoiceStatus: (() => void) | null = null;
private offAndroidNotification: (() => void) | null = null;
@@ -1586,6 +1587,10 @@ class DashboardController {
}
}
});
// A menu slide reaches the glasses as one frame whose display list
// animates on-device; the mirror replays it in the compositor and needs
// a pull per step, or it keeps whichever mid-motion frame it last got.
this.offPreviewAnimation = communicator.onPreviewAnimationFrame(() => this.schedulePreviewUpdate());
this.offFirmwareInfo = communicator.onFirmwareInfo((info) => {
this.appendLog(
`firmware: L=${info.leftVersion || "?"} R=${info.rightVersion || "?"}` +
@@ -1680,6 +1685,8 @@ class DashboardController {
this.offEvenAppConflict = null;
this.offFrameMetrics?.();
this.offFrameMetrics = null;
this.offPreviewAnimation?.();
this.offPreviewAnimation = null;
this.offFirmwareInfo?.();
this.offFirmwareInfo = null;
this.offVoiceStatus?.();
@@ -1785,6 +1792,8 @@ class DashboardController {
this.offEvenAppConflict = null;
this.offFrameMetrics?.();
this.offFrameMetrics = null;
this.offPreviewAnimation?.();
this.offPreviewAnimation = null;
this.offFirmwareInfo?.();
this.offFirmwareInfo = null;
this.offVoiceStatus?.();
@@ -2847,7 +2856,10 @@ class DashboardController {
}
this.previewTrailingTimer = setTimeout(() => {
this.previewTrailingTimer = null;
this.updateCompositePreview();
// Re-check rather than pull directly: a timer that fires a millisecond
// early would fail the floor in updateCompositePreview and drop the
// burst's last frame (an animation's settled frame) until the 1s poll.
this.schedulePreviewUpdate();
}, wait);
}
+1
View File
@@ -764,6 +764,7 @@ export class IosPreviewController {
if (this.active) this.onConnectionState({ ...this.state })
this.schedulePreviewUpdate()
}),
communicator.onPreviewAnimationFrame(() => { if (this.communicator === communicator) this.schedulePreviewUpdate() }),
communicator.onWearState(wearing => { if (this.communicator === communicator) this.handleWearState(wearing) }),
communicator.addCompassListener(receiveCompassEvent),
communicator.onAncsRelayFrame(frame => { if (this.communicator === communicator) notifications.receive(frame) }),
+2
View File
@@ -38,4 +38,6 @@ export class SurfaceCompositor {
}
setShellScene(bytes: Uint8Array): void { this.native.shellData(toData(bytes)) }
composite(): Uint8Array { return fromData(this.native.composite()) }
/** Called on the main queue after each step of an animation the preview is replaying. */
setPreviewAnimationListener(listener: (() => void) | null): void { this.native.setPreviewAnimationListenerListener(listener) }
}
+19 -1
View File
@@ -191,6 +191,7 @@ export class FaceclawCommunicatorBridge {
private latestPhoneLockState: boolean | null = null;
private readonly evenAppConflictListeners = new Set<(message: string) => void>();
private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>();
private readonly previewAnimationListeners = new Set<() => void>();
private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>();
private readonly ancsAuthorizationListeners = new Set<(authorized: boolean) => void>();
private readonly ancsRelayListeners = new Set<(frame: Uint8Array) => void>();
@@ -209,6 +210,10 @@ export class FaceclawCommunicatorBridge {
this.listenerProxy = SessionListener.new() as SessionListener;
this.listenerProxy.bridge = this;
this.communicator.setListenerListener(this.listenerProxy);
// Kotlin calls this on the main queue.
this.communicator.setPreviewAnimationListenerListener(() => {
for (const listener of Array.from(this.previewAnimationListeners)) listener();
});
}
// ----- Kotlin listener entry points (main queue) -----------------------------------
@@ -357,6 +362,15 @@ export class FaceclawCommunicatorBridge {
return () => this.frameMetricsListeners.delete(listener);
}
/**
* Each step of an animation the phone preview is replaying (a menu slide
* reaches the glasses as one frame, so frame metrics fire only at its start).
*/
onPreviewAnimationFrame(listener: () => void): () => void {
this.previewAnimationListeners.add(listener);
return () => this.previewAnimationListeners.delete(listener);
}
onFirmwareInfo(listener: (info: FirmwareInfo) => void): () => void {
this.firmwareInfoListeners.add(listener);
return () => this.firmwareInfoListeners.delete(listener);
@@ -603,7 +617,11 @@ export class FaceclawCommunicatorBridge {
async close(): Promise<void> {
this.setAncsListeners(false);
await this.enqueueNativeCall(() => this.communicator.close());
this.previewAnimationListeners.clear();
await this.enqueueNativeCall(() => {
this.communicator.setPreviewAnimationListenerListener(null);
this.communicator.close();
});
}
// ----- iOS extras: compass, microphone, iPhone notifications (ANCS) ----------------------
+23 -1
View File
@@ -159,6 +159,7 @@ export class FaceclawCommunicatorBridge {
private readonly evenAppConflictListeners = new Set<(message: string) => void>();
private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>();
private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>();
private readonly previewAnimationListeners = new Set<() => void>();
constructor(addresses: { right: string; left: string; ring?: string }) {
const context = Utils.android.getApplicationContext();
@@ -251,6 +252,14 @@ export class FaceclawCommunicatorBridge {
},
});
this.communicator.setListener(this.listenerProxy);
// Already posted to the main looper by the Java side.
this.communicator.setPreviewAnimationListener(
new java.lang.Runnable({
run: () => {
for (const listener of Array.from(this.previewAnimationListeners)) listener();
},
}),
);
}
private emitAsync<T>(listeners: Set<(value: T) => void>, value: T): void {
@@ -364,6 +373,15 @@ export class FaceclawCommunicatorBridge {
return () => this.frameMetricsListeners.delete(listener);
}
/**
* Each step of an animation the phone preview is replaying (a menu slide
* reaches the glasses as one frame, so frame metrics fire only at its start).
*/
onPreviewAnimationFrame(listener: () => void): () => void {
this.previewAnimationListeners.add(listener);
return () => this.previewAnimationListeners.delete(listener);
}
onFirmwareInfo(listener: (info: FirmwareInfo) => void): () => void {
this.firmwareInfoListeners.add(listener);
return () => this.firmwareInfoListeners.delete(listener);
@@ -720,6 +738,10 @@ export class FaceclawCommunicatorBridge {
}
async close(): Promise<void> {
await this.enqueueJavaCall(() => this.communicator.close());
this.previewAnimationListeners.clear();
await this.enqueueJavaCall(() => {
this.communicator.setPreviewAnimationListener(null);
this.communicator.close();
});
}
}
+9 -1
View File
@@ -45,14 +45,20 @@ export class PreviewDisplayTarget implements DisplayTarget {
private onFrameComposited: (() => void) | null = null;
private released = false;
/** Receive a callback per applied frame, the stand-in for the connected path's frame-finished callback. */
/**
* Receive a callback per applied frame, the stand-in for the connected
* path's frame-finished callback, and per step of an animation the
* preview is replaying.
*/
activate(onFrameComposited: () => void): void {
this.onFrameComposited = onFrameComposited;
this.compositor.setPreviewAnimationListener(() => this.composited());
}
release(): void {
this.released = true;
this.onFrameComposited = null;
this.compositor.setPreviewAnimationListener(null);
}
private composited(): void {
@@ -61,7 +67,9 @@ export class PreviewDisplayTarget implements DisplayTarget {
async configureCompositorScreen(width: number, height: number): Promise<void> {
if (Math.round(width) !== this.compositor.width || Math.round(height) !== this.compositor.height) {
this.compositor.setPreviewAnimationListener(null);
this.compositor = new SurfaceCompositor(Math.round(width), Math.round(height));
if (this.onFrameComposited) this.compositor.setPreviewAnimationListener(() => this.composited());
}
}