forked from Blendman974/faceclaw
Address review findings for the proximity-pairing PR
Correctness: - Pair-glasses flows no longer strand the app in the manual-disconnected state: the pre-scan disconnect is followed by resumeAutoReconnect(), and the config page's scan hand-off drops the live link too. - The mixed-arms serial warning is reachable now: pairs() groups by the canonical serial key, and a lone left + lone right with different serials get the mismatch warning on both rows (it previously required two different serials inside one serial-keyed group, which cannot happen). - A selected pair that degrades to one arm (prune while the page is open) is deselected, and Save never pads a missing arm from stored addresses. - DiscoveryAggregator.ingest no longer lets a bonded re-emit or split advertisement overwrite the note/name/flag learned from a full advertisement, and reclassifies split reports using remembered fields so a nameless half doesn't drop the arm. - estimateProximity ignores the advertised TX Power Level (radiated power, not measured-power-at-1m); the calibration table is the only reference. - Saving a ring without a glasses pair updates the stored identity's ring name/address instead of leaving the previous ring on record. - Ring detection requires the stock "EVEN R1" name prefix in both the TS classifier and the Java pre-filter; a bare "R1" substring matched unrelated devices, and ring rows are always selectable. - One-shot scans keep every sample (buildAddressSet merges them through DiscoveryAggregator), and flash-flow address resolution takes left/right from one serial-joined complete pair instead of latest-per-role. Lifecycle: - The pairing scan and its refresh timer pause on app suspend and resume with the app, and the model's app-event hooks are detached when the page is left for good. Cleanup: - One MAC normalizer (even-advertisement.normalizeMacAddress, re-exported by device-addresses), used for the ring "Yours" comparison too. - One serial-equality definition (serialKey/serialsMatch); the containment fallback in isPreviouslyPaired is gone. - Shared formatErrorMessage replaces five per-view-model copies; shared hex-util replaces the duplicate TS hex codecs; one Java bytesToHex in FaceclawFirmwareUtil replaces three hand-rolled encoders. - glassesRow/ringRow share a presentation-base helper; dead row address fields, the constant glassesSectionVisibility, the identical-branch status ternary, and zoneRank/ZONE_ORDER are removed. - .gitignore now actually covers .test-build/ as tests/README claims. UI: - Dark-mode styles for the pairing page: readable instructions, dark-gray cards with consistent light text; light mode keeps its current look. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
This commit is contained in:
1 parent
ee022cdc84
commit
17182532f4
24 files changed
+537
-250
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
import { glassesImagePath } from "../g2/glasses-artwork";
|
||||
import { GlassesHardwareIdentity } from "../g2/glasses-hardware-identity";
|
||||
import { buildAddressSet, DeviceDiscoveryBridge } from "../native/device-discovery";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
|
||||
type TextChangeArgs = { value?: string; object?: { text?: string } };
|
||||
|
||||
@@ -187,7 +188,23 @@ export class ConfigViewModel extends Observable {
|
||||
}
|
||||
|
||||
/** The live scan page identifies pairs by serial, model, and distance; hand off to it. */
|
||||
onScanTap(): void {
|
||||
async onScanTap(): Promise<void> {
|
||||
if (!this.onboarding) {
|
||||
// A connected arm stops advertising, so drop the link before scanning.
|
||||
// Required lazily: a module-scope import would instantiate the dashboard
|
||||
// controller singleton during onboarding, which this page is part of.
|
||||
// Outside onboarding the main page has already loaded it.
|
||||
const { dashboardController } = require("../g2/dashboard-controller") as typeof import("../g2/dashboard-controller");
|
||||
const { resumeAutoReconnect } = require("../g2/reconnect-policy") as typeof import("../g2/reconnect-policy");
|
||||
try {
|
||||
await dashboardController.disconnect();
|
||||
} catch {
|
||||
// proceed anyway; the pairing page reports what it hears
|
||||
}
|
||||
// disconnect() enters the manual-disconnected state; pairing is a
|
||||
// detour, so let the main page reconnect afterwards.
|
||||
resumeAutoReconnect();
|
||||
}
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/pairing-page",
|
||||
context: { onboarding: this.onboarding },
|
||||
@@ -273,7 +290,6 @@ export class ConfigViewModel extends Observable {
|
||||
}
|
||||
|
||||
private formatError(error: unknown): string {
|
||||
const raw = (error as Error)?.message ?? String(error);
|
||||
return raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return formatErrorMessage(error);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Application, Frame, ImageSource, Observable, Screen } from "@nativescript/core";
|
||||
import { dashboardController } from "../g2/dashboard-controller";
|
||||
import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
|
||||
import { isAutoReconnectSuppressed } from "../g2/reconnect-policy";
|
||||
import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-policy";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
|
||||
|
||||
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
|
||||
@@ -513,7 +514,10 @@ export class MainViewModel extends Observable {
|
||||
/**
|
||||
* Live scan that names each nearby pair by model, colour, and serial and
|
||||
* checks both arms belong together. A connected arm stops advertising, so
|
||||
* drop the current link first; autoConnect picks it back up afterwards.
|
||||
* drop the current link first. disconnect() enters the manual-disconnected
|
||||
* state; pairing is a detour, not a Disconnect, so lift the suppression
|
||||
* right away — nothing dials the glasses until the main page's autoConnect
|
||||
* runs again on the way back.
|
||||
*/
|
||||
async onPairGlassesTap(): Promise<void> {
|
||||
if (!this.canRun) return;
|
||||
@@ -523,6 +527,7 @@ export class MainViewModel extends Observable {
|
||||
} catch {
|
||||
// proceed anyway; the pairing page reports what it hears
|
||||
}
|
||||
resumeAutoReconnect();
|
||||
}
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/pairing-page", context: { onboarding: false } });
|
||||
}
|
||||
@@ -632,9 +637,6 @@ export class MainViewModel extends Observable {
|
||||
}
|
||||
|
||||
private formatError(error: unknown): string {
|
||||
const raw = (error as Error)?.message ?? String(error);
|
||||
const sanitized = raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
if (sanitized.length <= 240) return sanitized;
|
||||
return `${sanitized.slice(0, 237)}...`;
|
||||
return formatErrorMessage(error, 240);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { classifyOnboardingFirmware, FLASHABLE_STOCK_VERSION_TEXT } from "../g2/firmware-compat";
|
||||
import { DeviceInfoProbe, DeviceInfoState } from "../native/device-info-probe";
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
|
||||
type CheckPhase = "checking" | "fonts" | "custom" | "flashable" | "newer" | "error";
|
||||
|
||||
@@ -299,7 +300,6 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
}
|
||||
|
||||
private formatError(error: unknown): string {
|
||||
const raw = (error as Error)?.message ?? String(error);
|
||||
return raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return formatErrorMessage(error);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import { FirmwareFlasher, FlashProgress, FlashState } from "../native/firmware-f
|
||||
import { FlashPromptCommunicator, FlashPromptState } from "../native/flash-prompt-communicator";
|
||||
import { resumeAutoReconnect, suppressAutoReconnect } from "../g2/reconnect-policy";
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
|
||||
type FlashPhase = "intro" | "prompt" | "building" | "ready" | "flashing" | "flashed" | "error";
|
||||
|
||||
@@ -566,7 +567,6 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
}
|
||||
|
||||
private formatError(error: unknown): string {
|
||||
const raw = (error as Error)?.message ?? String(error);
|
||||
return raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return formatErrorMessage(error);
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,12 @@ export function navigatingTo(args: NavigatedData): void {
|
||||
export function navigatingFrom(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
const model = page.bindingContext as PairingViewModel | undefined;
|
||||
model?.stop();
|
||||
// Backing out destroys the page; a forward navigation (manual entry) keeps
|
||||
// it on the stack, so only pause the scan and keep the model's app-lifecycle
|
||||
// hooks for the return trip.
|
||||
if (args.isBackNavigation) {
|
||||
model?.dispose();
|
||||
} else {
|
||||
model?.stop();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<ScrollView row="2" class="m-t-12">
|
||||
<StackLayout>
|
||||
<Label text="Glasses" class="h2 pairing-section" visibility="{{ glassesSectionVisibility }}" />
|
||||
<Label text="Glasses" class="h2 pairing-section" />
|
||||
<Label text="{{ emptyGlassesMessage }}" class="pairing-empty" textWrap="true" visibility="{{ emptyGlassesVisibility }}" />
|
||||
<Repeater items="{{ glassesRows }}">
|
||||
<Repeater.itemsLayout>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
import { Application, EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
|
||||
import { ensureBlePermissions } from "../g2/android-permissions";
|
||||
import { loadDeviceAddresses, loadPairedGlassesIdentity, saveDeviceAddresses, savePairedGlassesIdentity } from "../g2/device-addresses";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
import {
|
||||
colorwayLabel,
|
||||
DEFAULT_STALE_AFTER_MS,
|
||||
@@ -71,10 +72,38 @@ export class PairingViewModel extends Observable {
|
||||
this.onboarding = options?.onboarding ?? false;
|
||||
this.previouslyPairedSerial = loadPairedGlassesIdentity()?.serial ?? null;
|
||||
this.previouslyPairedRing = loadDeviceAddresses().ring;
|
||||
// A backgrounded phone (Home, screen lock, a call) must not keep the
|
||||
// low-latency scan and the refresh timer burning; pick both back up when
|
||||
// the app returns.
|
||||
Application.on(Application.suspendEvent, this.onAppSuspend);
|
||||
Application.on(Application.resumeEvent, this.onAppResume);
|
||||
}
|
||||
|
||||
// --- lifecycle -------------------------------------------------------------
|
||||
|
||||
private resumeScanAfterSuspend = false;
|
||||
|
||||
private readonly onAppSuspend = (): void => {
|
||||
if (this._scanning) {
|
||||
this.resumeScanAfterSuspend = true;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
private readonly onAppResume = (): void => {
|
||||
if (this.resumeScanAfterSuspend) {
|
||||
this.resumeScanAfterSuspend = false;
|
||||
void this.start();
|
||||
}
|
||||
};
|
||||
|
||||
/** Final teardown when the page is left for good (not a detour to manual entry). */
|
||||
dispose(): void {
|
||||
this.stop();
|
||||
Application.off(Application.suspendEvent, this.onAppSuspend);
|
||||
Application.off(Application.resumeEvent, this.onAppResume);
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
if (this._scanning) return;
|
||||
if (!global.isAndroid) {
|
||||
@@ -187,10 +216,6 @@ export class PairingViewModel extends Observable {
|
||||
return this._ringRows;
|
||||
}
|
||||
|
||||
get glassesSectionVisibility(): "visible" | "collapse" {
|
||||
return "visible";
|
||||
}
|
||||
|
||||
get emptyGlassesVisibility(): "visible" | "collapse" {
|
||||
return this._glassesRows.length ? "collapse" : "visible";
|
||||
}
|
||||
@@ -280,26 +305,41 @@ export class PairingViewModel extends Observable {
|
||||
const pair = this.selectedPair;
|
||||
const ring = this.selectedRing;
|
||||
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?.right?.address ?? existing.right,
|
||||
left: pair?.left?.address ?? existing.left,
|
||||
right: pair ? pair.right!.address : existing.right,
|
||||
left: pair ? pair.left!.address : existing.left,
|
||||
ring: ring?.advertisement.address ?? existing.ring,
|
||||
};
|
||||
saveDeviceAddresses(addresses);
|
||||
if (pair?.left && pair.right) {
|
||||
if (pair) {
|
||||
savePairedGlassesIdentity({
|
||||
serial: pair.serial ?? "",
|
||||
leftName: pair.left.name,
|
||||
rightName: pair.right.name,
|
||||
leftAddress: pair.left.address,
|
||||
rightAddress: pair.right.address,
|
||||
leftName: pair.left!.name,
|
||||
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,
|
||||
pairedAtMs: Date.now(),
|
||||
});
|
||||
} else if (ring) {
|
||||
// Replacing just the ring: keep the stored glasses identity current so
|
||||
// the config page doesn't keep naming the old ring.
|
||||
const identity = loadPairedGlassesIdentity();
|
||||
if (identity) {
|
||||
savePairedGlassesIdentity({
|
||||
...identity,
|
||||
ringName: ring.advertisement.name,
|
||||
ringAddress: ring.advertisement.address,
|
||||
});
|
||||
}
|
||||
}
|
||||
this.stop();
|
||||
this.dispose();
|
||||
if (this.onboarding) {
|
||||
setPreviewOnlyMode(false);
|
||||
// Continue the onboarding chain: unpair the official app next.
|
||||
@@ -310,7 +350,7 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
onSecondaryTap(): void {
|
||||
this.stop();
|
||||
this.dispose();
|
||||
const frame = Frame.topmost();
|
||||
if (frame?.canGoBack()) {
|
||||
frame.goBack();
|
||||
@@ -348,9 +388,12 @@ export class PairingViewModel extends Observable {
|
||||
const rings = this.aggregator.rings();
|
||||
|
||||
// Keep the selection pointing at live data (addresses can only change if a
|
||||
// side was replaced); drop it if the pair disappeared.
|
||||
// side was replaced); drop it if the pair disappeared — or if it degraded
|
||||
// below complete (an arm went back in the case), so Save can never write a
|
||||
// one-armed selection padded with stale addresses.
|
||||
if (this.selectedPair) {
|
||||
this.selectedPair = pairs.find((pair) => pair.id === this.selectedPair!.id) ?? null;
|
||||
const live = pairs.find((pair) => pair.id === this.selectedPair!.id) ?? null;
|
||||
this.selectedPair = live?.completeness === "complete" ? live : null;
|
||||
}
|
||||
if (this.selectedRing) {
|
||||
this.selectedRing = rings.find((ring) => ring.id === this.selectedRing!.id) ?? null;
|
||||
@@ -378,7 +421,7 @@ export class PairingViewModel extends Observable {
|
||||
if (this.scanFailure) {
|
||||
this.status = `Scan failed: ${this.scanFailure}`;
|
||||
} else if (!this._scanning) {
|
||||
this.status = pairs.length ? "Scan paused." : "Scan paused.";
|
||||
this.status = "Scan paused.";
|
||||
} else if (!pairs.length && !rings.length) {
|
||||
this.status = "Scanning…";
|
||||
} else {
|
||||
@@ -413,8 +456,7 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
private formatError(error: unknown): string {
|
||||
const raw = (error as Error)?.message ?? String(error);
|
||||
return raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return formatErrorMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user