Merge upstream main preserving custom feature integrations

This commit is contained in:
MasterControl committed 2026-11-10 17:08:15 +00:00
commit 6150a1ac57
228 files changed
+16844 -1388

No files matched your search

+14 -1
View File
@@ -1,3 +1,4 @@
import type { GlassesType } from "../ui/dashboard-settings";
import type { RingInput } from "../g2/ring-input";
import { File, knownFolders, path, type ImageSource } from "@nativescript/core";
import { REQUIRED_FACECLAW_FIRMWARE_VERSION, type FirmwareInfo } from "../g2/firmware-compat";
@@ -248,7 +249,10 @@ export class FaceclawCommunicatorBridge {
return FaceclawCommunicatorBridge.active;
}
constructor(addresses: { right: string; left: string; ring?: string; ringRole?: string }) {
constructor(addresses: { right: string; left: string; ring?: string; ringRole?: string; glassesType?: GlassesType }) {
if (addresses.glassesType === "rayneo-io") {
throw new Error("RayNeo iO glasses are not supported on iOS yet.");
}
this.communicator = FaceclawKitIosGlassesSession.alloc().initWithRightAddressLeftAddressRingAddress(
String(addresses.right ?? "").toUpperCase(),
String(addresses.left ?? "").toUpperCase(),
@@ -256,6 +260,7 @@ export class FaceclawCommunicatorBridge {
);
// The shared session halts on any other firmware ("incompatible-firmware").
this.communicator.setRequiredFirmwareRevisionRevision(REQUIRED_FACECLAW_FIRMWARE_VERSION);
if (addresses.glassesType === "g1") this.communicator.useG1();
// Guarded: an older framework build may not export it yet.
if (addresses.ringRole && typeof this.communicator.setDirectRingRoleRole === "function") {
this.communicator.setDirectRingRoleRole(addresses.ringRole);
@@ -696,6 +701,9 @@ export class FaceclawCommunicatorBridge {
return this.enqueueNativeCall(() => Boolean(this.communicator.setFaceclawWakeLeaseEnabledEnabled(Boolean(enabled))));
}
/** The RayNeo iO's wake word; iOS doesn't drive an iO, so nothing to do. */
async setVoiceWakeEnabled(_enabled: boolean): Promise<void> {}
async awaitEvenHubSessionReady(timeoutMs: number): Promise<boolean> {
return this.enqueueNativeCall(() => Boolean(this.communicator.awaitEvenHubSessionReadyTimeoutMs(Math.round(nonNegativeNumber(timeoutMs)))));
}
@@ -849,6 +857,11 @@ export class FaceclawCommunicatorBridge {
return Boolean(this.communicator.isAncsAuthorized());
}
/** False on a G1 whose firmware has no relay; a G2's depends on its firmware revision. */
ancsRelayAvailable(): boolean {
return Boolean(this.communicator.ancsRelayAvailable());
}
onAncsAuthorization(listener: (authorized: boolean) => void): () => void {
this.ancsAuthorizationListeners.add(listener);
return () => this.ancsAuthorizationListeners.delete(listener);
+14 -1
View File
@@ -1,3 +1,4 @@
import type { GlassesType } from "../ui/dashboard-settings";
import type { RingInput } from "../g2/ring-input";
import { ImageSource, Utils } from "@nativescript/core";
import * as frameTimings from "./frame-timings";
@@ -169,7 +170,7 @@ export class FaceclawCommunicatorBridge {
private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>();
private readonly previewAnimationListeners = new Set<() => void>();
constructor(addresses: { right: string; left: string; ring?: string; ringRole?: string }) {
constructor(addresses: { right: string; left: string; ring?: string; ringRole?: string; glassesType?: GlassesType }) {
const context = Utils.android.getApplicationContext();
if (!context) throw new Error("Android application context unavailable");
@@ -181,6 +182,10 @@ export class FaceclawCommunicatorBridge {
);
// The shared session halts on any other firmware ("incompatible-firmware").
this.communicator.setRequiredFirmwareRevision(REQUIRED_FACECLAW_FIRMWARE_VERSION);
// RayNeo iO: one link (its address in both arm slots), its own handshake and page lease.
if (addresses.glassesType === "rayneo-io") this.communicator.useRayNeoIo();
// Even G1 on g1v0: two links, like a G2's arms, but frames composed here and sent to each arm.
if (addresses.glassesType === "g1") this.communicator.useG1();
// Which R1 role the direct ring link claims; only matters with a ring address.
if (addresses.ringRole) this.communicator.setDirectRingRole(addresses.ringRole);
this.listenerProxy = new com.faceclaw.app.FaceclawBleCommunicatorListener({
@@ -761,6 +766,14 @@ export class FaceclawCommunicatorBridge {
);
}
/**
* Whether the glasses' own wake word reaches Faceclaw: on a RayNeo iO, its
* "Hey RayNeo" switch (G2 glasses use the wake lease above instead).
*/
async setVoiceWakeEnabled(enabled: boolean): Promise<void> {
await this.enqueueJavaCall(() => this.communicator.setVoiceWakeEnabled(enabled));
}
/**
* Resolve only once the recreated layout and retained frame
* are visible. CFW's deferred-dashboard READY is emitted from this barrier.
+80
View File
@@ -0,0 +1,80 @@
import { Application } from '@nativescript/core'
import { parseG1FlashResult, type G1FlashResult } from '../g1/flash-plan'
import { iosBluetooth } from './ios-bluetooth'
import { kotlinListener } from './kotlin-listener.ios'
import type { G1FlasherOptions } from './g1-flasher'
export type { G1FlashMode, G1FlasherOptions } from './g1-flasher'
declare const FaceclawKitIosG1Flasher: any, FaceclawKitFaceclawFirmwareFlasherListener: any
/** CoreBluetooth has no way to remove a pairing; iOS Settings does it. */
export function forgetG1Pairing(_address: string): boolean {
return false
}
/**
* iOS twin of the Android G1Flasher: the shared Kotlin G1ArmFlashFlow over a CoreBluetooth central. As with the G2's
* flasher, the phone must stay in the foreground with the screen awake, and addresses are mapped to peripheral
* identifiers first.
*/
export class G1Flasher {
private flasher: any = null
private listenerProxy: object | null = null
private logListener: ((line: string) => void) | null = null
private progressListener: ((bytesSent: number, bytesTotal: number) => void) | null = null
private stateListener: ((state: string) => void) | null = null
private previousIdle = false
private cancelled = false
private foregroundError = ''
constructor(private readonly options: G1FlasherOptions) {}
onLog(listener: (line: string) => void): void { this.logListener = listener }
onProgress(listener: (bytesSent: number, bytesTotal: number) => void): void { this.progressListener = listener }
onState(listener: (state: string) => void): void { this.stateListener = listener }
private readonly backgrounded = () => {
this.foregroundError = 'The install stopped because Faceclaw left the foreground. Return to Faceclaw and try again.'
this.cancel()
}
run(): Promise<G1FlashResult> {
this.previousIdle = UIApplication.sharedApplication.idleTimerDisabled
UIApplication.sharedApplication.idleTimerDisabled = true
Application.on(Application.suspendEvent, this.backgrounded)
const restore = () => {
Application.off(Application.suspendEvent, this.backgrounded)
UIApplication.sharedApplication.idleTimerDisabled = this.previousIdle
}
return new Promise<G1FlashResult>((resolve, reject) => {
const identifier = iosBluetooth().peripheralIdentifier(this.options.address, this.options.side)
if (!identifier) throw new Error(`Could not find the ${this.options.side} arm. Keep the glasses in the case with the lid open.`)
this.flasher = FaceclawKitIosG1Flasher.alloc().initWithAddressSideFirmwarePathNetCorePathModeConnectWindowMs(
identifier, this.options.side, this.options.firmwarePath, this.options.netCorePath ?? '', this.options.mode, this.options.connectWindowMs)
this.listenerProxy = kotlinListener(FaceclawKitFaceclawFirmwareFlasherListener, {
onLogLine: (line: string) => this.logListener?.(String(line ?? '')),
onProgressLensComponentIndexComponentCountBlockIndexBlockCountBytesSentBytesTotal: (
_lens: string, _componentIndex: number, _componentCount: number, _blockIndex: number, _blockCount: number, sent: number, total: number,
) => this.progressListener?.(Number(sent), Number(total)),
onStateStateDetail: (state: string) => this.stateListener?.(String(state)),
onCompleteSuccessDetail: (success: boolean, detail: string) => {
if (success) resolve(parseG1FlashResult(String(detail ?? '')))
else reject(new Error(this.foregroundError || String(detail ?? '') || 'The install failed.'))
},
})
this.flasher.setListenerListener(this.listenerProxy)
if (this.cancelled) this.flasher.cancel()
this.flasher.start()
}).finally(restore)
}
cancel(): void {
this.cancelled = true
try { this.flasher?.cancel() } catch { /* ignore */ }
}
close(): void {
this.cancel()
try { this.flasher?.close() } catch { /* ignore */ }
}
}
+85
View File
@@ -0,0 +1,85 @@
import { Utils } from "@nativescript/core";
import { parseG1FlashResult, type G1FlashResult, type G1Side } from "../g1/flash-plan";
declare const com: any;
/** "restore": Even's firmware back on an arm running g1v0, both of its images. */
export type G1FlashMode = "stock" | "update" | "probe" | "restore";
export type G1FlasherOptions = {
address: string;
side: G1Side;
/** The application core's image. */
firmwarePath: string;
/** A restore's network-core image. */
netCorePath?: string;
mode: G1FlashMode;
/** How long to keep trying to reach the arm and pair with it. */
connectWindowMs: number;
};
/** Removes the phone's pairing with an address, which the glasses no longer use or no longer share. False: this phone can't. */
export function forgetG1Pairing(address: string): boolean {
const context = Utils.android.getApplicationContext();
if (!context) return false;
com.faceclaw.app.FaceclawG1Flasher.forgetPairing(context, address);
return true;
}
/** TS wrapper around FaceclawG1Flasher: one arm's install, its restore to Even's firmware, or a question about what it runs. */
export class G1Flasher {
private readonly flasher: any;
private readonly listenerProxy: any;
private logListener: ((line: string) => void) | null = null;
private progressListener: ((bytesSent: number, bytesTotal: number) => void) | null = null;
private stateListener: ((state: string) => void) | null = null;
private completion: ((success: boolean, detail: string) => void) | null = null;
constructor(options: G1FlasherOptions) {
const context = Utils.android.getApplicationContext();
if (!context) throw new Error("Android application context unavailable");
this.flasher = new com.faceclaw.app.FaceclawG1Flasher(
context, options.address, options.side, options.firmwarePath, options.netCorePath ?? "", options.mode, options.connectWindowMs,
);
this.listenerProxy = new com.faceclaw.app.FaceclawFirmwareFlasherListener({
onLog: (line: string) => this.logListener?.(String(line)),
onProgress: (_lens: string, _component: number, _components: number, _block: number, _blocks: number, sent: number, total: number) =>
this.progressListener?.(Number(sent), Number(total)),
onState: (state: string) => this.stateListener?.(String(state)),
onComplete: (success: boolean, detail: string) => this.completion?.(Boolean(success), String(detail ?? "")),
});
this.flasher.setListener(this.listenerProxy);
}
onLog(listener: (line: string) => void): void {
this.logListener = listener;
}
onProgress(listener: (bytesSent: number, bytesTotal: number) => void): void {
this.progressListener = listener;
}
onState(listener: (state: string) => void): void {
this.stateListener = listener;
}
run(): Promise<G1FlashResult> {
return new Promise((resolve, reject) => {
this.completion = (success, detail) => {
this.completion = null;
if (success) resolve(parseG1FlashResult(detail));
else reject(new Error(detail || "The install failed."));
};
this.flasher.start();
});
}
cancel(): void {
this.flasher.cancel();
}
close(): void {
this.flasher.close();
}
}
+9
View File
@@ -0,0 +1,9 @@
import { toData, fromData } from './kotlin-data'
import { rgbaFromPacket } from './image-rgba'
declare const FaceclawGraphics: any
/** Decoded RGBA of encoded image bytes, or null when undecodable (transparent pixels come out black). */
export function decodeImageRgba(bytes: Uint8Array): { width: number; height: number; rgba: Uint8Array } | null {
const data = FaceclawGraphics.rgbaPacketFromImageData(toData(bytes))
return data ? rgbaFromPacket(fromData(data)) : null
}
+22
View File
@@ -0,0 +1,22 @@
import { toUint8Array } from '../util/array-util'
import { copyToJavaByteBuffer } from './java-direct-buffer'
declare const com: any
/** Decoded RGBA (not premultiplied) of encoded image bytes, or null when undecodable. */
export function decodeImageRgba(bytes: Uint8Array): { width: number; height: number; rgba: Uint8Array } | null {
try {
return rgbaFromPacket(toUint8Array(com.faceclaw.app.ImageFileLoader.decodeRgbaFromBytes(copyToJavaByteBuffer(bytes))))
} catch (error) {
console.warn(`decodeImageRgba failed: ${error}`)
return null
}
}
/** [widthLo, widthHi, heightLo, heightHi, RGBA...] as an image, or null when short. */
export function rgbaFromPacket(packet: Uint8Array): { width: number; height: number; rgba: Uint8Array } | null {
if (packet.length < 4) return null
const width = packet[0]! | (packet[1]! << 8)
const height = packet[2]! | (packet[3]! << 8)
if (width <= 0 || height <= 0 || packet.length < 4 + width * height * 4) return null
return { width, height, rgba: packet.slice(4, 4 + width * height * 4) }
}
+19 -4
View File
@@ -7,6 +7,8 @@ declare const FaceclawKitIosBleCentral: any, FaceclawKitIosProtocolPlatform: any
/** CBManagerState raw values reported by the Kotlin central. */
export const BLE_STATE_UNSUPPORTED = 2, BLE_STATE_UNAUTHORIZED = 3, BLE_STATE_POWERED_OFF = 4, BLE_STATE_POWERED_ON = 5
/** CBManagerAuthorization.allowedAlways. */
const BLE_AUTHORIZATION_ALLOWED = 3
export type BluetoothEvent =
| { kind: 'state'; state: number; authorization: number }
@@ -50,17 +52,21 @@ export class IosBluetooth {
}
},
})
this.native.setScanListenerListener(this.scanListener)
}
onEvent(listener: (event: BluetoothEvent) => void): () => void {
this.listeners.add(listener); return () => { this.listeners.delete(listener) }
}
private emit(event: BluetoothEvent): void { for (const listener of [...this.listeners]) listener(event) }
/**
* Whether the user has allowed Bluetooth. Unlike `state` this is accurate before the
* central exists, and reading it never shows the permission prompt.
*/
isAuthorized(): boolean { return Number(this.native.authorization()) === BLE_AUTHORIZATION_ALLOWED }
/** Creates the central (first use shows the Bluetooth permission prompt) without blocking the JS thread. */
private ensureCentral(): void {
// A zero timeout returns immediately after creating the central; the state arrives
// through the scan listener on the main queue.
this.native.waitForPoweredOnTimeoutMs(0)
// Registering the listener creates the central, or has an existing one re-report its
// state; the state arrives through the listener on the main queue.
this.native.setScanListenerListener(this.scanListener)
}
ensureReady(): Promise<void> {
if (this.state === BLE_STATE_POWERED_ON) return Promise.resolve()
@@ -129,6 +135,15 @@ export class IosBluetooth {
})
return result
}
/** The peripheral last heard at this address, if it was on this side. */
peripheralIdentifier(address: string, role: string): string | null {
try {
const saved = JSON.parse(ApplicationSettings.getString(`ios.ble.peripheral.${address}`, '{}'))
return saved.role === role && typeof saved.identifier === 'string' ? saved.identifier : null
} catch {
return null
}
}
forget(address: string): void { ApplicationSettings.remove(`ios.ble.peripheral.${address}`); this.devices.delete(address) }
}
let instance: IosBluetooth | null = null