forked from Blendman974/faceclaw
Firmware uninstall/revert-to-stock for G1s
This commit is contained in:
1 parent
e103b89510
commit
479308f4a6
17 files changed
+1014
-98
No files matched your search
+13
-2
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Finding a G1's arms by listening for them. That's how an install knows what each arm runs before connecting to it,
|
||||
* and how it finds an arm again afterwards: an arm coming off Even's firmware has a new address.
|
||||
* and how it finds an arm again afterwards, when it advertises what it runs now (and, coming from g1v0 before 0.5.66, at
|
||||
* a new address).
|
||||
*/
|
||||
import { classifyAdvertisement, type EvenAdvertisement } from "../g2/even-advertisement";
|
||||
import { DiscoveryAggregator, type GlassesPairCandidate } from "../g2/pairing-candidates";
|
||||
@@ -27,11 +28,21 @@ export class G1ArmScanner {
|
||||
|
||||
/** Resolves when an arm of this side on g1v0 is heard, or null after [timeoutMs]. */
|
||||
waitForG1v0Arm(side: G1Side, serial: string | null | undefined, timeoutMs: number): Promise<EvenAdvertisement | null> {
|
||||
return this.waitForArm(side, serial, timeoutMs, (arm) => arm.g1Firmware !== "stock");
|
||||
}
|
||||
|
||||
/** Resolves when an arm of this side is heard that [accept] takes, on any firmware, or null after [timeoutMs]. */
|
||||
waitForArm(
|
||||
side: G1Side,
|
||||
serial: string | null | undefined,
|
||||
timeoutMs: number,
|
||||
accept: (arm: EvenAdvertisement) => boolean,
|
||||
): Promise<EvenAdvertisement | null> {
|
||||
const startedAt = Date.now();
|
||||
const others = new Map<string, EvenAdvertisement>();
|
||||
return this.listen<EvenAdvertisement>(timeoutMs, (raw, done) => {
|
||||
const arm = classifyAdvertisement(raw);
|
||||
if (!arm || arm.role !== side || !arm.g1Firmware || arm.g1Firmware === "stock") return;
|
||||
if (!arm || arm.role !== side || !arm.g1Firmware || !accept(arm)) return;
|
||||
if (!serial || sameG1Serial(arm.serial, serial)) {
|
||||
done(arm);
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Even's official G1 firmware, which an uninstall puts back: both images of one public release, the application core's
|
||||
* and the network core's (the Bluetooth controller), as Even's own update installs them, so the two always match.
|
||||
* From Even's CDN, checked against these SHA-256 sums (scouter_kit g1_firmware/stock_images.txt). Every public image
|
||||
* says 0.0.0 in its MCUboot header, so the hashes are the only way to tell releases apart.
|
||||
*/
|
||||
export type EvenG1Release = {
|
||||
version: string;
|
||||
zipUrl: string;
|
||||
zipSha256: string;
|
||||
appSha256: string;
|
||||
netCoreSha256: string;
|
||||
};
|
||||
|
||||
export const EVEN_G1_RESTORE: EvenG1Release = {
|
||||
version: "1.6.6",
|
||||
zipUrl: "https://cdn.evenreal.co/firmware/dcfa510c090e476c10a6f6c348a22415.zip",
|
||||
zipSha256: "748836f2d9d092b0783cbb7672fdccec4f730051cad27f095bbb156ac3e5d316",
|
||||
appSha256: "ae032838e27037156da98e19de90df78f5406715751f3b38adf50498db3010c1",
|
||||
netCoreSha256: "c277749be97a2763742db399afeb10ca6916059abd60d41bbc05c8892c002c77",
|
||||
};
|
||||
@@ -1,29 +1,34 @@
|
||||
/**
|
||||
* Prepares the g1v0 image on the phone, as app/g2/firmware-builder.ts does for a G2: downloads Even's public firmware,
|
||||
* checks it, and puts the parts this firmware embeds back into what the app ships. The result is byte for byte the
|
||||
* image that was built, tested and signed, and it is checked to be. It does not touch the glasses.
|
||||
* image that was built, tested and signed, and it is checked to be. Also prepares Even's own images for an uninstall.
|
||||
* It does not touch the glasses.
|
||||
*/
|
||||
import { knownFolders } from "@nativescript/core";
|
||||
|
||||
import { firmwareSha256, writeFirmwareFile } from "../native/firmware-files";
|
||||
import { decodeBase64 } from "../util/base64";
|
||||
import { fetchWithUserAgent } from "../util/http";
|
||||
import { EVEN_G1_RESTORE } from "./even-firmware";
|
||||
import { G1V0_IMAGE } from "./firmware/g1v0-image";
|
||||
import { G1V0_OWN_BYTES_BASE64 } from "./firmware/g1v0-own-bytes";
|
||||
import { assembleG1Image, decodeG1OwnBytes, G1FirmwareError, readZipEntry } from "./firmware-image";
|
||||
import { assembleG1Image, decodeG1OwnBytes, extractEvenG1Images, G1FirmwareError, readZipEntry } from "./firmware-image";
|
||||
|
||||
export type G1BuildProgress = "downloading" | "verifying" | "assembling" | "writing";
|
||||
|
||||
export type BuiltG1Firmware = { path: string; bytes: number; version: string };
|
||||
|
||||
/** Even's release for an uninstall: the application core's image and the network core's. */
|
||||
export type BuiltEvenG1Firmware = { appPath: string; netCorePath: string; bytes: number; version: string };
|
||||
|
||||
function sha256(bytes: Uint8Array): string {
|
||||
return firmwareSha256(bytes.slice().buffer);
|
||||
}
|
||||
|
||||
async function downloadStockZip(): Promise<Uint8Array> {
|
||||
async function downloadStockZip(url: string): Promise<Uint8Array> {
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetchWithUserAgent(G1V0_IMAGE.stockZipUrl);
|
||||
response = await fetchWithUserAgent(url);
|
||||
} catch (error) {
|
||||
throw new G1FirmwareError(`Could not reach Even's firmware server: ${(error as Error)?.message ?? error}`);
|
||||
}
|
||||
@@ -33,7 +38,7 @@ async function downloadStockZip(): Promise<Uint8Array> {
|
||||
|
||||
export async function buildG1Firmware(onProgress?: (progress: G1BuildProgress) => void): Promise<BuiltG1Firmware> {
|
||||
onProgress?.("downloading");
|
||||
const zip = await downloadStockZip();
|
||||
const zip = await downloadStockZip(G1V0_IMAGE.stockZipUrl);
|
||||
|
||||
onProgress?.("verifying");
|
||||
const zipHash = sha256(zip);
|
||||
@@ -50,3 +55,19 @@ export async function buildG1Firmware(onProgress?: (progress: G1BuildProgress) =
|
||||
writeFirmwareFile(path, image.slice().buffer);
|
||||
return { path, bytes: image.length, version: G1V0_IMAGE.version };
|
||||
}
|
||||
|
||||
export async function buildEvenG1Firmware(onProgress?: (progress: G1BuildProgress) => void): Promise<BuiltEvenG1Firmware> {
|
||||
onProgress?.("downloading");
|
||||
const zip = await downloadStockZip(EVEN_G1_RESTORE.zipUrl);
|
||||
|
||||
onProgress?.("verifying");
|
||||
const { app, netCore } = extractEvenG1Images(zip, EVEN_G1_RESTORE, sha256);
|
||||
|
||||
onProgress?.("writing");
|
||||
const folder = knownFolders.documents().path;
|
||||
const appPath = `${folder}/even_g1_${EVEN_G1_RESTORE.version}_app.bin`;
|
||||
const netCorePath = `${folder}/even_g1_${EVEN_G1_RESTORE.version}_net.bin`;
|
||||
writeFirmwareFile(appPath, app.slice().buffer);
|
||||
writeFirmwareFile(netCorePath, netCore.slice().buffer);
|
||||
return { appPath, netCorePath, bytes: app.length + netCore.length, version: EVEN_G1_RESTORE.version };
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import { inflate, inflateRaw } from "pako";
|
||||
|
||||
import type { EvenG1Release } from "./even-firmware";
|
||||
import type { G1FirmwareImage } from "./firmware/g1v0-image";
|
||||
|
||||
export class G1FirmwareError extends Error {}
|
||||
@@ -41,6 +42,31 @@ export function readZipEntry(zip: Uint8Array, name: string): Uint8Array {
|
||||
throw new G1FirmwareError(`The firmware download has no ${name}.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* The two images of Even's release from its download, each checked by its own SHA-256 as well as the zip's, so what
|
||||
* goes to the arms is byte for byte what Even published.
|
||||
*/
|
||||
export function extractEvenG1Images(
|
||||
zip: Uint8Array,
|
||||
release: EvenG1Release,
|
||||
sha256: (bytes: Uint8Array) => string,
|
||||
): { app: Uint8Array; netCore: Uint8Array } {
|
||||
const zipHash = sha256(zip);
|
||||
if (zipHash !== release.zipSha256) {
|
||||
throw new G1FirmwareError(`Even's firmware download failed verification.\nexpected ${release.zipSha256}\ngot ${zipHash}`);
|
||||
}
|
||||
const checked = (name: string, want: string) => {
|
||||
const bytes = readZipEntry(zip, name);
|
||||
const got = sha256(bytes);
|
||||
if (got !== want) throw new G1FirmwareError(`${name} in Even's download failed verification.\nexpected ${want}\ngot ${got}`);
|
||||
return bytes;
|
||||
};
|
||||
return {
|
||||
app: checked("app_update.bin", release.appSha256),
|
||||
netCore: checked("net_core_app_update.bin", release.netCoreSha256),
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeG1OwnBytes(base64: string, decode: (text: string) => Uint8Array): Uint8Array {
|
||||
return inflate(decode(base64));
|
||||
}
|
||||
|
||||
+16
-5
@@ -1,11 +1,15 @@
|
||||
/** What installing firmware on a G1 has to decide. No I/O. */
|
||||
import type { GlassesPairCandidate } from "../g2/pairing-candidates";
|
||||
import { EVEN_G1_RESTORE } from "./even-firmware";
|
||||
|
||||
export type G1Side = "left" | "right";
|
||||
|
||||
/** Left first: a right arm on g1v0 next to a left arm on Even's firmware would leave the left eye dark. */
|
||||
export const G1_SIDES: readonly G1Side[] = ["left", "right"];
|
||||
|
||||
/** Going back, right first, for the same reason: halfway, the pair is as halfway through an install. */
|
||||
export const G1_UNINSTALL_SIDES: readonly G1Side[] = ["right", "left"];
|
||||
|
||||
export const G1_CASE_INSTRUCTIONS =
|
||||
"Put the glasses in their charging case with the lid open, and plug the case in. Stay nearby, and leave Faceclaw open.";
|
||||
|
||||
@@ -14,13 +18,20 @@ export const G1_CASE_DELAY_HINT =
|
||||
"A fully charged arm can take up to 5 minutes to notice it's in the case, so this may take a while.";
|
||||
|
||||
export const G1_INSTALL_NOTICE =
|
||||
"This replaces the firmware on both arms, about two minutes each. Going back to Even's firmware later takes a computer, and " +
|
||||
"may not be the version you have now. Installing custom firmware is not covered by warranty.";
|
||||
"This replaces the firmware on both arms, about two minutes each. Faceclaw can put Even's firmware back later, but as version " +
|
||||
`${EVEN_G1_RESTORE.version}, which may not be the version you have now. Installing custom firmware is not covered by warranty.`;
|
||||
|
||||
export const G1_UNINSTALL_NOTICE =
|
||||
`This puts Even's official firmware ${EVEN_G1_RESTORE.version} back on both arms, Bluetooth controller included, a few minutes ` +
|
||||
"each. It may not be the version they came with. Afterwards they work with Even's app again, and not with Faceclaw until you " +
|
||||
"install its firmware again.";
|
||||
|
||||
/** What the native flow says when it finishes (G1ArmFlashFlow). */
|
||||
export type G1FlashResult = {
|
||||
flashed?: boolean;
|
||||
firmware?: "g1v0" | "stock";
|
||||
/** A restore erased g1v0's asset store, where Even's fonts and pictures were. */
|
||||
wiped?: boolean;
|
||||
version?: string;
|
||||
safeMode?: boolean;
|
||||
inCase?: boolean;
|
||||
@@ -102,8 +113,8 @@ export function g1StateFromAdvertising(
|
||||
return { state: compareG1Versions(lowest, shipped) < 0 ? "older" : "current", version: lowest };
|
||||
}
|
||||
|
||||
/** Each arm counts for half of the bar. */
|
||||
export function g1FlashPercent(side: G1Side, bytesSent: number, bytesTotal: number): number {
|
||||
/** Each arm counts for half of the bar, in the order they're done. */
|
||||
export function g1FlashPercent(side: G1Side, bytesSent: number, bytesTotal: number, order: readonly G1Side[] = G1_SIDES): number {
|
||||
const within = bytesTotal > 0 ? Math.min(1, bytesSent / bytesTotal) : 0;
|
||||
return ((side === "right" ? 1 + within : within) / 2) * 100;
|
||||
return ((order.indexOf(side) + within) / 2) * 100;
|
||||
}
|
||||
@@ -7,8 +7,10 @@ export type { G1FlashMode, G1FlasherOptions } from './g1-flasher'
|
||||
|
||||
declare const FaceclawKitIosG1Flasher: any, FaceclawKitFaceclawFirmwareFlasherListener: any
|
||||
|
||||
/** CoreBluetooth has no way to remove a pairing; iOS Settings does it, and a stale one does no harm. */
|
||||
export function forgetG1Pairing(_address: string): void {}
|
||||
/** CoreBluetooth has no way to remove a pairing; iOS Settings does it. */
|
||||
export function forgetG1Pairing(_address: string): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* iOS twin of the Android G1Flasher: the shared Kotlin G1ArmFlashFlow over a CoreBluetooth central. As with the G2's
|
||||
@@ -47,8 +49,8 @@ export class G1Flasher {
|
||||
return new Promise<G1FlashResult>((resolve, reject) => {
|
||||
const identifier = iosBluetooth().peripheralIdentifier(this.options.address, this.options.side)
|
||||
if (!identifier) throw new Error(`Could not find the ${this.options.side} arm. Keep the glasses in the case with the lid open.`)
|
||||
this.flasher = FaceclawKitIosG1Flasher.alloc().initWithAddressSideFirmwarePathModeConnectWindowMs(
|
||||
identifier, this.options.side, this.options.firmwarePath, this.options.mode, this.options.connectWindowMs)
|
||||
this.flasher = FaceclawKitIosG1Flasher.alloc().initWithAddressSideFirmwarePathNetCorePathModeConnectWindowMs(
|
||||
identifier, this.options.side, this.options.firmwarePath, this.options.netCorePath ?? '', this.options.mode, this.options.connectWindowMs)
|
||||
this.listenerProxy = kotlinListener(FaceclawKitFaceclawFirmwareFlasherListener, {
|
||||
onLogLine: (line: string) => this.logListener?.(String(line ?? '')),
|
||||
onProgressLensComponentIndexComponentCountBlockIndexBlockCountBytesSentBytesTotal: (
|
||||
|
||||
@@ -4,24 +4,30 @@ import { parseG1FlashResult, type G1FlashResult, type G1Side } from "../g1/flash
|
||||
|
||||
declare const com: any;
|
||||
|
||||
export type G1FlashMode = "stock" | "update" | "probe";
|
||||
/** "restore": Even's firmware back on an arm running g1v0, both of its images. */
|
||||
export type G1FlashMode = "stock" | "update" | "probe" | "restore";
|
||||
|
||||
export type G1FlasherOptions = {
|
||||
address: string;
|
||||
side: G1Side;
|
||||
/** The application core's image. */
|
||||
firmwarePath: string;
|
||||
/** A restore's network-core image. */
|
||||
netCorePath?: string;
|
||||
mode: G1FlashMode;
|
||||
/** How long to keep trying to reach the arm and pair with it. */
|
||||
connectWindowMs: number;
|
||||
};
|
||||
|
||||
/** Removes the phone's pairing with an address the glasses no longer use. */
|
||||
export function forgetG1Pairing(address: string): void {
|
||||
/** Removes the phone's pairing with an address, which the glasses no longer use or no longer share. False: this phone can't. */
|
||||
export function forgetG1Pairing(address: string): boolean {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
if (context) com.faceclaw.app.FaceclawG1Flasher.forgetPairing(context, address);
|
||||
if (!context) return false;
|
||||
com.faceclaw.app.FaceclawG1Flasher.forgetPairing(context, address);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** TS wrapper around FaceclawG1Flasher: one arm's install, or a question about what it runs. */
|
||||
/** TS wrapper around FaceclawG1Flasher: one arm's install, its restore to Even's firmware, or a question about what it runs. */
|
||||
export class G1Flasher {
|
||||
private readonly flasher: any;
|
||||
private readonly listenerProxy: any;
|
||||
@@ -34,7 +40,7 @@ export class G1Flasher {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
if (!context) throw new Error("Android application context unavailable");
|
||||
this.flasher = new com.faceclaw.app.FaceclawG1Flasher(
|
||||
context, options.address, options.side, options.firmwarePath, options.mode, options.connectWindowMs,
|
||||
context, options.address, options.side, options.firmwarePath, options.netCorePath ?? "", options.mode, options.connectWindowMs,
|
||||
);
|
||||
this.listenerProxy = new com.faceclaw.app.FaceclawFirmwareFlasherListener({
|
||||
onLog: (line: string) => this.logListener?.(String(line)),
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
|
||||
import { G1ArmScanner } from "../g1/arm-scanner";
|
||||
import { EVEN_G1_RESTORE } from "../g1/even-firmware";
|
||||
import { G1V0_IMAGE } from "../g1/firmware/g1v0-image";
|
||||
import { buildG1Firmware, type BuiltG1Firmware, type G1BuildProgress } from "../g1/firmware-builder";
|
||||
import {
|
||||
buildEvenG1Firmware,
|
||||
buildG1Firmware,
|
||||
type BuiltEvenG1Firmware,
|
||||
type BuiltG1Firmware,
|
||||
type G1BuildProgress,
|
||||
} from "../g1/firmware-builder";
|
||||
import { saveG1Arm, saveG1Pair } from "../g1/addresses";
|
||||
import {
|
||||
G1_CASE_DELAY_HINT,
|
||||
G1_CASE_INSTRUCTIONS,
|
||||
G1_INSTALL_NOTICE,
|
||||
G1_SIDES,
|
||||
G1_UNINSTALL_NOTICE,
|
||||
G1_UNINSTALL_SIDES,
|
||||
g1FlashPercent,
|
||||
type G1FlashResult,
|
||||
type G1Side,
|
||||
@@ -23,19 +32,27 @@ import { formatErrorMessage } from "../util/format-error";
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
type Phase = "intro" | "preparing" | "flashing" | "flashed" | "error" | "unavailable";
|
||||
type Phase = "intro" | "preparing" | "flashing" | "flashed" | "error";
|
||||
|
||||
const LOCATE_MS = 45_000;
|
||||
/** An arm takes about 20 s to copy the image, and a hung boot resets itself within two minutes. */
|
||||
const RETURN_MS = 240_000;
|
||||
/** Even's image is larger than g1v0, and MCUboot first installs the network core's. */
|
||||
const RESTORE_RETURN_MS = 300_000;
|
||||
/**
|
||||
* Just after its reset an arm may still be heard on g1v0. Later than this, one heard on g1v0 has booted it again:
|
||||
* MCUboot didn't take Even's firmware.
|
||||
*/
|
||||
const OLD_FIRMWARE_GRACE_MS = 15_000;
|
||||
const CONNECT_MS = 60_000;
|
||||
/** A new arm pairs only once it knows it's in the case, which a full case can take a while to tell it. */
|
||||
const FIRST_PAIRING_MS = 120_000;
|
||||
|
||||
/**
|
||||
* The install page on a G1, in place of OnboardingFlashViewModel. The two arms are separate devices that each take the
|
||||
* image over MCUmgr (G1ArmFlashFlow), left first. There is nothing on the lens to confirm with before g1v0 is on the arm,
|
||||
* so the confirmation is on the phone: the page before, or this one's intro.
|
||||
* The install and uninstall page on a G1, in place of OnboardingFlashViewModel. The two arms are separate devices that
|
||||
* each take the image over MCUmgr (G1ArmFlashFlow), left first; an uninstall goes right first and puts back both of
|
||||
* Even's images, the network core's too. There is nothing on the lens to confirm with while an arm runs Even's
|
||||
* firmware, so the confirmation is on the phone: the page before, or this one's intro.
|
||||
*
|
||||
* Every run starts by listening for what each arm runs now, so a retry picks up wherever the last one stopped. An arm's
|
||||
* new address is saved as soon as it's known.
|
||||
@@ -43,12 +60,18 @@ const FIRST_PAIRING_MS = 120_000;
|
||||
export class G1FlashViewModel extends Observable {
|
||||
private phase: Phase = "intro";
|
||||
private readonly fromOnboarding: boolean;
|
||||
private readonly uninstalling: boolean;
|
||||
private readonly scanner = new G1ArmScanner();
|
||||
private image: BuiltG1Firmware | null = null;
|
||||
private evenImage: BuiltEvenG1Firmware | null = null;
|
||||
private flasher: G1Flasher | null = null;
|
||||
private generation = 0;
|
||||
private disposed = false;
|
||||
private unpairedArm = false;
|
||||
/** An uninstall's outcome, for the last page: an arm's store erased, a pairing this phone couldn't remove, an arm done. */
|
||||
private wiped = false;
|
||||
private pairingLeft = false;
|
||||
private restoredArm = false;
|
||||
|
||||
headline = "Install Faceclaw's Firmware";
|
||||
status = "";
|
||||
@@ -59,17 +82,14 @@ export class G1FlashViewModel extends Observable {
|
||||
constructor(options?: { mode?: "install" | "uninstall"; fromOnboarding?: boolean; autoStart?: boolean }) {
|
||||
super();
|
||||
this.fromOnboarding = options?.fromOnboarding ?? true;
|
||||
if (options?.mode === "uninstall") {
|
||||
// Restoring Even's firmware has never been run on a real arm, and an arm whose network core is older than the
|
||||
// image may not come back, so the phone doesn't offer it yet.
|
||||
this.phase = "unavailable";
|
||||
this.headline = "Back to Even's Firmware";
|
||||
this.status = "Faceclaw can't restore Even's firmware on a G1 yet. It takes a computer: see \"Restore Even's firmware\" in " +
|
||||
"the ScouterKit firmware's README.";
|
||||
return;
|
||||
}
|
||||
this.uninstalling = options?.mode === "uninstall";
|
||||
suppressAutoReconnect();
|
||||
this.status = `${G1_CASE_INSTRUCTIONS}\n\n${G1_INSTALL_NOTICE}`;
|
||||
if (this.uninstalling) {
|
||||
this.headline = "Back to Even's Firmware";
|
||||
this.status = `${G1_CASE_INSTRUCTIONS}\n\n${G1_UNINSTALL_NOTICE}`;
|
||||
} else {
|
||||
this.status = `${G1_CASE_INSTRUCTIONS}\n\n${G1_INSTALL_NOTICE}`;
|
||||
}
|
||||
if (options?.autoStart) void this.run();
|
||||
}
|
||||
|
||||
@@ -90,7 +110,7 @@ export class G1FlashViewModel extends Observable {
|
||||
get primaryLabel(): string {
|
||||
switch (this.phase) {
|
||||
case "intro":
|
||||
return "Install";
|
||||
return this.uninstalling ? "Uninstall" : "Install";
|
||||
case "flashed":
|
||||
return "Finish";
|
||||
case "error":
|
||||
@@ -119,7 +139,7 @@ export class G1FlashViewModel extends Observable {
|
||||
}
|
||||
|
||||
onSecondaryTap(): void {
|
||||
if (this.phase === "intro" || this.phase === "error" || this.phase === "unavailable") this.leave();
|
||||
if (this.phase === "intro" || this.phase === "error") this.leave();
|
||||
}
|
||||
|
||||
// --- the install ----------------------------------------------------------
|
||||
@@ -129,21 +149,30 @@ export class G1FlashViewModel extends Observable {
|
||||
const live = () => !this.disposed && generation === this.generation;
|
||||
this.setPhase("preparing");
|
||||
this.setBusy(true);
|
||||
this.setText("Preparing Firmware", "Getting the firmware ready...");
|
||||
this.setText("Preparing Firmware", this.uninstalling ? "Getting Even's firmware ready..." : "Getting the firmware ready...");
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
if (!live()) return;
|
||||
if (!this.image) {
|
||||
this.image = await buildG1Firmware((progress) => {
|
||||
if (live()) this.setStatus(describeBuild(progress));
|
||||
});
|
||||
this.appendLog(`firmware ${this.image.version} prepared and verified (${this.image.bytes.toLocaleString()} bytes)`);
|
||||
if (this.uninstalling) {
|
||||
if (!this.evenImage) {
|
||||
this.evenImage = await buildEvenG1Firmware((progress) => {
|
||||
if (live()) this.setStatus(describeEvenBuild(progress));
|
||||
});
|
||||
this.appendLog(`Even's firmware ${this.evenImage.version} downloaded and verified (${this.evenImage.bytes.toLocaleString()} bytes)`);
|
||||
}
|
||||
} else {
|
||||
if (!this.image) {
|
||||
this.image = await buildG1Firmware((progress) => {
|
||||
if (live()) this.setStatus(describeBuild(progress));
|
||||
});
|
||||
this.appendLog(`firmware ${this.image.version} prepared and verified (${this.image.bytes.toLocaleString()} bytes)`);
|
||||
}
|
||||
await this.prepareFonts(live);
|
||||
}
|
||||
await this.prepareFonts(live);
|
||||
if (!live()) return;
|
||||
|
||||
this.setPhase("flashing");
|
||||
this.setText("Installing Firmware", "Listening for your glasses...");
|
||||
this.setText(this.uninstalling ? "Restoring Even's Firmware" : "Installing Firmware", "Listening for your glasses...");
|
||||
const identity = loadPairedGlassesIdentity();
|
||||
const stored = loadDeviceAddresses();
|
||||
const pair = await this.scanner.waitForPair({ serial: identity?.serial, left: stored.left, right: stored.right }, LOCATE_MS);
|
||||
@@ -154,6 +183,14 @@ export class G1FlashViewModel extends Observable {
|
||||
}
|
||||
saveG1Pair(pair);
|
||||
|
||||
if (this.uninstalling) {
|
||||
for (const side of G1_UNINSTALL_SIDES) {
|
||||
await this.restoreArm(side, pair, live);
|
||||
if (!live()) return;
|
||||
}
|
||||
this.restored();
|
||||
return;
|
||||
}
|
||||
this.unpairedArm = false;
|
||||
for (const side of G1_SIDES) {
|
||||
await this.installArm(side, pair, live);
|
||||
@@ -231,6 +268,65 @@ export class G1FlashViewModel extends Observable {
|
||||
this.appendLog(`${side} arm runs ${running.version}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Even's firmware back on one arm, then a wait for it to advertise as Even's. An arm already on Even's firmware is
|
||||
* left alone: a retry goes on from there.
|
||||
*/
|
||||
private async restoreArm(side: G1Side, pair: GlassesPairCandidate, live: () => boolean): Promise<void> {
|
||||
const arm = pair[side]!;
|
||||
if (arm.g1Firmware === "stock") {
|
||||
this.appendLog(`${side} arm already runs Even's firmware`);
|
||||
this.setProgress(g1FlashPercent(side, 1, 1, G1_UNINSTALL_SIDES));
|
||||
return;
|
||||
}
|
||||
const even = this.evenImage!;
|
||||
this.setProgress(g1FlashPercent(side, 0, 1, G1_UNINSTALL_SIDES));
|
||||
this.setStatus(`Connecting to the ${side} arm...`);
|
||||
const result = await this.flash({
|
||||
address: arm.address,
|
||||
side,
|
||||
firmwarePath: even.appPath,
|
||||
netCorePath: even.netCorePath,
|
||||
mode: "restore",
|
||||
connectWindowMs: CONNECT_MS,
|
||||
}, (state) => {
|
||||
if (state === "pairing") this.setStatus(`Pairing with the ${side} arm. If your phone asks, accept it.`);
|
||||
else if (state === "checking") this.setStatus(`Checking the ${side} arm...`);
|
||||
else if (state === "wiping") {
|
||||
this.setStatus(`Erasing Faceclaw's storage on the ${side} arm, where Even's fonts were. This can take several minutes; keep the ` +
|
||||
"glasses in the case. Nothing else has changed yet.");
|
||||
} else if (state === "flashing") this.setStatus(`Sending Even's firmware to the ${side} arm. Its firmware hasn't changed yet.`);
|
||||
else if (state === "committing") this.setStatus(`Installing on the ${side} arm. Keep the glasses in the case.`);
|
||||
}, (sent, total) => this.setProgress(g1FlashPercent(side, sent, total, G1_UNINSTALL_SIDES)));
|
||||
if (!live()) return;
|
||||
if (result.wiped) this.wiped = true;
|
||||
this.setProgress(g1FlashPercent(side, 1, 1, G1_UNINSTALL_SIDES));
|
||||
|
||||
this.setStatus(`The ${side} arm is restarting into Even's firmware. This takes a minute or two; keep it in the case.`);
|
||||
const resetAt = Date.now();
|
||||
const identity = loadPairedGlassesIdentity();
|
||||
const back = await this.scanner.waitForArm(side, identity?.serial ?? pair.serial, RESTORE_RETURN_MS,
|
||||
(heard) => heard.g1Firmware === "stock" || Date.now() - resetAt >= OLD_FIRMWARE_GRACE_MS);
|
||||
if (!live()) return;
|
||||
if (!back) {
|
||||
throw new Error(`The ${side} arm hasn't come back yet. Leave the glasses in the plugged-in case for a few minutes, with the lid ` +
|
||||
"open: an interrupted install finishes by itself. Then retry.");
|
||||
}
|
||||
if (back.g1Firmware !== "stock") {
|
||||
throw new Error(`The ${side} arm came back on Faceclaw's firmware: it didn't take Even's. Retry to try again.`);
|
||||
}
|
||||
saveG1Arm(side, back);
|
||||
this.restoredArm = true;
|
||||
// Even's app makes its own pairing with Even's firmware; the one this phone made with g1v0 would only be in its way.
|
||||
this.forgetPairing(back.address);
|
||||
if (back.address !== arm.address) this.forgetPairing(arm.address);
|
||||
this.appendLog(`${side} arm runs Even's firmware`);
|
||||
}
|
||||
|
||||
private forgetPairing(address: string): void {
|
||||
if (!forgetG1Pairing(address)) this.pairingLeft = true;
|
||||
}
|
||||
|
||||
private async flash(
|
||||
options: G1FlasherOptions,
|
||||
onState?: (state: string) => void,
|
||||
@@ -271,6 +367,28 @@ export class G1FlashViewModel extends Observable {
|
||||
: ""));
|
||||
}
|
||||
|
||||
private restored(): void {
|
||||
// Stays manually disconnected: Faceclaw would only find firmware it can't run.
|
||||
this.setBusy(false);
|
||||
this.setProgress(100);
|
||||
this.setPhase("flashed");
|
||||
if (!this.restoredArm) {
|
||||
this.setText("All Done", "Both arms already run Even's firmware.");
|
||||
return;
|
||||
}
|
||||
const steps = [`Both arms run Even's firmware ${EVEN_G1_RESTORE.version}.`];
|
||||
if (this.pairingLeft) {
|
||||
steps.push("Before pairing them in Even's app, remove both arms in this phone's Bluetooth settings (\"Forget This Device\"): " +
|
||||
"Faceclaw's firmware made that pairing, and Even's firmware makes its own.");
|
||||
} else {
|
||||
steps.push("To use them, pair them in Even's app.");
|
||||
}
|
||||
if (this.wiped) {
|
||||
steps.push("Even's Chinese, Japanese and Korean text and its demo pictures were erased with Faceclaw's storage, and don't come back.");
|
||||
}
|
||||
this.setText("All Done", steps.join("\n\n"));
|
||||
}
|
||||
|
||||
private failed(message: string): void {
|
||||
this.setBusy(false);
|
||||
this.setPhase("error");
|
||||
@@ -278,8 +396,10 @@ export class G1FlashViewModel extends Observable {
|
||||
}
|
||||
|
||||
private finish(): void {
|
||||
setPreviewOnlyMode(false);
|
||||
setOnboardingCompleted(true);
|
||||
if (!this.uninstalling) {
|
||||
setPreviewOnlyMode(false);
|
||||
setOnboardingCompleted(true);
|
||||
}
|
||||
this.teardown();
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
@@ -344,6 +464,17 @@ export class G1FlashViewModel extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
function describeEvenBuild(progress: G1BuildProgress): string {
|
||||
switch (progress) {
|
||||
case "downloading":
|
||||
return "Downloading Even's firmware from Even's firmware server...";
|
||||
case "verifying":
|
||||
return "Verifying the download...";
|
||||
default:
|
||||
return "Saving the firmware...";
|
||||
}
|
||||
}
|
||||
|
||||
function describeBuild(progress: G1BuildProgress): string {
|
||||
switch (progress) {
|
||||
case "downloading":
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
import { EVEN_G1_RESTORE } from "../g1/even-firmware";
|
||||
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
|
||||
|
||||
import { isPreviewOnlyMode } from "./onboarding-state";
|
||||
@@ -38,7 +39,7 @@ function firmwareBody(glasses: GlassesType): string {
|
||||
return `Faceclaw only runs on a RayNeo iO that has Faceclaw's custom firmware installed. This app can't install it on an iO, so that has to be done separately before you pair your glasses. ${WARRANTY_NOTE}\n\n${PREVIEW_HINT}`;
|
||||
}
|
||||
const restore = glasses === "g1"
|
||||
? "Returning to the official firmware later takes a computer."
|
||||
? `You can return to the official firmware later from Faceclaw, as version ${EVEN_G1_RESTORE.version}.`
|
||||
: "You can uninstall and return to the official firmware later, by reconnecting the official Even Realities app.";
|
||||
return `Faceclaw only runs on ${GLASSES_MAKER[glasses].product} glasses that have Faceclaw's custom firmware installed. Next, Faceclaw will pair with your glasses, check their firmware, and install the custom firmware if it isn't there yet.\n\nFlashing replaces the official firmware. ${restore} ${WARRANTY_NOTE}\n\n${PREVIEW_HINT}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user