forked from Blendman974/faceclaw
Merge upstream main preserving custom feature integrations
This commit is contained in:
commit
6150a1ac57
228 files changed
+16844
-1388
No files matched your search
@@ -0,0 +1,489 @@
|
||||
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 {
|
||||
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,
|
||||
} from "../g1/flash-plan";
|
||||
import { loadDeviceAddresses, loadPairedGlassesIdentity } from "../g2/device-addresses";
|
||||
import { downloadAndExtractEvenHubFonts, hasExtractedEvenHubFonts } from "../g2/firmware-builder";
|
||||
import { type GlassesPairCandidate } from "../g2/pairing-candidates";
|
||||
import { resumeAutoReconnect, suppressAutoReconnect } from "../g2/reconnect-policy";
|
||||
import { ensureBlePermissions } from "../native/ble-permissions";
|
||||
import { forgetG1Pairing, G1Flasher, type G1FlasherOptions } from "../native/g1-flasher";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
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 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.
|
||||
*/
|
||||
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 = "";
|
||||
log = "";
|
||||
busy = false;
|
||||
progress = 0;
|
||||
|
||||
constructor(options?: { mode?: "install" | "uninstall"; fromOnboarding?: boolean; autoStart?: boolean }) {
|
||||
super();
|
||||
this.fromOnboarding = options?.fromOnboarding ?? true;
|
||||
this.uninstalling = options?.mode === "uninstall";
|
||||
suppressAutoReconnect();
|
||||
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();
|
||||
}
|
||||
|
||||
// --- what the page binds --------------------------------------------------
|
||||
|
||||
get logVisibility(): "visible" | "collapse" {
|
||||
return this.log ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get busyVisibility(): "visible" | "collapse" {
|
||||
return this.busy ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get progressVisibility(): "visible" | "collapse" {
|
||||
return this.phase === "flashing" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get primaryLabel(): string {
|
||||
switch (this.phase) {
|
||||
case "intro":
|
||||
return this.uninstalling ? "Uninstall" : "Install";
|
||||
case "flashed":
|
||||
return "Finish";
|
||||
case "error":
|
||||
return "Retry";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
get primaryVisibility(): "visible" | "collapse" {
|
||||
return this.primaryLabel ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get secondaryLabel(): string {
|
||||
return "Back";
|
||||
}
|
||||
|
||||
get secondaryVisibility(): "visible" | "collapse" {
|
||||
// No way out mid-install, or after one.
|
||||
return this.phase === "preparing" || this.phase === "flashing" || this.phase === "flashed" ? "collapse" : "visible";
|
||||
}
|
||||
|
||||
onPrimaryTap(): void {
|
||||
if (this.phase === "intro" || this.phase === "error") void this.run();
|
||||
else if (this.phase === "flashed") this.finish();
|
||||
}
|
||||
|
||||
onSecondaryTap(): void {
|
||||
if (this.phase === "intro" || this.phase === "error") this.leave();
|
||||
}
|
||||
|
||||
// --- the install ----------------------------------------------------------
|
||||
|
||||
private async run(): Promise<void> {
|
||||
const generation = ++this.generation;
|
||||
const live = () => !this.disposed && generation === this.generation;
|
||||
this.setPhase("preparing");
|
||||
this.setBusy(true);
|
||||
this.setText("Preparing Firmware", this.uninstalling ? "Getting Even's firmware ready..." : "Getting the firmware ready...");
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
if (!live()) return;
|
||||
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);
|
||||
}
|
||||
if (!live()) return;
|
||||
|
||||
this.setPhase("flashing");
|
||||
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);
|
||||
if (!live()) return;
|
||||
if (!pair) {
|
||||
throw new Error("Couldn't hear both arms of your glasses. Make sure they're in the case with the lid open, and that no other app " +
|
||||
"or phone is connected to them, then retry.");
|
||||
}
|
||||
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);
|
||||
if (!live()) return;
|
||||
}
|
||||
this.finished();
|
||||
} catch (error) {
|
||||
if (live()) this.failed(formatErrorMessage(error));
|
||||
}
|
||||
}
|
||||
|
||||
private async installArm(side: G1Side, pair: GlassesPairCandidate, live: () => boolean): Promise<void> {
|
||||
const arm = pair[side]!;
|
||||
const fromStock = arm.g1Firmware === "stock";
|
||||
this.setProgress(g1FlashPercent(side, 0, 1));
|
||||
this.setStatus(`Connecting to the ${side} arm...`);
|
||||
const installed = await this.flash({
|
||||
address: arm.address,
|
||||
side,
|
||||
firmwarePath: this.image!.path,
|
||||
mode: fromStock ? "stock" : "update",
|
||||
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 === "flashing") this.setStatus(`Sending the firmware to the ${side} arm. Nothing has 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)));
|
||||
if (!live()) return;
|
||||
this.setProgress(g1FlashPercent(side, 1, 1));
|
||||
if (!installed.flashed) {
|
||||
this.appendLog(`${side} arm already runs ${installed.version}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setStatus(`The ${side} arm is restarting into the new firmware. This takes about 20 seconds; keep it in the case.`);
|
||||
const identity = loadPairedGlassesIdentity();
|
||||
const back = await this.scanner.waitForG1v0Arm(side, identity?.serial ?? pair.serial, RETURN_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.");
|
||||
}
|
||||
saveG1Arm(side, back);
|
||||
// Coming from firmware before 0.5.66, which had an address of its own: the phone needn't remember that one.
|
||||
if (back.address !== arm.address) forgetG1Pairing(arm.address);
|
||||
if (back.g1Firmware === "g1v0-safe") {
|
||||
throw new Error(`The ${side} arm came back in safe mode: the new firmware restarted repeatedly. Retry to install it again.`);
|
||||
}
|
||||
|
||||
this.setStatus(`Checking the ${side} arm. If your phone asks to pair, accept it. ${G1_CASE_DELAY_HINT}`);
|
||||
// An arm at a new address has no bond yet (coming from Even's firmware the address is kept from 0.5.66 on, and so is the
|
||||
// bond). It may refuse one for a while: it's installed either way, and the session pairs it later.
|
||||
const newAddress = back.address !== arm.address;
|
||||
let running: G1FlashResult;
|
||||
try {
|
||||
running = await this.flash({
|
||||
address: back.address,
|
||||
side,
|
||||
firmwarePath: "",
|
||||
mode: "probe",
|
||||
connectWindowMs: newAddress ? FIRST_PAIRING_MS : RETURN_MS,
|
||||
});
|
||||
} catch (error) {
|
||||
if (!newAddress || !live()) throw error;
|
||||
// Installed, as its advertising shows; it just won't pair yet. The next connection pairs it.
|
||||
this.appendLog(`${side} arm not paired yet: ${formatErrorMessage(error)}`);
|
||||
this.unpairedArm = true;
|
||||
return;
|
||||
}
|
||||
if (!live()) return;
|
||||
if (running.version !== installed.version) {
|
||||
throw new Error(`The ${side} arm runs ${running.version}, not ${installed.version}: it didn't take the new firmware. Retry to try again.`);
|
||||
}
|
||||
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,
|
||||
onProgress?: (sent: number, total: number) => void,
|
||||
) {
|
||||
const flasher = new G1Flasher(options);
|
||||
this.flasher = flasher;
|
||||
flasher.onLog((line) => this.appendLog(line));
|
||||
if (onState) flasher.onState(onState);
|
||||
if (onProgress) flasher.onProgress(onProgress);
|
||||
try {
|
||||
return await flasher.run();
|
||||
} finally {
|
||||
if (this.flasher === flasher) this.flasher = null;
|
||||
flasher.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** A G2's install gets these from the same download; Faceclaw's fonts are a phone-side matter, so a failure here is no reason to stop. */
|
||||
private async prepareFonts(live: () => boolean): Promise<void> {
|
||||
if (hasExtractedEvenHubFonts()) return;
|
||||
if (live()) this.setStatus("Preparing fonts...");
|
||||
try {
|
||||
await downloadAndExtractEvenHubFonts();
|
||||
} catch (error) {
|
||||
this.appendLog(`fonts not prepared: ${formatErrorMessage(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
private finished(): void {
|
||||
// The glasses are ready for the main page to connect to.
|
||||
resumeAutoReconnect();
|
||||
this.setBusy(false);
|
||||
this.setProgress(100);
|
||||
this.setPhase("flashed");
|
||||
this.setText("All Done", `Both arms run Faceclaw's firmware ${G1V0_IMAGE.version}.` + (this.unpairedArm
|
||||
? " Keep the glasses in the case with the lid open until Faceclaw has connected: they only pair in the case."
|
||||
: ""));
|
||||
}
|
||||
|
||||
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");
|
||||
this.setText("Something Went Wrong", message);
|
||||
}
|
||||
|
||||
private finish(): void {
|
||||
if (!this.uninstalling) {
|
||||
setPreviewOnlyMode(false);
|
||||
setOnboardingCompleted(true);
|
||||
}
|
||||
this.teardown();
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
|
||||
private leave(): void {
|
||||
this.teardown();
|
||||
const frame = Frame.topmost();
|
||||
if (this.fromOnboarding && frame?.canGoBack()) {
|
||||
frame.goBack();
|
||||
return;
|
||||
}
|
||||
if (!this.fromOnboarding) {
|
||||
finishOnboardingNavigation();
|
||||
return;
|
||||
}
|
||||
frame?.navigate({ moduleName: "phone-ui/onboarding-page", clearHistory: true });
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposed = true;
|
||||
this.teardown();
|
||||
}
|
||||
|
||||
private teardown(): void {
|
||||
++this.generation;
|
||||
this.scanner.stop();
|
||||
this.flasher?.close();
|
||||
this.flasher = null;
|
||||
}
|
||||
|
||||
// --- page state -----------------------------------------------------------
|
||||
|
||||
private setText(headline: string, status: string): void {
|
||||
this.set("headline", headline);
|
||||
this.set("status", status);
|
||||
}
|
||||
|
||||
private setStatus(status: string): void {
|
||||
this.set("status", status);
|
||||
}
|
||||
|
||||
private setBusy(busy: boolean): void {
|
||||
this.set("busy", busy);
|
||||
this.notifyPropertyChange("busyVisibility", this.busyVisibility);
|
||||
}
|
||||
|
||||
private setProgress(percent: number): void {
|
||||
this.set("progress", Math.max(0, Math.min(100, Math.round(percent))));
|
||||
}
|
||||
|
||||
private setPhase(phase: Phase): void {
|
||||
this.phase = phase;
|
||||
for (const property of ["primaryLabel", "primaryVisibility", "secondaryVisibility", "progressVisibility"] as const) {
|
||||
this.notifyPropertyChange(property, this[property]);
|
||||
}
|
||||
}
|
||||
|
||||
private appendLog(line: string): void {
|
||||
const stamp = new Date().toISOString().slice(11, 19);
|
||||
this.set("log", this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`);
|
||||
this.notifyPropertyChange("logVisibility", this.logVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
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":
|
||||
return "Downloading the parts it needs from Even's firmware server...";
|
||||
case "verifying":
|
||||
return "Verifying the download...";
|
||||
case "assembling":
|
||||
return "Assembling the firmware...";
|
||||
default:
|
||||
return "Saving the firmware...";
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { IosPreviewController } from '../g2/ios-preview-controller'
|
||||
import { PhoneGestureRecognizer } from './phone-gestures'
|
||||
import { BleBandwidthMeter } from './ble-bandwidth-meter'
|
||||
import { sampleBleTraffic } from '../native/ble-traffic'
|
||||
import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
|
||||
import { glassesModelName, onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
|
||||
import { loadDeviceAddresses } from '../g2/device-addresses'
|
||||
import { deviceAddressError } from '../g2/ios-peripheral-identity'
|
||||
import { formatBatteryLine } from '../g2/glasses-display-state'
|
||||
@@ -75,7 +75,7 @@ export function createMainPage(): Page {
|
||||
// The Settings tab's battery row. iOS reports charging sessions as
|
||||
// connected, so "connected" is the whole live-link condition here.
|
||||
let glassesLinked = false
|
||||
const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked) }
|
||||
const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked, glassesModelName()) }
|
||||
const keyboardField = () => keyboardPanel.getViewById<TextView>('keyboardInputField')
|
||||
const controller = new IosPreviewController((image, label) => {
|
||||
mirror.imageSource = image; model.set('padFocusLine', label)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<ActionItem text="Conversations" tap="{{ onConversationsTap }}" android.position="popup" />
|
||||
<ActionItem text="Take screenshot" tap="{{ onTakeScreenshotTap }}" android.position="popup" />
|
||||
<ActionItem text="Record screen" tap="{{ onRecordScreenTap }}" android.position="popup" />
|
||||
<ActionItem text="Check firmware" tap="{{ onCheckFirmwareTap }}" isEnabled="{{ canRun }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
|
||||
<ActionItem text="Uninstall custom firmware" tap="{{ onUninstallFirmwareTap }}" isEnabled="{{ canRun }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
|
||||
</ActionBar>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
|
||||
import { formatBatteryLine } from "../g2/glasses-display-state";
|
||||
import {
|
||||
glassesModelName,
|
||||
mirrorTouchSetting,
|
||||
onAnySettingChanged,
|
||||
showBleBandwidthSetting,
|
||||
@@ -26,10 +27,13 @@ import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
|
||||
import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-policy";
|
||||
import { isPreviewOnlyMode } from "./onboarding-state";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
|
||||
import { screenHeight, screenWidth } from "../ui/shell/geometry";
|
||||
import { type PhoneUiButton } from "../apps/evenhub/manager";
|
||||
|
||||
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
|
||||
/** The paired glasses' screen aspect (4:3 on the G2, 27:11 on the RayNeo iO). */
|
||||
function lensAspectRatio(): number {
|
||||
return screenWidth() / screenHeight();
|
||||
}
|
||||
|
||||
type LayoutOrientation = "portrait" | "landscape";
|
||||
|
||||
@@ -96,6 +100,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.batteryLine = formatBatteryLine(
|
||||
snapshot.batteries,
|
||||
snapshot.phase === "connected" || snapshot.phase === "charging",
|
||||
glassesModelName(),
|
||||
);
|
||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||
@@ -246,7 +251,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
}
|
||||
|
||||
get displayPreviewHeight(): number {
|
||||
return Screen.mainScreen.widthDIPs / LENS_ASPECT_RATIO;
|
||||
return Screen.mainScreen.widthDIPs / lensAspectRatio();
|
||||
}
|
||||
|
||||
get landscapeDisplayPreviewWidth(): number {
|
||||
@@ -262,8 +267,8 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
// and controls, and updates for rotation, split-screen, and the keyboard.
|
||||
const { width, height } = args.object.getActualSize();
|
||||
if (width <= 0 || height <= 0) return;
|
||||
const previewHeight = Math.min(height, width / LENS_ASPECT_RATIO);
|
||||
const previewWidth = previewHeight * LENS_ASPECT_RATIO;
|
||||
const previewHeight = Math.min(height, width / lensAspectRatio());
|
||||
const previewWidth = previewHeight * lensAspectRatio();
|
||||
if (previewWidth === this._landscapePreviewWidth && previewHeight === this._landscapePreviewHeight) return;
|
||||
this._landscapePreviewWidth = previewWidth;
|
||||
this._landscapePreviewHeight = previewHeight;
|
||||
@@ -672,6 +677,14 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
* auto-reconnect suppression right away.
|
||||
*/
|
||||
async onPrepareFontsTap(): Promise<void> {
|
||||
await this.openFirmwareCheck();
|
||||
}
|
||||
|
||||
async onCheckFirmwareTap(): Promise<void> {
|
||||
await this.openFirmwareCheck();
|
||||
}
|
||||
|
||||
private async openFirmwareCheck(): Promise<void> {
|
||||
this.setWarningsModalVisible(false);
|
||||
if (this.phase === "connected" || this.phase === "charging" || this.phase === "connecting") {
|
||||
try {
|
||||
@@ -919,8 +932,9 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
}
|
||||
|
||||
private async openFlashPage(mode: "install" | "uninstall"): Promise<void> {
|
||||
// The flasher needs the glasses to itself, so drop the main connection first.
|
||||
if (this.phase === "connected" || this.phase === "charging") {
|
||||
// The flasher needs the glasses to itself, so drop the main connection first. That includes a session
|
||||
// still retrying: an install brings arms back at the addresses it is dialling.
|
||||
if (this.phase === "connected" || this.phase === "charging" || this.phase === "connecting") {
|
||||
try {
|
||||
await dashboardController.disconnect();
|
||||
} catch {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { EventData, Page } from "@nativescript/core";
|
||||
|
||||
import { OnboardingDevicesViewModel } from "./onboarding-devices-view-model";
|
||||
|
||||
export function navigatingTo(args: EventData): void {
|
||||
const page = args.object as Page;
|
||||
if (!page.bindingContext) {
|
||||
page.bindingContext = new OnboardingDevicesViewModel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
|
||||
<GridLayout rows="*,auto" class="p-20">
|
||||
<ScrollView row="0">
|
||||
<StackLayout>
|
||||
<Label text="Your Devices" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="Which devices do you have?"
|
||||
class="body-text m-t-24" textWrap="true" />
|
||||
|
||||
<Label text="Glasses" class="h2 pairing-section m-t-24" />
|
||||
<Repeater items="{{ glassesOptions }}">
|
||||
<Repeater.itemsLayout>
|
||||
<StackLayout />
|
||||
</Repeater.itemsLayout>
|
||||
<Repeater.itemTemplate>
|
||||
<GridLayout columns="*,auto" rows="auto" class="{{ rowClass }}" tap="{{ onRowTap }}">
|
||||
<StackLayout col="0" verticalAlignment="center">
|
||||
<Label text="{{ label }}" class="pairing-title" />
|
||||
<Label text="{{ note }}" class="permissions-description" textWrap="true" visibility="{{ noteVisibility }}" />
|
||||
</StackLayout>
|
||||
<Label col="1" text="✓" class="permissions-check" verticalAlignment="center" visibility="{{ checkVisibility }}" />
|
||||
</GridLayout>
|
||||
</Repeater.itemTemplate>
|
||||
</Repeater>
|
||||
|
||||
<Label text="Accessories" class="h2 pairing-section m-t-16" />
|
||||
<GridLayout columns="*,auto" rows="auto" class="pairing-row">
|
||||
<Label col="0" text="Even R1 ring" class="pairing-title" verticalAlignment="center" />
|
||||
<Switch col="1" checked="{{ hasRing }}" verticalAlignment="center" margin="0" />
|
||||
</GridLayout>
|
||||
<GridLayout columns="*,auto" rows="auto" class="pairing-row">
|
||||
<Label col="0" text="{{ watchLabel }}" class="pairing-title" verticalAlignment="center" />
|
||||
<Switch col="1" checked="{{ hasWatch }}" verticalAlignment="center" margin="0" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
<GridLayout row="1" columns="*,*" class="m-t-20">
|
||||
<Button col="0" text="Back" tap="{{ onBackTap }}" />
|
||||
<Button col="1" text="Next" tap="{{ onNextTap }}" class="-primary" isEnabled="{{ nextEnabled }}" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -0,0 +1,124 @@
|
||||
import { EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
|
||||
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
|
||||
import { ownsRing, ownsWatch, setOwnsRing, setOwnsWatch, setPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
/** A row in the glasses list: a kind of glasses, or no glasses at all. */
|
||||
type GlassesChoice = GlassesType | "preview";
|
||||
|
||||
const GLASSES_OPTIONS: { choice: GlassesChoice; label: string; description?: string }[] = [
|
||||
{ choice: "preview", label: "Preview Only", description: "No glasses: explore Faceclaw on your phone's screen" },
|
||||
{ choice: "g1", label: "Even G1" },
|
||||
{ choice: "g2", label: "Even G2" },
|
||||
{ choice: "rayneo-io", label: "RayNeo iO" },
|
||||
];
|
||||
|
||||
/** RayNeo iO support isn't ready to offer in a release yet; set this to show its row again. */
|
||||
const OFFER_RAYNEO_IO = false;
|
||||
|
||||
/** Why this choice can't be made on this phone, or "" when it can. */
|
||||
function unavailableReason(choice: GlassesChoice): string {
|
||||
// FaceclawCommunicatorBridge refuses to start a session with one on iOS.
|
||||
return choice === "rayneo-io" && global.isIOS ? "Not supported on iOS yet" : "";
|
||||
}
|
||||
|
||||
export type GlassesOptionItem = {
|
||||
choice: GlassesChoice;
|
||||
label: string;
|
||||
selectable: boolean;
|
||||
note: string;
|
||||
noteVisibility: "visible" | "collapse";
|
||||
rowClass: string;
|
||||
/** Hidden, not collapsed: the check is what sets a row's height, so collapsing it would shift the list on every selection. */
|
||||
checkVisibility: "visible" | "hidden";
|
||||
onRowTap: (args: EventData) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Your Devices onboarding page, between the splash and the disclaimer: one
|
||||
* kind of glasses (or Preview Only) plus any accessories, which later setup
|
||||
* pages tailor themselves to. Pairing still has the last word on the glasses,
|
||||
* since it can tell what it heard.
|
||||
*
|
||||
* Nothing starts out selected, whatever an earlier run stored, and Next waits
|
||||
* for a choice. A tap stores it straight away: Preview Only sets the persisted
|
||||
* preview-only flag and leaves the glasses type alone, so the Permissions page
|
||||
* finishes onboarding instead of moving on to the firmware step.
|
||||
*/
|
||||
export class OnboardingDevicesViewModel extends Observable {
|
||||
/** This visit's choice; the page keeps this model when you come Back to it. */
|
||||
private selected: GlassesChoice | null = null;
|
||||
|
||||
get glassesOptions(): GlassesOptionItem[] {
|
||||
const selected = this.selected;
|
||||
const options = OFFER_RAYNEO_IO ? GLASSES_OPTIONS : GLASSES_OPTIONS.filter(({ choice }) => choice !== "rayneo-io");
|
||||
return options.map(({ choice, label, description }) => {
|
||||
const reason = unavailableReason(choice);
|
||||
const note = reason || description || "";
|
||||
const isSelected = choice === selected;
|
||||
return {
|
||||
choice,
|
||||
label,
|
||||
selectable: !reason,
|
||||
note,
|
||||
noteVisibility: note ? "visible" : "collapse",
|
||||
rowClass: isSelected ? "pairing-row pairing-row-selected" : reason ? "pairing-row pairing-row-incomplete" : "pairing-row",
|
||||
checkVisibility: isSelected ? "visible" : "hidden",
|
||||
onRowTap: this.onGlassesRowTap,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Arrow property: NativeScript fires XML event handlers with `this` bound to
|
||||
// the tapped view's bindingContext (the row item), not the view model.
|
||||
readonly onGlassesRowTap = (args: EventData): void => {
|
||||
const item = (args.object as View).bindingContext as GlassesOptionItem | undefined;
|
||||
if (!item?.selectable) return;
|
||||
this.selected = item.choice;
|
||||
setPreviewOnlyMode(item.choice === "preview");
|
||||
if (item.choice !== "preview") glassesTypeSetting.set(item.choice);
|
||||
this.notifyPropertyChange("glassesOptions", this.glassesOptions);
|
||||
this.notifyPropertyChange("nextEnabled", this.nextEnabled);
|
||||
};
|
||||
|
||||
get nextEnabled(): boolean {
|
||||
return this.selected !== null;
|
||||
}
|
||||
|
||||
get hasRing(): boolean {
|
||||
return ownsRing();
|
||||
}
|
||||
|
||||
set hasRing(value: boolean) {
|
||||
setOwnsRing(value);
|
||||
}
|
||||
|
||||
get hasWatch(): boolean {
|
||||
return ownsWatch();
|
||||
}
|
||||
|
||||
set hasWatch(value: boolean) {
|
||||
setOwnsWatch(value);
|
||||
}
|
||||
|
||||
get watchLabel(): string {
|
||||
return global.isIOS ? "Apple Watch" : "Wear OS watch";
|
||||
}
|
||||
|
||||
onNextTap(): void {
|
||||
if (!this.nextEnabled) return;
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/onboarding-page",
|
||||
context: { step: 2 },
|
||||
});
|
||||
}
|
||||
|
||||
onBackTap(): void {
|
||||
const frame = Frame.topmost();
|
||||
if (frame?.canGoBack()) {
|
||||
frame.goBack();
|
||||
return;
|
||||
}
|
||||
frame?.navigate({ moduleName: "phone-ui/onboarding-page", clearHistory: true });
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,29 @@ import {
|
||||
type OnboardingFirmwareKind,
|
||||
} from "../g2/firmware-compat";
|
||||
import { DeviceInfoProbe, DeviceInfoState } from "../native/device-info-probe";
|
||||
import { G1Flasher } from "../native/g1-flasher";
|
||||
import { saveG1Pair } from "../g1/addresses";
|
||||
import { G1ArmScanner } from "../g1/arm-scanner";
|
||||
import { G1V0_IMAGE } from "../g1/firmware/g1v0-image";
|
||||
import {
|
||||
G1_CASE_DELAY_HINT,
|
||||
G1_CASE_INSTRUCTIONS,
|
||||
G1_INSTALL_NOTICE,
|
||||
g1FirmwareState,
|
||||
g1StateFromAdvertising,
|
||||
type G1FlashResult,
|
||||
type G1Side,
|
||||
} from "../g1/flash-plan";
|
||||
import { loadPairedGlassesIdentity } from "../g2/device-addresses";
|
||||
import { glassesTypeSetting } from "../ui/dashboard-settings";
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
|
||||
type CheckPhase = "checking" | "fonts" | "custom" | "flashable" | "newer-validated" | "newer" | "error";
|
||||
|
||||
const G1_LOCATE_MS = 30_000;
|
||||
const G1_CHECK_CONNECT_MS = 45_000;
|
||||
|
||||
export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
private _phase: CheckPhase = "checking";
|
||||
private _headline = "Checking Firmware";
|
||||
@@ -31,7 +49,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
|
||||
private generation = 0;
|
||||
|
||||
private probeInstance: DeviceInfoProbe | null = null;
|
||||
private probeInstance: { close(): void } | null = null;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -175,6 +193,10 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
if (generation !== this.generation) return;
|
||||
if (glassesTypeSetting.get() === "g1") {
|
||||
await this.checkG1(generation);
|
||||
return;
|
||||
}
|
||||
const stored = loadDeviceAddresses();
|
||||
if (!isValidMacAddress(stored.right)) {
|
||||
this.toError("No glasses address is configured. Go back and set the device addresses.");
|
||||
@@ -194,11 +216,71 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
this.applyClassification(kind, version, extension);
|
||||
} catch (error) {
|
||||
if (generation !== this.generation) return;
|
||||
this.probeInstance = null;
|
||||
this.toError(this.formatError(error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What the arms advertise first, as that needs no connection or pairing. Only firmware from before it advertised its
|
||||
* version (0.5.66) has to be asked.
|
||||
*/
|
||||
private async checkG1(generation: number): Promise<void> {
|
||||
this.status = "Listening for your glasses...";
|
||||
const scanner = new G1ArmScanner();
|
||||
this.probeInstance = { close: () => scanner.stop() };
|
||||
const stored = loadDeviceAddresses();
|
||||
const pair = await scanner.waitForPair({ serial: loadPairedGlassesIdentity()?.serial, left: stored.left, right: stored.right }, G1_LOCATE_MS);
|
||||
if (generation !== this.generation) return;
|
||||
this.probeInstance = null;
|
||||
if (!pair) {
|
||||
this.toError(`Couldn't hear both arms of your glasses. ${G1_CASE_INSTRUCTIONS} Make sure no other app or phone is connected to them, then retry.`);
|
||||
return;
|
||||
}
|
||||
saveG1Pair(pair);
|
||||
const advertised = g1StateFromAdvertising(pair, G1V0_IMAGE.version);
|
||||
if (advertised) {
|
||||
if (advertised.state === "current") this.applyClassification("custom", advertised.version, { kind: "none" });
|
||||
else if (advertised.state === "stock") this.showG1Install({ firmware: "stock" });
|
||||
else if (advertised.state === "safe-mode") this.showG1Install({ safeMode: true });
|
||||
else this.showG1Install({ version: advertised.version });
|
||||
return;
|
||||
}
|
||||
const arms: G1FlashResult[] = [];
|
||||
for (const side of ["left", "right"] as G1Side[]) {
|
||||
const flasher = new G1Flasher({ address: pair[side]!.address, side, firmwarePath: "", mode: "probe", connectWindowMs: G1_CHECK_CONNECT_MS });
|
||||
this.probeInstance = flasher;
|
||||
flasher.onState((state) => {
|
||||
if (generation !== this.generation) return;
|
||||
if (state === "pairing") {
|
||||
this.status = `Pairing with the ${side} arm. If your phone asks, accept it. A G1 pairs only in its case, with the lid open. ${G1_CASE_DELAY_HINT}`;
|
||||
} else {
|
||||
this.status = `Checking the ${side} arm...`;
|
||||
}
|
||||
});
|
||||
arms.push(await flasher.run());
|
||||
if (generation !== this.generation) return;
|
||||
this.disposeProbe();
|
||||
}
|
||||
const state = g1FirmwareState(arms, G1V0_IMAGE.version);
|
||||
if (state === "current") this.applyClassification("custom", arms[0]!.version ?? "", { kind: "none" });
|
||||
else this.showG1Install(state === "stock" ? { firmware: "stock" } : state === "safe-mode" ? { safeMode: true } : arms.find((arm) => arm.version) ?? {});
|
||||
}
|
||||
|
||||
private showG1Install(found: G1FlashResult): void {
|
||||
this.busy = false;
|
||||
this.setPhase("flashable");
|
||||
if (found.firmware === "stock") {
|
||||
this.headline = "Ready to Install";
|
||||
this.status = `Your glasses run Even's firmware.\n\n${G1_CASE_INSTRUCTIONS}\n\n${G1_INSTALL_NOTICE}`;
|
||||
} else if (found.safeMode) {
|
||||
this.headline = "Firmware Needs Reinstalling";
|
||||
this.status = `An arm of your glasses is in safe mode: its firmware restarted repeatedly. Installing it again usually fixes this.\n\n${G1_CASE_INSTRUCTIONS}`;
|
||||
} else {
|
||||
this.headline = "Firmware Update Available";
|
||||
this.status = `Your glasses run Faceclaw's firmware ${found.version ?? ""}, and this version of Faceclaw comes with ${G1V0_IMAGE.version}.\n\n${G1_CASE_INSTRUCTIONS}`;
|
||||
}
|
||||
}
|
||||
|
||||
private reportProbeState(state: DeviceInfoState, detail: string): void {
|
||||
// The probe brings up the right lens, then the left, and pairs with each
|
||||
// in turn (they are separate Bluetooth devices with separate bonds).
|
||||
@@ -326,7 +408,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
this.busy = false;
|
||||
this.setPhase("custom");
|
||||
this.headline = extractedFonts ? "Fonts Ready" : "Custom Firmware Detected";
|
||||
const details = [
|
||||
const details = glassesTypeSetting.get() === "g1" ? [version].filter(Boolean) : [
|
||||
extension.kind === "faceclaw" ? `revision ${extension.version}` : "",
|
||||
version ? `based on stock ${version}` : "",
|
||||
].filter(Boolean);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NavigatedData, Page } from "@nativescript/core";
|
||||
|
||||
import { glassesTypeSetting } from "../ui/dashboard-settings";
|
||||
import { G1FlashViewModel } from "./g1-flash-view-model";
|
||||
import { FlashMode, OnboardingFlashViewModel } from "./onboarding-flash-view-model";
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
@@ -7,16 +9,17 @@ export function navigatingTo(args: NavigatedData): void {
|
||||
if (!page.bindingContext) {
|
||||
const context =
|
||||
(args.context as { mode?: FlashMode; fromOnboarding?: boolean; autoStart?: boolean } | undefined) ?? undefined;
|
||||
page.bindingContext = new OnboardingFlashViewModel({
|
||||
const options = {
|
||||
mode: context?.mode ?? "install",
|
||||
fromOnboarding: context?.fromOnboarding ?? true,
|
||||
autoStart: context?.autoStart ?? false,
|
||||
});
|
||||
};
|
||||
page.bindingContext = glassesTypeSetting.get() === "g1" ? new G1FlashViewModel(options) : new OnboardingFlashViewModel(options);
|
||||
}
|
||||
}
|
||||
|
||||
export function navigatingFrom(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
(page.bindingContext as OnboardingFlashViewModel | undefined)?.dispose();
|
||||
(page.bindingContext as OnboardingFlashViewModel | G1FlashViewModel | undefined)?.dispose();
|
||||
page.bindingContext = null;
|
||||
}
|
||||
@@ -2,6 +2,8 @@ require('@nativescript/core/bundle-entry-points');
|
||||
// iOS reuses Android's NativeScript XML forms and view models.
|
||||
global.registerModule('phone-ui/onboarding-page', () => require('./onboarding-page'));
|
||||
global.registerModule('phone-ui/onboarding-page.xml', () => require('./onboarding-page.xml'));
|
||||
global.registerModule('phone-ui/onboarding-devices-page', () => require('./onboarding-devices-page'));
|
||||
global.registerModule('phone-ui/onboarding-devices-page.xml', () => require('./onboarding-devices-page.xml'));
|
||||
global.registerModule('phone-ui/onboarding-unpair-page', () => require('./onboarding-unpair-page'));
|
||||
global.registerModule('phone-ui/onboarding-unpair-page.xml', () => require('./onboarding-unpair-page.xml'));
|
||||
global.registerModule('phone-ui/pairing-page', () => require('./pairing-page'));
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { ApplicationSettings } from "@nativescript/core";
|
||||
|
||||
import { getBooleanSetting, setBooleanSetting } from "../native/settings-store";
|
||||
|
||||
const ONBOARDING_COMPLETE_KEY = "onboarding.complete";
|
||||
const PREVIEW_ONLY_KEY = "onboarding.previewOnly";
|
||||
// The "onboarding." prefix keeps these on this phone in config transfers and
|
||||
// lets scripts/resetOnboarding.sh clear them.
|
||||
const OWNS_RING_KEY = "onboarding.ownsRing";
|
||||
const OWNS_WATCH_KEY = "onboarding.ownsWatch";
|
||||
|
||||
export function hasCompletedOnboarding(): boolean {
|
||||
return ApplicationSettings.getBoolean(ONBOARDING_COMPLETE_KEY, false);
|
||||
@@ -27,3 +33,24 @@ export function isPreviewOnlyMode(): boolean {
|
||||
export function setPreviewOnlyMode(previewOnly: boolean): void {
|
||||
ApplicationSettings.setBoolean(PREVIEW_ONLY_KEY, previewOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessories chosen on the Your Devices onboarding page, for tailoring the
|
||||
* rest of setup. The glasses chosen there go in glassesTypeSetting instead.
|
||||
*/
|
||||
export function ownsRing(): boolean {
|
||||
return getBooleanSetting(OWNS_RING_KEY, false);
|
||||
}
|
||||
|
||||
export function setOwnsRing(owns: boolean): void {
|
||||
setBooleanSetting(OWNS_RING_KEY, owns);
|
||||
}
|
||||
|
||||
/** An Apple Watch on iOS, a Wear OS watch on Android. */
|
||||
export function ownsWatch(): boolean {
|
||||
return getBooleanSetting(OWNS_WATCH_KEY, false);
|
||||
}
|
||||
|
||||
export function setOwnsWatch(owns: boolean): void {
|
||||
setBooleanSetting(OWNS_WATCH_KEY, owns);
|
||||
}
|
||||
@@ -4,10 +4,11 @@
|
||||
<StackLayout>
|
||||
<Label text="Disconnect Other Apps" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="Your glasses can only be connected to one app or phone at a time. If they're connected to another app (such as Even Realities or MentraOS) or another phone, disconnect them there before continuing. If nothing else is connected, you can continue."
|
||||
text="{{ otherAppsInstructions }}"
|
||||
class="body-text m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="{{ evenAppInstructions }}"
|
||||
visibility="{{ evenAppVisibility }}"
|
||||
class="body-text m-t-16" textWrap="true" />
|
||||
<Button text="Open Even App Settings" tap="{{ onOpenEvenAppSettingsTap }}" visibility="{{ settingsButtonVisibility }}" width="{{ settingsButtonWidth }}" horizontalAlignment="center" class="-primary m-t-24" />
|
||||
</StackLayout>
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
|
||||
import { openEvenAppSettings } from "../native/even-app-conflict";
|
||||
import { glassesTypeSetting } from "../ui/dashboard-settings";
|
||||
import { hasCompletedOnboarding } from "./onboarding-state";
|
||||
|
||||
export class OnboardingUnpairViewModel extends Observable {
|
||||
/**
|
||||
* Setting up a RayNeo iO, so the Even app doesn't apply. Only during first-run
|
||||
* setup: "Pair glasses" in the main menu also opens this page, and you may be
|
||||
* pairing something other than the glasses you paired before.
|
||||
*/
|
||||
private readonly settingUpIo = !hasCompletedOnboarding() && glassesTypeSetting.get() === "rayneo-io";
|
||||
|
||||
get otherAppsInstructions(): string {
|
||||
const apps = this.settingUpIo ? "another app" : "another app (such as Even Realities or MentraOS)";
|
||||
return `Your glasses can only be connected to one app or phone at a time. If they're connected to ${apps} or another phone, disconnect them there before continuing. If nothing else is connected, you can continue.`;
|
||||
}
|
||||
|
||||
get evenAppVisibility(): "visible" | "collapse" {
|
||||
return this.settingUpIo ? "collapse" : "visible";
|
||||
}
|
||||
|
||||
get settingsButtonVisibility(): "visible" | "collapse" {
|
||||
return global.isAndroid ? "visible" : "collapse";
|
||||
return global.isAndroid && !this.settingUpIo ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get evenAppInstructions(): string {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
import { IOS_PRIVACY_NOTICE } from "../analytics/privacy-disclosure";
|
||||
import { EVEN_G1_RESTORE } from "../g1/even-firmware";
|
||||
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
|
||||
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { isPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
/** Steps are separate pages in the flow; the devices page follows the splash. */
|
||||
type OnboardingStep = 1 | 2 | 3;
|
||||
|
||||
type StepContent = {
|
||||
@@ -17,52 +18,84 @@ type StepContent = {
|
||||
showSecondary: boolean;
|
||||
};
|
||||
|
||||
const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
|
||||
1: {
|
||||
headline: "Faceclaw",
|
||||
tagline: "Perching on the faces of giants",
|
||||
body: "",
|
||||
primaryLabel: "Next",
|
||||
secondaryLabel: "",
|
||||
splash: true,
|
||||
showSecondary: false,
|
||||
},
|
||||
2: {
|
||||
headline: "Before You Continue",
|
||||
tagline: "",
|
||||
body: "This software provides a custom user interface and functionality for the Even Realities G2 smart glasses. It is not created or supported by Even Realities. If this software somehow breaks your headset, this is not Even's fault and is not covered by the hardware's warranty. If this software doesn't break you headset, using this software may void the hardware's warranty anyways, at the sole discretion of Even Realities. This software is beta; don't rely on it for anything critically important." +
|
||||
(global.isIOS ? "\n\niOS / TestFlight privacy\n\n" + IOS_PRIVACY_NOTICE : ""),
|
||||
primaryLabel: "Agree",
|
||||
secondaryLabel: "Back",
|
||||
splash: false,
|
||||
showSecondary: true,
|
||||
},
|
||||
3: {
|
||||
headline: "Custom Firmware Required",
|
||||
tagline: "",
|
||||
body: "Faceclaw only runs on Even Realities G2 glasses that have Faceclaw's custom firmware installed. You have two choices:\n\n• Preview Only — explore Faceclaw's interface on your phone's screen without pairing any glasses. Nothing is written to a headset.\n\n• Flash Firmware — install the custom firmware on your glasses now, then use Faceclaw for real.\n\nFlashing replaces the official firmware. You can uninstall and return to the official firmware later, by reconnecting the official Even Realities app. Installing custom firmware is not covered by warranty.",
|
||||
primaryLabel: "Flash Firmware",
|
||||
secondaryLabel: "Preview Only",
|
||||
splash: false,
|
||||
showSecondary: true,
|
||||
},
|
||||
type Makers = { product: string; maker: string; makerPossessive: string };
|
||||
|
||||
const GLASSES_MAKER: Record<GlassesType, Makers> = {
|
||||
g1: { product: "Even Realities G1", maker: "Even Realities", makerPossessive: "Even's" },
|
||||
g2: { product: "Even Realities G2", maker: "Even Realities", makerPossessive: "Even's" },
|
||||
"rayneo-io": { product: "RayNeo iO", maker: "RayNeo", makerPossessive: "RayNeo's" },
|
||||
};
|
||||
|
||||
/** Preview Only: no particular glasses yet, so the disclaimer covers every kind Faceclaw supports. */
|
||||
const ANY_GLASSES_MAKER: Makers = { product: "Even Realities G1 and G2 and RayNeo iO", maker: "Even Realities or RayNeo", makerPossessive: "their" };
|
||||
|
||||
const WARRANTY_NOTE = "Installing custom firmware is not covered by warranty.";
|
||||
// Preview Only is chosen on Your Devices, which is three pages back from here.
|
||||
const PREVIEW_HINT = "Not ready? Go back to Your Devices and choose Preview Only to explore Faceclaw on your phone's screen instead.";
|
||||
|
||||
function firmwareBody(glasses: GlassesType): string {
|
||||
// Pairing skips the firmware pages for an iO: the app has no flasher for it.
|
||||
if (glasses === "rayneo-io") {
|
||||
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"
|
||||
? `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}`;
|
||||
}
|
||||
|
||||
function stepContent(step: OnboardingStep, glasses: GlassesType, previewOnly: boolean): StepContent {
|
||||
const { product, maker, makerPossessive } = previewOnly ? ANY_GLASSES_MAKER : GLASSES_MAKER[glasses];
|
||||
switch (step) {
|
||||
case 1:
|
||||
return {
|
||||
headline: "Faceclaw",
|
||||
tagline: "Perching on the faces of giants",
|
||||
body: "",
|
||||
primaryLabel: "Next",
|
||||
secondaryLabel: "",
|
||||
splash: true,
|
||||
showSecondary: false,
|
||||
};
|
||||
case 2:
|
||||
return {
|
||||
headline: "Before You Continue",
|
||||
tagline: "",
|
||||
body: `This software provides a custom user interface and functionality for the ${product} smart glasses. It is not created or supported by ${maker}. If this software somehow breaks your headset, this is not ${makerPossessive} fault and is not covered by the hardware's warranty. If this software doesn't break your headset, using this software may void the hardware's warranty anyways, at the sole discretion of ${maker}. This software is beta; don't rely on it for anything critically important.`,
|
||||
primaryLabel: "Agree",
|
||||
secondaryLabel: "Back",
|
||||
splash: false,
|
||||
showSecondary: true,
|
||||
};
|
||||
case 3:
|
||||
return {
|
||||
headline: "Custom Firmware Required",
|
||||
tagline: "",
|
||||
body: firmwareBody(glasses),
|
||||
primaryLabel: glasses === "rayneo-io" ? "Pair Glasses" : "Flash Firmware",
|
||||
secondaryLabel: "Back",
|
||||
splash: false,
|
||||
showSecondary: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class OnboardingViewModel extends Observable {
|
||||
private _step: OnboardingStep = 1;
|
||||
private readonly step: OnboardingStep;
|
||||
private readonly content: StepContent;
|
||||
|
||||
constructor(initialStep?: number) {
|
||||
super();
|
||||
if (initialStep === 2 || initialStep === 3) this._step = initialStep;
|
||||
this.publish();
|
||||
this.step = initialStep === 2 || initialStep === 3 ? initialStep : 1;
|
||||
this.content = stepContent(this.step, glassesTypeSetting.get(), isPreviewOnlyMode());
|
||||
}
|
||||
|
||||
onPrimaryTap(): void {
|
||||
if (this._step === 1) {
|
||||
this.setStep(2);
|
||||
if (this.step === 1) {
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-devices-page" });
|
||||
return;
|
||||
}
|
||||
if (this._step === 2) {
|
||||
if (this.step === 2) {
|
||||
// The Permissions screen sits between the disclaimer and the firmware
|
||||
// step; it navigates forward to a fresh onboarding page at step 3.
|
||||
Frame.topmost()?.navigate({
|
||||
@@ -93,49 +126,47 @@ export class OnboardingViewModel extends Observable {
|
||||
});
|
||||
}
|
||||
|
||||
/** Back, on the disclaimer and firmware steps. */
|
||||
onSecondaryTap(): void {
|
||||
if (this._step === 2) {
|
||||
this.setStep(1);
|
||||
const frame = Frame.topmost();
|
||||
if (frame?.canGoBack()) {
|
||||
frame.goBack();
|
||||
return;
|
||||
}
|
||||
if (this._step === 3) {
|
||||
// Step 3 secondary: skip flashing, use the on-phone preview only.
|
||||
setPreviewOnlyMode(true);
|
||||
setOnboardingCompleted(true);
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
// The disconnect page's Back can open step 3 on a fresh history.
|
||||
frame?.navigate({ moduleName: "phone-ui/onboarding-devices-page", clearHistory: true });
|
||||
}
|
||||
|
||||
get headline(): string {
|
||||
return STEP_CONTENT[this._step].headline;
|
||||
return this.content.headline;
|
||||
}
|
||||
|
||||
get tagline(): string {
|
||||
return STEP_CONTENT[this._step].tagline;
|
||||
return this.content.tagline;
|
||||
}
|
||||
|
||||
get body(): string {
|
||||
return STEP_CONTENT[this._step].body;
|
||||
return this.content.body;
|
||||
}
|
||||
|
||||
get primaryLabel(): string {
|
||||
return STEP_CONTENT[this._step].primaryLabel;
|
||||
return this.content.primaryLabel;
|
||||
}
|
||||
|
||||
get secondaryLabel(): string {
|
||||
return STEP_CONTENT[this._step].secondaryLabel;
|
||||
return this.content.secondaryLabel;
|
||||
}
|
||||
|
||||
get showSecondary(): boolean {
|
||||
return STEP_CONTENT[this._step].showSecondary;
|
||||
return this.content.showSecondary;
|
||||
}
|
||||
|
||||
get splashVisibility(): "visible" | "collapse" {
|
||||
return STEP_CONTENT[this._step].splash ? "visible" : "collapse";
|
||||
return this.content.splash ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get contentVisibility(): "visible" | "collapse" {
|
||||
return STEP_CONTENT[this._step].splash ? "collapse" : "visible";
|
||||
return this.content.splash ? "collapse" : "visible";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,25 +184,6 @@ export class OnboardingViewModel extends Observable {
|
||||
|
||||
/** License and privacy-policy links, shown only under the disclaimer step. */
|
||||
get footerVisibility(): "visible" | "collapse" {
|
||||
return this._step === 2 ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
private setStep(step: OnboardingStep): void {
|
||||
if (this._step === step) return;
|
||||
this._step = step;
|
||||
this.publish();
|
||||
}
|
||||
|
||||
private publish(): void {
|
||||
this.notifyPropertyChange("headline", this.headline);
|
||||
this.notifyPropertyChange("tagline", this.tagline);
|
||||
this.notifyPropertyChange("body", this.body);
|
||||
this.notifyPropertyChange("primaryLabel", this.primaryLabel);
|
||||
this.notifyPropertyChange("secondaryLabel", this.secondaryLabel);
|
||||
this.notifyPropertyChange("showSecondary", this.showSecondary);
|
||||
this.notifyPropertyChange("splashVisibility", this.splashVisibility);
|
||||
this.notifyPropertyChange("contentVisibility", this.contentVisibility);
|
||||
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
|
||||
this.notifyPropertyChange("footerVisibility", this.footerVisibility);
|
||||
return this.step === 2 ? "visible" : "collapse";
|
||||
}
|
||||
}
|
||||
@@ -45,29 +45,31 @@
|
||||
</Repeater.itemTemplate>
|
||||
</Repeater>
|
||||
|
||||
<Label text="Ring (optional)" class="h2 pairing-section m-t-16" />
|
||||
<Label text="{{ emptyRingMessage }}" class="pairing-empty" textWrap="true" visibility="{{ emptyRingVisibility }}" />
|
||||
<Repeater items="{{ ringRows }}">
|
||||
<Repeater.itemsLayout>
|
||||
<StackLayout />
|
||||
</Repeater.itemsLayout>
|
||||
<Repeater.itemTemplate>
|
||||
<GridLayout columns="84,*,auto" rows="auto" class="{{ rowClass }}" tap="{{ onRowTap }}">
|
||||
<Image col="0" src="{{ imagePath }}" stretch="aspectFit" width="56" height="30" class="pairing-art" />
|
||||
<StackLayout col="1" class="m-l-8">
|
||||
<GridLayout columns="auto,auto">
|
||||
<Label col="0" text="{{ modelTitle }}" class="pairing-title" />
|
||||
<Label col="1" text="{{ badge }}" class="pairing-badge m-l-6" visibility="{{ badgeVisibility }}" />
|
||||
</GridLayout>
|
||||
<Label text="{{ proximityLine }}" class="{{ proximityClass }}" />
|
||||
<Label text="{{ deviceName }}" class="pairing-serial" />
|
||||
<Label text="{{ armsSummary }}" class="pairing-arms" textWrap="true" visibility="{{ armsVisibility }}" />
|
||||
<Label text="{{ warning }}" class="pairing-warning" textWrap="true" visibility="{{ warningVisibility }}" />
|
||||
</StackLayout>
|
||||
<Label col="2" text="{{ chevron }}" class="pairing-chevron" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
</Repeater.itemTemplate>
|
||||
</Repeater>
|
||||
<StackLayout visibility="{{ ringSectionVisibility }}">
|
||||
<Label text="Ring (optional)" class="h2 pairing-section m-t-16" />
|
||||
<Label text="{{ emptyRingMessage }}" class="pairing-empty" textWrap="true" visibility="{{ emptyRingVisibility }}" />
|
||||
<Repeater items="{{ ringRows }}">
|
||||
<Repeater.itemsLayout>
|
||||
<StackLayout />
|
||||
</Repeater.itemsLayout>
|
||||
<Repeater.itemTemplate>
|
||||
<GridLayout columns="84,*,auto" rows="auto" class="{{ rowClass }}" tap="{{ onRowTap }}">
|
||||
<Image col="0" src="{{ imagePath }}" stretch="aspectFit" width="56" height="30" class="pairing-art" />
|
||||
<StackLayout col="1" class="m-l-8">
|
||||
<GridLayout columns="auto,auto">
|
||||
<Label col="0" text="{{ modelTitle }}" class="pairing-title" />
|
||||
<Label col="1" text="{{ badge }}" class="pairing-badge m-l-6" visibility="{{ badgeVisibility }}" />
|
||||
</GridLayout>
|
||||
<Label text="{{ proximityLine }}" class="{{ proximityClass }}" />
|
||||
<Label text="{{ deviceName }}" class="pairing-serial" />
|
||||
<Label text="{{ armsSummary }}" class="pairing-arms" textWrap="true" visibility="{{ armsVisibility }}" />
|
||||
<Label text="{{ warning }}" class="pairing-warning" textWrap="true" visibility="{{ warningVisibility }}" />
|
||||
</StackLayout>
|
||||
<Label col="2" text="{{ chevron }}" class="pairing-chevron" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
</Repeater.itemTemplate>
|
||||
</Repeater>
|
||||
</StackLayout>
|
||||
|
||||
<StackLayout class="pairing-selection m-t-16" visibility="{{ selectionVisibility }}">
|
||||
<Label text="Selected" class="h2 pairing-section" />
|
||||
|
||||
@@ -10,13 +10,16 @@ import {
|
||||
DiscoveryAggregator,
|
||||
glassesRow,
|
||||
nearestCandidateId,
|
||||
rayneoRow,
|
||||
ringRow,
|
||||
type GlassesPairCandidate,
|
||||
type PairingRowPresentation,
|
||||
type RayNeoCandidate,
|
||||
type RingCandidate,
|
||||
} from "../g2/pairing-candidates";
|
||||
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
|
||||
import { DeviceDiscoveryBridge } from "../native/device-discovery";
|
||||
import { setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { hasCompletedOnboarding, ownsRing, setPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
/** One Repeater row: the presentation plus the display-only fields the XML binds. */
|
||||
export type PairingRowItem = PairingRowPresentation & {
|
||||
@@ -42,6 +45,12 @@ export type PairingRowItem = PairingRowPresentation & {
|
||||
const REFRESH_INTERVAL_MS = 500;
|
||||
const NO_RESULTS_HINT_AFTER_MS = 10_000;
|
||||
|
||||
const SETUP_GLASSES_NAME: Record<GlassesType, string> = {
|
||||
g1: "G1 glasses",
|
||||
g2: "G2 glasses",
|
||||
"rayneo-io": "RayNeo iO",
|
||||
};
|
||||
|
||||
/**
|
||||
* Live pairing scan. Streams advertisements into a `DiscoveryAggregator`,
|
||||
* re-renders the pair/ring lists at a calm cadence, and saves the chosen
|
||||
@@ -65,12 +74,25 @@ export class PairingViewModel extends Observable {
|
||||
private _ringRows: PairingRowItem[] = [];
|
||||
private selectedPair: GlassesPairCandidate | null = null;
|
||||
private selectedRing: RingCandidate | null = null;
|
||||
/** A RayNeo iO instead of a G2 pair (the two are exclusive; either takes a ring). */
|
||||
private selectedIo: RayNeoCandidate | null = null;
|
||||
private readonly previouslyPairedSerial: string | null;
|
||||
private readonly previouslyPairedRing: string;
|
||||
/**
|
||||
* The glasses chosen on the Your Devices page, during first-run setup. Null
|
||||
* otherwise: the main menu's "Pair glasses" also comes here with onboarding
|
||||
* set, to pair whatever you've got now, so it offers everything. Only the
|
||||
* wording follows this; any glasses heard are still listed, so a wrong choice
|
||||
* can't strand anyone.
|
||||
*/
|
||||
private readonly setupGlasses: GlassesType | null;
|
||||
private readonly showRings: boolean;
|
||||
|
||||
constructor(options?: { onboarding?: boolean }) {
|
||||
super();
|
||||
this.onboarding = options?.onboarding ?? false;
|
||||
this.setupGlasses = this.onboarding && !hasCompletedOnboarding() ? glassesTypeSetting.get() : null;
|
||||
this.showRings = !this.setupGlasses || ownsRing();
|
||||
this.previouslyPairedSerial = loadPairedGlassesIdentity()?.serial ?? null;
|
||||
this.previouslyPairedRing = loadDeviceAddresses().ring;
|
||||
// A backgrounded phone (Home, screen lock, a call) must not keep the
|
||||
@@ -180,10 +202,18 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
get instructions(): string {
|
||||
if (this.setupGlasses) {
|
||||
const name = SETUP_GLASSES_NAME[this.setupGlasses];
|
||||
const ready = this.setupGlasses === "g1"
|
||||
? "Put the glasses in their case with the lid open"
|
||||
: "Wear the glasses or take them out of the case";
|
||||
return `Select your ${name}${this.showRings ? " and your R1 ring" : ""} below. ${ready}, and keep them near your phone. ` +
|
||||
"If they are not detected, make sure no other apps are connected.";
|
||||
}
|
||||
return (
|
||||
"Select your G2 glasses and R1 ring below. Wear the glasses or take them out of the case, " +
|
||||
"and keep the glasses and phone nearby. If your glasses are not detected, make sure no other " +
|
||||
"apps are connected."
|
||||
"Select your G2 or G1 glasses or RayNeo iO, and your R1 ring if you have one, below. Wear the glasses or take them out of the case " +
|
||||
"(a G1 pairs only in its case, with the lid open), and keep the glasses and phone nearby. If your glasses are not detected, " +
|
||||
"make sure no other apps are connected."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -235,11 +265,15 @@ export class PairingViewModel extends Observable {
|
||||
const elapsed = Date.now() - this.startedAtMs;
|
||||
if (elapsed < NO_RESULTS_HINT_AFTER_MS) return "Listening for glasses…";
|
||||
return (
|
||||
"No glasses heard yet. Make sure they are out of the case and not connected to another app. " +
|
||||
`No glasses heard yet. Make sure they are ${this.setupGlasses === "g1" ? "in their case with the lid open" : "out of the case"} and not connected to another app. ` +
|
||||
"On Android 11 and older, Location must also be switched on for Bluetooth scanning to return results."
|
||||
);
|
||||
}
|
||||
|
||||
get ringSectionVisibility(): "visible" | "collapse" {
|
||||
return this.showRings ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get emptyRingVisibility(): "visible" | "collapse" {
|
||||
return this._ringRows.length ? "collapse" : "visible";
|
||||
}
|
||||
@@ -249,14 +283,17 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
get selectionVisibility(): "visible" | "collapse" {
|
||||
return this.selectedPair || this.selectedRing ? "visible" : "collapse";
|
||||
return this.selectedPair || this.selectedRing || this.selectedIo ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get selectionSummary(): string {
|
||||
const parts: string[] = [];
|
||||
if (this.selectedIo) {
|
||||
parts.push(`RayNeo iO · ${this.selectedIo.advertisement.name} · ${this.selectedIo.advertisement.address}`);
|
||||
}
|
||||
if (this.selectedPair) {
|
||||
const identity = this.selectedPair.identity;
|
||||
const label = identity ? identity.displayName : "Even Realities G2";
|
||||
const label = identity ? identity.displayName : this.selectedPair.g1Firmware ? "Even Realities G1" : "Even Realities G2";
|
||||
parts.push(
|
||||
`${label} · serial ${this.selectedPair.serial ?? "unknown"}\n` +
|
||||
`Left ${this.selectedPair.left?.address ?? "?"} · Right ${this.selectedPair.right?.address ?? "?"}`,
|
||||
@@ -273,7 +310,7 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
get primaryEnabled(): boolean {
|
||||
return !!this.selectedPair || (!this.onboarding && !!this.selectedRing);
|
||||
return !!this.selectedPair || !!this.selectedIo || (!this.onboarding && !!this.selectedRing);
|
||||
}
|
||||
|
||||
get secondaryLabel(): string {
|
||||
@@ -287,7 +324,11 @@ export class PairingViewModel extends Observable {
|
||||
readonly onRowTap = (args: EventData): void => {
|
||||
const row = (args.object as View).bindingContext as PairingRowItem | undefined;
|
||||
if (!row) return;
|
||||
if (row.kind === "glasses") {
|
||||
if (row.kind === "rayneo-io") {
|
||||
const io = this.aggregator.rayneos().find((candidate) => candidate.id === row.id) ?? null;
|
||||
this.selectedIo = this.selectedIo?.id === io?.id ? null : io;
|
||||
if (this.selectedIo) this.selectedPair = null;
|
||||
} else if (row.kind === "glasses") {
|
||||
const pair = this.aggregator.pairs().find((candidate) => candidate.id === row.id) ?? null;
|
||||
if (!pair) return;
|
||||
if (!row.canSelect) {
|
||||
@@ -295,6 +336,7 @@ export class PairingViewModel extends Observable {
|
||||
return;
|
||||
}
|
||||
this.selectedPair = this.selectedPair?.id === pair.id ? null : pair;
|
||||
if (this.selectedPair) this.selectedIo = null;
|
||||
} else {
|
||||
const ring = this.aggregator.rings().find((candidate) => candidate.id === row.id) ?? null;
|
||||
this.selectedRing = this.selectedRing?.id === ring?.id ? null : ring;
|
||||
@@ -303,20 +345,49 @@ export class PairingViewModel extends Observable {
|
||||
};
|
||||
|
||||
onPrimaryTap(): void {
|
||||
const io = this.selectedIo;
|
||||
const pair = this.selectedPair;
|
||||
const ring = this.selectedRing;
|
||||
const existing = loadDeviceAddresses();
|
||||
// Glasses saved without a ring selected keep the ring paired before.
|
||||
const ringAddress = ring?.advertisement.address ?? existing.ring;
|
||||
const ringName = ring?.advertisement.name ??
|
||||
(ringAddress === existing.ring ? (loadPairedGlassesIdentity()?.ringName ?? "") : "");
|
||||
if (io) {
|
||||
// One link: the same address stands for both arms. The iO can't relay a
|
||||
// ring, so the session connects to it directly (Direct ring mode).
|
||||
const address = io.advertisement.address;
|
||||
saveDeviceAddresses({ right: address, left: address, ring: ringAddress });
|
||||
glassesTypeSetting.set("rayneo-io");
|
||||
savePairedGlassesIdentity({
|
||||
serial: io.advertisement.embeddedMac ?? address,
|
||||
leftName: io.advertisement.name,
|
||||
rightName: io.advertisement.name,
|
||||
leftAddress: address,
|
||||
rightAddress: address,
|
||||
ringName,
|
||||
ringAddress,
|
||||
pairedAtMs: Date.now(),
|
||||
});
|
||||
this.dispose();
|
||||
if (this.onboarding) setPreviewOnlyMode(false);
|
||||
// The G2 firmware check/flash pages don't apply; the session reports
|
||||
// incompatible firmware if the iO lacks the Faceclaw build.
|
||||
finishOnboardingNavigation();
|
||||
return;
|
||||
}
|
||||
if (!pair && !ring) return;
|
||||
// refresh() drops a selection whose pair regressed below complete, but the
|
||||
// tap can race a prune: never fall back to previously stored addresses for
|
||||
// a missing arm — that silently welds together arms of two different pairs.
|
||||
if (pair && (!pair.left || !pair.right)) return;
|
||||
const existing = loadDeviceAddresses();
|
||||
const addresses = {
|
||||
right: pair ? pair.right!.address : existing.right,
|
||||
left: pair ? pair.left!.address : existing.left,
|
||||
ring: ring?.advertisement.address ?? existing.ring,
|
||||
ring: ringAddress,
|
||||
};
|
||||
saveDeviceAddresses(addresses);
|
||||
if (pair) glassesTypeSetting.set(pair.g1Firmware ? "g1" : "g2");
|
||||
if (pair) {
|
||||
savePairedGlassesIdentity({
|
||||
serial: pair.serial ?? "",
|
||||
@@ -324,8 +395,8 @@ export class PairingViewModel extends Observable {
|
||||
rightName: pair.right!.name,
|
||||
leftAddress: pair.left!.address,
|
||||
rightAddress: pair.right!.address,
|
||||
ringName: ring?.advertisement.name ?? (addresses.ring === existing.ring ? (loadPairedGlassesIdentity()?.ringName ?? "") : ""),
|
||||
ringAddress: addresses.ring,
|
||||
ringName,
|
||||
ringAddress,
|
||||
pairedAtMs: Date.now(),
|
||||
});
|
||||
} else if (ring) {
|
||||
@@ -341,9 +412,10 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
}
|
||||
this.dispose();
|
||||
if (this.onboarding) {
|
||||
setPreviewOnlyMode(false);
|
||||
// Continue the onboarding chain: check the glasses' firmware next.
|
||||
if (this.onboarding) setPreviewOnlyMode(false);
|
||||
// Onboarding checks the glasses' firmware next. So does choosing a G1 from anywhere: it may run Even's firmware,
|
||||
// and whether it does is known without connecting.
|
||||
if (this.onboarding || pair?.g1Firmware) {
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" });
|
||||
return;
|
||||
}
|
||||
@@ -386,7 +458,11 @@ export class PairingViewModel extends Observable {
|
||||
private refresh(): void {
|
||||
this.aggregator.prune(Date.now(), DEFAULT_STALE_AFTER_MS);
|
||||
const pairs = this.aggregator.pairs();
|
||||
const rings = this.aggregator.rings();
|
||||
const rings = this.showRings ? this.aggregator.rings() : [];
|
||||
const rayneos = this.aggregator.rayneos();
|
||||
if (this.selectedIo) {
|
||||
this.selectedIo = rayneos.find((candidate) => candidate.id === this.selectedIo!.id) ?? null;
|
||||
}
|
||||
|
||||
// Keep the selection pointing at live data (addresses can only change if a
|
||||
// side was replaced); drop it if the pair disappeared — or if it degraded
|
||||
@@ -402,13 +478,24 @@ export class PairingViewModel extends Observable {
|
||||
|
||||
const nearestPair = nearestCandidateId(pairs);
|
||||
const nearestRing = nearestCandidateId(rings);
|
||||
this._glassesRows = pairs.map((pair) =>
|
||||
toRowItem(
|
||||
glassesRow(pair, { pairedSerial: this.previouslyPairedSerial, nearestId: nearestPair }),
|
||||
this.selectedPair?.id === pair.id,
|
||||
this.onRowTap,
|
||||
const pairedAddress = glassesTypeSetting.get() === "rayneo-io" ? loadDeviceAddresses().right : "";
|
||||
const nearestIo = nearestCandidateId(rayneos);
|
||||
this._glassesRows = [
|
||||
...rayneos.map((candidate) =>
|
||||
toRowItem(
|
||||
rayneoRow(candidate, { pairedAddress, nearestId: nearestIo }),
|
||||
this.selectedIo?.id === candidate.id,
|
||||
this.onRowTap,
|
||||
),
|
||||
),
|
||||
);
|
||||
...pairs.map((pair) =>
|
||||
toRowItem(
|
||||
glassesRow(pair, { pairedSerial: this.previouslyPairedSerial, nearestId: nearestPair }),
|
||||
this.selectedPair?.id === pair.id,
|
||||
this.onRowTap,
|
||||
),
|
||||
),
|
||||
];
|
||||
this._ringRows = rings.map((ring) =>
|
||||
toRowItem(
|
||||
ringRow(ring, { pairedRingAddress: this.previouslyPairedRing, nearestId: nearestRing }),
|
||||
@@ -417,21 +504,12 @@ export class PairingViewModel extends Observable {
|
||||
),
|
||||
);
|
||||
|
||||
const complete = pairs.filter((pair) => pair.completeness === "complete").length;
|
||||
const partial = pairs.length - complete;
|
||||
if (this.scanFailure) {
|
||||
this.status = `Scan failed: ${this.scanFailure}`;
|
||||
} else if (!this._scanning) {
|
||||
this.status = "Scan paused.";
|
||||
} else if (!pairs.length && !rings.length) {
|
||||
this.status = "Scanning…";
|
||||
} else {
|
||||
const bits = [
|
||||
complete ? `${complete} ${complete === 1 ? "pair" : "pairs"} ready` : null,
|
||||
partial ? `${partial} with one arm heard` : null,
|
||||
rings.length ? `${rings.length} ${rings.length === 1 ? "ring" : "rings"}` : null,
|
||||
].filter(Boolean);
|
||||
this.status = `Scanning… ${bits.join(" · ")}. Tap a pair to select it.`;
|
||||
this.status = "Scanning…";
|
||||
}
|
||||
|
||||
for (const property of [
|
||||
@@ -466,7 +544,7 @@ function toRowItem(row: PairingRowPresentation, selected: boolean, onRowTap: (ar
|
||||
colorwayLabel: colorwayLabel(row.colorway),
|
||||
badgeVisibility: row.badge ? "visible" : "collapse",
|
||||
variantVisibility: row.variantSummary ? "visible" : "collapse",
|
||||
proximityLine: `${row.proximityGlyph} ${row.proximitySummary}`,
|
||||
proximityLine: row.proximityGlyph,
|
||||
proximityClass: row.zone === "immediate" ? "pairing-proximity pairing-proximity-immediate" : "pairing-proximity",
|
||||
armsVisibility: row.armsSummary ? "visible" : "collapse",
|
||||
warningVisibility: row.warning ? "visible" : "collapse",
|
||||
|
||||
@@ -236,3 +236,10 @@ Button.permissions-primary-dimmed {
|
||||
.ns-dark .permissions-check {
|
||||
color: #7bc47f;
|
||||
}
|
||||
|
||||
/* Onboarding splash (phone-ui/onboarding-page). The logo art is
|
||||
* black-on-transparent; tint it white in dark mode so it doesn't vanish into
|
||||
* the dark page background. */
|
||||
.ns-dark .onboarding-logo {
|
||||
tint-color: #ffffff;
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } fro
|
||||
import { hasAllFilesAccess, requestAllFilesAccess } from "../native/file-access";
|
||||
import { isNotificationListenerEnabled, requestNotificationListenerAccess } from "../native/notification-access";
|
||||
import { mediaControllerBridge } from "../native/media-controller";
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { isPreviewOnlyMode, setOnboardingCompleted } from "./onboarding-state";
|
||||
|
||||
type PermissionDefinition = {
|
||||
id: string;
|
||||
@@ -105,7 +107,7 @@ const ANDROID_PERMISSIONS: PermissionDefinition[] = [
|
||||
const PERMISSIONS: PermissionDefinition[] = global.isIOS ? [{
|
||||
id: "nearby-devices", title: "Nearby Devices",
|
||||
description: "Needed to communicate with your smart glasses over Bluetooth.", optional: false,
|
||||
isGranted: () => iosBluetooth().state === 5,
|
||||
isGranted: () => iosBluetooth().isAuthorized(),
|
||||
request: () => iosBluetooth().ensureReady(),
|
||||
}, {
|
||||
id: "calendar", title: "Calendar",
|
||||
@@ -141,6 +143,7 @@ export class PermissionsViewModel extends Observable {
|
||||
private readonly onboarding: boolean;
|
||||
private _cards: PermissionCardItem[] = [];
|
||||
private requesting = false;
|
||||
private stopWatchingBluetooth: (() => void) | null = null;
|
||||
|
||||
constructor(options?: { onboarding?: boolean }) {
|
||||
super();
|
||||
@@ -157,11 +160,20 @@ export class PermissionsViewModel extends Observable {
|
||||
|
||||
onPageLoaded(): void {
|
||||
Application.on(Application.resumeEvent, this.onAppResume);
|
||||
// The answer to the Bluetooth prompt can arrive after request() has stopped
|
||||
// waiting for it, and with no resume to re-check on.
|
||||
if (global.isIOS) {
|
||||
this.stopWatchingBluetooth = iosBluetooth().onEvent((event) => {
|
||||
if (event.kind === "state") this.refresh();
|
||||
});
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
onPageUnloaded(): void {
|
||||
Application.off(Application.resumeEvent, this.onAppResume);
|
||||
this.stopWatchingBluetooth?.();
|
||||
this.stopWatchingBluetooth = null;
|
||||
}
|
||||
|
||||
// --- observable properties -------------------------------------------------
|
||||
@@ -175,7 +187,7 @@ export class PermissionsViewModel extends Observable {
|
||||
}
|
||||
|
||||
get instructions(): string {
|
||||
if (global.isIOS) return "Faceclaw uses Bluetooth to communicate with your smart glasses. Calendar and Apple Music access are optional. Tap a card to allow access; a checkmark means it is ready.";
|
||||
if (global.isIOS) return "Faceclaw uses Bluetooth to communicate with your smart glasses. Calendar and Apple Music access are optional. Tap a card to allow access; a checkmark means access is allowed.";
|
||||
return this.onboarding
|
||||
? `Faceclaw uses these ${global.isIOS ? "iOS" : "Android"} permissions. Tap a card to grant one; a checkmark means it is already granted. ` +
|
||||
"Optional permissions can also be granted later, from the Permissions item in the main-screen menu."
|
||||
@@ -228,6 +240,13 @@ export class PermissionsViewModel extends Observable {
|
||||
});
|
||||
if (!proceed) return;
|
||||
}
|
||||
if (isPreviewOnlyMode()) {
|
||||
// Preview Only was chosen on Your Devices: with no glasses to set up,
|
||||
// this is the last page.
|
||||
setOnboardingCompleted(true);
|
||||
finishOnboardingNavigation();
|
||||
return;
|
||||
}
|
||||
// Continue the onboarding chain at the Custom Firmware Required step.
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/onboarding-page",
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
color: #6a6a6a;
|
||||
margin-top: 4;
|
||||
}
|
||||
/* The charging case's level under "Charging · G2 n%". */
|
||||
/* The charging case's level under "Charging: G2 n%". */
|
||||
.pad-detail {
|
||||
font-size: 15;
|
||||
color: #b0b0b0;
|
||||
|
||||
Reference in new issue
Block a user