forked from Blendman974/faceclaw
We're going to extend the Faceclaw app onboarding process to include checking for and installing the custom firmware (currently handled externally with the scripts in ../g2flash). We'll add script scripts/resetOnboarding.sh that uses adb to reset the app on the attached phone to default/pre-onboarding state for testing. The onboarding process will explain that it's only compatible with custom firmware, with options to either skip and try out the app using only the phone-screen preview (instead of pairing with glasses), or proceed with flashing. If the user proceeds with flashing, we first connect to the glasses (with the existing mechanism), and display an on-glasses confirmation prompt. Because this prompt needs compatibility with stock firmware, it will use a different subset of the BLE protocol than the main app does (in particular, no image containers), so we'll have a separate bluetooth communication class rather than extending FaceclawBleCommunicator. We'll send an init message to start a Hub app, initialize a layout with a text container and a list, populate the text container with a message saying that flashing will void warranty and the list with No and Yes, set up a keepalive/heartbeat message timer, and wait for a menu selection. (Refer to ../g2-kit-unofficial/ble/docs and ../g2-kit-unofficial/ble/gen for protocol details). If the prompt is approved, we go to the flashing screen. On the flashing screen, we first download the official firmware, apply patches to it, and check that it has the expected result hash. See ../g2flash/build_cfw.sh and ../g2flash/apply_patches.py for details. Let's implement everything prior to the update itself now, ie, the on-device confirmation prompt, and downloading, patching and verifying the modded firmware. scripts/resetOnboarding.sh is meant to reset a pref so that Faceclaw reruns its first-run onboarding on next launch, but fails with "No onboarding keys were set. App is already in pre-onboarding state." (And onboarding doesn't trigger on next launch) Thanks. I tested the on-glasses prompt on real hardware and it worked as expected. Next up, let's port the flashing procedure itself. One detail of the flashing procedure worth noting: the two lenses get updated separately, and at the end of updating either lens, both lenses get rebooted, creating a brief period when neither is reachable, so the timeout to look for the second lens should not be too short.
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { Utils } from "@nativescript/core";
|
|
|
|
declare const com: any;
|
|
|
|
export type FlashPromptState =
|
|
| "connecting"
|
|
| "connected"
|
|
| "prompting"
|
|
| "result"
|
|
| "cancelled"
|
|
| "timeout"
|
|
| "disconnected"
|
|
| "error";
|
|
|
|
/**
|
|
* TS wrapper around the native FaceclawFlashPromptCommunicator — the
|
|
* stock-firmware-compatible BLE path that shows the pre-flash confirmation on
|
|
* the glasses and reports the user's Yes/No choice. Separate from
|
|
* FaceclawCommunicatorBridge on purpose (different, minimal protocol subset).
|
|
*/
|
|
export class FlashPromptCommunicator {
|
|
private readonly communicator: any;
|
|
private readonly listenerProxy: any;
|
|
private readonly logListeners = new Set<(line: string) => void>();
|
|
private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>();
|
|
private readonly resultListeners = new Set<(approved: boolean) => void>();
|
|
|
|
constructor(addresses: { right: string; left: string }, warningText: string) {
|
|
const context = Utils.android.getApplicationContext();
|
|
if (!context) throw new Error("Android application context unavailable");
|
|
|
|
this.communicator = new com.faceclaw.app.FaceclawFlashPromptCommunicator(
|
|
context,
|
|
addresses.right,
|
|
addresses.left,
|
|
warningText,
|
|
);
|
|
this.listenerProxy = new com.faceclaw.app.FaceclawFlashPromptListener({
|
|
onLog: (line: string) => this.emit(this.logListeners, String(line)),
|
|
onState: (state: string, detail: string) =>
|
|
this.emit(this.stateListeners, String(state) as FlashPromptState, String(detail ?? "")),
|
|
onResult: (approved: boolean) => this.emit(this.resultListeners, Boolean(approved)),
|
|
});
|
|
this.communicator.setListener(this.listenerProxy);
|
|
}
|
|
|
|
onLog(listener: (line: string) => void): () => void {
|
|
this.logListeners.add(listener);
|
|
return () => this.logListeners.delete(listener);
|
|
}
|
|
|
|
onStateChange(listener: (state: FlashPromptState, detail: string) => void): () => void {
|
|
this.stateListeners.add(listener);
|
|
return () => this.stateListeners.delete(listener);
|
|
}
|
|
|
|
onResult(listener: (approved: boolean) => void): () => void {
|
|
this.resultListeners.add(listener);
|
|
return () => this.resultListeners.delete(listener);
|
|
}
|
|
|
|
start(): void {
|
|
this.communicator.start();
|
|
}
|
|
|
|
cancel(): void {
|
|
this.communicator.cancel();
|
|
}
|
|
|
|
close(): void {
|
|
this.communicator.close();
|
|
}
|
|
|
|
private emit<A extends unknown[]>(listeners: Set<(...args: A) => void>, ...args: A): void {
|
|
const snapshot = Array.from(listeners);
|
|
setTimeout(() => {
|
|
for (const listener of snapshot) {
|
|
listener(...args);
|
|
}
|
|
}, 0);
|
|
}
|
|
}
|