forked from Blendman974/faceclaw
Porting onboarding/flashing flow io iOS
This commit is contained in:
1 parent
68b459751e
commit
64bf600ef9
46 files changed
+1419
-211
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { NavigatedData, Page } from "@nativescript/core";
|
||||
|
||||
import { ConfigViewModel } from "./config-view-model";
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
// Preserve the model across back-navigation (returning from the firmware
|
||||
// check page) so the onboarding "Continue" flow isn't lost.
|
||||
if (!page.bindingContext) {
|
||||
const context = (args.context as { onboarding?: boolean } | undefined) ?? undefined;
|
||||
page.bindingContext = new ConfigViewModel({ onboarding: context?.onboarding ?? false });
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1 @@
|
||||
import { Button, Color, GridLayout, Label, Page, ScrollView, StackLayout, TextField } from '@nativescript/core'
|
||||
import { loadDeviceAddresses, normalizeMacAddress, saveDeviceAddresses } from '../g2/device-addresses'
|
||||
import { deviceAddressError, type IosDevice } from '../g2/ios-peripheral-identity'
|
||||
import { iosBluetooth } from '../native/ios-bluetooth'
|
||||
|
||||
export function createConfigureDevicesPage(): Page {
|
||||
const page = new Page(); page.actionBarHidden = true
|
||||
const root = new GridLayout(); root.rows = 'auto,*,auto'; root.padding = 16; page.content = root
|
||||
const title = new Label(); title.text = 'Configure devices'; title.fontSize = 24; title.fontWeight = 'bold'; root.addChild(title)
|
||||
const scroll = new ScrollView(); GridLayout.setRow(scroll, 1); root.addChild(scroll)
|
||||
const form = new StackLayout(); scroll.content = form
|
||||
const text = (value: string, size = 15) => {
|
||||
const label = new Label(); label.text = value; label.fontSize = size; label.textWrap = true; label.marginTop = 12; form.addChild(label); return label
|
||||
}
|
||||
text('Enter the G2 arm MAC addresses and optional R1 ring address. Scan once so this iPhone can find the matching devices. Saving does not connect.')
|
||||
const stored = loadDeviceAddresses()
|
||||
const fields = {} as Record<'left' | 'right' | 'ring', TextField>
|
||||
for (const role of ['right', 'left', 'ring'] as const) {
|
||||
text(role === 'ring' ? 'R1 ring MAC (optional)' : `${role === 'left' ? 'Left' : 'Right'} arm MAC`)
|
||||
const field = new TextField(); field.text = stored[role]; field.hint = 'AA:BB:CC:DD:EE:FF'
|
||||
field.autocorrect = false; field.autocapitalizationType = 'allcharacters'; field.fontSize = 18
|
||||
field.padding = 10; field.backgroundColor = new Color('#ffffff'); field.accessibilityLabel = `${role} MAC address`
|
||||
field.accessibilityIdentifier = `device-address-${role}`; form.addChild(field); fields[role] = field
|
||||
}
|
||||
const status = text('Addresses are saved only when you tap Save.'); status.color = new Color('#285c45')
|
||||
const button = (label: string, action: () => void) => {
|
||||
const view = new Button(); view.text = label; view.fontSize = 15; view.marginTop = 12; view.on('tap', action); return view
|
||||
}
|
||||
let off: (() => void) | null = null
|
||||
let closed = false
|
||||
const found = new StackLayout()
|
||||
const rows = new Map<string, Button>()
|
||||
const showDevice = (device: IosDevice) => {
|
||||
if (device.connectable === false) return
|
||||
let row = rows.get(device.address)
|
||||
if (!row) {
|
||||
row = button('', () => { fields[device.role].text = device.address; status.text = `${device.role} address selected. Tap Save to keep it.` })
|
||||
row.textWrap = true; row.fontSize = 13; rows.set(device.address, row); found.addChild(row)
|
||||
}
|
||||
row.text = `${device.role === 'ring' ? 'Ring' : device.role === 'left' ? 'Left arm' : 'Right arm'} · ${device.address}\n${device.serial || device.name} · ${device.rssi ?? '?'} dBm`
|
||||
}
|
||||
const scan = button('Scan for devices', () => {
|
||||
for (const field of Object.values(fields)) field.dismissSoftInput()
|
||||
const ble = iosBluetooth()
|
||||
off?.(); off = ble.onEvent(event => {
|
||||
if (closed) return
|
||||
if (event.kind === 'device' && 'device' in event) showDevice(event.device)
|
||||
if (event.kind === 'scan-stopped') { scan.isEnabled = true; status.text = rows.size ? 'Tap a device to fill its address, then Save.' : 'No matching devices found. Wake the glasses and disconnect other apps, then scan again.' }
|
||||
})
|
||||
rows.clear(); found.removeChildren(); scan.isEnabled = false; status.text = 'Scanning… Allow Bluetooth if iOS asks.'
|
||||
void ble.startScan().catch(error => { if (!closed) { status.text = String(error.message ?? error); scan.isEnabled = true } })
|
||||
})
|
||||
form.addChild(scan); form.addChild(found)
|
||||
const footer = new GridLayout(); footer.columns = '*,*'; GridLayout.setRow(footer, 2); root.addChild(footer)
|
||||
const close = () => { closed = true; off?.(); off = null; iosBluetooth().stopScan(); page.closeModal() }
|
||||
const back = button('Back', close); footer.addChild(back)
|
||||
const save = button('Save', () => {
|
||||
const addresses = { right: normalizeMacAddress(fields.right.text), left: normalizeMacAddress(fields.left.text), ring: normalizeMacAddress(fields.ring.text) }
|
||||
const error = deviceAddressError(addresses)
|
||||
if (error) { status.text = error; return }
|
||||
saveDeviceAddresses(addresses)
|
||||
for (const role of ['left', 'right', 'ring'] as const) { fields[role].text = addresses[role]; fields[role].dismissSoftInput() }
|
||||
status.text = 'Saved device addresses. Return to the main screen and choose Connect.'
|
||||
})
|
||||
GridLayout.setColumn(save, 1); footer.addChild(save)
|
||||
page.on('unloaded', () => { closed = true; off?.(); off = null; iosBluetooth().stopScan() })
|
||||
return page
|
||||
}
|
||||
export { navigatingTo } from "./config-page-shared";
|
||||
@@ -1,13 +1 @@
|
||||
import { NavigatedData, Page } from "@nativescript/core";
|
||||
|
||||
import { ConfigViewModel } from "./config-view-model";
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
// Preserve the model across back-navigation (returning from the firmware
|
||||
// check page) so the onboarding "Continue" flow isn't lost.
|
||||
if (!page.bindingContext) {
|
||||
const context = (args.context as { onboarding?: boolean } | undefined) ?? undefined;
|
||||
page.bindingContext = new ConfigViewModel({ onboarding: context?.onboarding ?? false });
|
||||
}
|
||||
}
|
||||
export { navigatingTo } from "./config-page-shared";
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
<StackLayout row="2" class="m-t-16">
|
||||
<Label text="Right arm MAC" />
|
||||
<TextField text="{{ rightAddress }}" textChange="{{ onRightAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
|
||||
<TextField accessibilityLabel="Right arm MAC" text="{{ rightAddress }}" textChange="{{ onRightAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
|
||||
</StackLayout>
|
||||
|
||||
<StackLayout row="3" class="m-t-12">
|
||||
<Label text="Left arm MAC" />
|
||||
<TextField text="{{ leftAddress }}" textChange="{{ onLeftAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
|
||||
<TextField accessibilityLabel="Left arm MAC" text="{{ leftAddress }}" textChange="{{ onLeftAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
|
||||
</StackLayout>
|
||||
|
||||
<StackLayout row="4" class="m-t-12">
|
||||
<Label text="R1 ring MAC (optional)" />
|
||||
<TextField text="{{ ringAddress }}" textChange="{{ onRingAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
|
||||
<TextField accessibilityLabel="R1 ring MAC" text="{{ ringAddress }}" textChange="{{ onRingAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
|
||||
</StackLayout>
|
||||
|
||||
<GridLayout row="5" columns="*,*" class="m-t-16">
|
||||
<Button col="0" text="Load paired devices" tap="{{ onLoadPairedTap }}" class="-primary" isEnabled="{{ canDiscover }}" />
|
||||
<Button col="0" text="Load paired devices" visibility="{{ pairedDevicesVisibility }}" tap="{{ onLoadPairedTap }}" class="-primary" isEnabled="{{ canDiscover }}" />
|
||||
<Button col="1" text="Scan for glasses" tap="{{ onScanTap }}" class="-primary" isEnabled="{{ canDiscover }}" />
|
||||
</GridLayout>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
|
||||
import { ensureBlePermissions } from "../g2/android-permissions";
|
||||
import { ensureBlePermissions } from "../native/ble-permissions";
|
||||
import {
|
||||
isValidMacAddress,
|
||||
loadDeviceAddresses,
|
||||
@@ -38,6 +39,9 @@ export class ConfigViewModel extends Observable {
|
||||
this.status = this.onboarding
|
||||
? "Scan for glasses to pick yours by model and serial, load the addresses of devices paired with this phone, or enter them by hand, then Continue."
|
||||
: "Edit addresses manually, scan for glasses, or load them from paired devices.";
|
||||
if (global.isIOS) this.status = this.onboarding
|
||||
? "Scan for glasses to pick yours by model and serial, or enter the addresses by hand, then Continue."
|
||||
: "Edit addresses manually or scan for glasses.";
|
||||
}
|
||||
|
||||
// --- paired identity card --------------------------------------------------
|
||||
@@ -183,13 +187,15 @@ export class ConfigViewModel extends Observable {
|
||||
this.ringAddress = args.object?.text ?? args.value ?? "";
|
||||
}
|
||||
|
||||
get pairedDevicesVisibility(): "visible" | "collapse" { return global.isIOS ? "collapse" : "visible"; }
|
||||
|
||||
async onLoadPairedTap(): Promise<void> {
|
||||
await this.populateFromDiscovery(async () => this.discovery.getBondedCandidates(), "Loaded paired devices.");
|
||||
}
|
||||
|
||||
/** The live scan page identifies pairs by serial, model, and distance; hand off to it. */
|
||||
async onScanTap(): Promise<void> {
|
||||
if (!this.onboarding) {
|
||||
if (!this.onboarding && global.isAndroid) {
|
||||
// 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.
|
||||
@@ -221,10 +227,7 @@ export class ConfigViewModel extends Observable {
|
||||
frame?.navigate({ moduleName: "phone-ui/onboarding-page", clearHistory: true });
|
||||
return;
|
||||
}
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/main-page",
|
||||
clearHistory: true,
|
||||
});
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
|
||||
onSaveTap(): void {
|
||||
@@ -254,6 +257,10 @@ export class ConfigViewModel extends Observable {
|
||||
this.status = "Ring MAC address is invalid.";
|
||||
return false;
|
||||
}
|
||||
if (right === left || ring === right || ring === left) {
|
||||
this.status = "Each device must have a different MAC address.";
|
||||
return false;
|
||||
}
|
||||
|
||||
saveDeviceAddresses({ right, left, ring });
|
||||
this.rightAddress = right;
|
||||
@@ -267,7 +274,7 @@ export class ConfigViewModel extends Observable {
|
||||
load: () => Promise<Parameters<typeof buildAddressSet>[0]>,
|
||||
successMessage: string,
|
||||
): Promise<void> {
|
||||
if (!global.isAndroid) {
|
||||
if (!global.isAndroid && !global.isIOS) {
|
||||
this.status = "Discovery is only available on Android.";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Application, Button, Color, Dialogs, GridLayout, Image, Label, Page, StackLayout, type TouchGestureEventData } from '@nativescript/core'
|
||||
import { createConfigureDevicesPage } from './config-page.ios'
|
||||
import { Application, Button, Color, Dialogs, Frame, GridLayout, Image, Label, Page, StackLayout, type TouchGestureEventData } from '@nativescript/core'
|
||||
import { isPreviewOnlyMode } from './onboarding-state'
|
||||
import { isAutoReconnectSuppressed, resumeAutoReconnect, suppressAutoReconnect } from '../g2/reconnect-policy'
|
||||
import { launcherEntries } from '../apps/launcher'
|
||||
import { ALL_APPS } from '../apps/all-apps'
|
||||
import { IosPreviewController } from '../g2/ios-preview-controller'
|
||||
@@ -69,12 +70,21 @@ export function createMainPage(): Page {
|
||||
async function openDevices(): Promise<void> {
|
||||
const connected = ['connected', 'connecting', 'retrying'].includes(controller.connectionState?.phase ?? '')
|
||||
const choice = await Dialogs.action({ title: 'Devices', message: controller.connectionState?.status ?? 'Preview only', cancelButtonText: 'Cancel',
|
||||
actions: ['Configure devices', connected ? 'Disconnect' : 'Connect', 'Connection details'] })
|
||||
if (choice === 'Configure devices') {
|
||||
actions: ['Pair glasses', 'Configure devices', connected ? 'Disconnect' : 'Connect', 'Check firmware', 'Install custom firmware', 'Uninstall custom firmware', 'Connection details'] })
|
||||
if (['Pair glasses', 'Configure devices', 'Check firmware', 'Install custom firmware', 'Uninstall custom firmware'].includes(choice)) {
|
||||
suppressAutoReconnect()
|
||||
await controller.disconnect()
|
||||
page.showModal(createConfigureDevicesPage(), { fullscreen: true, closeCallback: () => {} })
|
||||
} else if (choice === 'Connect') await controller.connect()
|
||||
else if (choice === 'Disconnect') await controller.disconnect()
|
||||
if (choice === 'Pair glasses') {
|
||||
Frame.topmost()?.navigate({ moduleName: 'phone-ui/onboarding-unpair-page' })
|
||||
} else if (choice === 'Configure devices') {
|
||||
Frame.topmost()?.navigate({ moduleName: 'phone-ui/config-page', context: { onboarding: isPreviewOnlyMode() } })
|
||||
} else if (choice === 'Check firmware') {
|
||||
Frame.topmost()?.navigate({ moduleName: 'phone-ui/onboarding-firmware-check-page' })
|
||||
} else {
|
||||
Frame.topmost()?.navigate({ moduleName: 'phone-ui/onboarding-flash-page', context: { mode: choice === 'Uninstall custom firmware' ? 'uninstall' : 'install', fromOnboarding: false } })
|
||||
}
|
||||
} else if (choice === 'Connect') { resumeAutoReconnect(); await controller.connect() }
|
||||
else if (choice === 'Disconnect') { suppressAutoReconnect(); await controller.disconnect() }
|
||||
else if (choice === 'Connection details') await Dialogs.alert({ title: 'Connection details', message: controller.connectionDetails, okButtonText: 'OK' })
|
||||
}
|
||||
const padInput = new PhoneGestureRecognizer(gesture => controller.gesture(gesture, selectedTab === 'ring' ? 'ring' : 'watch'))
|
||||
@@ -184,16 +194,11 @@ export function createMainPage(): Page {
|
||||
}
|
||||
const resume = () => { foreground = true; controller.resume(); syncBandwidth() }
|
||||
let offSettings: (() => void) | null = null
|
||||
let firstLoad = true
|
||||
page.on('loaded', () => {
|
||||
Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume)
|
||||
offSettings?.(); offSettings = onAnySettingChanged(() => { sizeButton.text = controller.displayModeLabel; syncBandwidth() })
|
||||
selectTab(selectedTab); resume()
|
||||
if (firstLoad) {
|
||||
firstLoad = false
|
||||
// Match Android's reconnect-on-launch behavior once addresses are saved.
|
||||
if (!deviceAddressError(loadDeviceAddresses())) void controller.connect()
|
||||
}
|
||||
if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect()
|
||||
})
|
||||
page.on('unloaded', () => {
|
||||
pause(); offSettings?.(); offSettings = null
|
||||
@@ -201,3 +206,5 @@ export function createMainPage(): Page {
|
||||
})
|
||||
return page
|
||||
}
|
||||
|
||||
export const createPage = createMainPage
|
||||
@@ -8,3 +8,9 @@ export function navigatingTo(args: EventData): void {
|
||||
page.bindingContext = new OnboardingFirmwareCheckViewModel();
|
||||
}
|
||||
}
|
||||
|
||||
export function navigatingFrom(args: EventData): void {
|
||||
const page = args.object as Page;
|
||||
(page.bindingContext as OnboardingFirmwareCheckViewModel | undefined)?.dispose();
|
||||
page.bindingContext = null;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" navigatingFrom="navigatingFrom" actionBarHidden="true">
|
||||
<GridLayout rows="*,auto" class="p-20">
|
||||
<ScrollView row="0">
|
||||
<StackLayout>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { resumeAutoReconnect } from "../g2/reconnect-policy";
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
|
||||
import { ensureBlePermissions } from "../g2/android-permissions";
|
||||
import { ensureBlePermissions } from "../native/ble-permissions";
|
||||
import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
|
||||
import {
|
||||
downloadAndExtractEvenHubFonts,
|
||||
@@ -27,6 +29,8 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
private _status = "";
|
||||
private _busy = true;
|
||||
|
||||
private generation = 0;
|
||||
|
||||
private probeInstance: DeviceInfoProbe | null = null;
|
||||
|
||||
constructor() {
|
||||
@@ -158,7 +162,8 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
// --- probe flow ------------------------------------------------------------
|
||||
|
||||
private async check(): Promise<void> {
|
||||
if (!global.isAndroid) {
|
||||
const generation = ++this.generation;
|
||||
if (!global.isAndroid && !global.isIOS) {
|
||||
this.toError("Firmware checking is only available on Android.");
|
||||
return;
|
||||
}
|
||||
@@ -169,6 +174,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
if (generation !== this.generation) return;
|
||||
const stored = loadDeviceAddresses();
|
||||
if (!isValidMacAddress(stored.right)) {
|
||||
this.toError("No glasses address is configured. Go back and set the device addresses.");
|
||||
@@ -181,11 +187,13 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
probe.onStateChange((state, detail) => this.reportProbeState(state, detail));
|
||||
|
||||
const info = await probe.run();
|
||||
if (generation !== this.generation) return;
|
||||
this.probeInstance = null;
|
||||
|
||||
const { kind, version, extension } = classifyOnboardingFirmware(info);
|
||||
this.applyClassification(kind, version, extension);
|
||||
} catch (error) {
|
||||
if (generation !== this.generation) return;
|
||||
this.probeInstance = null;
|
||||
this.toError(this.formatError(error));
|
||||
}
|
||||
@@ -199,7 +207,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
this.status = `Connecting to ${lens}...`;
|
||||
} else if (state === "authenticating") {
|
||||
// First-time connections pair here; the OS may show a Bluetooth dialog.
|
||||
this.status = `Pairing with ${lens}... Each lens pairs separately; if Android asks to pair, tap Pair.`;
|
||||
this.status = `Pairing with ${lens}... Each lens pairs separately; if your phone asks to pair, tap Pair.`;
|
||||
} else if (state === "querying") {
|
||||
this.status = "Reading the firmware version...";
|
||||
}
|
||||
@@ -276,6 +284,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
}
|
||||
|
||||
private async extractFontsForCustomFirmware(version: string, extension: FirmwareExtension): Promise<void> {
|
||||
const generation = this.generation;
|
||||
this.setPhase("fonts");
|
||||
this.headline = "Preparing G2 Fonts";
|
||||
this.busy = true;
|
||||
@@ -283,9 +292,13 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
"Custom firmware is already installed, but its phone-side fonts are missing. " +
|
||||
"Downloading the official firmware to extract them; your glasses will not be reflashed.";
|
||||
try {
|
||||
await downloadAndExtractEvenHubFonts((progress) => this.reportFontProgress(progress));
|
||||
await downloadAndExtractEvenHubFonts((progress) => {
|
||||
if (generation === this.generation) this.reportFontProgress(progress);
|
||||
});
|
||||
if (generation !== this.generation) return;
|
||||
this.showCustomReady(version, extension, true);
|
||||
} catch (error) {
|
||||
if (generation !== this.generation) return;
|
||||
this.toError(
|
||||
`Custom firmware is installed, but the G2 fonts could not be prepared: ${this.formatError(error)}`,
|
||||
"Couldn't Prepare Fonts",
|
||||
@@ -337,13 +350,11 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
}
|
||||
|
||||
private finish(): void {
|
||||
resumeAutoReconnect();
|
||||
setPreviewOnlyMode(false);
|
||||
setOnboardingCompleted(true);
|
||||
this.disposeProbe();
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/main-page",
|
||||
clearHistory: true,
|
||||
});
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
|
||||
private toError(message: string, headline = "Couldn't Check Firmware"): void {
|
||||
@@ -366,6 +377,8 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
this.notifyPropertyChange("errorActionsVisibility", this.errorActionsVisibility);
|
||||
}
|
||||
|
||||
dispose(): void { ++this.generation; this.disposeProbe(); }
|
||||
|
||||
private disposeProbe(): void {
|
||||
if (this.probeInstance) {
|
||||
try {
|
||||
|
||||
@@ -14,3 +14,9 @@ export function navigatingTo(args: NavigatedData): void {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function navigatingFrom(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
(page.bindingContext as OnboardingFlashViewModel | undefined)?.dispose();
|
||||
page.bindingContext = null;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" navigatingFrom="navigatingFrom" enableSwipeBackNavigation="false" actionBarHidden="true">
|
||||
<GridLayout rows="*,auto" class="p-20">
|
||||
<ScrollView row="0">
|
||||
<StackLayout>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
|
||||
import { ensureBlePermissions } from "../g2/android-permissions";
|
||||
import { ensureBlePermissions } from "../native/ble-permissions";
|
||||
import {
|
||||
isValidMacAddress,
|
||||
loadDeviceAddresses,
|
||||
@@ -46,6 +47,9 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
private addresses: { right: string; left: string } | null = null;
|
||||
private firmwarePath = "";
|
||||
|
||||
private disposed = false;
|
||||
private promptGeneration = 0;
|
||||
|
||||
private prompt: FlashPromptCommunicator | null = null;
|
||||
private promptUnsubscribers: Array<() => void> = [];
|
||||
private promptBattery: FlashPromptBattery | null = null;
|
||||
@@ -228,15 +232,17 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
// --- prompt flow -----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Connect to both arms, authenticate (this is where any Android pairing
|
||||
* Connect to both arms, authenticate (this is where any system pairing
|
||||
* prompts appear), show the Yes/No confirmation on the lens, then read the
|
||||
* battery. With `skipPrompt` (retrying after a low-battery refusal, when
|
||||
* the user has already confirmed) the on-glasses confirmation is skipped
|
||||
* and only the battery is re-checked.
|
||||
*/
|
||||
private async beginPrompt(options?: { skipPrompt?: boolean }): Promise<void> {
|
||||
if (this.disposed) return;
|
||||
const generation = ++this.promptGeneration;
|
||||
const skipPrompt = Boolean(options?.skipPrompt);
|
||||
if (!global.isAndroid) {
|
||||
if (!global.isAndroid && !global.isIOS) {
|
||||
this.toError("Flashing is only available on Android.", () => this.beginPrompt(options));
|
||||
return;
|
||||
}
|
||||
@@ -249,7 +255,9 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
if (this.disposed || generation !== this.promptGeneration) return;
|
||||
const addresses = await this.resolveAddresses();
|
||||
if (this.disposed || generation !== this.promptGeneration) return;
|
||||
if (!addresses) {
|
||||
this.busy = false;
|
||||
this.toError(
|
||||
@@ -265,6 +273,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
: "Connecting to your glasses. Watch the lens for a Yes/No prompt.";
|
||||
this.startCommunicator(addresses, skipPrompt);
|
||||
} catch (error) {
|
||||
if (this.disposed || generation !== this.promptGeneration) return;
|
||||
this.busy = false;
|
||||
this.toError(this.formatError(error), () => this.beginPrompt(options));
|
||||
}
|
||||
@@ -293,7 +302,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
break;
|
||||
case "connected":
|
||||
this.status =
|
||||
"Connected. Pairing with both lenses — if Android asks to pair, accept it (once per lens)." +
|
||||
"Connected. Pairing with both lenses — if your phone asks to pair, accept it (once per lens)." +
|
||||
(skipPrompt ? "" : " Then watch the lens for the confirmation.");
|
||||
break;
|
||||
case "battery":
|
||||
@@ -368,6 +377,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
}
|
||||
|
||||
private cancelPrompt(): void {
|
||||
++this.promptGeneration;
|
||||
this.status = "Cancelling...";
|
||||
try {
|
||||
this.prompt?.cancel();
|
||||
@@ -390,11 +400,13 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
try {
|
||||
const build = this.mode === "uninstall" ? buildStockFirmware : buildCustomFirmware;
|
||||
const result = await build((progress) => this.reportBuildProgress(progress));
|
||||
if (this.disposed) return;
|
||||
this.firmwarePath = result.path;
|
||||
this.appendLog(`${this.noun} prepared and verified (${result.bytes.toLocaleString()} bytes), saved to ${result.path}`);
|
||||
// The user already said Yes on the lens; no second confirmation here.
|
||||
this.startFlashing();
|
||||
} catch (error) {
|
||||
if (this.disposed) return;
|
||||
this.busy = false;
|
||||
const message =
|
||||
error instanceof FirmwareBuildError ? error.message : this.formatError(error);
|
||||
@@ -403,6 +415,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
}
|
||||
|
||||
private reportBuildProgress(progress: FirmwareProgress): void {
|
||||
if (this.disposed) return;
|
||||
switch (progress.phase) {
|
||||
case "downloading":
|
||||
this.status = "Downloading the stock firmware from Even's CDN...";
|
||||
@@ -430,6 +443,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
// --- flashing flow ---------------------------------------------------------
|
||||
|
||||
private startFlashing(): void {
|
||||
if (this.disposed) return;
|
||||
if (!this.addresses || !this.firmwarePath) {
|
||||
this.toError("Missing glasses addresses or firmware; start over.", () => this.beginPrompt());
|
||||
return;
|
||||
@@ -537,10 +551,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
}
|
||||
this.disposePrompt();
|
||||
this.disposeFlasher();
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/main-page",
|
||||
clearHistory: true,
|
||||
});
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
|
||||
private leave(): void {
|
||||
@@ -551,6 +562,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
frame.goBack();
|
||||
return;
|
||||
}
|
||||
if (!this.fromOnboarding) { finishOnboardingNavigation(); return; }
|
||||
frame?.navigate({
|
||||
moduleName: this.fromOnboarding ? "phone-ui/onboarding-page" : "phone-ui/main-page",
|
||||
clearHistory: true,
|
||||
@@ -581,6 +593,11 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
this.log = this._log ? `${this._log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposed = true; ++this.promptGeneration;
|
||||
this.discovery.stopScan(); this.disposePrompt(); this.disposeFlasher();
|
||||
}
|
||||
|
||||
private disposePrompt(): void {
|
||||
for (const unsubscribe of this.promptUnsubscribers) {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Frame } from '@nativescript/core'
|
||||
|
||||
/** Return to the existing iOS controller after a devices/firmware detour. */
|
||||
export function finishOnboardingNavigation(): void {
|
||||
const frame = Frame.topmost()
|
||||
const main = global.isIOS && frame?.backStack.find(entry => entry.entry.moduleName === 'phone-ui/main-page')
|
||||
if (main) frame.goBack(main)
|
||||
else frame?.navigate({ moduleName: 'phone-ui/main-page', clearHistory: true })
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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-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'));
|
||||
global.registerModule('phone-ui/pairing-page.xml', () => require('./pairing-page.xml'));
|
||||
global.registerModule('phone-ui/config-page', () => require('./config-page'));
|
||||
global.registerModule('phone-ui/config-page.xml', () => require('./config-page.xml'));
|
||||
global.registerModule('phone-ui/permissions-page', () => require('./permissions-page'));
|
||||
global.registerModule('phone-ui/permissions-page.xml', () => require('./permissions-page.xml'));
|
||||
global.registerModule('phone-ui/onboarding-firmware-check-page', () => require('./onboarding-firmware-check-page'));
|
||||
global.registerModule('phone-ui/onboarding-firmware-check-page.xml', () => require('./onboarding-firmware-check-page.xml'));
|
||||
global.registerModule('phone-ui/onboarding-flash-page', () => require('./onboarding-flash-page'));
|
||||
global.registerModule('phone-ui/onboarding-flash-page.xml', () => require('./onboarding-flash-page.xml'));
|
||||
global.registerModule('phone-ui/document-page', () => require('./document-page'));
|
||||
global.registerModule('phone-ui/document-page.xml', () => require('./document-page.xml'));
|
||||
global.registerModule('phone-ui/main-page', () => require('./main-page.ios'));
|
||||
@@ -7,7 +7,7 @@
|
||||
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."
|
||||
class="body-text m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="If you use the Even Realities app, go to Home, select your glasses, open the Connection submenu, and press Disconnect (or disable the Even app's "nearby devices" permission)."
|
||||
text="{{ evenAppInstructions }}"
|
||||
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>
|
||||
|
||||
@@ -3,8 +3,13 @@ import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
import { openEvenAppSettings } from "../native/even-app-conflict";
|
||||
|
||||
export class OnboardingUnpairViewModel extends Observable {
|
||||
get settingsButtonVisibility(): "visible" | "collapsed" {
|
||||
return global.isAndroid ? "visible" : "collapsed";
|
||||
get settingsButtonVisibility(): "visible" | "collapse" {
|
||||
return global.isAndroid ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get evenAppInstructions(): string {
|
||||
return "If you use the Even Realities app, go to Home, select your glasses, open the Connection submenu, and press Disconnect" +
|
||||
(global.isIOS ? "." : " (or disable the Even app's \"nearby devices\" permission).");
|
||||
}
|
||||
|
||||
onOpenEvenAppSettingsTap(): void {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
|
||||
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
|
||||
@@ -99,10 +100,7 @@ export class OnboardingViewModel extends Observable {
|
||||
// Step 3 secondary: skip flashing, use the on-phone preview only.
|
||||
setPreviewOnlyMode(true);
|
||||
setOnboardingCompleted(true);
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/main-page",
|
||||
clearHistory: true,
|
||||
});
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { finishOnboardingNavigation } from "./onboarding-navigation";
|
||||
import { Application, EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
|
||||
import { ensureBlePermissions } from "../g2/android-permissions";
|
||||
import { ensureBlePermissions } from "../native/ble-permissions";
|
||||
import { loadDeviceAddresses, loadPairedGlassesIdentity, saveDeviceAddresses, savePairedGlassesIdentity } from "../g2/device-addresses";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
import {
|
||||
@@ -82,6 +83,7 @@ export class PairingViewModel extends Observable {
|
||||
// --- lifecycle -------------------------------------------------------------
|
||||
|
||||
private resumeScanAfterSuspend = false;
|
||||
private scanGeneration = 0;
|
||||
|
||||
private readonly onAppSuspend = (): void => {
|
||||
if (this._scanning) {
|
||||
@@ -106,12 +108,19 @@ export class PairingViewModel extends Observable {
|
||||
|
||||
async start(): Promise<void> {
|
||||
if (this._scanning) return;
|
||||
if (!global.isAndroid) {
|
||||
// A saved selection can be revisited from the firmware check page.
|
||||
Application.off(Application.suspendEvent, this.onAppSuspend);
|
||||
Application.off(Application.resumeEvent, this.onAppResume);
|
||||
Application.on(Application.suspendEvent, this.onAppSuspend);
|
||||
Application.on(Application.resumeEvent, this.onAppResume);
|
||||
const generation = ++this.scanGeneration;
|
||||
if (!global.isAndroid && !global.isIOS) {
|
||||
this.status = "Pairing is only available on Android.";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await ensureBlePermissions();
|
||||
if (generation !== this.scanGeneration) return;
|
||||
} catch (error) {
|
||||
this.status = this.formatError(error);
|
||||
return;
|
||||
@@ -150,6 +159,7 @@ export class PairingViewModel extends Observable {
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
++this.scanGeneration;
|
||||
if (this.refreshTimer) {
|
||||
clearInterval(this.refreshTimer);
|
||||
this.refreshTimer = null;
|
||||
@@ -337,7 +347,7 @@ export class PairingViewModel extends Observable {
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" });
|
||||
return;
|
||||
}
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/main-page", clearHistory: true });
|
||||
finishOnboardingNavigation();
|
||||
}
|
||||
|
||||
onSecondaryTap(): void {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { iosBluetooth } from "../native/ios-bluetooth";
|
||||
import { Application, Dialogs, EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
|
||||
import {
|
||||
@@ -30,7 +31,7 @@ type PermissionDefinition = {
|
||||
* their request() opens a system screen, so the granted state can only be
|
||||
* re-checked when the app resumes (the page refreshes on Application.resume).
|
||||
*/
|
||||
const PERMISSIONS: PermissionDefinition[] = [
|
||||
const ANDROID_PERMISSIONS: PermissionDefinition[] = [
|
||||
{
|
||||
id: "nearby-devices",
|
||||
title: "Nearby Devices",
|
||||
@@ -91,6 +92,13 @@ const 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,
|
||||
request: () => iosBluetooth().ensureReady(),
|
||||
}] : ANDROID_PERMISSIONS;
|
||||
|
||||
/** One Repeater card: the permission's copy plus the display-only fields the XML binds. */
|
||||
export type PermissionCardItem = {
|
||||
id: string;
|
||||
@@ -144,8 +152,9 @@ export class PermissionsViewModel extends Observable {
|
||||
}
|
||||
|
||||
get instructions(): string {
|
||||
if (global.isIOS) return "Faceclaw uses Bluetooth to communicate with your smart glasses. Tap the card to allow access; a checkmark means Bluetooth is ready.";
|
||||
return this.onboarding
|
||||
? "Faceclaw uses these Android permissions. Tap a card to grant one; a checkmark means it is already granted. " +
|
||||
? `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."
|
||||
: "Tap a card to grant a permission; a checkmark means it is already granted.";
|
||||
}
|
||||
@@ -216,7 +225,8 @@ export class PermissionsViewModel extends Observable {
|
||||
this.requesting = true;
|
||||
try {
|
||||
await definition.request();
|
||||
} catch {
|
||||
} catch (error) {
|
||||
if (global.isIOS) await Dialogs.alert({ title: "Bluetooth Unavailable", message: String((error as Error).message ?? error), okButtonText: "OK" });
|
||||
// A denial simply leaves the card unchecked; the user can tap again.
|
||||
} finally {
|
||||
this.requesting = false;
|
||||
|
||||
Reference in new issue
Block a user