forked from Blendman974/faceclaw
Merge branch 'bluetooth-pairing-improvements'
This commit is contained in:
commit
ca183e5aed
54 files changed
+1115
-474
No files matched your search
@@ -2,7 +2,7 @@
|
||||
<ActionBar title="Configure Devices" />
|
||||
|
||||
<GridLayout rows="auto,auto,auto,auto,auto,auto,auto,auto,*" class="p-20">
|
||||
<Label row="0" text="Configure the MAC addresses for the G2 headset arms and optional R1 ring. This page does not test a connection." textWrap="true" />
|
||||
<Label row="0" text="Configure the MAC addresses for the G2 headset arms and optional R1 ring. This page does not test a connection." class="body-text" textWrap="true" />
|
||||
|
||||
<GridLayout row="1" columns="96,*" class="pairing-row m-t-12" visibility="{{ identityVisibility }}">
|
||||
<Image col="0" src="{{ identityImagePath }}" stretch="aspectFit" width="90" height="34" />
|
||||
@@ -34,11 +34,11 @@
|
||||
<Button col="1" text="Scan for glasses" tap="{{ onScanTap }}" class="-primary" isEnabled="{{ canDiscover }}" />
|
||||
</GridLayout>
|
||||
|
||||
<Label row="6" text="{{ status }}" class="m-t-16" textWrap="true" />
|
||||
<Label row="6" text="{{ status }}" class="body-text m-t-16" textWrap="true" />
|
||||
|
||||
<GridLayout row="7" columns="*,*" class="m-t-16">
|
||||
<Button col="0" text="{{ saveLabel }}" tap="{{ onSaveTap }}" class="-primary" />
|
||||
<Button col="1" text="Back" tap="{{ onBackTap }}" />
|
||||
<Button col="0" text="Back" tap="{{ onBackTap }}" />
|
||||
<Button col="1" text="{{ saveLabel }}" tap="{{ onSaveTap }}" class="-primary" />
|
||||
</GridLayout>
|
||||
|
||||
<ScrollView row="8" class="m-t-16">
|
||||
|
||||
@@ -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;
|
||||
@@ -486,7 +487,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;
|
||||
@@ -496,6 +500,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 } });
|
||||
}
|
||||
@@ -596,9 +601,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);
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,20 @@
|
||||
<StackLayout>
|
||||
<Label text="{{ headline }}" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<ActivityIndicator busy="{{ busy }}" visibility="{{ busyVisibility }}" class="m-t-16" />
|
||||
<Label text="{{ status }}" class="m-t-16 text-center" textWrap="true" />
|
||||
<Label text="{{ status }}" class="body-text m-t-16 text-center" textWrap="true" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
<GridLayout row="1" columns="*,*" class="m-t-20">
|
||||
<Button col="0" text="{{ secondaryLabel }}" tap="{{ onSecondaryTap }}" visibility="{{ secondaryVisibility }}" />
|
||||
<Button col="1" text="{{ primaryLabel }}" tap="{{ onPrimaryTap }}" visibility="{{ primaryVisibility }}" class="-primary" />
|
||||
</GridLayout>
|
||||
<StackLayout row="1" class="m-t-20">
|
||||
<!-- Error-only escape hatches: flash anyway, or trust that the custom firmware is present. -->
|
||||
<GridLayout columns="*,*" visibility="{{ errorActionsVisibility }}">
|
||||
<Button col="0" text="Install" tap="{{ onInstallTap }}" />
|
||||
<Button col="1" text="Skip" tap="{{ onSkipTap }}" />
|
||||
</GridLayout>
|
||||
<GridLayout columns="*,*">
|
||||
<Button col="0" text="{{ secondaryLabel }}" tap="{{ onSecondaryTap }}" visibility="{{ secondaryVisibility }}" />
|
||||
<Button col="1" text="{{ primaryLabel }}" tap="{{ onPrimaryTap }}" visibility="{{ primaryVisibility }}" class="-primary" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -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";
|
||||
|
||||
@@ -94,6 +95,10 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
return this._phase === "custom" || this._phase === "fonts" ? "collapse" : "visible";
|
||||
}
|
||||
|
||||
get errorActionsVisibility(): "visible" | "collapse" {
|
||||
return this._phase === "error" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
// --- button handlers -------------------------------------------------------
|
||||
|
||||
onPrimaryTap(): void {
|
||||
@@ -123,6 +128,20 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
frame?.navigate({ moduleName: "phone-ui/onboarding-unpair-page", clearHistory: true });
|
||||
}
|
||||
|
||||
/** Escape hatch when the check itself fails: flash as if stock firmware had been detected. */
|
||||
onInstallTap(): void {
|
||||
if (this._phase !== "error") return;
|
||||
this.goToFlashing();
|
||||
}
|
||||
|
||||
/** Escape hatch when the check itself fails: continue as if compatible custom firmware had been detected. */
|
||||
onSkipTap(): void {
|
||||
if (this._phase !== "error") return;
|
||||
// Same path as a real "custom" classification, so the phone-side G2 fonts
|
||||
// still get extracted when they're missing.
|
||||
this.applyClassification("custom", "", "");
|
||||
}
|
||||
|
||||
// --- probe flow ------------------------------------------------------------
|
||||
|
||||
private async check(): Promise<void> {
|
||||
@@ -144,7 +163,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
}
|
||||
|
||||
this.disposeProbe();
|
||||
const probe = new DeviceInfoProbe(stored.right);
|
||||
const probe = new DeviceInfoProbe(stored.right, stored.left);
|
||||
this.probeInstance = probe;
|
||||
probe.onStateChange((state) => this.reportProbeState(state));
|
||||
|
||||
@@ -162,6 +181,9 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
private reportProbeState(state: DeviceInfoState): void {
|
||||
if (state === "connecting") {
|
||||
this.status = "Connecting to your glasses...";
|
||||
} else if (state === "authenticating") {
|
||||
// First-time connections pair here; the OS may show a Bluetooth dialog.
|
||||
this.status = "Authenticating with your glasses... If Android asks to pair, tap Pair.";
|
||||
} else if (state === "querying") {
|
||||
this.status = "Reading the firmware version...";
|
||||
}
|
||||
@@ -285,6 +307,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
this.notifyPropertyChange("secondaryLabel", this.secondaryLabel);
|
||||
this.notifyPropertyChange("primaryVisibility", this.primaryVisibility);
|
||||
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
|
||||
this.notifyPropertyChange("errorActionsVisibility", this.errorActionsVisibility);
|
||||
}
|
||||
|
||||
private disposeProbe(): void {
|
||||
@@ -299,7 +322,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);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<Label text="{{ headline }}" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<ActivityIndicator busy="{{ busy }}" visibility="{{ busyVisibility }}" class="m-t-16" />
|
||||
<Progress value="{{ progress }}" maxValue="100" visibility="{{ progressVisibility }}" class="m-t-16" />
|
||||
<Label text="{{ status }}" class="m-t-16 text-center" textWrap="true" />
|
||||
<Label text="{{ status }}" class="body-text m-t-16 text-center" textWrap="true" />
|
||||
<Label text="{{ log }}" class="m-t-24" textWrap="true" fontSize="12" visibility="{{ logVisibility }}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -421,11 +422,9 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
|
||||
private handleFlashProgress(progress: FlashProgress): void {
|
||||
const lensIndex = progress.lens === "right" ? 1 : 0;
|
||||
const withinLens =
|
||||
progress.componentCount > 0
|
||||
? (progress.componentIndex - 1 + (progress.blockCount > 0 ? progress.blockIndex / progress.blockCount : 0)) /
|
||||
progress.componentCount
|
||||
: 0;
|
||||
// Weight by bytes, not by component index: the image is one large segment
|
||||
// plus several small ones, so per-component steps move wildly unevenly.
|
||||
const withinLens = progress.bytesTotal > 0 ? Math.min(1, progress.bytesSent / progress.bytesTotal) : 0;
|
||||
this.progress = ((lensIndex + withinLens) / 2) * 100;
|
||||
this.status =
|
||||
`Flashing ${progress.lens} lens — part ${progress.componentIndex}/${progress.componentCount}, ` +
|
||||
@@ -566,7 +565,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);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
|
||||
<GridLayout rows="*,auto" class="p-20">
|
||||
<ScrollView row="0">
|
||||
<StackLayout row="0" verticalAlignment="middle" visibility="{{ splashVisibility }}">
|
||||
<Label text="{{ headline }}" class="h1 text-center" textWrap="true" />
|
||||
<Label text="{{ tagline }}" class="body-text text-center m-t-8" textWrap="true" />
|
||||
<Image src="~/images/faceclaw-logo.png" stretch="aspectFit" height="{{ logoHeight }}" horizontalAlignment="center" class="onboarding-logo m-t-24" />
|
||||
</StackLayout>
|
||||
|
||||
<ScrollView row="0" visibility="{{ contentVisibility }}">
|
||||
<StackLayout>
|
||||
<Image src="res://logo" stretch="aspectFit" height="140" horizontalAlignment="center" visibility="{{ logoVisibility }}" class="m-t-24" />
|
||||
<Label text="{{ headline }}" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label text="{{ tagline }}" class="text-center m-t-8" textWrap="true" visibility="{{ taglineVisibility }}" />
|
||||
<Label text="{{ body }}" class="m-t-24" textWrap="true" />
|
||||
<Label text="{{ body }}" class="body-text m-t-24" textWrap="true" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Label text="Disconnect the Even App" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="Faceclaw and the official Even Realities app can't both be connected to the glasses at once. Before continuing, open the Even app, go to Home, select your glasses, open the Connection submenu, and press Disconnect (or turn off the Even app's Bluetooth)."
|
||||
class="m-t-24" textWrap="true" />
|
||||
class="body-text m-t-24" textWrap="true" />
|
||||
<Button text="Open Even App Settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary m-t-24" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
|
||||
@@ -10,8 +10,8 @@ type StepContent = {
|
||||
body: string;
|
||||
primaryLabel: string;
|
||||
secondaryLabel: string;
|
||||
showLogo: boolean;
|
||||
showTagline: boolean;
|
||||
/** Step 1 renders as the vertically-centered splash (headline + tagline + logo) instead of the scrolling body. */
|
||||
splash: boolean;
|
||||
showSecondary: boolean;
|
||||
};
|
||||
|
||||
@@ -22,8 +22,7 @@ const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
|
||||
body: "",
|
||||
primaryLabel: "Next",
|
||||
secondaryLabel: "",
|
||||
showLogo: true,
|
||||
showTagline: true,
|
||||
splash: true,
|
||||
showSecondary: false,
|
||||
},
|
||||
2: {
|
||||
@@ -33,8 +32,7 @@ const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
|
||||
"This unofficial 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 my headset, this is not Even's fault and is not covered by the hardware's warranty. If this software doesn't break my headset, using this software may void the hardware's warranty anyways, at the sole discretion of Even Realities. This software is a development prototype and may not be relied on for anything important. This software may be broken at any time by software or firmware updates created by Even, and this will not be Even's fault.",
|
||||
primaryLabel: "Agree",
|
||||
secondaryLabel: "Back",
|
||||
showLogo: false,
|
||||
showTagline: false,
|
||||
splash: false,
|
||||
showSecondary: true,
|
||||
},
|
||||
3: {
|
||||
@@ -44,8 +42,7 @@ const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
|
||||
"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. Faceclaw first scans for nearby glasses so you can pick yours by model, colour, and serial, then connects, asks for confirmation on the lens, and downloads and prepares the firmware.\n\nFlashing replaces the official firmware. It may void your warranty and, like any firmware update, carries a risk of bricking the device. You can only be connected to one app at a time, so disconnect the official Even app before flashing (open it, go to Home, select your glasses, open Connection, and press Disconnect).",
|
||||
primaryLabel: "Flash Firmware",
|
||||
secondaryLabel: "Preview Only",
|
||||
showLogo: false,
|
||||
showTagline: false,
|
||||
splash: false,
|
||||
showSecondary: true,
|
||||
},
|
||||
};
|
||||
@@ -112,24 +109,25 @@ export class OnboardingViewModel extends Observable {
|
||||
return STEP_CONTENT[this._step].secondaryLabel;
|
||||
}
|
||||
|
||||
get showLogo(): boolean {
|
||||
return STEP_CONTENT[this._step].showLogo;
|
||||
}
|
||||
|
||||
get showTagline(): boolean {
|
||||
return STEP_CONTENT[this._step].showTagline;
|
||||
}
|
||||
|
||||
get showSecondary(): boolean {
|
||||
return STEP_CONTENT[this._step].showSecondary;
|
||||
}
|
||||
|
||||
get logoVisibility(): "visible" | "collapse" {
|
||||
return this.showLogo ? "visible" : "collapse";
|
||||
get splashVisibility(): "visible" | "collapse" {
|
||||
return STEP_CONTENT[this._step].splash ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get taglineVisibility(): "visible" | "collapse" {
|
||||
return this.showTagline ? "visible" : "collapse";
|
||||
get contentVisibility(): "visible" | "collapse" {
|
||||
return STEP_CONTENT[this._step].splash ? "collapse" : "visible";
|
||||
}
|
||||
|
||||
/**
|
||||
* The logo scales with the screen (~40% of its height) so it reads as a
|
||||
* splash on tablets too, capped near the source PNG's height so it doesn't
|
||||
* upscale into mush.
|
||||
*/
|
||||
get logoHeight(): number {
|
||||
return Math.min(480, Math.round(Screen.mainScreen.heightDIPs * 0.4));
|
||||
}
|
||||
|
||||
get secondaryVisibility(): "visible" | "collapse" {
|
||||
@@ -148,11 +146,9 @@ export class OnboardingViewModel extends Observable {
|
||||
this.notifyPropertyChange("body", this.body);
|
||||
this.notifyPropertyChange("primaryLabel", this.primaryLabel);
|
||||
this.notifyPropertyChange("secondaryLabel", this.secondaryLabel);
|
||||
this.notifyPropertyChange("showLogo", this.showLogo);
|
||||
this.notifyPropertyChange("showTagline", this.showTagline);
|
||||
this.notifyPropertyChange("showSecondary", this.showSecondary);
|
||||
this.notifyPropertyChange("logoVisibility", this.logoVisibility);
|
||||
this.notifyPropertyChange("taglineVisibility", this.taglineVisibility);
|
||||
this.notifyPropertyChange("splashVisibility", this.splashVisibility);
|
||||
this.notifyPropertyChange("contentVisibility", this.contentVisibility);
|
||||
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -37,7 +37,7 @@
|
||||
<Label text="{{ variantSummary }}" class="pairing-variant" visibility="{{ variantVisibility }}" />
|
||||
<Label text="{{ proximityLine }}" class="{{ proximityClass }}" />
|
||||
<Label text="{{ deviceName }}" class="pairing-serial" />
|
||||
<Label text="{{ armsSummary }}" class="pairing-arms" textWrap="true" />
|
||||
<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" />
|
||||
@@ -61,7 +61,7 @@
|
||||
</GridLayout>
|
||||
<Label text="{{ proximityLine }}" class="{{ proximityClass }}" />
|
||||
<Label text="{{ deviceName }}" class="pairing-serial" />
|
||||
<Label text="{{ armsSummary }}" class="pairing-arms" textWrap="true" />
|
||||
<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" />
|
||||
@@ -73,8 +73,6 @@
|
||||
<Label text="Selected" class="h2 pairing-section" />
|
||||
<Label text="{{ selectionSummary }}" textWrap="true" />
|
||||
</StackLayout>
|
||||
|
||||
<Label text="{{ diagnostics }}" class="pairing-diagnostics m-t-16" textWrap="true" visibility="{{ diagnosticsVisibility }}" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -25,6 +26,7 @@ export type PairingRowItem = PairingRowPresentation & {
|
||||
variantVisibility: "visible" | "collapse";
|
||||
proximityLine: string;
|
||||
proximityClass: string;
|
||||
armsVisibility: "visible" | "collapse";
|
||||
warningVisibility: "visible" | "collapse";
|
||||
chevron: string;
|
||||
/**
|
||||
@@ -55,7 +57,6 @@ export class PairingViewModel extends Observable {
|
||||
private startedAtMs = 0;
|
||||
private advertisementCount = 0;
|
||||
private scanFailure = "";
|
||||
private readonly logLines: string[] = [];
|
||||
|
||||
private _scanning = false;
|
||||
private _status = "";
|
||||
@@ -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) {
|
||||
@@ -108,7 +137,6 @@ export class PairingViewModel extends Observable {
|
||||
this.scanning = false;
|
||||
this.refresh();
|
||||
},
|
||||
onLog: (line) => this.appendLog(line),
|
||||
});
|
||||
if (!started) {
|
||||
this.status = "Could not start the Bluetooth scan. Check that Bluetooth is on.";
|
||||
@@ -187,10 +215,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";
|
||||
}
|
||||
@@ -246,14 +270,6 @@ export class PairingViewModel extends Observable {
|
||||
return this.onboarding ? "Back" : "Cancel";
|
||||
}
|
||||
|
||||
get diagnostics(): string {
|
||||
return this.logLines.slice(-12).join("\n");
|
||||
}
|
||||
|
||||
get diagnosticsVisibility(): "visible" | "collapse" {
|
||||
return this.logLines.length ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
// --- actions ---------------------------------------------------------------
|
||||
|
||||
// Arrow property: NativeScript fires XML event handlers with `this` bound to the
|
||||
@@ -280,26 +296,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 +341,7 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
onSecondaryTap(): void {
|
||||
this.stop();
|
||||
this.dispose();
|
||||
const frame = Frame.topmost();
|
||||
if (frame?.canGoBack()) {
|
||||
frame.goBack();
|
||||
@@ -348,9 +379,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 +412,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 {
|
||||
@@ -400,21 +434,13 @@ export class PairingViewModel extends Observable {
|
||||
"selectionVisibility",
|
||||
"selectionSummary",
|
||||
"primaryEnabled",
|
||||
"diagnostics",
|
||||
"diagnosticsVisibility",
|
||||
] as const) {
|
||||
this.notifyPropertyChange(property, this[property]);
|
||||
}
|
||||
}
|
||||
|
||||
private appendLog(line: string): void {
|
||||
this.logLines.push(line);
|
||||
if (this.logLines.length > 50) this.logLines.splice(0, this.logLines.length - 50);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,6 +458,7 @@ function toRowItem(row: PairingRowPresentation, selected: boolean, onRowTap: (ar
|
||||
variantVisibility: row.variantSummary ? "visible" : "collapse",
|
||||
proximityLine: `${row.proximityGlyph} ${row.proximitySummary}`,
|
||||
proximityClass: row.zone === "immediate" ? "pairing-proximity pairing-proximity-immediate" : "pairing-proximity",
|
||||
armsVisibility: row.armsSummary ? "visible" : "collapse",
|
||||
warningVisibility: row.warning ? "visible" : "collapse",
|
||||
chevron: selected ? "✓" : row.canSelect ? "›" : "…",
|
||||
onRowTap,
|
||||
|
||||
Reference in new issue
Block a user