Merge pull request 'build: intégrer upstream et la lisibilité des notifications/menus' (#15) from MasterControl/faceclaw:sync/upstream-main-all-features into build/all-features

Reviewed-on: https://git.undefined-dev.fr/Blendman974/faceclaw/pulls/15
This commit is contained in:
Blendman974 committed 2026-11-10 17:36:23 +00:00
commit 35b02aef52
234 files changed
+17438 -1417

No files matched your search

+10
View File
@@ -13,6 +13,16 @@ and others who contributed to documenting the G2's bluetooth protocol and firmwa
G2 microphone LC3 decoding uses Google's liblc3: https://github.com/google/liblc3
Even G1 support builds on ScouterKit (MIT License), by the ScouterKit authors:
https://github.com/mafik/scouter_kit. The firmware Faceclaw installs on a G1 is a
modified build of its g1v0, using the Zephyr RTOS and Nordic's nRF Connect SDK; the
parts of it that are Even Realities' own are downloaded from Even, not shipped here.
RayNeo iO support builds on the Glassly SDK and custom firmware by Tetramo, Inc.
and Mentra Labs, Inc. (MIT License): https://github.com/tetramo-labs/glassly and
https://github.com/tetramo-labs/glassly-rayneo-cfw. The iO wire codecs in
native/kotlin/shared/.../rayneo/RayNeoIoProtocol.kt follow their protocol work.
iPhone notification icons are Pebble's notification and timeline icons, from
https://github.com/pebble-dev/iconography: the original Pebble Technology icons
and Rebble community additions. They are licensed under the Apache License 2.0;
+3
View File
@@ -19,6 +19,9 @@ dependencies {
// app's captions (translation models download on demand, per language).
implementation 'com.google.mlkit:language-id:17.0.6'
implementation 'com.google.mlkit:translate:17.0.3'
// Pure-Java Opus decoder for the RayNeo iO's microphone (16 kHz mono Opus over
// BLE); the same one Glassly uses. See AndroidSpeechEngines.OpusDecoderAdapter.
implementation 'io.github.jaredmdobson:concentus:1.0.1'
}
def faceclawSherpaOnnxVersion = "1.13.0"
@@ -46,6 +46,15 @@ class AndroidSessionLink(private val bleManager: FaceclawBleManager) : SessionLi
override fun isBonded(address: String): Boolean = bleManager.isBonded(address)
override fun requestBond(address: String) = bleManager.requestBond(address)
override fun removeBond(address: String): Boolean = bleManager.removeBond(address)
override fun hasCharacteristic(address: String, characteristicUuid: String): Boolean =
bleManager.hasCharacteristic(address, characteristicUuid)
override fun refreshServices(address: String, timeoutMs: Int): Boolean = bleManager.refreshServices(address, timeoutMs)
override fun prepareBenchmarkLink(address: String, mode: Int) = bleManager.prepareBenchmarkLink(address, mode)
override fun recordDisplayFrameSent() = FaceclawBleManager.recordDisplayFrameSent()
@@ -97,6 +97,44 @@ internal object AndroidSpeechEngines {
override fun close() = decoder.close()
}
/**
* The RayNeo iO's microphone: one 16 kHz mono Opus packet per BLE message (its remote
* audio stream, GlassesSessionIo), decoded with Concentus. No G2 DSP metadata; packets
* carry no counter, so "missing" stays 0 and a lost one is just a gap.
*/
class OpusDecoderAdapter : AudioPacketDecoder {
private val decoder = io.github.jaredmdobson.OpusDecoder(RayNeoIoProtocol.VOICE_SAMPLE_RATE, 1)
private var packets = 0L
private var errors = 0L
override fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int {
if (packet == null || packet.isEmpty() || pcmOut == null) return 0
return try {
val count = decoder.decode(packet, 0, packet.size, pcmOut, 0, pcmOut.size, false)
packets++
count
} catch (e: io.github.jaredmdobson.OpusException) {
errors++
if (errors == 1L || errors % 100 == 0L) {
android.util.Log.w("FaceclawVoice", "Opus decode error ($errors so far): ${e.message}")
}
0
}
}
/** 120 ms, Opus's longest frame. */
override val maxSamplesPerPacket: Int get() = RayNeoIoProtocol.VOICE_SAMPLE_RATE * 120 / 1000
override val hasFrameMeta: Boolean get() = false
override val lastAngleDegrees: Int get() = 0
override val lastSsr: Int get() = 0
override val realPackets: Long get() = packets
override val duplicatePackets: Long get() = 0
override val missingPackets: Long get() = 0
override val decodeErrors: Long get() = errors
override fun close() = decoder.resetState()
}
/**
* Open the phone's own microphone at the pipeline's native format (16 kHz
* mono PCM16), or null when it cannot start — the permission is missing
@@ -48,6 +48,17 @@ class AndroidStockLink(context: Context) : StockLink, FaceclawBleListener {
else -> BondState.UNKNOWN
}
override fun negotiatedMtu(address: String): Int = bleManager.getNegotiatedMtu(address)
override fun requestBond(address: String) = bleManager.requestBond(address)
override fun removeBond(address: String): Boolean = bleManager.removeBond(address)
override fun hasCharacteristic(address: String, characteristicUuid: String): Boolean =
bleManager.hasCharacteristic(address, characteristicUuid)
override fun refreshServices(address: String, timeoutMs: Int): Boolean = bleManager.refreshServices(address, timeoutMs)
override fun disconnect(address: String) = bleManager.disconnect(address)
override fun close() = bleManager.close()
@@ -189,6 +189,28 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun setRequiredFirmwareRevision(revision: Int) = core.setRequiredFirmwareRevision(revision)
/**
* Drive a RayNeo iO (constructed with its address as both arms and no ring). The phone's
* protocol identity is derived from ANDROID_ID so it survives reinstalls: the glasses bind
* to the first identity that authenticates and refuse others until put in pairing mode.
*/
fun useRayNeoIo() {
val androidId = try {
android.provider.Settings.Secure.getString(appContext.contentResolver, android.provider.Settings.Secure.ANDROID_ID)
} catch (_: Exception) {
null
}
val seed = "faceclaw-rayneo-phone-id:" + (androidId ?: android.os.Build.FINGERPRINT)
val phoneId = java.security.MessageDigest.getInstance("SHA-256").digest(seed.toByteArray(Charsets.UTF_8)).copyOf(6)
val model = android.os.Build.MODEL ?: "Android"
core.useRayNeoIo(phoneId, model, android.os.Build.MANUFACTURER ?: "Android", model)
}
fun isRayNeoIo(): Boolean = core.isRayNeoIo()
/** Drive an Even G1 on g1v0 (two arms, as a G2 pair's addresses). */
fun useG1() = core.useG1()
fun start() {
if (core.start()) {
activeInstance = this
@@ -235,6 +257,9 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean = core.setFaceclawWakeLeaseEnabled(enabled)
/** See [GlassesSessionCore.setVoiceWakeEnabled]. */
fun setVoiceWakeEnabled(enabled: Boolean) = core.setVoiceWakeEnabled(enabled)
fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean = core.awaitEvenHubSessionReady(timeoutMs)
fun setImuReportEnabled(enable: Boolean, reportFrq: Int) = core.setImuReportEnabled(enable, reportFrq)
@@ -27,6 +27,11 @@ import java.util.concurrent.atomic.AtomicLong
class FaceclawBleManager(context: Context) {
companion object {
private const val TAG = "FaceclawBle"
/** Not public API, but long stable, and the only way short of sending the user to Settings. */
fun removeBond(device: BluetoothDevice): Boolean =
device.bondState == BluetoothDevice.BOND_NONE || device.javaClass.getMethod("removeBond").invoke(device) == true
private val WRITE_RETRY_DELAYS_MS = intArrayOf(1, 1, 1, 2, 4, 8, 12, 20, 35, 100, 200)
// Gap after each LE 2M PHY request before checking whether it landed and asking
@@ -160,6 +165,36 @@ class FaceclawBleManager(context: Context) {
}
}
/**
* Remove this phone's half of a pairing the other side no longer has. False when the platform refused.
*/
fun removeBond(address: String?): Boolean {
if (address == null || address.trim().isEmpty()) {
return false
}
return try {
removeBond(bluetoothAdapter.getRemoteDevice(address))
} catch (t: Throwable) {
Log.w(TAG, "removeBond failed: $address", t)
false
}
}
/** Start bonding, without waiting: the OS may ask the user, and [isBonded] tells when it is done. */
fun requestBond(address: String?) {
if (address == null || address.trim().isEmpty()) {
return
}
try {
val device = bluetoothAdapter.getRemoteDevice(address)
if (device.bondState == BluetoothDevice.BOND_NONE) {
Log.i(TAG, "requestBond " + address + ": " + device.createBond())
}
} catch (t: Throwable) {
Log.w(TAG, "requestBond failed: " + address, t)
}
}
/**
* Android's bond state for this address (BluetoothDevice.BOND_NONE /
* BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined.
@@ -364,6 +399,31 @@ class FaceclawBleManager(context: Context) {
return status == BluetoothGatt.GATT_SUCCESS
}
/** After discovery: whether the service table has this characteristic. */
fun hasCharacteristic(address: String, characteristicUuid: String): Boolean {
synchronized(bluetoothApiLock) {
val gatt = links[address]?.gatt ?: return false
val target = UUID.fromString(characteristicUuid)
return gatt.services.any { it.getCharacteristic(target) != null }
}
}
/**
* Forget the service table Android remembers for a bonded device and read it again. A G1 arm keeps its address across an
* install that changes its services, and a cached table would make new firmware look like the old one.
*/
fun refreshServices(address: String, timeoutMs: Int): Boolean {
synchronized(bluetoothApiLock) {
val gatt = links[address]?.gatt ?: return false
try {
gatt.javaClass.getMethod("refresh").invoke(gatt)
} catch (t: Throwable) {
Log.w(TAG, "refresh failed: $address", t)
}
}
return discoverServices(address, timeoutMs)
}
fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean {
synchronized(bluetoothApiLock) {
val gatt = requireGatt(address)
@@ -129,13 +129,21 @@ class FaceclawDeviceDiscovery(context: Context) {
&& manufacturerData[0] == 0x45.toByte() && manufacturerData[1] == 0x52.toByte()) {
return true
}
// RayNeo iO: manufacturer company 0x5716 ([07][MAC]...) outside pairing mode;
// in pairing mode only the "RayNeo iO-xxxx" name identifies it.
if (manufacturerData != null && manufacturerData.size >= 2
&& manufacturerData[0] == 0x16.toByte() && manufacturerData[1] == 0x57.toByte()) {
return true
}
if (name == null) {
return false
}
val upper = name.uppercase()
// A bare "R1" substring also matches unrelated hardware ("Oppo Enco
// R1"), and TS only classifies rings from the stock name prefix.
return upper.contains("G2") || upper.startsWith("EVEN R1")
// Even G1: its stock name, or g1v0's G1CFW_L_XXXXXX (before 0.5.66: G1v0_L, G1v0S_R).
return upper.contains("G2") || upper.startsWith("EVEN R1") || upper.startsWith("RAYNEO") ||
upper.startsWith("EVEN G1") || upper.startsWith("G1CFW_") || upper.startsWith("G1V0")
}
private fun buildJson(
@@ -0,0 +1,106 @@
package com.faceclaw.app
import android.content.Context
import android.os.Handler
import android.os.Looper
/**
* Android host for the shared [G1ArmFlashFlow]: owns the GATT link and the worker thread for one G1 arm's install, its
* restore to Even's firmware, or a question about what it runs, and delivers listener callbacks on the main thread. For app/native/g1-flasher.ts.
*/
class FaceclawG1Flasher(
context: Context,
address: String?,
side: String?,
firmwarePath: String?,
netCorePath: String?,
mode: String?,
connectWindowMs: Int,
) {
private val link = AndroidStockLink(context.applicationContext)
private val mainHandler = Handler(Looper.getMainLooper())
private val lock = Any()
@Volatile
private var listener: FaceclawFirmwareFlasherListener? = null
@Volatile
private var worker: Thread? = null
private val flow =
G1ArmFlashFlow(
link,
address ?: "",
side ?: "",
firmwarePath ?: "",
netCorePath ?: "",
G1ArmFlashFlow.mode(mode ?: ""),
connectWindowMs,
object : FaceclawFirmwareFlasherListener {
override fun onLog(line: String?) {
android.util.Log.i(G1ArmFlashFlow.TAG, line ?: "")
post { it.onLog(line) }
}
override fun onProgress(
lens: String?,
componentIndex: Int,
componentCount: Int,
blockIndex: Int,
blockCount: Int,
bytesSent: Long,
bytesTotal: Long,
) = post { it.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal) }
override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") }
override fun onComplete(success: Boolean, detail: String?) = post { it.onComplete(success, detail ?: "") }
},
)
fun setListener(listener: FaceclawFirmwareFlasherListener?) {
this.listener = listener
}
fun start() {
synchronized(lock) {
if (worker != null) {
return
}
val w = Thread({ flow.run() }, "faceclaw-g1-flash")
worker = w
w.start()
}
}
fun cancel() {
flow.cancel()
}
fun close() {
cancel()
try {
link.close()
} catch (ignored: Exception) {
}
}
companion object {
/** The phone's pairing with an address these glasses no longer use. */
@JvmStatic
fun forgetPairing(context: Context, address: String?) {
if (address == null) return
val manager = context.applicationContext.getSystemService(Context.BLUETOOTH_SERVICE) as android.bluetooth.BluetoothManager
FaceclawBleManager.removeBond(manager.adapter.getRemoteDevice(address))
}
}
private fun post(action: (FaceclawFirmwareFlasherListener) -> Unit) {
mainHandler.post {
val current = listener
if (current != null) {
action(current)
}
}
}
}
@@ -104,7 +104,9 @@ class FaceclawVoiceController(context: Context) {
}
}
override fun createPacketDecoder(): AudioPacketDecoder = AndroidSpeechEngines.Lc3DecoderAdapter()
override fun createPacketDecoder(): AudioPacketDecoder =
if (communicator?.isRayNeoIo() == true) AndroidSpeechEngines.OpusDecoderAdapter()
else AndroidSpeechEngines.Lc3DecoderAdapter()
override fun openPhoneMic(): PcmAudioSource? = AndroidSpeechEngines.openPhoneMic(PHONE_MIC_CHUNK_SAMPLES)
@@ -167,6 +167,7 @@ class FontFileRenderer private constructor() {
* [width u16][height u16]
* [width*height coverage bytes, gamma-mapped]
* An ink-free glyph (space) has width = height = 0 but a valid advance.
* A color glyph (emoji) carries its ColorGlyphArt shade as its coverage.
* Empty array when the font cannot be loaded or the render fails.
*/
@JvmStatic
@@ -196,11 +197,16 @@ class FontFileRenderer private constructor() {
}
val penX = pad - bounds.left
val baselineY = pad - bounds.top
val bitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ALPHA_8)
// Drawn in color: an emoji the system fallback supplies from a color font
// would keep only its silhouette in an alpha-only bitmap. ColorGlyphArt shades
// color glyphs and passes white ones through as their alpha.
val bitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawText(text, penX.toFloat(), baselineY.toFloat(), paint)
val pixels = alpha8Pixels(bitmap, bw, bh)
val argb = IntArray(bw * bh)
bitmap.getPixels(argb, 0, bw, 0, 0, bw, bh)
bitmap.recycle()
val pixels = ColorGlyphArt.coverage(argb)
// Trim to the tight ink box; bearing/inkTop become pen- and
// line-relative inside the shared packer.
@@ -108,6 +108,64 @@ class ImageFileLoader private constructor() {
}
}
/** Longest side decodeRgbaFromBytes decodes at; larger images are subsampled. */
private const val MAX_RGBA_SIDE = 4096
/**
* Decode encoded image bytes (JPEG, PNG, WebP, GIF's first frame, BMP)
* to [widthLo, widthHi, heightLo, heightHi, R, G, B, A, ...] at native
* size, not premultiplied, so a transparent pixel keeps its colour;
* empty when undecodable. The EvenHub host converts these to grey the
* way the Even app does (app/apps/evenhub/image-pipeline.ts).
*/
@JvmStatic
fun decodeRgbaFromBytes(buffer: java.nio.ByteBuffer?): ByteArray {
if (buffer == null) return ByteArray(0)
try {
val source = buffer.duplicate()
source.rewind()
val data = ByteArray(source.remaining())
source.get(data)
if (data.isEmpty()) return ByteArray(0)
val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }
BitmapFactory.decodeByteArray(data, 0, data.size, bounds)
if (bounds.outWidth <= 0 || bounds.outHeight <= 0) return ByteArray(0)
var sample = 1
while (maxOf(bounds.outWidth, bounds.outHeight) / sample > MAX_RGBA_SIDE) sample *= 2
val options = BitmapFactory.Options().apply {
inPreferredConfig = Bitmap.Config.ARGB_8888
inPremultiplied = false
inSampleSize = sample
}
val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size, options) ?: return ByteArray(0)
val width = bitmap.width
val height = bitmap.height
val argb = IntArray(width * height)
bitmap.getPixels(argb, 0, width, 0, 0, width, height)
bitmap.recycle()
val packet = ByteArray(4 + argb.size * 4)
packet[0] = (width and 0xff).toByte()
packet[1] = ((width shr 8) and 0xff).toByte()
packet[2] = (height and 0xff).toByte()
packet[3] = ((height shr 8) and 0xff).toByte()
for (i in argb.indices) {
val pixel = argb[i]
val o = 4 + i * 4
packet[o] = (pixel shr 16).toByte()
packet[o + 1] = (pixel shr 8).toByte()
packet[o + 2] = pixel.toByte()
packet[o + 3] = (pixel ushr 24).toByte()
}
return packet
} catch (e: Exception) {
Log.w(TAG, "RGBA image decode failed", e)
return ByteArray(0)
} catch (e: OutOfMemoryError) {
Log.w(TAG, "RGBA image decode failed", e)
return ByteArray(0)
}
}
/**
* Scale a bitmap to fit within maxWidth x maxHeight (preserving aspect,
* never upscaling) and convert it to the grayscale packet format.
+1 -1
View File
@@ -13,7 +13,7 @@
<key>CFBundleDisplayName</key>
<string>Faceclaw</string>
<key>CFBundleShortVersionString</key>
<string>0.8.6</string>
<string>0.9.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
+30 -9
View File
@@ -1,6 +1,7 @@
#import "FaceclawFontRenderer.h"
#import <CoreText/CoreText.h>
#import <CoreGraphics/CoreGraphics.h>
#import <FaceclawKit/FaceclawKit.h>
#import <math.h>
// Immutable font descriptors may be shared; layout objects never cross threads.
@@ -42,8 +43,9 @@ static BOOL HasColorRun(CTLineRef line) {
}
// iOS falls back to Apple Color Emoji for default-text symbols the face lacks
// (▶ U+25B6 in Roboto), where Android's minikin picks a text font; the
// alpha-only raster keeps just the emoji's silhouette (▶ becomes a solid
// rounded square). Request text presentation (U+FE0E) for each lone codepoint
// emoji is a tile (▶ becomes a rounded square: a silhouette in the alpha-only
// line rasters, a shaded tile in glyph cells), which reads worse than the
// text symbol. Request text presentation (U+FE0E) for each lone codepoint
// that fell back to a color font, wherever a text font can supply it. Returns
// `text` itself when nothing changes.
static NSString *PreferTextPresentation(CTFontRef font, NSString *text, CTLineRef line, BOOL glyphLayout) {
@@ -78,18 +80,34 @@ static BOOL ValidText(NSString *text) { return text != nil && text.length <= 100
static BOOL ValidRaster(NSInteger width, NSInteger height) {
return width > 0 && height > 0 && width <= 65535 && height <= 65535 && width * height <= 4000000;
}
static void ConfigureTextContext(CGContextRef ctx) {
CGContextSetShouldAntialias(ctx, true);
CGContextSetShouldSmoothFonts(ctx, false); // Grayscale coverage, never LCD subpixel color.
CGContextSetShouldSubpixelPositionFonts(ctx, true);
CGContextSetShouldSubpixelQuantizeFonts(ctx, false);
CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
}
static CGContextRef CreateContext(NSMutableData *pixels, NSInteger width, NSInteger height) CF_RETURNS_RETAINED {
CGContextRef ctx = CGBitmapContextCreate(pixels.mutableBytes, width, height, 8, width, NULL, (CGBitmapInfo)kCGImageAlphaOnly);
if (ctx) {
CGContextSetShouldAntialias(ctx, true);
CGContextSetShouldSmoothFonts(ctx, false); // Grayscale coverage, never LCD subpixel color.
CGContextSetShouldSubpixelPositionFonts(ctx, true);
CGContextSetShouldSubpixelQuantizeFonts(ctx, false);
CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
ConfigureTextContext(ctx);
CGContextSetGrayFillColor(ctx, 1, 1);
}
return ctx;
}
// Premultiplied RGBA bytes, for a line with a color (emoji) run: an alpha-only raster keeps
// just the emoji's silhouette, so its colors go to ColorGlyphArt to be shaded instead.
static CGContextRef CreateColorContext(NSMutableData *pixels, NSInteger width, NSInteger height) CF_RETURNS_RETAINED {
CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
CGContextRef ctx = CGBitmapContextCreate(pixels.mutableBytes, width, height, 8, width * 4, space,
(CGBitmapInfo)kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(space);
if (ctx) {
ConfigureTextContext(ctx);
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1);
}
return ctx;
}
static void U16(uint8_t *out, NSInteger value) { out[0] = value & 255; out[1] = (value >> 8) & 255; }
static void GammaCopy(uint8_t *dst, const uint8_t *src, NSInteger count, double gamma) {
if (!isfinite(gamma) || gamma <= 0) gamma = 1;
@@ -150,10 +168,13 @@ static NSData *ImagePacket(NSData *pixels, NSInteger width, NSInteger height, do
NSInteger bottom = floor(CGRectGetMinY(bounds)) - 2;
NSInteger width = ceil(CGRectGetMaxX(bounds)) + 2 - left, height = top - bottom;
if (!ValidRaster(width, height)) { CFRelease(line); CFRelease(font); return [NSData data]; }
NSMutableData *pixels = [NSMutableData dataWithLength:width * height];
CGContextRef ctx = CreateContext(pixels, width, height);
BOOL color = HasColorRun(line);
NSMutableData *raster = [NSMutableData dataWithLength:width * height * (color ? 4 : 1)];
CGContextRef ctx = color ? CreateColorContext(raster, width, height) : CreateContext(raster, width, height);
if (!ctx) { CFRelease(line); CFRelease(font); return [NSData data]; }
CGContextSetTextPosition(ctx, -left, -bottom); CTLineDraw(line, ctx); CGContextRelease(ctx);
NSData *pixels = color ? [[FaceclawKitIosColorGlyph shared] shadeRgba:raster] : raster;
if ((NSInteger)pixels.length != width * height) { CFRelease(line); CFRelease(font); return [NSData data]; }
const uint8_t *src = pixels.bytes;
NSInteger x0 = width, y0 = height, x1 = -1, y1 = -1;
for (NSInteger y = 0; y < height; y++) for (NSInteger x = 0; x < width; x++) if (src[y * width + x]) {
+6
View File
@@ -14,4 +14,10 @@
+ (NSData *)bgraPacket:(CGImageRef)image maxSize:(NSInteger)maxSize;
/** bgraPacket of encoded image bytes (JPEG, PNG, ...); nil when undecodable. */
+ (NSData *)bgraPacketFromImageData:(NSData *)data maxSize:(NSInteger)maxSize;
/**
* [widthLo, widthHi, heightLo, heightHi, RGBA...] of encoded image bytes at native size
* (at most 4096 px a side), first frame only; nil when undecodable. CoreGraphics
* premultiplies, so transparent pixels come out black. For the EvenHub image pipeline.
*/
+ (NSData *)rgbaPacketFromImageData:(NSData *)data;
@end
+22
View File
@@ -158,4 +158,26 @@
CGImageRelease(image);
return packet;
}
+ (NSData *)rgbaPacketFromImageData:(NSData *)data {
if (!data.length) return nil;
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
if (!source) return nil;
CGImageRef image = CGImageSourceCreateImageAtIndex(source, 0, NULL);
CFRelease(source);
if (!image) return nil;
size_t width = CGImageGetWidth(image), height = CGImageGetHeight(image);
if (width == 0 || height == 0 || width > 4096 || height > 4096) { CGImageRelease(image); return nil; }
uint8_t dimensions[] = { width & 255, (width >> 8) & 255, height & 255, (height >> 8) & 255 };
NSMutableData *packet = [NSMutableData dataWithBytes:dimensions length:4];
[packet increaseLengthBy:width * height * 4];
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate((uint8_t *)packet.mutableBytes + 4, width, height, 8, width * 4, space,
kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(space);
if (!context) { CGImageRelease(image); return nil; }
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
CGContextRelease(context);
CGImageRelease(image);
return packet;
}
@end
+21
View File
@@ -1,5 +1,26 @@
# Changelog
## 0.9.0 - 2026-11-08
### Major Features
* Add support for the Even Realities G1
* Add support for the Apple Watch
### Minor Features
* Show charging case battery for the G2
* Terminals now default to opening in the same window rather than opening a new window
* Better rendering of color emojis
* Inrease the max timeout for glanceboard show-on-tap display
* Fix some minor issues in the oboarding flow
* Add option to auto-close notification popups after a delay
### Bug Fixes
* Fix an issue that would cause microphone permission check to fail if you swiped away the Android Activity
* Fix an issue that broke the Nightscout widget on the status bar on iOS
* Fix an issue were EvenHub app texet containers weren't indented correctly
## 0.8.6 - 2026-11-01
* Connect directly to the R1 ring rather than indirectly via the glasses
+6 -3
View File
@@ -43,7 +43,10 @@ local checkout above this workspace at ../g2-kit-unofficial.
This Android app uses a modded firmware for the G2 smart glasses. Source code
to the corresponding firmware modifications lives in
https://github.com/jimrandomh/g2flash; there is a compiled version of the
firmware patch-set in app/g2/firmware/cfw-patches.ts. Strongly prefer making
changes to the Android app over making changes to changes to the firmware, as
firmware development is considerably more fraught.
firmware patch-set in app/g2/firmware/cfw-patches.ts, regenerated by
scripts/update_deltas.sh. Even G1 glasses run g1v0, a firmware from ScouterKit
(currently checked out at ~/src/scouter_kit, in g1_firmware/); Faceclaw embeds
it in app/g1/firmware/, regenerated by scripts/update_g1_firmware.sh VERSION.
Strongly prefer making changes to the Android app over making changes to the
firmware, as firmware development is considerably more fraught.
+5 -9
View File
@@ -1,10 +1,6 @@
/** Conditional wording: also shown on self-built iOS apps, where TestFlight does not apply. */
export const IOS_PRIVACY_NOTICE = [
"If installed with TestFlight, Apple automatically collects crash logs, installs, sessions, and device/app details and shares them with Faceclaw's developers. This continues even when Faceclaw statistics are None; the app cannot turn it off.",
"Joining only through a public link hides your name and email from us, not from Apple. Email invitations can identify you. Optional feedback can disclose your email, comments, screenshots and diagnostics. Review what you send.",
"iPhone Settings > Privacy & Security > Analytics & Improvements controls ordinary iOS analytics. It does not stop TestFlight crash reports. Faceclaw cannot change Apple's analytics settings.",
"To leave the beta, open Faceclaw in TestFlight and choose Stop Testing, then stop using and uninstall the beta. This does not erase earlier reports. Details: Settings > Privacy > Privacy policy.",
].join("\n\n");
/**
* One-line pointer for iOS. The full TestFlight disclosure lives only in the
* PRIVACY file (shown in-app as Settings > Privacy > Privacy policy).
*/
export const IOS_PRIVACY_SUMMARY =
"With TestFlight, crash/usage reports continue even with None. Open iOS / TestFlight privacy for details.";
"With TestFlight, crash/usage reports continue even with None. See Privacy policy for details.";
-6
View File
@@ -81,12 +81,6 @@ Button.-primary {
font-size: 18;
}
/* The logo art is black-on-transparent; tint it light in dark mode so it
* doesn't vanish into the dark page background. */
.ns-dark .onboarding-logo {
tint-color: #e6e6e6;
}
/* License / privacy-policy links in the onboarding disclaimer footer. The
* padding widens the tap target beyond the small text. */
.footer-link {
+1
View File
@@ -5,6 +5,7 @@
.body-text { font-size: 18; }
.h1 { font-size: 28; font-weight: bold; }
.footer-link { color: #285c45; padding: 4 8; text-decoration: underline; }
.ns-dark .footer-link { color: #7bc47f; }
Page {
background-color: #f5f5f2;
+7
View File
@@ -30,6 +30,13 @@ export type AppDefinition = {
boot?: (ctx: AppContext) => void;
/** False for apps that must not appear in the launcher grid (the launcher itself). */
showInLauncher?: boolean;
/**
* False while the paired glasses can't run the app (absent means they can).
* It then leaves the launcher grid and what mirrors it: the watch remote and
* the apps.launch tool. A window restored from before a re-pair still opens,
* so the app needs to say what's wrong rather than assume it never runs.
*/
isSupported?: () => boolean;
/** Present on the app that handles text shared via the Android share intent. */
openSharedText?: (ctx: AppContext, title: string, text: string) => void;
/**
+8 -4
View File
@@ -10,6 +10,7 @@ import {
type CompassDiagnostics,
} from "../../native/compass";
import { wrapText } from "../../graphics/textwrap";
import { glassesHaveCompass } from "../../ui/dashboard-settings";
import { type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerContext } from "../../ui/layers";
import { lineStep } from "../../ui/metrics";
@@ -151,6 +152,7 @@ class CompassLayer implements Layer {
}
private statusText(): string {
if (!glassesHaveCompass()) return "These glasses have no compass sensor";
if (this.firmwareStatus !== null) return this.firmwareStatus;
if (!this.enabled) return "Compass paused";
if (this.rawHeading === null) return "Waiting for compass data…";
@@ -206,8 +208,10 @@ class CompassLayer implements Layer {
image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125);
y += smallStep;
}
const accuracyText = magneticAccuracyText(this.diagnostics);
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175);
if (glassesHaveCompass()) {
const accuracyText = magneticAccuracyText(this.diagnostics);
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175);
}
return image;
}
@@ -216,7 +220,7 @@ class CompassLayer implements Layer {
// "Uncalibrated" prompt advertises, and re-calibrating is a normal thing to
// want once the glasses have been taken off and put back on.
handleInput(event: InputEvent, ctx: LayerContext): void {
if (event.type === "click") this.openCalibration(ctx);
if (event.type === "click" && glassesHaveCompass()) this.openCalibration(ctx);
}
}
@@ -231,7 +235,7 @@ export function createCompassAppWindow(options: InProcessAppOptions): InProcessW
icon: "compass",
closeable: true,
actions: options.actions,
menuItems: () => [
menuItems: () => !glassesHaveCompass() ? [] : [
{
label: "Calibrate",
onSelect: (ctx) => {
+2
View File
@@ -1,3 +1,4 @@
import { glassesHaveCompass } from "../../ui/dashboard-settings";
import { type AppDefinition } from "../app-definition";
import { COMPASS_SURFACE_ID, COMPASS_WINDOW_ID, createCompassAppWindow } from "./compass-app";
@@ -5,6 +6,7 @@ const compassApp: AppDefinition = {
appId: "compass",
title: "Compass",
icon: "compass",
isSupported: glassesHaveCompass,
launch: (ctx) => ctx.launchInProcessApp(COMPASS_WINDOW_ID, COMPASS_SURFACE_ID, createCompassAppWindow),
};
+2 -2
View File
@@ -4,7 +4,7 @@ import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
import { shell } from "../../ui/shell/shell";
import { MenuLayer, type MenuItem } from "../../ui/menu";
import { ringConnectionModeSetting } from "../../ui/dashboard-settings";
import { effectiveRingConnectionMode, ringConnectionModeSetting } from "../../ui/dashboard-settings";
import { loadDeviceAddresses } from "../../g2/device-addresses";
import {
getRingSessionStatus,
@@ -146,7 +146,7 @@ export class RingStatusLayer implements Layer {
}
if (!s.directEnabled) {
const pending = ringConnectionModeSetting.get() !== "glasses";
const pending = effectiveRingConnectionMode() !== "glasses";
rows.push({ label: "Direct link", value: pending ? "on after glasses reconnect" : "off (only via glasses)", dim: true });
} else {
const state = s.directNotificationsReady ? "subscribed"
+129 -48
View File
@@ -7,16 +7,23 @@
* match what apps expect. Extended layouts may pick other fonts per container
* (fonts.ts), which wrap with Faceclaw's own text wrapping.
*
* Containers stack in stock's order (paintOrder): without zOrderIndex, lists,
* then texts, then images, so an image container covers text beneath it. Text
* containers are transparent windows that clip their text and scroll it.
*
* Known deviations from stock, acceptable for now:
* - List rendering is a plain vertical list. A non-zero itemWidth sets the
* selection outline's width and truncates long items to fit, as on stock;
* whether stock also lays narrow items out side by side is unknown.
* - Lists scroll with our menus' animation and bounce (see list-menu.ts).
* - Text scrolls in jumps; stock eases each 28px step over 200ms and
* rubber-bands at the ends.
*/
import { GrayImage } from "../../graphics/image";
import { containerFace } from "./fonts";
import {
type EvenHubContainer,
borderGrey,
paintOrder,
type EvenHubImageContainer,
type EvenHubListContainer,
type EvenHubPage,
@@ -30,35 +37,122 @@ export const EVENHUB_SCREEN_HEIGHT = 288;
const TEXT_WHITE = 255;
/**
* SDK 0.0.14 textColor levels 0..4 as grey values. Level 4 is the default and
* the only one apps got before 0.0.14, so it must stay exactly TEXT_WHITE.
* Level 0 is the firmware's "fully dim" step, which over the black page
* background means the text is effectively not shown.
* SDK 0.0.14 textColor levels 0..4 as the greys stock draws them (measured
* in the firmware emulator): level 0 is dim, not off. A missing or
* out-of-range level draws white, the only colour before 0.0.14.
*/
const TEXT_BRIGHTNESS_GREYS = [0, 64, 128, 191, 255];
const TEXT_BRIGHTNESS_GREYS = [51, 102, 153, 204, 255];
function textGrey(level: number | undefined): number {
return level === undefined ? TEXT_WHITE : (TEXT_BRIGHTNESS_GREYS[level] ?? TEXT_WHITE);
}
/** Chars the font lacks are skipped silently on stock (no tofu); EvenHubFont
* skips unknown glyphs, matching that. */
function paintTextContainer(image: GrayImage, container: EvenHubTextContainer): void {
// Only the text dims: textColor is a text-brightness level, and stock draws
// the container's border at full brightness regardless.
paintBorder(image, container);
/**
* The scrollbar stock draws on any text container whose text overflows
* (LV_SCROLLBAR_MODE_AUTO), whether or not it captures input: 4px wide, 10px
* in from the right edge, in a track 6px in from top and bottom, with its
* corner pixels cut. Measured in the firmware emulator.
*/
const SCROLLBAR_GREY = 187;
const SCROLLBAR_WIDTH = 4;
const SCROLLBAR_RIGHT_INSET = 10;
const SCROLLBAR_TRACK_INSET = 6;
type Rect = { x: number; y: number; width: number; height: number };
/** A text container's wrapped lines and the geometry its scrolling works in. */
export type TextLayout = {
lines: string[];
lineHeight: number;
/** Left edge and unscrolled top of the text. */
contentX: number;
contentY: number;
/** Height of the window the text scrolls in (inside border and padding). */
viewportHeight: number;
/** Largest scrollY: how far the text overflows that window. */
maxScroll: number;
};
/**
* Stock lays text out at x + border + padding and wraps it at width - 2 *
* padding: the label is sized ignoring the border, so a line can run into
* the right border, where it is clipped.
*/
export function layoutText(container: EvenHubTextContainer): TextLayout {
const inset = container.borderWidth + container.paddingLength;
const face = containerFace(container.font);
const lines = face.wrap(container.content, Math.max(1, container.width - 2 * inset));
for (let i = 0; i < lines.length; i++) {
face.drawText(image, container.x + inset, container.y + inset + i * face.lineHeight, lines[i]!, textGrey(container.textColor));
const lines = face.wrap(container.content, Math.max(1, container.width - 2 * container.paddingLength));
const viewportHeight = Math.max(0, container.height - 2 * inset);
return {
lines,
lineHeight: face.lineHeight,
contentX: container.x + inset,
contentY: container.y + inset,
viewportHeight,
maxScroll: Math.max(0, lines.length * face.lineHeight - viewportHeight),
};
}
/**
* Text is clipped at the border's inner edge (at the container's edge when it
* has no border). Lines wholly inside stay deferred firmware-text draws; a
* line the edge cuts is rasterized and blitted clipped. Chars the font lacks
* are skipped silently, as on stock (no tofu).
*/
function paintTextContainer(image: GrayImage, container: EvenHubTextContainer): void {
// Only the text dims: textColor is a text-brightness level; the border has its own color.
paintBorder(image, container);
const layout = layoutText(container);
const face = containerFace(container.font);
const grey = textGrey(container.textColor);
const border = container.borderWidth;
const clip: Rect = {
x: container.x + border,
y: container.y + border,
width: Math.max(0, container.width - 2 * border),
height: Math.max(0, container.height - 2 * border),
};
for (let i = 0; i < layout.lines.length; i++) {
const y = layout.contentY + i * layout.lineHeight - container.scrollY;
const bottom = y + layout.lineHeight;
if (bottom <= clip.y || y >= clip.y + clip.height) continue;
const line = layout.lines[i]!;
if (y >= clip.y && bottom <= clip.y + clip.height && layout.contentX + face.measureLine(line) <= clip.x + clip.width) {
face.drawText(image, layout.contentX, y, line, grey);
continue;
}
const strip = new GrayImage(container.width, layout.lineHeight, 0);
face.drawText(strip, layout.contentX - container.x, 0, line, grey);
const visibleTop = Math.max(y, clip.y);
image.bitBlt(strip.withDrawsBaked(), clip.x, visibleTop, {
sx: clip.x - container.x,
sy: visibleTop - y,
width: clip.width,
height: Math.min(bottom, clip.y + clip.height) - visibleTop,
transparentZero: true,
});
}
if (layout.maxScroll > 0) paintScrollbar(image, container, layout);
}
function paintScrollbar(image: GrayImage, container: EvenHubTextContainer, layout: TextLayout): void {
const height = container.height;
const track = height - 2 * SCROLLBAR_TRACK_INSET;
const length = Math.floor((track * height) / (height + layout.maxScroll));
if (track <= 0 || length <= 0) return;
const top = container.y + SCROLLBAR_TRACK_INSET + Math.floor(((track - length) * container.scrollY) / layout.maxScroll);
const left = container.x + container.width - SCROLLBAR_RIGHT_INSET;
for (let row = 0; row < length; row++) {
const end = row === 0 || row === length - 1;
image.fillRect(end ? left + 1 : left, top + row, end ? SCROLLBAR_WIDTH - 2 : SCROLLBAR_WIDTH, 1, SCROLLBAR_GREY);
}
}
function paintBorder(
image: GrayImage,
container: { x: number; y: number; width: number; height: number; borderWidth: number; borderRadius: number },
container: { x: number; y: number; width: number; height: number; borderWidth: number; borderColor: number; borderRadius: number },
): void {
const grey = borderGrey(container.borderColor);
for (let i = 0; i < container.borderWidth; i++) {
if (container.borderRadius > 0) {
image.drawRoundedRect(
@@ -66,28 +160,28 @@ function paintBorder(
container.y + i,
container.width - 2 * i,
container.height - 2 * i,
TEXT_WHITE,
grey,
Math.max(0, container.borderRadius - i),
);
} else {
image.drawRect(container.x + i, container.y + i, container.width - 2 * i, container.height - 2 * i, TEXT_WHITE);
image.drawRect(container.x + i, container.y + i, container.width - 2 * i, container.height - 2 * i, grey);
}
}
}
/**
* An opaque bitmap (black pixels cover what's beneath). Updates are converted
* to exactly the container's size (image-pipeline.ts); pixels an extended
* layout carried over from a differently sized container are clipped.
*/
function paintImageContainer(image: GrayImage, container: EvenHubImageContainer): void {
if (!container.pixels || container.pixelsWidth <= 0 || container.pixelsHeight <= 0) return;
const source = new GrayImage(container.pixelsWidth, container.pixelsHeight, 0);
source.pixels.set(container.pixels);
// Stock quirk: raw data smaller than the container tiles/repeats to fill it.
for (let ty = 0; ty < container.height; ty += container.pixelsHeight) {
for (let tx = 0; tx < container.width; tx += container.pixelsWidth) {
image.bitBlt(source, container.x + tx, container.y + ty, {
width: Math.min(container.pixelsWidth, container.width - tx),
height: Math.min(container.pixelsHeight, container.height - ty),
});
}
}
image.bitBlt(source, container.x, container.y, {
width: Math.min(container.pixelsWidth, container.width),
height: Math.min(container.pixelsHeight, container.height),
});
}
function paintListContainer(image: GrayImage, container: EvenHubListContainer, focused: boolean): void {
@@ -95,36 +189,23 @@ function paintListContainer(image: GrayImage, container: EvenHubListContainer, f
paintListItems(image, container, containerFace(container.font), focused);
}
/** Bottom-to-top paint order for a page's containers. */
function paintOrder(containers: EvenHubContainer[]): EvenHubContainer[] {
const anyZ = containers.some((c) => c.zOrderIndex !== undefined);
if (anyZ) {
// Explicit z-order: larger zOrderIndex renders closer to the front, i.e.
// painted later. (Stock requires all-or-nothing + unique values.)
return [...containers].sort((a, b) => (a.zOrderIndex ?? 0) - (b.zOrderIndex ?? 0));
}
// Default (no z-order): image containers sit below lists and text. Cross-type
// order isn't defined by the wire format (separate object arrays), so this is
// our choice, matching stock. Order within each group is preserved.
const images = containers.filter((c) => c.kind === "image");
const rest = containers.filter((c) => c.kind !== "image");
return [...images, ...rest];
}
/** Render a page into a fresh app-viewport image (positioned by the shell). */
export function compositePage(page: EvenHubPage | null, size: { width: number; height: number }, focused: boolean): GrayImage {
const image = new GrayImage(size.width, size.height, 0);
if (!page) return image;
for (const container of paintOrder(page.containers)) {
switch (container.kind) {
case "image":
case "image": {
if (!container.pixels) break; // Nothing is drawn before the first update.
// Text painted so far is deferred draws (firmware-text runs), which
// would otherwise render above this container's raster. Stock puts a
// later image container OVER earlier text, so bake the pending draws
// first; text painted after this container stays deferred (and above).
image.bakeDeferredDrawsInPlace();
// would otherwise render above this container's raster. The image is
// opaque and covers what's under it, so bake the draws it overlaps
// first; the others, and text painted later, stay deferred.
const box: Rect = { x: container.x, y: container.y, width: container.width, height: container.height };
image.bakeDeferredDrawsWithin(box);
paintImageContainer(image, container);
break;
}
case "text":
paintTextContainer(image, container);
break;
+130 -13
View File
@@ -6,6 +6,7 @@
* reads go through loose key matching (the SDK's pickLoose behavior).
*/
import { mergeFontSpecs, parseFontSpec, type EvenHubFontSpec } from "./font-spec";
import { inStockImageRange } from "./image-pipeline";
export type EvenHubTextContainer = {
kind: "text";
@@ -16,6 +17,8 @@ export type EvenHubTextContainer = {
width: number;
height: number;
borderWidth: number;
/** Firmware border color index 0..16; see borderGrey. */
borderColor: number;
borderRadius: number;
paddingLength: number;
isEventCapture: boolean;
@@ -27,6 +30,11 @@ export type EvenHubTextContainer = {
textColor: number | undefined;
/** Extended-layout font (merged with the layout's default); undefined is the stock font. */
font: EvenHubFontSpec | undefined;
/**
* How far the text is scrolled up, in pixels. Host-local like a list's
* selection: stock scrolls an overflowing capture container itself.
*/
scrollY: number;
};
export type EvenHubImageContainer = {
@@ -54,6 +62,8 @@ export type EvenHubListContainer = {
width: number;
height: number;
borderWidth: number;
/** Firmware border color index 0..16; see borderGrey. */
borderColor: number;
borderRadius: number;
paddingLength: number;
isEventCapture: boolean;
@@ -80,7 +90,7 @@ export type EvenHubMenuItem = {
};
export type EvenHubPage = {
/** In declaration order (lists, images, texts); z-sorted at paint time. */
/** Lists, then texts, then images, each in declaration order (stock's container list order); z-sorted at paint time. */
containers: EvenHubContainer[];
/**
* The page's contextual-menu entries (SDK 0.0.14 `menuObject`). Empty when
@@ -92,6 +102,26 @@ export type EvenHubPage = {
/** Stock draws at most a 5px border; wider requests are clamped. */
const MAX_BORDER_WIDTH = 5;
/**
* Stock firmware limits for list and text containers (common_text_create /
* common_list_create clamp to these), from the evenRealities-openCFW
* reconstruction. Extended layouts are exempt: they have their own canvas.
*/
const STOCK_SCREEN_WIDTH = 576;
const STOCK_SCREEN_HEIGHT = 288;
const STOCK_MAX_BORDER_COLOR = 16;
const STOCK_MAX_BORDER_RADIUS = 10;
const STOCK_MAX_PADDING = 32;
const STOCK_MAX_LIST_ITEMS = 20;
/**
* The border color index's grey: indices 0..15 step by 0x11 (0 is black, so a
* border without a color is invisible) and 16 is white.
*/
export function borderGrey(index: number): number {
return index >= 0 && index < 16 ? index * 0x11 : 0xff;
}
/** Firmware brightness levels for text; 4 is the device default. */
const MIN_TEXT_BRIGHTNESS = 0;
const MAX_TEXT_BRIGHTNESS = 4;
@@ -154,6 +184,11 @@ function readBorderWidth(json: Record<string, unknown>): number {
return Math.max(0, Math.min(MAX_BORDER_WIDTH, readNumber(json, "borderWidth", 0)));
}
/** A protobuf field, so an omitted borderColor is 0 (black). */
function readBorderColor(json: Record<string, unknown>): number {
return Math.max(0, readNumber(json, "borderColor", 0));
}
/** A container's font: its own `font` over the layout-wide default. */
function readFont(json: Record<string, unknown>, layoutFont: EvenHubFontSpec | undefined): EvenHubFontSpec | undefined {
return mergeFontSpecs(layoutFont, parseFontSpec(pickLoose(json, "font")));
@@ -169,6 +204,7 @@ function parseTextContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
width: readNumber(json, "width", 0),
height: readNumber(json, "height", 0),
borderWidth: readBorderWidth(json),
borderColor: readBorderColor(json),
borderRadius: readNumber(json, "borderRadius", 0),
paddingLength: readNumber(json, "paddingLength", 0),
isEventCapture: readFlag(json, "isEventCapture"),
@@ -177,6 +213,7 @@ function parseTextContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
content: readString(json, "content", ""),
textColor: readTextBrightness(json),
font: readFont(json, layoutFont),
scrollY: 0,
};
}
@@ -262,6 +299,7 @@ function parseListContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
width: readNumber(json, "width", 0),
height: readNumber(json, "height", 0),
borderWidth: readBorderWidth(json),
borderColor: readBorderColor(json),
borderRadius: readNumber(json, "borderRadius", 0),
paddingLength: readNumber(json, "paddingLength", 0),
isEventCapture: readFlag(json, "isEventCapture"),
@@ -277,9 +315,8 @@ function parseListContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
/**
* Parse a CreateStartUpPageContainer / RebuildPageContainer payload into a
* page. Containers keep declaration order within and across the three arrays
* (lists, then images, then texts — texts last so info panels and capture
* containers sit above image tiles when no zOrderIndex is given).
* page. Containers are kept in stock's container-list order: lists, then
* texts, then images, each in declaration order (evenhub_build_container_list).
*
* The whole page is replaced on rebuild, which is also what gives an omitted
* menuObject its documented meaning: the previous contextual menu goes away.
@@ -292,20 +329,100 @@ export function parsePage(data: Record<string, unknown>): EvenHubPage {
if (Array.isArray(lists)) {
for (const item of lists) containers.push(parseListContainer(asRecord(item), layoutFont));
}
const images = pickLoose(data, "imageObject");
if (Array.isArray(images)) {
for (const item of images) containers.push(parseImageContainer(asRecord(item)));
}
const texts = pickLoose(data, "textObject");
if (Array.isArray(texts)) {
for (const item of texts) containers.push(parseTextContainer(asRecord(item), layoutFont));
}
const images = pickLoose(data, "imageObject");
if (Array.isArray(images)) {
for (const item of images) containers.push(parseImageContainer(asRecord(item)));
}
return { containers, menuItems: parseMenuItems(data) };
}
/** The container that owns gesture events (exactly one per valid page). */
export function eventCaptureContainer(page: EvenHubPage): EvenHubContainer | undefined {
return page.containers.find(
(container) => container.kind !== "image" && container.isEventCapture,
);
/**
* Clamp a stock page's containers the way the firmware does when it creates
* them: positions and sizes to the 576x288 screen (images keep their size,
* which a separate check rejects instead), border color, radius and padding to
* their maxima, and lists to 20 items. Not for extended layouts.
*/
export function clampToStockLimits(page: EvenHubPage): void {
for (const c of page.containers) {
c.x = Math.min(c.x, STOCK_SCREEN_WIDTH);
c.y = Math.min(c.y, STOCK_SCREEN_HEIGHT);
if (c.kind === "image") continue;
c.width = Math.min(c.width, STOCK_SCREEN_WIDTH);
c.height = Math.min(c.height, STOCK_SCREEN_HEIGHT);
c.borderColor = Math.min(c.borderColor, STOCK_MAX_BORDER_COLOR);
c.borderRadius = Math.min(c.borderRadius, STOCK_MAX_BORDER_RADIUS);
c.paddingLength = Math.min(c.paddingLength, STOCK_MAX_PADDING);
if (c.kind === "list" && c.itemNames.length > STOCK_MAX_LIST_ITEMS) {
c.itemNames = c.itemNames.slice(0, STOCK_MAX_LIST_ITEMS);
}
}
}
/** The firmware's fixed protobuf arrays: more containers than this fail to decode. */
const STOCK_MAX_LISTS = 4;
const STOCK_MAX_TEXTS = 8;
const STOCK_MAX_IMAGES = 4;
/** EhStartUpPageCreateResult values for a page the firmware can't build. */
export const PAGE_CREATE_INVALID = 1;
export const PAGE_CREATE_OUT_OF_MEMORY = 3;
/**
* Why the stock firmware would fail to build this page, with the create result
* the app gets, or null when it builds. Too many containers overflow the
* firmware's protobuf arrays, so decoding fails (it replies with the code the
* phone app maps to outOfMemory). An image container outside 20..288 x 20..144
* fails to create (invalid container).
*/
export function stockPageFailure(page: EvenHubPage): { code: number; reason: string } | null {
const count = (kind: EvenHubContainer["kind"]) => page.containers.filter((c) => c.kind === kind).length;
const [lists, texts, images] = [count("list"), count("text"), count("image")];
if (lists > STOCK_MAX_LISTS || texts > STOCK_MAX_TEXTS || images > STOCK_MAX_IMAGES) {
return {
code: PAGE_CREATE_OUT_OF_MEMORY,
reason: `${lists} list, ${texts} text and ${images} image containers (at most ${STOCK_MAX_LISTS}, ${STOCK_MAX_TEXTS} and ${STOCK_MAX_IMAGES})`,
};
}
for (const c of page.containers) {
if (c.kind === "image" && !inStockImageRange(c.width, c.height)) {
return { code: PAGE_CREATE_INVALID, reason: `image container ${JSON.stringify(c.name)} is ${c.width}x${c.height}, outside 20..288 x 20..144` };
}
}
return null;
}
/**
* Bottom-to-top paint order, as stock stacks its containers: the container
* list order (lists, texts, images), stably sorted by zOrderIndex (larger is
* closer to the front) only when every container has one and there are at
* least two. So without z-order, images are drawn over text.
*/
export function paintOrder(containers: readonly EvenHubContainer[]): EvenHubContainer[] {
const allHaveZ = containers.every((c) => c.zOrderIndex !== undefined);
if (!allHaveZ || containers.length < 2) return [...containers];
return [...containers].sort((a, b) => (a.zOrderIndex ?? 0) - (b.zOrderIndex ?? 0));
}
/**
* The container that owns gesture events. Stock binds the first list or text
* container with isEventCapture in paint order and ignores any later ones.
*/
export function eventCaptureContainer(page: EvenHubPage): EvenHubTextContainer | EvenHubListContainer | undefined {
for (const c of paintOrder(page.containers)) {
if (c.kind !== "image" && c.isEventCapture) return c;
}
return undefined;
}
/**
* The container stock resolves an id to: the first one with that id in paint
* order, whatever its kind, so an update aimed at a later container that
* shares the id never reaches it.
*/
export function containerById(page: EvenHubPage | null, id: number): EvenHubContainer | undefined {
return page ? paintOrder(page.containers).find((c) => c.id === id) : undefined;
}
@@ -0,0 +1,65 @@
import { wrapText } from "../../graphics/textwrap";
import { type LayerContext } from "../../ui/layers";
import { lineStep } from "../../ui/metrics";
import { ScrollingDialogLayer, type DialogBody, type DialogRow } from "./scrolling-dialog";
/** Wider than the permission dialog: the RayNeo iO's window is short, so fewer, longer lines fit better. */
const DIALOG_WIDTH = 420;
/**
* Shown over an EvenHub app the first time it runs with a RayNeo iO paired
* (see glasses-compat.ts): the app is made for Even Realities glasses and
* won't display correctly on the iO's screen. The app starts underneath.
* Continue (or double-click) dismisses the warning; Close app closes the
* app's window. Either answer counts as having seen it; a window closed with
* the warning still up shows it again next time.
*/
export class EvenHubDisplayWarningLayer extends ScrollingDialogLayer {
constructor(
private readonly appName: string,
private readonly onAnswered: () => void,
private readonly closeApp: () => void,
) {
super(DIALOG_WIDTH);
}
protected bodyRows({ image, font, left, textWidth }: DialogBody): DialogRow[] {
const step = lineStep(font);
const rows: DialogRow[] = [];
for (const line of wrapText(font, "Compatibility warning", textWidth)) {
rows.push({ height: step + 2, draw: (top) => image.drawText(font, left, top, line, 235) });
}
rows[rows.length - 1]!.height += 6;
const message =
`${this.appName} is an EvenHub app, made for Even Realities glasses. It will not display correctly ` +
"on the RayNeo iO, because the iO's screen has a different resolution.";
// One row per wrapped line, so a large font scrolls line by line.
const lines = wrapText(font, message, textWidth);
for (let index = 0; index < lines.length; index++) {
rows.push({
height: step + (index === lines.length - 1 ? 8 : 0),
draw: (top) => image.drawText(font, left, top, lines[index]!, 190),
});
}
return rows;
}
protected actions(): string[] {
return ["Continue", "Close app"];
}
protected activate(action: string, ctx: LayerContext): void {
this.close(ctx, () => {
this.onAnswered();
if (action === "Close app") this.closeApp();
});
}
protected backedOut(): void {
this.onAnswered();
}
protected abandoned(): void {
// Not answered: the next launch shows it again.
}
}
+13
View File
@@ -16,6 +16,8 @@ import { shell } from "../../ui/shell/shell";
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
import { EvenHubSession } from "./session";
import { renderInstalledEvenHubIcon } from "./installed-apps";
import { markDisplayWarningShown, needsDisplayWarning } from "./glasses-compat";
import { EvenHubDisplayWarningLayer } from "./display-warning-dialog";
class EvenHubAppLayer implements Layer {
/**
@@ -158,5 +160,16 @@ export function createEvenHubWindow(
session.setScreenOn(on);
};
// The app's first run with a RayNeo iO paired: warn, over the app itself,
// that it won't display correctly there.
const packageId = session.manifest.packageId;
if (needsDisplayWarning(packageId)) {
created.stack.push(new EvenHubDisplayWarningLayer(
session.manifest.name,
() => markDisplayWarningShown(packageId),
() => shell.closeWindow(windowId),
));
}
return created;
}
+38
View File
@@ -0,0 +1,38 @@
/**
* EvenHub with glasses that aren't Even Realities': with a RayNeo iO paired,
* the store is off (it is Even's, and its apps are made for their glasses),
* while apps sideloaded through Files or the Developer app still run, after a
* warning the first time each one launches that it won't display correctly
* (EvenHub apps lay out for the G2's 576x288 display; the iO's is 540x220).
*/
import { glassesTypeSetting } from "../../ui/dashboard-settings";
import { getStringSetting, setStringSetting } from "../../native/settings-store";
/** The package IDs whose RayNeo iO display warning has been answered, as a JSON array. */
const DISPLAY_WARNED_KEY = "evenhub.rayneoDisplayWarned";
/** Whether the EvenHub store can be used: with Even Realities glasses paired, not a RayNeo iO. */
export function isEvenHubStoreAvailable(): boolean {
return glassesTypeSetting.get() !== "rayneo-io";
}
/** Whether launching this package should warn that it won't display correctly on these glasses. */
export function needsDisplayWarning(packageId: string): boolean {
return glassesTypeSetting.get() === "rayneo-io" && !displayWarnedPackages().includes(packageId);
}
/** The user answered the package's display warning: don't show it again. */
export function markDisplayWarningShown(packageId: string): void {
const warned = displayWarnedPackages();
if (warned.includes(packageId)) return;
setStringSetting(DISPLAY_WARNED_KEY, JSON.stringify([...warned, packageId]));
}
function displayWarnedPackages(): string[] {
try {
const parsed: unknown = JSON.parse(getStringSetting(DISPLAY_WARNED_KEY, "[]"));
return Array.isArray(parsed) ? parsed.filter((id): id is string => typeof id === "string") : [];
} catch {
return [];
}
}
+247
View File
@@ -0,0 +1,247 @@
/**
* updateImageRawData the way stock turns an app's imageData into the 4-bit
* bitmap the glasses show. The Even phone app does the conversion
* (EvenHubAppService.updateImageRawData → _prepare / _prepareLegacyRaw, read
* from its blutter decompilation); the glasses firmware then shows the result
* only if it is exactly the container's size (common_image_container_set_data).
*
* - imageData must be a JSON array of integers; a base64 string or an object
* (a typed array that skipped the SDK's toJson) fails as sendFailed.
* - PNG, JPEG, WebP, GIF and BMP are decoded, scaled to cover the container
* (aspect-fill, centre crop, nearest neighbour) and converted to grey with
* alpha ignored.
* - Anything else is raw pixels, accepted only with compressMode 2 (which the
* SDK sends since 0.0.12) and exactly the container's size: one byte per
* pixel (values up to 15 are already 4-bit levels) or 4-bit packed rows.
*
* Native-free so it runs under Node; JPEG/WebP/GIF decoding is injected.
*/
const UPNG = require("upng-js");
/** EhImageUpdateResult, as the SDK reads the host's integer. */
export const IMAGE_SUCCESS = 0;
export const IMAGE_EXCEPTION = 1;
export const IMAGE_SIZE_INVALID = 2;
export const IMAGE_TO_GRAY4_FAILED = 3;
export const IMAGE_SEND_FAILED = 4;
/** Stock image containers are 20..288 wide and 20..144 high. */
export const STOCK_IMAGE_MIN_SIZE = 20;
export const STOCK_IMAGE_MAX_WIDTH = 288;
export const STOCK_IMAGE_MAX_HEIGHT = 144;
/** The compressMode the SDK sends, and the phone app requires for raw pixels. */
const RAW_COMPRESS_MODE = 2;
export function inStockImageRange(width: number, height: number): boolean {
return width >= STOCK_IMAGE_MIN_SIZE && width <= STOCK_IMAGE_MAX_WIDTH &&
height >= STOCK_IMAGE_MIN_SIZE && height <= STOCK_IMAGE_MAX_HEIGHT;
}
export type ImageFormat = "png" | "jpeg" | "webp" | "gif" | "bmp" | "raw";
/** Format by magic bytes, as the phone app's EvenHubImageFormatDetector. */
export function detectImageFormat(b: Uint8Array): ImageFormat {
const at = (i: number, ...values: number[]) => values.every((v, j) => b[i + j] === v);
if (at(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a)) return "png";
if (at(0, 0xff, 0xd8, 0xff)) return "jpeg";
if (at(0, 0x52, 0x49, 0x46, 0x46) && at(8, 0x57, 0x45, 0x42, 0x50)) return "webp";
if (at(0, 0x47, 0x49, 0x46, 0x38, 0x37, 0x61) || at(0, 0x47, 0x49, 0x46, 0x38, 0x39, 0x61)) return "gif";
if (at(0, 0x42, 0x4d)) return "bmp";
return "raw";
}
/** Decoded pixels, RGBA, not premultiplied. */
export type RgbaImage = { width: number; height: number; rgba: Uint8Array };
export type NativeImageDecoder = (bytes: Uint8Array) => RgbaImage | null;
/** 8-bit grey from RGB (alpha ignored), then the nearest of 16 levels. */
export function grayLevel(r: number, g: number, b: number): number {
const g8 = Math.floor((299 * r + 587 * g + 114 * b + 500) / 1000);
return Math.min(15, Math.max(0, Math.floor((g8 * 15 + 127) / 255)));
}
export function rgbaToLevels(image: RgbaImage): Uint8Array {
const levels = new Uint8Array(image.width * image.height);
for (let i = 0; i < levels.length; i++) {
const o = i * 4;
levels[i] = grayLevel(image.rgba[o]!, image.rgba[o + 1]!, image.rgba[o + 2]!);
}
return levels;
}
/**
* Scale to exactly width x height covering it (aspect-fill), cropping the
* overflow equally on both sides, sampling the nearest source pixel centre.
*/
export function resizeRgbaCover(image: RgbaImage, width: number, height: number): RgbaImage {
const scale = Math.max(width / image.width, height / image.height);
const offX = (image.width - width / scale) / 2;
const offY = (image.height - height / scale) / 2;
const rgba = new Uint8Array(width * height * 4);
for (let y = 0; y < height; y++) {
const sy = Math.min(image.height - 1, Math.max(0, Math.floor(offY + (y + 0.5) / scale)));
for (let x = 0; x < width; x++) {
const sx = Math.min(image.width - 1, Math.max(0, Math.floor(offX + (x + 0.5) / scale)));
const from = (sy * image.width + sx) * 4;
rgba.set(image.rgba.subarray(from, from + 4), (y * width + x) * 4);
}
}
return { width, height, rgba };
}
function decodePng(bytes: Uint8Array): RgbaImage | null {
try {
const decoded = UPNG.decode(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
const frames = UPNG.toRGBA8(decoded) as ArrayBuffer[];
if (!frames.length) return null;
return { width: decoded.width, height: decoded.height, rgba: new Uint8Array(frames[0]!) };
} catch {
return null;
}
}
/**
* Uncompressed Windows BMP ('BM', BI_RGB): 1/4/8-bit paletted and 24/32-bit,
* top-down or bottom-up. Null for other variants (the native decoder may still
* read them). EvenChess sends 1-bit BMPs for full-board refreshes.
*/
export function decodeBmp(bytes: Uint8Array): RgbaImage | null {
if (bytes.length < 54 || bytes[0] !== 0x42 || bytes[1] !== 0x4d) return null;
const u16 = (o: number) => bytes[o]! | (bytes[o + 1]! << 8);
const u32 = (o: number) => (bytes[o]! | (bytes[o + 1]! << 8) | (bytes[o + 2]! << 16) | (bytes[o + 3]! << 24)) >>> 0;
const i32 = (o: number) => bytes[o]! | (bytes[o + 1]! << 8) | (bytes[o + 2]! << 16) | (bytes[o + 3]! << 24);
const pixelOffset = u32(10);
const dibSize = u32(14);
const width = i32(18);
const heightRaw = i32(22);
const bitCount = u16(28);
if (u32(30) !== 0) return null; // only BI_RGB
if (width <= 0 || width > 4096) return null;
const topDown = heightRaw < 0;
const height = Math.abs(heightRaw);
if (height === 0 || height > 4096) return null;
if (![1, 4, 8, 24, 32].includes(bitCount)) return null;
// Palette entries are 4 bytes, BGRx.
let palette: Uint8Array | null = null;
if (bitCount <= 8) {
let count = u32(46);
if (count === 0 || count > 1 << bitCount) count = 1 << bitCount;
palette = new Uint8Array(count * 3);
for (let i = 0; i < count; i++) {
const o = 14 + dibSize + i * 4;
if (o + 2 >= bytes.length) break;
palette.set([bytes[o + 2]!, bytes[o + 1]!, bytes[o]!], i * 3);
}
}
const stride = ((width * bitCount + 31) >> 5) << 2;
const rgba = new Uint8Array(width * height * 4);
for (let y = 0; y < height; y++) {
const row = pixelOffset + (topDown ? y : height - 1 - y) * stride;
if (row >= bytes.length) break;
for (let x = 0; x < width; x++) {
let r: number, g: number, b: number;
if (palette) {
let index: number;
if (bitCount === 1) index = ((bytes[row + (x >> 3)] ?? 0) >> (7 - (x & 7))) & 1;
else if (bitCount === 4) index = (x & 1) === 0 ? (bytes[row + (x >> 1)] ?? 0) >> 4 : (bytes[row + (x >> 1)] ?? 0) & 0x0f;
else index = bytes[row + x] ?? 0;
if (index * 3 >= palette.length) index = 0;
[r, g, b] = [palette[index * 3]!, palette[index * 3 + 1]!, palette[index * 3 + 2]!];
} else {
const o = row + x * (bitCount / 8);
[r, g, b] = [bytes[o + 2] ?? 0, bytes[o + 1] ?? 0, bytes[o] ?? 0];
}
rgba.set([r, g, b, 255], (y * width + x) * 4);
}
}
return { width, height, rgba };
}
/** imageData as bytes: a JSON array of integers only (Uint8List.fromList keeps the low 8 bits). */
function imageDataBytes(raw: unknown): Uint8Array | null {
if (raw === undefined || raw === null) return new Uint8Array(0);
if (!Array.isArray(raw)) return null;
const out = new Uint8Array(raw.length);
for (let i = 0; i < raw.length; i++) {
const value: unknown = raw[i];
if (typeof value !== "number" || !Number.isInteger(value)) return null;
out[i] = value & 0xff;
}
return out;
}
export type PreparedImage = {
result: number;
/** 4-bit levels (0..15), row-major, when result is success. */
levels: Uint8Array | null;
width: number;
height: number;
format: ImageFormat | null;
/** Why it failed, for the debug log. */
reason: string;
};
export type ImageRequest = {
imageData: unknown;
compressMode: number;
/** width/height sent with the update; when both are positive they replace the container's. */
requestWidth: number;
requestHeight: number;
/** The image container's size, looked up by id or name; null when none matched. */
geometry: { width: number; height: number } | null;
decodeNative: NativeImageDecoder;
/** Stock pages limit image sizes; Faceclaw's extended layouts don't. */
stockLimits: boolean;
};
/** Convert an update's imageData to 4-bit levels the way the phone app does. */
export function prepareImageUpdate(request: ImageRequest): PreparedImage {
const fail = (result: number, reason: string, format: ImageFormat | null = null): PreparedImage =>
({ result, levels: null, width: 0, height: 0, format, reason });
const bytes = imageDataBytes(request.imageData);
if (!bytes) return fail(IMAGE_SEND_FAILED, "imageData is not an array of integers");
const inRange = (w: number, h: number) => (request.stockLimits ? inStockImageRange(w, h) : w > 0 && h > 0);
const [width, height] = request.requestWidth > 0 && request.requestHeight > 0
? [request.requestWidth, request.requestHeight]
: [request.geometry?.width ?? 0, request.geometry?.height ?? 0];
const format = detectImageFormat(bytes);
if (format === "raw") {
if (request.stockLimits && request.compressMode !== RAW_COMPRESS_MODE) {
return fail(IMAGE_EXCEPTION, `raw pixels need compressMode ${RAW_COMPRESS_MODE}`, format);
}
if (!inRange(width, height)) return fail(IMAGE_SIZE_INVALID, `raw size ${width}x${height} out of range`, format);
const levels = new Uint8Array(width * height);
const packedStride = Math.ceil(width / 2);
if (bytes.length === width * height) {
for (let i = 0; i < levels.length; i++) {
const v = bytes[i]!;
levels[i] = v <= 15 ? v : Math.floor((v * 15 + 127) / 255);
}
} else if (bytes.length === packedStride * height) {
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const byte = bytes[y * packedStride + (x >> 1)]!;
levels[y * width + x] = (x & 1) === 0 ? byte >> 4 : byte & 0x0f;
}
}
} else {
return fail(IMAGE_EXCEPTION, `raw length ${bytes.length} fits neither ${width}x${height} 8-bit nor 4-bit`, format);
}
return { result: IMAGE_SUCCESS, levels, width, height, format, reason: "" };
}
let decoded = format === "png" ? decodePng(bytes) : format === "bmp" ? decodeBmp(bytes) : null;
decoded ??= request.decodeNative(bytes);
if (!decoded || decoded.width <= 0 || decoded.height <= 0) return fail(IMAGE_EXCEPTION, `${format} decode failed`, format);
if (inRange(width, height) && (decoded.width !== width || decoded.height !== height)) {
decoded = resizeRgbaCover(decoded, width, height);
}
if (!inRange(decoded.width, decoded.height)) {
return fail(IMAGE_SIZE_INVALID, `${decoded.width}x${decoded.height} out of range`, format);
}
return { result: IMAGE_SUCCESS, levels: rgbaToLevels(decoded), width: decoded.width, height: decoded.height, format, reason: "" };
}
+14 -1
View File
@@ -5,6 +5,9 @@
* a phone WebView (its runtime + phone UI) and a 576x288 glasses window
* composited by Faceclaw instead of the stock firmware.
*
* With a RayNeo iO paired the store is unavailable and sideloaded apps warn
* on first run that they won't display correctly; see glasses-compat.ts.
*
* Design notes: notes/evenhub_compatibility.txt.
*/
import { type AppContext, type AppDefinition } from "../app-definition";
@@ -15,6 +18,7 @@ import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-p
import { renderEvenRealitiesLogo } from "../../graphics/even-realities-logo";
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
import { type InstalledEvenHubApp } from "./installed-apps";
import { isEvenHubStoreAvailable } from "./glasses-compat";
const EVENHUB_STORE_WINDOW_ID = "evenhub:store";
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
@@ -104,8 +108,17 @@ const evenhubApp: AppDefinition = {
title: "EvenHub",
icon: "package",
renderIcon: renderEvenRealitiesLogo,
// Off the launcher with a RayNeo iO paired. A store window that opens
// anyway (restored from before a re-pair, or the launcher's route for an
// installed app whose package is missing) says why instead of loading.
isSupported: isEvenHubStoreAvailable,
launch: async (ctx) => {
await ensureStoreWindow(ctx);
const { window } = await ensureStoreWindow(ctx);
if (!isEvenHubStoreAvailable()) {
// Store pages opened while Even glasses were paired would cover the notice.
window.stack.clearToBase();
window.requestRender();
}
},
};
+181
View File
@@ -0,0 +1,181 @@
/**
* Debug-log descriptions of EvenHub page layouts and container updates.
* session.ts sends them to logcat at debug level (tag FaceclawEvenHubLayout).
*
* "note:" lines point out page quirks that change what stock (and so we) do
* with it: shared ids, missing or extra capture containers, a wrong
* containerTotalNum.
*/
import {
paintOrder,
readOptionalNumber,
type EvenHubContainer,
type EvenHubListContainer,
type EvenHubPage,
type EvenHubTextContainer,
} from "./containers";
import type { PreparedImage } from "./image-pipeline";
const CONTENT_PREVIEW_CHARS = 40;
const RAW_STRING_CHARS = 120;
const RAW_ARRAY_ITEMS = 32;
function label(c: EvenHubContainer): string {
return `${c.kind}#${c.id} ${JSON.stringify(c.name)}`;
}
function preview(text: string): string {
return JSON.stringify(text.length > CONTENT_PREVIEW_CHARS ? `${text.slice(0, CONTENT_PREVIEW_CHARS)}…` : text);
}
function decoration(c: EvenHubTextContainer | EvenHubListContainer): string {
let out = "";
if (c.borderWidth > 0) out += ` border=${c.borderWidth}c${c.borderColor}${c.borderRadius > 0 ? `r${c.borderRadius}` : ""}`;
if (c.paddingLength > 0) out += ` pad=${c.paddingLength}`;
if (c.isEventCapture) out += " capture";
if (c.font) out += " font";
return out;
}
function describeContainer(c: EvenHubContainer): string {
const z = c.zOrderIndex === undefined ? "" : ` z=${c.zOrderIndex}`;
const head = `${label(c)} @${c.x},${c.y} ${c.width}x${c.height}${z}`;
switch (c.kind) {
case "image":
return `${head} ${c.pixels ? `pixels=${c.pixelsWidth}x${c.pixelsHeight}` : "no pixels yet"}`;
case "text": {
const color = c.textColor === undefined ? "" : ` color=${c.textColor}`;
return `${head}${decoration(c)}${color} len=${c.content.length} ${preview(c.content)}`;
}
case "list":
return `${head}${decoration(c)} items=${c.itemNames.length} itemWidth=${c.itemWidth}${c.selectBorder ? " selectBorder" : ""} selected=${c.selectedIndex}`;
}
}
/** Quirks of a page that change how stock treats it. */
export function pageNotes(page: EvenHubPage, declaredTotal?: number): string[] {
const notes: string[] = [];
const ordered = paintOrder(page.containers);
const byId = new Map<number, EvenHubContainer[]>();
for (const c of ordered) byId.set(c.id, [...(byId.get(c.id) ?? []), c]);
byId.forEach((shared, id) => {
if (shared.length > 1) {
notes.push(`id ${id} is shared by ${shared.map(label).join(", ")}; updates and events resolve to ${label(shared[0]!)} only`);
}
});
const captures = ordered.filter((c) => c.kind !== "image" && c.isEventCapture);
if (captures.length === 0) notes.push("no event-capture container, so the app gets no input");
else if (captures.length > 1) notes.push(`${captures.length} event-capture containers; only the first, ${label(captures[0]!)}, gets input`);
if (declaredTotal !== undefined && declaredTotal !== page.containers.length) {
notes.push(`containerTotalNum is ${declaredTotal} but ${page.containers.length} containers were sent (nothing checks it)`);
}
return notes;
}
/** The payload, as compact JSON with long strings and arrays cut short. */
function rawJson(data: Record<string, unknown>): string {
try {
return JSON.stringify(data, (_key, value: unknown) => {
if (typeof value === "string" && value.length > RAW_STRING_CHARS) {
return `${value.slice(0, RAW_STRING_CHARS)}…(${value.length} chars)`;
}
if (Array.isArray(value) && value.length > RAW_ARRAY_ITEMS) {
return [...value.slice(0, RAW_ARRAY_ITEMS), `…(${value.length} items)`];
}
return value;
});
} catch (error) {
return `(unserializable: ${String(error)})`;
}
}
/** A create/rebuild/extension layout: one line per container in paint order, then notes, then the raw payload. */
export function describePage(method: string, page: EvenHubPage, data: Record<string, unknown>): string[] {
const containers = page.containers;
const count = (kind: EvenHubContainer["kind"]) => containers.filter((c) => c.kind === kind).length;
const declaredTotal = readOptionalNumber(data, "containerTotalNum");
const total = declaredTotal === undefined ? "" : `, containerTotalNum=${declaredTotal}`;
const menu = page.menuItems.length > 0 ? `, ${page.menuItems.length} menu items` : "";
const lines = [
`${method}: ${containers.length} containers (${count("list")} list, ${count("text")} text, ${count("image")} image)` +
`${total}${menu}; painted bottom to top:`,
];
paintOrder(containers).forEach((c, i) => lines.push(` ${i}: ${describeContainer(c)}`));
for (const note of pageNotes(page, declaredTotal)) lines.push(` note: ${note}`);
lines.push(` raw: ${rawJson(data)}`);
return lines;
}
function payloadKind(raw: unknown): string {
if (raw === undefined || raw === null) return "missing";
if (Array.isArray(raw)) return `number[${raw.length}]`;
if (typeof raw === "string") return `string(${raw.length} chars)`;
if (typeof raw === "object") return `object(${Object.keys(raw).length} keys)`;
return typeof raw;
}
/** Lit-pixel count and bounding box of 4-bit levels, so a blank "hide this" image is recognizable. */
function litSummary(levels: Uint8Array, width: number): string {
let lit = 0;
let max = 0;
let x0 = width;
let y0 = Infinity;
let x1 = -1;
let y1 = -1;
for (let i = 0; i < levels.length; i++) {
const level = levels[i]!;
if (level === 0) continue;
lit++;
if (level > max) max = level;
const x = i % width;
const y = Math.floor(i / width);
if (x < x0) x0 = x;
if (x > x1) x1 = x;
if (y < y0) y0 = y;
if (y > y1) y1 = y;
}
return lit === 0 ? "blank" : `lit=${lit}px max=${max}/15 bbox=${x0},${y0}-${x1},${y1}`;
}
export type ImageUpdateDebug = {
sentId: number;
sentName: string;
raw: unknown;
/** The container the id resolves to. */
target: EvenHubContainer | undefined;
prepared: PreparedImage;
/** Whether the container now shows the update. */
shown: boolean;
/** EhImageUpdateResult returned to the app. */
result: number;
};
export function describeImageUpdate(u: ImageUpdateDebug): string[] {
const parts = [`updateImageRawData id=${u.sentId} ${JSON.stringify(u.sentName)}`];
parts.push(`-> ${u.target ? label(u.target) : "no container"}`);
parts.push(`payload=${payloadKind(u.raw)}`);
if (u.prepared.format) parts.push(`format=${u.prepared.format}`);
if (u.prepared.levels) parts.push(`${u.prepared.width}x${u.prepared.height} ${litSummary(u.prepared.levels, u.prepared.width)}`);
parts.push(`result=${u.result}`, u.shown ? "shown" : "not shown");
const lines = [parts.join(" ")];
if (u.prepared.reason) lines.push(` ${u.prepared.reason}`);
if (u.prepared.result === 0 && u.target?.kind !== "image") {
lines.push(` the id ${u.target ? `resolves to ${label(u.target)}` : "matches no container"}, so the glasses refuse the transfer`);
} else if (u.prepared.result === 0 && !u.shown && u.target) {
lines.push(` ${u.prepared.width}x${u.prepared.height} isn't the container's ${u.target.width}x${u.target.height}, so the glasses drop it`);
}
return lines;
}
export function describeTextUpgrade(
sentId: number,
sentName: string,
container: EvenHubTextContainer | null,
offset: number | undefined,
sentLength: number,
): string {
if (!container) return `textContainerUpgrade id=${sentId} ${JSON.stringify(sentName)}: no container with that id`;
const at = offset === undefined ? "" : ` offset=${offset}`;
const color = container.textColor === undefined ? "" : ` color=${container.textColor}`;
return `textContainerUpgrade ${label(container)}${at} sent=${sentLength} chars -> len=${container.content.length}${color} ${preview(container.content)}`;
}
+141
View File
@@ -0,0 +1,141 @@
/**
* The checks the Even phone app applies to createStartUpPageContainer,
* rebuildPageContainer and textContainerUpgrade payloads before it sends
* anything to the glasses (read from its blutter decompilation:
* EvenHubProtoJsonMapper.validateTextBrightness, mapProtoJsonKeys and
* protobuf.dart's tag-keyed JSON parsing):
*
* - every key must be one the message defines (a numeric key passes as a raw
* protobuf tag, which we then ignore);
* - numeric fields take an integer or a numeric string — not a boolean, a
* fraction or null; string fields take a string; repeated fields an array;
* - any key named textColor, anywhere, must be an integer from 0 to 4.
*
* A failure means the call fails without reaching the glasses: create
* returns invalid (1), rebuild and textContainerUpgrade return false.
* Faceclaw's extended layouts are not checked; they carry their own keys.
*/
type FieldType = "uint" | "string" | "any" | { list: FieldType } | { message: Schema };
type Schema = Readonly<Record<string, FieldType>>;
const BOX: Schema = {
xPosition: "uint",
yPosition: "uint",
width: "uint",
height: "uint",
containerID: "uint",
containerName: "string",
zOrderIndex: "uint",
};
const DECORATED: Schema = {
...BOX,
borderWidth: "uint",
borderColor: "uint",
borderRadius: "uint",
paddingLength: "uint",
isEventCapture: "uint",
};
const TEXT: Schema = { ...DECORATED, content: "string", textColor: "uint" };
const ITEM_CONTAINER: Schema = {
itemCount: "uint",
itemWidth: "uint",
isItemSelectBorderEn: "uint",
itemName: { list: "string" },
};
const LIST: Schema = { ...DECORATED, itemContainer: { message: ITEM_CONTAINER } };
// The app knows position, subItems and checkedIndex (second-level menus, not
// yet in the SDK); their value types are unconfirmed, so they aren't checked.
const MENU_ITEM: Schema = { itemName: "string", itemID: "uint", position: "any", subItems: "any", checkedIndex: "any" };
const MENU: Schema = { menuItems: { list: { message: MENU_ITEM } } };
const REBUILD: Schema = {
containerTotalNum: "uint",
listObject: { list: { message: LIST } },
textObject: { list: { message: TEXT } },
imageObject: { list: { message: BOX } },
menuObject: { message: MENU },
};
const CREATE: Schema = { ...REBUILD, widgetId: "uint" };
const TEXT_UPGRADE: Schema = {
containerID: "uint",
containerName: "string",
contentOffset: "uint",
contentLength: "uint",
content: "string",
textColor: "uint",
};
const SCHEMAS = { create: CREATE, rebuild: REBUILD, textUpgrade: TEXT_UPGRADE } as const;
/** What Dart's int.parse accepts. */
const INT_STRING = /^\s*[+-]?(?:\d+|0[xX][0-9a-fA-F]+)\s*$/;
function isRecord(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
function checkValue(type: FieldType, value: unknown, path: string): string | null {
if (type === "any") return null;
if (value === null || value === undefined) return `${path} is null`;
if (type === "uint") {
if (typeof value === "number" ? Number.isInteger(value) : typeof value === "string" && INT_STRING.test(value)) return null;
return `${path} must be an integer, not ${JSON.stringify(value)}`;
}
if (type === "string") return typeof value === "string" ? null : `${path} must be a string, not ${JSON.stringify(value)}`;
if ("list" in type) {
if (!Array.isArray(value)) return `${path} must be an array`;
for (let i = 0; i < value.length; i++) {
const error = checkValue(type.list, value[i], `${path}[${i}]`);
if (error) return error;
}
return null;
}
return isRecord(value) ? checkMessage(type.message, value, path) : `${path} must be an object`;
}
function checkMessage(schema: Schema, message: Record<string, unknown>, path: string): string | null {
for (const [key, value] of Object.entries(message)) {
const field = schema[key];
if (!field) {
if (INT_STRING.test(key)) continue;
return `unknown key ${path ? `${path}.` : ""}${key}`;
}
const error = checkValue(field, value, path ? `${path}.${key}` : key);
if (error) return error;
}
return null;
}
/** validateTextBrightness: every textColor key, at any depth, holds an integer 0..4. */
function checkTextColors(value: unknown, path: string): string | null {
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
const error = checkTextColors(value[i], `${path}[${i}]`);
if (error) return error;
}
} else if (isRecord(value)) {
for (const [key, child] of Object.entries(value)) {
const at = path ? `${path}.${key}` : key;
if (key === "textColor" && !(typeof child === "number" && Number.isInteger(child) && child >= 0 && child <= 4)) {
return `${at} must be an integer from 0 to 4, not ${JSON.stringify(child)}`;
}
const error = checkTextColors(child, at);
if (error) return error;
}
}
return null;
}
/** Why the Even app would refuse this payload without sending it, or null if it would send it. */
export function stockPayloadError(kind: keyof typeof SCHEMAS, data: Record<string, unknown>): string | null {
return checkTextColors(data, "") ?? checkMessage(SCHEMAS[kind], data, "");
}
+31 -152
View File
@@ -1,17 +1,11 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { truncateText, wrapText } from "../../graphics/textwrap";
import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
import { type LayerContext } from "../../ui/layers";
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
import { lineStep, listRowHeight } from "../../ui/metrics";
import { lineStep } from "../../ui/metrics";
import { ScrollingDialogLayer, type DialogBody, type DialogRow } from "./scrolling-dialog";
/** Minimum gap between the dialog and the edges of the window it's centered in. */
const DIALOG_MARGIN = 8;
const DIALOG_WIDTH = 320;
const PADDING = 10;
const PERM_GAP = 4;
/**
@@ -20,56 +14,26 @@ const PERM_GAP = 4;
* Cancel (or double-click) backs out. A privacy-policy-only app still reaches
* this dialog so the user can review the policy before allowing first run.
*
* When the list overflows the viewport the dialog scrolls: scroll events move
* through the content row by row, and only once the bottom is fully visible do
* further scrolls move the action selection. The actions are inert until then
* (a click just scrolls), so the user can't Allow without having had the whole
* list on screen.
* A long list scrolls a page at a time, and Allow stays inert until the
* bottom has been reached (see ScrollingDialogLayer), so the user can't
* Allow without having had the whole list on screen.
*/
export class EvenHubPermissionDialogLayer implements Layer {
/** Floats in front of the window content, like the context menus. */
readonly depth = 2;
/** Starts on Allow; the optional privacy-policy action is inserted after it. */
private selectedIndex = 0;
/** First content row drawn; rows above it are scrolled off. */
private firstRow = 0;
/** Scroll position at which the last row is fully visible; set by paint. */
private maxFirstRow = 0;
private resolved = false;
export class EvenHubPermissionDialogLayer extends ScrollingDialogLayer {
constructor(
private readonly appName: string,
private readonly permissions: EvenHubPermission[],
private readonly privacyPolicyUrl: string,
private readonly onConfirm: () => void,
private readonly onCancel: () => void,
) {}
/** Whether the dialog is scrolled to the bottom, making the actions live. */
private atBottom(): boolean {
return this.firstRow >= this.maxFirstRow;
) {
super(DIALOG_WIDTH);
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const font = getDefaultSmallFont();
const { width: viewportWidth, height: viewportHeight } = ctx.stack.getBaseSize();
const image = paintBelow();
const dialogWidth = Math.min(DIALOG_WIDTH, viewportWidth - 2 * DIALOG_MARGIN);
const dialogX = ((viewportWidth - dialogWidth) / 2) | 0;
const textWidth = dialogWidth - 2 * PADDING - 4;
const left = dialogX + PADDING + 2;
protected bodyRows({ image, font, left, textWidth }: DialogBody): DialogRow[] {
const headerStep = lineStep(font) + 2;
const permLabelStep = lineStep(font) + 1;
const permDetailStep = lineStep(font) - 1;
const actionRowH = listRowHeight(font);
const actions = this.actions();
const focused = ctx.stack.isFocused();
// The dialog body as scrollable rows; each row's height includes the gap
// below it, so scrolling and visibility checks work on whole rows.
type Row = { height: number; draw: (top: number) => void };
const rows: Row[] = [];
const rows: DialogRow[] = [];
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
rows.push({
height: headerStep + 6,
@@ -98,113 +62,28 @@ export class EvenHubPermissionDialogLayer implements Layer {
});
}
}
for (let index = 0; index < actions.length; index++) {
rows.push({
height: actionRowH,
draw: (top) => {
const selected = this.atBottom() && index === this.selectedIndex;
if (selected) {
drawSelectionHighlight(image, dialogX + 12, top, dialogWidth - 24, actionRowH - 1, focused, 8);
}
image.drawText(font, dialogX + 22, top + 3, actions[index]!, selected ? 255 : 200);
},
});
}
const contentHeight = rows.reduce((sum, row) => sum + row.height, 0);
const height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_MARGIN);
const dialogY = ((viewportHeight - height) / 2) | 0;
const visibleHeight = height - 2 * PADDING;
// The bottommost scroll position: the largest suffix of rows that fits.
let maxFirstRow = rows.length;
for (let suffixHeight = 0; maxFirstRow > 0; maxFirstRow--) {
const rowHeight = rows[maxFirstRow - 1]!.height;
if (suffixHeight + rowHeight > visibleHeight) break;
suffixHeight += rowHeight;
}
this.maxFirstRow = maxFirstRow;
this.firstRow = Math.max(0, Math.min(this.firstRow, maxFirstRow));
// Fill 1 (transparent color key is 0), outline for the dialog edge.
image.fillRoundedRect(dialogX, dialogY, dialogWidth, height, 1);
image.drawRoundedRect(dialogX, dialogY, dialogWidth, height, 72);
let y = dialogY + PADDING;
for (let index = this.firstRow; index < rows.length; index++) {
const row = rows[index]!;
if (y + row.height > dialogY + PADDING + visibleHeight) break;
row.draw(y);
y += row.height;
}
if (maxFirstRow > 0) {
drawListScrollbar(
image,
dialogX + dialogWidth - 7,
dialogY + PADDING,
visibleHeight,
this.firstRow,
rows.length - maxFirstRow,
rows.length,
);
}
return image;
return rows;
}
handleInput(event: InputEvent, ctx: LayerContext): void {
const actions = this.actions();
switch (event.type) {
case "scroll-up":
if (this.atBottom() && this.selectedIndex > 0) {
this.selectedIndex -= 1;
} else if (this.firstRow > 0) {
this.firstRow -= 1;
}
return;
case "scroll-down":
if (!this.atBottom()) {
this.firstRow += 1;
} else {
this.selectedIndex = Math.min(actions.length - 1, this.selectedIndex + 1);
}
return;
case "click":
if (!this.atBottom()) {
this.firstRow += 1;
return;
}
if (actions[this.selectedIndex] === "Privacy policy") {
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
} else {
this.resolve(ctx, actions[this.selectedIndex] === "Allow");
}
return;
case "double-click":
this.resolve(ctx, false);
return;
default:
return;
}
}
onRemoved(): void {
// Dismissed some other way (window closed, back button): treat as cancel.
if (!this.resolved) {
this.resolved = true;
this.onCancel();
}
}
private resolve(ctx: LayerContext, confirmed: boolean): void {
if (this.resolved) return;
this.resolved = true;
ctx.stack.pop();
if (confirmed) this.onConfirm();
else this.onCancel();
}
private actions(): string[] {
protected actions(): string[] {
return this.privacyPolicyUrl ? ["Allow", "Privacy policy", "Cancel"] : ["Allow", "Cancel"];
}
protected activate(action: string, ctx: LayerContext): void {
if (action === "Privacy policy") {
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
} else if (action === "Allow") {
this.close(ctx, () => this.onConfirm());
} else {
this.close(ctx, () => this.onCancel());
}
}
protected backedOut(): void {
this.onCancel();
}
protected abandoned(): void {
this.onCancel();
}
}
+201
View File
@@ -0,0 +1,201 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { type GrayImage, type UiFont } from "../../graphics/image";
import { type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
import { listRowHeight } from "../../ui/metrics";
/** Minimum gap between the dialog and the edges of the window it's centered in. */
const DIALOG_MARGIN = 8;
const PADDING = 10;
/** One row of a dialog's content. Its height includes the gap below it, so scrolling works on whole rows. */
export type DialogRow = { height: number; draw: (top: number) => void };
/** What a dialog's body rows draw with: the canvas, the font, and the text column. */
export type DialogBody = { image: GrayImage; font: UiFont; left: number; textWidth: number };
/**
* A dialog box centered over the window it opens in: body rows, then a
* column of actions, starting on the first. EvenHub's confirmations and
* warnings (permissions, the RayNeo iO display warning) are built on it.
*
* When the content overflows the viewport the dialog scrolls a page at a
* time, keeping one line of overlap (the last line of one page is the first
* of the next), and only once the bottom is fully visible do further scrolls
* move the action selection. The actions are inert until then (a click just
* pages down), so nothing can be chosen without the whole dialog having been
* on screen. Double-click backs out.
*/
export abstract class ScrollingDialogLayer implements Layer {
/** Floats in front of the window content, like the context menus. */
readonly depth = 2;
private selectedIndex = 0;
/** First content row drawn; rows above it are scrolled off. */
private firstRow = 0;
/** Scroll position at which the last row is fully visible; set by paint. */
private maxFirstRow = 0;
/** Heights of the content rows and of the viewport they scroll in, as last painted (for paging). */
private rowHeights: number[] = [];
private visibleHeight = 0;
private resolved = false;
constructor(private readonly maxWidth: number) {}
/** The rows above the actions. */
protected abstract bodyRows(body: DialogBody): DialogRow[];
/** The action labels, top to bottom. */
protected abstract actions(): string[];
/** A click on an action once the actions are live; close() dismisses the dialog with it. */
protected abstract activate(action: string, ctx: LayerContext): void;
/** Double-click: the user backed out of the dialog. */
protected abstract backedOut(): void;
/** The dialog left the stack unanswered (its window closed). */
protected abstract abandoned(): void;
/** Whether the dialog is scrolled to the bottom, making the actions live. */
private atBottom(): boolean {
return this.firstRow >= this.maxFirstRow;
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const font = getDefaultSmallFont();
const { width: viewportWidth, height: viewportHeight } = ctx.stack.getBaseSize();
const image = paintBelow();
const dialogWidth = Math.min(this.maxWidth, viewportWidth - 2 * DIALOG_MARGIN);
const dialogX = ((viewportWidth - dialogWidth) / 2) | 0;
const textWidth = dialogWidth - 2 * PADDING - 4;
const left = dialogX + PADDING + 2;
const actionRowH = listRowHeight(font);
const actions = this.actions();
const focused = ctx.stack.isFocused();
const rows = this.bodyRows({ image, font, left, textWidth });
for (let index = 0; index < actions.length; index++) {
rows.push({
height: actionRowH,
draw: (top) => {
const selected = this.atBottom() && index === this.selectedIndex;
if (selected) {
drawSelectionHighlight(image, dialogX + 12, top, dialogWidth - 24, actionRowH - 1, focused, 8);
}
image.drawText(font, dialogX + 22, top + 3, actions[index]!, selected ? 255 : 200);
},
});
}
const contentHeight = rows.reduce((sum, row) => sum + row.height, 0);
const height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_MARGIN);
const dialogY = ((viewportHeight - height) / 2) | 0;
const visibleHeight = height - 2 * PADDING;
// The bottommost scroll position: the largest suffix of rows that fits.
let maxFirstRow = rows.length;
for (let suffixHeight = 0; maxFirstRow > 0; maxFirstRow--) {
const rowHeight = rows[maxFirstRow - 1]!.height;
if (suffixHeight + rowHeight > visibleHeight) break;
suffixHeight += rowHeight;
}
this.maxFirstRow = maxFirstRow;
this.firstRow = Math.max(0, Math.min(this.firstRow, maxFirstRow));
this.rowHeights = rows.map((row) => row.height);
this.visibleHeight = visibleHeight;
// Fill 1 (transparent color key is 0), outline for the dialog edge.
image.fillRoundedRect(dialogX, dialogY, dialogWidth, height, 1);
image.drawRoundedRect(dialogX, dialogY, dialogWidth, height, 72);
let y = dialogY + PADDING;
for (let index = this.firstRow; index < rows.length; index++) {
const row = rows[index]!;
if (y + row.height > dialogY + PADDING + visibleHeight) break;
row.draw(y);
y += row.height;
}
if (maxFirstRow > 0) {
drawListScrollbar(
image,
dialogX + dialogWidth - 7,
dialogY + PADDING,
visibleHeight,
this.firstRow,
rows.length - maxFirstRow,
rows.length,
);
}
return image;
}
handleInput(event: InputEvent, ctx: LayerContext): void {
const actions = this.actions();
switch (event.type) {
case "scroll-up":
if (this.atBottom() && this.selectedIndex > 0) {
this.selectedIndex -= 1;
} else if (this.firstRow > 0) {
this.pageUp();
}
return;
case "scroll-down":
if (!this.atBottom()) {
this.pageDown();
} else {
this.selectedIndex = Math.min(actions.length - 1, this.selectedIndex + 1);
}
return;
case "click":
if (!this.atBottom()) {
this.pageDown();
return;
}
this.activate(actions[this.selectedIndex]!, ctx);
return;
case "double-click":
this.close(ctx, () => this.backedOut());
return;
default:
return;
}
}
/** Scroll so the last fully visible row becomes the first (one row of overlap). */
private pageDown(): void {
let y = 0;
let lastVisible = this.firstRow;
for (let index = this.firstRow; index < this.rowHeights.length; index++) {
y += this.rowHeights[index]!;
if (y > this.visibleHeight) break;
lastVisible = index;
}
this.firstRow = Math.min(this.maxFirstRow, Math.max(this.firstRow + 1, lastVisible));
}
/** Scroll so the current first row becomes the last fully visible one (one row of overlap). */
private pageUp(): void {
let first = this.firstRow;
let y = this.rowHeights[first] ?? 0;
while (first > 0 && y + this.rowHeights[first - 1]! <= this.visibleHeight) {
first -= 1;
y += this.rowHeights[first]!;
}
this.firstRow = Math.max(0, Math.min(this.firstRow - 1, first));
}
onRemoved(): void {
// Dismissed some other way (window closed, back button).
if (!this.resolved) {
this.resolved = true;
this.abandoned();
}
}
/** Take the dialog down, then run the answer's effect (once, however it was answered). */
protected close(ctx: LayerContext, then: () => void): void {
if (this.resolved) return;
this.resolved = true;
ctx.stack.pop();
then();
}
}
+191 -219
View File
@@ -38,7 +38,11 @@ import {
import { EvenHubApiKeyDialogLayer } from "./api-key-dialog";
import {
asRecord,
clampToStockLimits,
containerById,
declaredMenuItems,
PAGE_CREATE_INVALID,
stockPageFailure,
eventCaptureContainer,
parsePage,
readNumber,
@@ -50,8 +54,13 @@ import {
type EvenHubContainer,
type EvenHubMenuItem,
type EvenHubPage,
type EvenHubTextContainer,
} from "./containers";
import { compositePage } from "./compositor";
import { compositePage, layoutText } from "./compositor";
import { describeImageUpdate, describePage, describeTextUpgrade } from "./layout-debug";
import { IMAGE_SEND_FAILED, IMAGE_SUCCESS, prepareImageUpdate } from "./image-pipeline";
import { stockPayloadError } from "./payload-validation";
import { decodeImageRgba } from "../../native/image-rgba";
import { stepListSelection } from "./list-menu";
import { type EvenHubManifest } from "./ehpk";
import { permissionsIncludeMicrophone, permissionsInclude } from "./permissions";
@@ -74,7 +83,15 @@ import { parseWindowIcon, WindowIconRenderer } from "./window-icon";
import { availableFontFamilies, containerFace, measureContainerText } from "./fonts";
import { parseFontSpec } from "./font-spec";
const UPNG = require("upng-js");
/**
* Page layouts and container updates go to logcat at debug level (see
* layout-debug.ts): `adb logcat -s FaceclawEvenHubLayout:D`. Android only.
*/
const LAYOUT_LOG_TAG = "FaceclawEvenHubLayout";
const LAYOUT_LOG_ENABLED = !!global.isAndroid;
/** Logcat truncates entries around 4 KB; split longer lines below that. */
const LOGCAT_CHUNK_CHARS = 3000;
/** OsEventTypeList values (PB ordinals). */
const CLICK_EVENT = 0;
@@ -83,12 +100,20 @@ const SCROLL_BOTTOM_EVENT = 2;
const DOUBLE_CLICK_EVENT = 3;
const FOREGROUND_ENTER_EVENT = 4;
const FOREGROUND_EXIT_EVENT = 5;
const ABNORMAL_EXIT_EVENT = 6;
const SYSTEM_EXIT_EVENT = 7;
const IMU_DATA_REPORT_EVENT = 8;
/** SDK 0.0.14: the press gesture, delivered like any other list/text/sys event. */
const LONG_PRESS_EVENT = 9;
const LONG_PRESS_RELEASE_EVENT = 10;
/** After a failed rebuild, how long the app gets to hear ABNORMAL_EXIT before it is closed. */
const ABNORMAL_EXIT_CLOSE_DELAY_MS = 200;
/** Stock text scrolling: one step per swipe, and "at an end" within this tolerance. */
const TEXT_SCROLL_STEP_PX = 28;
const TEXT_SCROLL_EDGE_PX = 3;
/**
* Injected into every served HTML document at document start (before any app
* JS): (1) the promise-returning flutter_inappwebview.callHandler the EvenHub
@@ -416,6 +441,8 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
private page: EvenHubPage | null = null;
private pageCreated = false;
/** The page came from Faceclaw's extended layout API, which isn't held to stock limits. */
private extendedLayout = false;
private webViewHandle: EvenHubWebViewHandle | null = null;
private windowHooks: EvenHubWindowHooks | null = null;
private closed = false;
@@ -596,6 +623,8 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
const eventType = event.type === "scroll-up" ? SCROLL_TOP_EVENT : SCROLL_BOTTOM_EVENT;
if (capture?.kind === "list") {
this.scrollList(capture, eventType, inputSource);
} else if (capture?.kind === "text") {
this.scrollText(capture, eventType, inputSource);
} else {
this.emitSysEvent(eventType, 0, inputSource);
}
@@ -620,6 +649,25 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
this.pushMessage("evenHubEvent", { type: "menuItemClickEvent", jsonData: { itemID } });
}
/**
* Stock scrolls a capture text container that overflows by itself, a 28px
* step per swipe, and tells the app only at the ends (a textEvent naming the
* container). Text that fits reports every swipe as reaching an end.
*/
private scrollText(text: EvenHubTextContainer, eventType: number, inputSource?: ExtensionInputSource): void {
const { maxScroll } = layoutText(text);
const forward = eventType === SCROLL_BOTTOM_EVENT;
const atEnd = forward ? maxScroll - text.scrollY < TEXT_SCROLL_EDGE_PX : text.scrollY < TEXT_SCROLL_EDGE_PX;
if (maxScroll === 0 || atEnd) {
this.emitTextEvent(text, eventType, inputSource);
return;
}
text.scrollY = forward
? Math.min(maxScroll, text.scrollY + TEXT_SCROLL_STEP_PX)
: Math.max(0, text.scrollY - TEXT_SCROLL_STEP_PX);
this.windowHooks?.requestRender();
}
private scrollList(list: EvenHubListContainer, eventType: number, inputSource?: ExtensionInputSource): void {
// Swipe up selects the previous item, swipe down the next (stock direction).
const delta = eventType === SCROLL_TOP_EVENT ? -1 : 1;
@@ -808,7 +856,8 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
deliverImu(reading: ImuReading): void {
this.pushEvenHubEvent("sysEvent", {
eventType: IMU_DATA_REPORT_EVENT,
imuData: { x: reading.x, y: reading.y, z: reading.z },
// The Even app's field name (protobuf IMU_Data); the SDK reads it as imuData.
iMUData: { x: reading.x, y: reading.y, z: reading.z },
});
}
@@ -858,7 +907,8 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
const first = args[0];
const message = asRecord(typeof first === "string" ? JSON.parse(first) : first);
const method = readString(message, "method", "");
const data = asRecord(message.data);
// As the Even app: `data`, else `payload`.
const data = asRecord(message.data ?? message.payload);
result = await this.dispatch(method, data);
} catch (error) {
this.log(`evenhub bridge call failed: ${error}`);
@@ -916,13 +966,29 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
private async createStartUpPage(data: Record<string, unknown>): Promise<number> {
if (this.pageCreated) {
// One-shot per session on stock: a second call blocks ~2s, then fails.
this.layoutLog(() => ["createStartUpPageContainer: repeated call, rejected as stock does"]);
await delay(DUPLICATE_CREATE_DELAY_MS);
return 1;
}
// The Even app refuses some payloads without sending them; then the
// firmware may fail to build the page.
const payloadError = stockPayloadError("create", data);
if (payloadError) {
this.layoutLog(() => [`createStartUpPageContainer refused, as the Even app would: ${payloadError}`]);
return PAGE_CREATE_INVALID;
}
const page = parsePage(data);
this.warnOnInvalidPage(page, data);
const failure = stockPageFailure(page);
if (failure) {
this.layoutLog(() => [`createStartUpPageContainer failed, as the firmware would: ${failure.reason}`]);
return failure.code;
}
clampToStockLimits(page);
this.warnOnDroppedMenuItems(page, data);
this.layoutLog(() => describePage("createStartUpPageContainer", page, data));
this.page = page;
this.pageCreated = true;
this.extendedLayout = false;
// The launch focus arrived before the page existed; deliver the ENTER now.
if (this.foreground && !this.launchEnterSent) {
this.launchEnterSent = true;
@@ -933,16 +999,39 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
}
private rebuildPage(data: Record<string, unknown>): boolean {
// Also serves as create for apps that fall back to rebuild-on-error.
// Only createStartUpPageContainer starts an EvenHub page on the glasses.
if (!this.pageCreated) {
this.layoutLog(() => ["rebuildPageContainer before createStartUpPageContainer: no page to rebuild"]);
return false;
}
const payloadError = stockPayloadError("rebuild", data);
if (payloadError) {
this.layoutLog(() => [`rebuildPageContainer refused, as the Even app would: ${payloadError}`]);
return false;
}
const page = parsePage(data);
this.warnOnInvalidPage(page, data);
const failure = stockPageFailure(page);
if (failure) {
// The firmware has already torn the old page down; it reports an
// abnormal exit and the Even app closes the app.
this.layoutLog(() => [`rebuildPageContainer failed, as the firmware would: ${failure.reason}; closing the app`]);
this.page = { containers: [], menuItems: [] };
this.windowHooks?.requestRender();
this.emitSysEvent(ABNORMAL_EXIT_EVENT, 0);
this.systemExitSent = true;
setTimeout(() => this.close(), ABNORMAL_EXIT_CLOSE_DELAY_MS);
return false;
}
clampToStockLimits(page);
this.warnOnDroppedMenuItems(page, data);
this.layoutLog(() => describePage("rebuildPageContainer", page, data));
this.page = page;
this.pageCreated = true;
this.extendedLayout = false;
this.windowHooks?.requestRender();
return true;
}
private warnOnInvalidPage(page: EvenHubPage, data: Record<string, unknown>): void {
private warnOnDroppedMenuItems(page: EvenHubPage, data: Record<string, unknown>): void {
const declaredMenuCount = declaredMenuItems(data).length;
if (declaredMenuCount > page.menuItems.length) {
this.log(
@@ -950,64 +1039,106 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
"items (max 10, itemID must be non-zero and unique, itemName at most 32 UTF-8 bytes)",
);
}
// Stock rejects these outright; we accept-and-log until rejection is
// proven necessary for compatibility.
const captures = page.containers.filter((c) => c.kind !== "image" && c.isEventCapture).length;
if (captures !== 1) this.log(`evenhub: page has ${captures} event-capture containers (stock requires exactly 1)`);
const texts = page.containers.filter((c) => c.kind === "text").length;
const images = page.containers.filter((c) => c.kind === "image").length;
if (texts > 8 || images > 4) this.log(`evenhub: page exceeds stock limits (${texts} text, ${images} image)`);
}
private textUpgrade(data: Record<string, unknown>): boolean {
const id = readNumber(data, "containerID", -1);
// containerID is the identity; containerName is optional in the wild (e.g.
// level-even-g2 omits it). Match by id, enforcing the name only when the app
// actually supplies a non-empty one. (updateImage already matches by id.)
const id = readNumber(data, "containerID", 0);
const name = readString(data, "containerName", "");
const container = this.page?.containers.find(
(c) => c.kind === "text" && c.id === id && (name === "" || c.name === name),
);
if (!container || container.kind !== "text") return false;
const content = readString(data, "content", "");
const offset = readOptionalNumber(data, "contentOffset");
// (contentLength is intentionally ignored — see below.)
// Stock semantics are "write `content` at contentOffset and truncate the
// rest" (a null-terminating strcpy(buf+offset, content)), NOT a splice that
// keeps the old tail after offset+contentLength. Keeping the tail left stray
// trailing text when an app (e.g. g2oom) shrank a string with an
// under-sized contentLength; dropping it matches stock and still supports
// suffix rewrites (offset>0) and full replaces (offset 0 / omitted).
if (offset !== undefined && offset > 0) {
container.content = container.content.slice(0, offset) + content;
} else {
container.content = content;
const payloadError = stockPayloadError("textUpgrade", data);
if (payloadError) {
this.layoutLog(() => [`textContainerUpgrade refused, as the Even app would: ${payloadError}`]);
return false;
}
// The firmware finds the container by id alone (its first container with
// that id, of any kind); the name isn't checked anywhere.
const target = containerById(this.page, id);
if (!target) {
this.layoutLog(() => [describeTextUpgrade(id, name, null, offset, content.length)]);
return false;
}
// Aimed at a list or image, the firmware writes into it as if it were
// text and reports success; nothing we could show.
if (target.kind !== "text") return true;
// The content replaces the whole text: stock ignores contentOffset and
// contentLength (firmware 2.2.9.22 in the emulator showed "XY" alone for
// every offset/length tried). The firmware re-sets the label, scrolled
// back to the top, only for non-empty text, so emptying a container
// leaves its old text showing (apps send " " to clear one).
if (content !== "") {
target.content = content;
target.scrollY = 0;
}
// SDK 0.0.14: textColor on an incremental update sets the container's
// brightness; omitting it keeps whatever level the container has.
const brightness = readTextBrightness(data);
if (brightness !== undefined) container.textColor = brightness;
if (brightness !== undefined) target.textColor = brightness;
this.layoutLog(() => [describeTextUpgrade(id, name, target, offset, content.length)]);
this.windowHooks?.requestRender();
return true;
}
/** BleEhSendImageResult: 0 success, 1 imageException, 2 sizeInvalid, 3 sendFailed. */
/** EhImageUpdateResult: 0 success, 1 imageException, 2 sizeInvalid, 3 toGray4Failed, 4 sendFailed. */
private updateImage(data: Record<string, unknown>): number {
const id = readNumber(data, "containerID", -1);
const container = this.page?.containers.find((c) => c.kind === "image" && c.id === id);
if (!container || container.kind !== "image") return 3;
const bytes = imagePayloadBytes(data.imageData ?? data.rawData ?? asRecord(data).mapRawData);
if (!bytes || bytes.length === 0) return 1;
const decoded = decodeImageBytes(bytes, container);
if (!decoded) return 1;
container.pixels = decoded.pixels;
container.pixelsWidth = decoded.width;
container.pixelsHeight = decoded.height;
this.windowHooks?.requestRender();
return 0;
const id = readNumber(data, "containerID", 0);
const name = readString(data, "containerName", "");
const raw = data.imageData;
// Before the page exists (and after shutdown) the Even app fails it outright.
if (!this.pageCreated || !this.page) {
this.layoutLog(() => [`updateImageRawData id=${id}: no page yet, sendFailed`]);
return IMAGE_SEND_FAILED;
}
// The Even app sizes the bitmap from the image container it finds by id,
// then by trimmed name.
const images = this.page.containers.filter((c): c is EvenHubImageContainer => c.kind === "image");
const geometry = (id > 0 ? images.find((c) => c.id === id) : undefined) ??
(name.trim() ? images.find((c) => c.name.trim() === name.trim()) : undefined);
const prepared = prepareImageUpdate({
imageData: raw,
compressMode: readNumber(data, "compressMode", 0),
requestWidth: readNumber(data, "width", 0),
requestHeight: readNumber(data, "height", 0),
geometry: geometry ?? null,
decodeNative: decodeImageRgba,
stockLimits: !this.extendedLayout,
});
// The firmware takes the transfer only for an id whose first container is
// an image, and then shows the bitmap only if it's exactly that size.
const target = containerById(this.page, id);
let result = prepared.result;
let shown = false;
if (result === IMAGE_SUCCESS && target?.kind !== "image") {
result = IMAGE_SEND_FAILED;
} else if (result === IMAGE_SUCCESS && target?.kind === "image" && prepared.levels &&
prepared.width === target.width && prepared.height === target.height) {
target.pixels = prepared.levels.map((level) => level * 17);
target.pixelsWidth = prepared.width;
target.pixelsHeight = prepared.height;
shown = true;
this.windowHooks?.requestRender();
}
this.layoutLog(() => describeImageUpdate({ sentId: id, sentName: name, raw, target, prepared, shown, result }));
return result;
}
/** Debug-level logcat for layouts and updates; `describe` runs only when logging is on. */
private layoutLog(describe: () => string[]): void {
if (!LAYOUT_LOG_ENABLED) return;
try {
const prefix = `[${this.manifest.packageId}] `;
for (const line of describe()) {
for (let i = 0; i < line.length; i += LOGCAT_CHUNK_CHARS) {
android.util.Log.d(LAYOUT_LOG_TAG, prefix + line.slice(i, i + LOGCAT_CHUNK_CHARS));
}
}
} catch (error) {
console.warn(`evenhub: layout log failed: ${error}`);
}
}
private shutDown(exitMode: number): boolean {
this.layoutLog(() => [`shutDownPageContainer exitMode=${exitMode}`]);
if (exitMode === 1) {
// The app asked to quit (stock would pop an on-glasses confirm). We
// decline and hand focus to the app switcher instead, leaving the app
@@ -1075,6 +1206,15 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
this.pushEvenHubEvent("sysEvent", { eventType, eventSource, [INPUT_SOURCE_FIELD]: inputSource });
}
private emitTextEvent(text: EvenHubTextContainer, eventType: number, inputSource?: ExtensionInputSource): void {
this.pushEvenHubEvent("textEvent", {
containerID: text.id,
containerName: text.name,
eventType,
[INPUT_SOURCE_FIELD]: inputSource,
});
}
private emitListEvent(list: EvenHubListContainer, eventType: number, inputSource?: ExtensionInputSource): void {
this.pushEvenHubEvent("listEvent", {
containerID: list.id,
@@ -1252,8 +1392,10 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
for (const container of page.containers) {
if (container.preserve) preserveContent(container, previous);
}
this.layoutLog(() => describePage("extension layout", page, data));
this.page = page;
this.pageCreated = true;
this.extendedLayout = true;
// The extended layout uses the taller app area.
this.windowHooks?.setTallCanvas(true);
if (this.foreground && !this.launchEnterSent) {
@@ -1559,82 +1701,6 @@ function normalizeBuzzerSteps(raw: unknown[]): Step[] {
return out;
}
/**
* Decode an uncompressed Windows BMP ('BM', BI_RGB) to 8bpp grayscale. Handles
* 1/4/8-bit paletted and 24/32-bit BGR(A), top-down or bottom-up. Returns null
* for compressed or unsupported variants. Apps like EvenChess send 1-bit BMPs
* (black/white palette) for full-board refreshes.
*/
function decodeBmp(bytes: Uint8Array): { pixels: Uint8Array; width: number; height: number } | null {
if (bytes.length < 54 || bytes[0] !== 0x42 || bytes[1] !== 0x4d) return null;
const u16 = (o: number) => bytes[o]! | (bytes[o + 1]! << 8);
const u32 = (o: number) => (bytes[o]! | (bytes[o + 1]! << 8) | (bytes[o + 2]! << 16) | (bytes[o + 3]! << 24)) >>> 0;
const i32 = (o: number) => bytes[o]! | (bytes[o + 1]! << 8) | (bytes[o + 2]! << 16) | (bytes[o + 3]! << 24);
const pixelOffset = u32(10);
const dibSize = u32(14);
const width = i32(18);
const heightRaw = i32(22);
const bitCount = u16(28);
const compression = u32(30);
if (compression !== 0) return null; // only BI_RGB (uncompressed)
if (width <= 0 || width > 4096) return null;
const topDown = heightRaw < 0;
const height = Math.abs(heightRaw);
if (height === 0 || height > 4096) return null;
// Palette (grayscale per index) for <=8bpp; each entry is 4 bytes BGRA.
let palette: Uint8Array | null = null;
if (bitCount <= 8) {
let numColors = u32(46);
if (numColors === 0 || numColors > (1 << bitCount)) numColors = 1 << bitCount;
const palOffset = 14 + dibSize;
palette = new Uint8Array(numColors);
for (let i = 0; i < numColors; i++) {
const o = palOffset + i * 4;
if (o + 2 >= bytes.length) break;
palette[i] = luminance(bytes[o + 2]!, bytes[o + 1]!, bytes[o]!);
}
}
const stride = (((width * bitCount + 31) >> 5) << 2); // rows are 4-byte aligned
const pixels = new Uint8Array(width * height);
for (let y = 0; y < height; y++) {
const srcY = topDown ? y : height - 1 - y;
const rowStart = pixelOffset + srcY * stride;
if (rowStart >= bytes.length) break;
const dstRow = y * width;
for (let x = 0; x < width; x++) {
let gray: number;
if (bitCount === 1) {
const bit = ((bytes[rowStart + (x >> 3)] ?? 0) >> (7 - (x & 7))) & 1;
gray = palette?.[bit] ?? (bit ? 255 : 0);
} else if (bitCount === 4) {
const byte = bytes[rowStart + (x >> 1)] ?? 0;
const nib = (x & 1) === 0 ? byte >> 4 : byte & 0x0f;
gray = palette?.[nib] ?? nib * 17;
} else if (bitCount === 8) {
const idx = bytes[rowStart + x] ?? 0;
gray = palette?.[idx] ?? idx;
} else if (bitCount === 24) {
const o = rowStart + x * 3;
gray = luminance(bytes[o + 2] ?? 0, bytes[o + 1] ?? 0, bytes[o] ?? 0);
} else if (bitCount === 32) {
const o = rowStart + x * 4;
gray = luminance(bytes[o + 2] ?? 0, bytes[o + 1] ?? 0, bytes[o] ?? 0);
} else {
return null;
}
pixels[dstRow + x] = gray;
}
}
return { pixels, width, height };
}
function luminance(r: number, g: number, b: number): number {
return Math.round(0.2126 * r + 0.7152 * g + 0.0722 * b);
}
/**
* Input-device names in the extension API: the touchDown event's source, and
* the `faceclawInputSource` field added to stock gesture events.
@@ -1686,97 +1752,3 @@ function elideZeroFields(obj: Record<string, unknown>): Record<string, unknown>
return out;
}
/** Accept the payload forms seen on the wire: number[], JSON-ified typed
* array ({"0": 1, ...}), or base64 string. */
function imagePayloadBytes(raw: unknown): Uint8Array | null {
if (Array.isArray(raw)) {
const out = new Uint8Array(raw.length);
for (let i = 0; i < raw.length; i++) out[i] = Number(raw[i]) & 0xff;
return out;
}
if (typeof raw === "string") return base64Decode(raw);
if (raw && typeof raw === "object") {
const record = raw as Record<string, unknown>;
const keys = Object.keys(record);
const out = new Uint8Array(keys.length);
for (let i = 0; i < keys.length; i++) {
const value = record[String(i)];
if (typeof value !== "number") return null;
out[i] = value & 0xff;
}
return out;
}
return null;
}
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function base64Decode(text: string): Uint8Array | null {
const clean = text.replace(/[\s=]+$/g, "").replace(/\s+/g, "");
const out = new Uint8Array(Math.floor((clean.length * 3) / 4));
let bits = 0;
let bitCount = 0;
let outIndex = 0;
for (const char of clean) {
const value = BASE64_ALPHABET.indexOf(char);
if (value < 0) return null;
bits = (bits << 6) | value;
bitCount += 6;
if (bitCount >= 8) {
bitCount -= 8;
out[outIndex++] = (bits >> bitCount) & 0xff;
}
}
return out.subarray(0, outIndex);
}
/**
* Decode an image payload: PNG or BMP (both are sent by real apps — EvenChess
* force-refreshes as 1-bit BMP but streams live moves as PNG, so a host that
* only did PNG dropped the initial board), or raw grayscale sized to the
* container (8bpp, or 4bpp packed two pixels per byte, high nibble first).
*/
function decodeImageBytes(
bytes: Uint8Array,
container: EvenHubImageContainer,
): { pixels: Uint8Array; width: number; height: number } | null {
if (bytes.length > 2 && bytes[0] === 0x42 && bytes[1] === 0x4d) {
const bmp = decodeBmp(bytes);
if (bmp) return bmp;
}
if (bytes.length > 4 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) {
try {
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
const decoded = UPNG.decode(buffer);
const frames = UPNG.toRGBA8(decoded) as ArrayBuffer[];
if (!frames.length) return null;
const rgba = new Uint8Array(frames[0]!);
const pixels = new Uint8Array(decoded.width * decoded.height);
for (let i = 0; i < pixels.length; i++) {
const offset = i * 4;
const alpha = (rgba[offset + 3] ?? 0) / 255;
pixels[i] = Math.round(
(0.2126 * (rgba[offset] ?? 0) + 0.7152 * (rgba[offset + 1] ?? 0) + 0.0722 * (rgba[offset + 2] ?? 0)) * alpha,
);
}
return { pixels, width: decoded.width, height: decoded.height };
} catch (error) {
console.warn(`evenhub: PNG decode failed: ${error}`);
return null;
}
}
const area = container.width * container.height;
if (bytes.length === area) {
return { pixels: Uint8Array.from(bytes), width: container.width, height: container.height };
}
if (bytes.length === Math.ceil(area / 2)) {
const pixels = new Uint8Array(area);
for (let i = 0; i < area; i++) {
const byte = bytes[i >> 1]!;
const nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;
pixels[i] = nibble * 17;
}
return { pixels, width: container.width, height: container.height };
}
return null;
}
+110 -20
View File
@@ -1,7 +1,7 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage, type UiFont } from "../../graphics/image";
import { truncateText, wrapText } from "../../graphics/textwrap";
import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures";
import { directionalFallback, GESTURE_CLICK, isDirectionalInput, type InputEvent } from "../../ui/gestures";
import { type Layer, type LayerActions, type LayerContext, type LayerStack } from "../../ui/layers";
import { drawSelectionHighlight, type MenuItem } from "../../ui/menu";
import { Menu } from "../../ui/menu-core";
@@ -14,6 +14,7 @@ import { EvenHubStoreDetailLayer, type EvenHubStoreDetailOptions } from "./store
import { cleanError, installStoreApp } from "./store-install";
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
import { lineStep } from "../../ui/metrics";
import { isEvenHubStoreAvailable } from "./glasses-compat";
const LIST_X = 18;
/** Horizontal gap between tab labels. */
@@ -55,7 +56,32 @@ type StoreRow =
/** The Search tab's first row: shows the query and opens the phone editor. */
| { kind: "search-query" }
/** A registry entry whose package is gone and which the store no longer lists. */
| { kind: "orphan"; update: EvenHubAppUpdate };
| { kind: "orphan"; update: EvenHubAppUpdate }
/** The Updates tab's first row while any update is installable; `busy` while Update All runs. */
| { kind: "update-all"; count: number; busy: boolean };
type AppRow = Extract<StoreRow, { kind: "app" }>;
/** An Updates row that installing the store's version would satisfy. */
function isUpdatableRow(row: StoreRow): row is AppRow {
return row.kind === "app" && row.update !== undefined;
}
/** An Updates row for one installed app (not the Update All row). */
function isInstalledAppRow(row: StoreRow): boolean {
return row.kind === "app" || row.kind === "orphan";
}
function rowPackageId(row: StoreRow): string | undefined {
switch (row.kind) {
case "app":
return row.app.packageId;
case "orphan":
return row.update.installed.packageId;
default:
return undefined;
}
}
type TabState = {
rows: StoreRow[];
@@ -118,10 +144,18 @@ export type EvenHubStoreLayerOptions = {
* The EvenHub storefront: Top (leaderboard), New (by first publication),
* Search, and Updates (installed apps that are stale or whose package is
* missing). The tab row is its own focus level above the list: double-click
* in the list focuses the tabs, scrolling there switches tabs, and a click
* returns to the list.
* in the list focuses the tabs, scrolling (or a watch swipe in any direction)
* there switches tabs, and a click returns to the list.
*
* With glasses that can't use the store (a RayNeo iO; see glasses-compat.ts)
* it shows only a notice saying so, and loads nothing. That is checked on
* every paint and input, so a window open across a re-pair follows the
* glasses either way.
*/
export class EvenHubStoreLayer implements Layer {
/** Swipes left/right switch tabs on the tab strip; elsewhere they get the usual fallback. */
readonly acceptsDirectional = true;
private readonly tabs: Record<StoreTab, TabState> = {
top: emptyTab(),
new: emptyTab(),
@@ -140,12 +174,15 @@ export class EvenHubStoreLayer implements Layer {
private updatingAll = false;
/** An app page requested while the login form was up; opened once signed in. */
private pendingPackage: InstalledEvenHubApp | null = null;
/** An app page requested while the store was unavailable, named on its notice. */
private unavailablePackageName: string | null = null;
constructor(private readonly options: EvenHubStoreLayerOptions) {
if (this.showingLogin) resetEvenHubLoginForm();
}
paint(ctx: LayerContext): GrayImage {
if (!isEvenHubStoreAvailable()) return this.paintUnavailable(ctx);
if (!this.started) {
this.started = true;
// Do NOT open the phone credential editor here. This runs on the first
@@ -205,6 +242,23 @@ export class EvenHubStoreLayer implements Layer {
return image;
}
/** The notice that replaces the store when the paired glasses can't use it. */
private paintUnavailable(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
image.drawText(font, LIST_X, 8, "EvenHub", 220);
if (this.unavailablePackageName) {
const status = `${this.unavailablePackageName}'s package is missing.`;
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, status, width - LIST_X * 2), 125);
}
const message = "Using the Even Realities app store requires Even Realities glasses.";
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) {
image.drawText(font, LIST_X, headerHeight(font) + 16 + index * lineStep(font), line, 190);
}
return image;
}
/** Tab labels to the right of the title; the active one is bright and underlined. */
private paintTabs(image: GrayImage, font: UiFont, ctx: LayerContext): void {
const tabsFocused = ctx.stack.isFocused() && this.focus === "tabs";
@@ -229,7 +283,7 @@ export class EvenHubStoreLayer implements Layer {
const label = TABS.find((entry) => entry.id === tab)!.label;
if (tab !== "updates") return label;
const updates = this.tabs.updates;
const count = updates.rows.filter((row) => row.kind !== "search-query").length;
const count = updates.rows.filter(isInstalledAppRow).length;
return updates.loaded && count > 0 ? `${label} (${count})` : label;
}
@@ -245,9 +299,11 @@ export class EvenHubStoreLayer implements Layer {
if (!state.query) return "Search public apps";
return results === 1 ? `1 result for "${state.query}"` : `${results} results for "${state.query}"`;
}
case "updates":
case "updates": {
if (!state.loaded) return "Installed apps with newer versions";
return count === 0 ? "All installed apps are up to date" : count === 1 ? "1 app needs attention" : `${count} apps need attention`;
const apps = state.rows.filter(isInstalledAppRow).length;
return apps === 0 ? "All installed apps are up to date" : apps === 1 ? "1 app needs attention" : `${apps} apps need attention`;
}
}
}
@@ -263,7 +319,14 @@ export class EvenHubStoreLayer implements Layer {
}
}
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
async handleInput(rawEvent: InputEvent, ctx: LayerContext): Promise<void> {
if (!isEvenHubStoreAvailable()) {
if (directionalFallback(rawEvent).type === "double-click") shell.yieldFocusToSidebar();
return;
}
const tabSwipe = !this.showingLogin && this.focus === "tabs"
&& (rawEvent.type === "swipe-left" || rawEvent.type === "swipe-right");
const event = isDirectionalInput(rawEvent) && !tabSwipe ? directionalFallback(rawEvent) : rawEvent;
if (this.showingLogin) {
if (event.type === "click" && !this.loginBusy) {
this.openCredentialEditor(ctx);
@@ -301,9 +364,11 @@ export class EvenHubStoreLayer implements Layer {
const index = TABS.findIndex((tab) => tab.id === this.activeTab);
switch (event.type) {
case "scroll-up":
case "swipe-left":
this.switchTab(ctx, TABS[Math.max(0, index - 1)]!.id);
return;
case "scroll-down":
case "swipe-right":
this.switchTab(ctx, TABS[Math.min(TABS.length - 1, index + 1)]!.id);
return;
case "click":
@@ -333,6 +398,9 @@ export class EvenHubStoreLayer implements Layer {
case "search-query":
this.openSearchEditor(ctx);
return;
case "update-all":
void this.updateAll(ctx);
return;
case "orphan": {
// Nothing can be reinstalled; the only useful action is to drop the
// dead registry entry so the launcher stops offering it.
@@ -358,6 +426,12 @@ export class EvenHubStoreLayer implements Layer {
* placeholder built from the registry entry stands in.
*/
showInstalledPackage(stack: LayerStack, installed: InstalledEvenHubApp): void {
if (!isEvenHubStoreAvailable()) {
this.unavailablePackageName = installed.name;
stack.clearToBase();
return;
}
this.unavailablePackageName = null;
if (this.showingLogin) {
this.pendingPackage = installed;
return;
@@ -369,7 +443,7 @@ export class EvenHubStoreLayer implements Layer {
/** Dictated text becomes a search (the shell's "Type Into App" / voice input). */
receiveTextInput(text: string, ctx: LayerContext): void {
if (this.showingLogin) return;
if (this.showingLogin || !isEvenHubStoreAvailable()) return;
const query = evenHubSearchQuerySetting.set(text);
if (!query) return;
this.closePhoneEditor(ctx.actions, "search");
@@ -379,7 +453,7 @@ export class EvenHubStoreLayer implements Layer {
}
buildMenuItems(): MenuItem[] {
if (this.showingLogin) return [];
if (this.showingLogin || !isEvenHubStoreAvailable()) return [];
const items: MenuItem[] = [];
if (this.activeTab === "search") {
items.push({
@@ -532,8 +606,7 @@ export class EvenHubStoreLayer implements Layer {
const rows: StoreRow[] = updates.map((update) =>
update.latest ? { kind: "app", app: update.latest, update } : { kind: "orphan", update },
);
state.rows = rows;
state.menu.setItems(rows, 0);
this.setUpdateRows(state, rows, 0);
state.menu.scrollTop = 0;
state.status = "";
state.exhausted = true;
@@ -548,10 +621,20 @@ export class EvenHubStoreLayer implements Layer {
}
}
private updatableRows(): Extract<StoreRow, { kind: "app" }>[] {
return this.tabs.updates.rows.filter(
(row): row is Extract<StoreRow, { kind: "app" }> => row.kind === "app" && row.update !== undefined,
);
private updatableRows(): AppRow[] {
return this.tabs.updates.rows.filter(isUpdatableRow);
}
/**
* Replace the Updates rows, putting an Update All row on top while any of
* them can be installed (and dropping it once none can).
*/
private setUpdateRows(state: TabState, entries: readonly StoreRow[], selectedIndex?: number): void {
const rows = entries.filter(isInstalledAppRow);
const count = rows.filter(isUpdatableRow).length;
if (count > 0) rows.unshift({ kind: "update-all", count, busy: this.updatingAll });
state.rows = rows;
state.menu.setItems(rows, selectedIndex);
}
/** Install every pending update in turn; a declined permission dialog skips that app. */
@@ -559,6 +642,7 @@ export class EvenHubStoreLayer implements Layer {
if (this.updatingAll) return;
this.updatingAll = true;
const state = this.tabs.updates;
this.setUpdateRows(state, state.rows);
const pending = this.updatableRows();
let installed = 0;
const failures: string[] = [];
@@ -593,6 +677,7 @@ export class EvenHubStoreLayer implements Layer {
: installed === 1 ? "Updated 1 app." : `Updated ${installed} apps.`;
} finally {
this.updatingAll = false;
this.setUpdateRows(this.tabs.updates, this.tabs.updates.rows);
if (!this.closed) ctx.actions.requestRender();
}
}
@@ -609,10 +694,7 @@ export class EvenHubStoreLayer implements Layer {
private removeUpdateRow(packageId: string): void {
const state = this.tabs.updates;
state.rows = state.rows.filter((row) =>
row.kind === "search-query" ? true : row.kind === "app" ? row.app.packageId !== packageId : row.update.installed.packageId !== packageId,
);
state.menu.setItems(state.rows);
this.setUpdateRows(state, state.rows.filter((row) => rowPackageId(row) !== packageId));
}
// ---- login and phone editors --------------------------------------------
@@ -751,6 +833,14 @@ function rowText(row: StoreRow): { title: string; detail: string; titleValue: nu
titleValue: 200,
};
}
case "update-all":
return {
title: row.busy ? "Updating..." : "Update All",
detail: row.busy
? "Installing updates; progress is shown above."
: row.count === 1 ? "Install the 1 available update" : `Install all ${row.count} available updates`,
titleValue: row.busy ? 150 : 230,
};
case "orphan":
return {
title: row.update.installed.name,
+50 -19
View File
@@ -1,4 +1,4 @@
import { ConfigSettingBoolean, ConfigSettingEnum } from "../../ui/dashboard-settings";
import { ConfigSettingBoolean, ConfigSettingEnum, glassesHaveCompass } from "../../ui/dashboard-settings";
import { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout";
import { type GlanceWidgetId } from "./widget";
import { glanceWidgetSpans } from "./widgets";
@@ -23,6 +23,11 @@ export function glanceSlotChoiceLabel(choice: GlanceSlotChoice): string {
return SLOT_CHOICE_LABELS[choice] ?? choice;
}
/** Whether the paired glasses can drive this widget; if not, it is left out of the slot picker. */
function slotChoiceAvailable(choice: GlanceSlotChoice): boolean {
return choice !== "compass" || glassesHaveCompass();
}
/**
* Slot order follows QUADRANT_LAYOUT: top left, top right, bottom left, bottom
* right. Calendar in both right slots merges into one double-height region.
@@ -56,9 +61,28 @@ export const glanceboardEnabledSetting = new ConfigSettingBoolean({
"While the display is asleep, a tap, a long-press or a head-tilt shows the Glanceboard instead of the regular UI. Double-tap still wakes the regular UI.",
});
export type GlanceTapDuration = "off" | "3s" | "5s" | "7s" | "10s";
const TAP_DURATION_SECONDS = {
"3s": 3,
"5s": 5,
"7s": 7,
"10s": 10,
"20s": 20,
"30s": 30,
"1min": 60,
} as const;
const DEFAULT_TAP_DURATION: GlanceTapDuration = "5s";
type GlanceTapDurationTimed = keyof typeof TAP_DURATION_SECONDS;
export type GlanceTapDuration = "off" | GlanceTapDurationTimed;
const TAP_DURATION_VALUES: readonly GlanceTapDuration[] = ["off", ...(Object.keys(TAP_DURATION_SECONDS) as GlanceTapDurationTimed[])];
const DEFAULT_TAP_DURATION: GlanceTapDurationTimed = "5s";
function formatTapDuration(value: GlanceTapDuration): string {
if (value === "off") return "Disabled";
const seconds = TAP_DURATION_SECONDS[value];
return seconds % 60 === 0 ? `${seconds / 60} min` : `${seconds} s`;
}
/**
* How long a tap (or head-tilt) keeps the board up; each further tap restarts
@@ -70,8 +94,8 @@ export const glanceTapDurationSetting = new ConfigSettingEnum<GlanceTapDuration>
label: "Show on tap",
storageKey: "glanceboard.tapDuration",
defaultValue: DEFAULT_TAP_DURATION,
values: ["off", "3s", "5s", "7s", "10s"],
formatValue: (value) => (value === "off" ? "Disabled" : value.replace("s", " s")),
values: TAP_DURATION_VALUES,
formatValue: formatTapDuration,
description:
"How long a single tap (or a head-tilt) keeps the Glanceboard on screen. Disabled: a single tap does not show the Glanceboard.",
});
@@ -83,8 +107,7 @@ export function glanceShowOnTap(): boolean {
export function glanceTapTimeoutMs(): number {
const duration = glanceTapDurationSetting.get();
const seconds = duration === "off" ? DEFAULT_TAP_DURATION : duration;
return Number.parseInt(seconds, 10) * 1000;
return TAP_DURATION_SECONDS[duration === "off" ? DEFAULT_TAP_DURATION : duration] * 1000;
}
/** A long-press holds the board up until the press is released. */
@@ -146,18 +169,26 @@ export const glanceShowLinesSetting = new ConfigSettingBoolean({
export function glanceSlotSettings(layout: GlanceLayout = glanceLayout()): ConfigSettingEnum<GlanceSlotChoice>[] {
const grid = layout === QUADRANT_LAYOUT || layout === SIX_SLOT_LAYOUT;
const storageId = grid ? QUADRANT_LAYOUT.id : layout.id;
return layout.slots.map(
(slot, index) =>
new ConfigSettingEnum<GlanceSlotChoice>({
id: `glanceboard-${layout.id}-slot-${index}`,
label: slot.label,
storageKey: `glanceboard.${storageId}.slot.${index}`,
defaultValue: (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none",
values: SLOT_CHOICES,
formatValue: glanceSlotChoiceLabel,
description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`,
}),
);
return layout.slots.map((slot, index) => {
const defaultValue: GlanceSlotChoice = (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none";
return new ConfigSettingEnum<GlanceSlotChoice>({
id: `glanceboard-${layout.id}-slot-${index}`,
label: slot.label,
storageKey: `glanceboard.${storageId}.slot.${index}`,
defaultValue,
values: SLOT_CHOICES.filter(slotChoiceAvailable),
// A stored choice the glasses can't drive reads as Empty, not the slot's
// default (which could put a widget on the board twice). The stored value
// stays, so pairing glasses that can drive it brings it back.
normalize: (value) => {
const choice = value as GlanceSlotChoice;
if (!SLOT_CHOICES.includes(choice)) return defaultValue;
return slotChoiceAvailable(choice) ? choice : "none";
},
formatValue: glanceSlotChoiceLabel,
description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`,
});
});
}
/**
+2 -1
View File
@@ -18,6 +18,7 @@ import {
batteryIndicatorVisible,
ConfigSettingBoolean,
glassesBatteryVisibilitySetting,
glassesModelName,
onAnySettingChanged,
phoneBatteryVisibilitySetting,
ringBatteryVisibilitySetting,
@@ -328,7 +329,7 @@ function collectBatteryItems(): BatteryItem[] {
push(phoneBatteryVisibilitySetting.get(), "Phone", "phone", phone.battery, phone.charging);
const levels = shell.getBatteryLevels();
push(watchBatteryVisibilitySetting.get(), "Watch", "watch", levels.watch, levels.watchCharging);
push(glassesBatteryVisibilitySetting.get(), "G2", "glasses", levels.headset, levels.headsetCharging);
push(glassesBatteryVisibilitySetting.get(), glassesModelName(), "glasses", levels.headset, levels.headsetCharging);
if (levels.ring !== null && Number.isInteger(levels.ring) && levels.ring >= 0 && levels.ring <= 100) {
push(ringBatteryVisibilitySetting.get(), "R1", "ring", levels.ring, levels.ringCharging);
}
+1 -1
View File
@@ -11,7 +11,7 @@ import {
export function launcherEntries(apps: readonly AppDefinition[]) {
return [
...apps
.filter((app) => app.showInLauncher !== false)
.filter((app) => app.showInLauncher !== false && app.isSupported?.() !== false)
.map((app) => ({
appId: app.appId,
label: app.title,
+2 -1
View File
@@ -84,7 +84,8 @@ function buildNightscoutTrayIcon(state: NightscoutState): GrayImage {
const font = getDefaultSmallFont();
const nowMs = Date.now();
const label = state.latest ? `${state.latest.sgv}` : "--";
const labelWidth = font.measureText(label);
// A TTF face measures fractionally; the icon's size and layout need whole pixels.
const labelWidth = Math.ceil(font.measureText(label));
const warning = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs).any;
const graphEnd = labelWidth + 4 + TRAY_GRAPH_WIDTH;
const image = new GrayImage(graphEnd + (warning ? 24 : 0), TRAY_HEIGHT, 0);
+6 -1
View File
@@ -14,7 +14,12 @@ const notificationsApp: AppDefinition = {
if (listenerState === "no-access" || listenerState === "stuck") {
requestNotificationListenerAccess();
}
return ctx.launchInProcessApp(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow);
return ctx.launchInProcessApp(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, (options) =>
createNotificationsAppWindow(options, (section) => {
void ctx.launchApp("settings", { section }).catch((error) => {
ctx.appendLog(`settings launch failed: ${error}`);
});
}));
},
};
+9 -5
View File
@@ -1,5 +1,5 @@
import { NotificationsListLayer } from "../../ui/notifications";
import { NotificationFilterLayer } from "../../ui/notification-filter";
import { NOTIFICATIONS_SETTINGS_SECTION } from "../../ui/dashboard/settings-menus";
import { ALL_NOTIFICATIONS, dismissAllNotifications, onAndroidNotificationsChanged, readActiveNotifications } from "../../native/notification-icons";
import {
createInProcessWindow,
@@ -14,9 +14,13 @@ export const NOTIFICATIONS_SURFACE_ID = "window:notifications";
/**
* The Notifications app: the Android-notification list (previously a
* dashboard page) in its own in-process window; selecting a notification
* opens the detail view with its quick actions.
* opens the detail view with its quick actions. `openSettings` opens a
* Settings section (the menu's "Settings" goes to Notifications).
*/
export function createNotificationsAppWindow(options: InProcessAppOptions): InProcessWindow {
export function createNotificationsAppWindow(
options: InProcessAppOptions,
openSettings: (section: string) => void,
): InProcessWindow {
// Newly posted notifications repaint the list while the window is open.
let offNotificationsChanged: (() => void) | null = null;
const created = createInProcessWindow({
@@ -27,10 +31,10 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
icon: "bell",
closeable: true,
menuItems: () => [{
label: "Notification filter",
label: "Settings",
onSelect: (ctx) => {
ctx.stack.pop();
ctx.stack.push(new NotificationFilterLayer());
openSettings(NOTIFICATIONS_SETTINGS_SECTION);
},
}, {
label: "Dismiss all notifications",
-43
View File
@@ -1,43 +0,0 @@
import { IOS_PRIVACY_NOTICE } from "../../analytics/privacy-disclosure";
import type { GrayImage } from "../../graphics/image";
import { wrapText } from "../../graphics/textwrap";
import type { InputEvent } from "../../ui/gestures";
import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
/** Paginate the notice so no disclosure is silently clipped on a short glasses viewport. */
export class IosPrivacyPage implements OnboardingPage {
readonly immersive = true;
private page = 0;
private pageCount = 1;
enter(): void { this.page = 0; }
paint(image: GrayImage): void {
const top = drawPageHeading(image, "iOS / TestFlight privacy", "") + 8;
const font = onboardingFont("detail");
const lines = IOS_PRIVACY_NOTICE.split("\n\n").flatMap((paragraph, index) => [
...(index ? [""] : []), ...wrapText(font, paragraph, image.width - 2 * PAGE_X),
]);
const perPage = Math.max(1, Math.floor((image.height - top - font.lineHeight - 20) / font.lineHeight));
this.pageCount = Math.ceil(lines.length / perPage);
this.page = Math.min(this.page, this.pageCount - 1);
lines.slice(this.page * perPage, (this.page + 1) * perPage).forEach((line, index) => {
image.drawText(font, PAGE_X, top + index * font.lineHeight, line, 200);
});
const action = this.page + 1 < this.pageCount ? "Tap for more" : "Tap to choose statistics";
image.drawText(font, PAGE_X, image.height - font.lineHeight - 8,
`${this.page + 1}/${this.pageCount} - ${action}`, 230);
}
handleInput(event: InputEvent, nav: OnboardingNav): void {
if (event.type === "click") {
if (this.page + 1 < this.pageCount) this.page++;
else nav.next();
} else if (event.type === "scroll-down" || event.type === "swipe-up") {
this.page = Math.min(this.page + 1, this.pageCount - 1);
} else if (event.type === "scroll-up" || event.type === "swipe-down") {
this.page = Math.max(0, this.page - 1);
}
}
}
+22 -11
View File
@@ -3,9 +3,9 @@
* page: to scale in real-display pixels, simplified, and drawn brighter
* than the real chrome, which they shrink to a few pixels.
*/
import { G2_LENS_WIDTH, type GrayImage } from "../../graphics/image";
import type { GrayImage } from "../../graphics/image";
import { statusBarPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
import { SIDEBAR_WIDTH, SWITCHER_ROW_HEIGHT, MIN_WINDOW_HEIGHT, TOP_BAR_HEIGHT } from "../../ui/shell/geometry";
import { MIN_WINDOW_HEIGHT, screenHeight, screenWidth, SIDEBAR_WIDTH, SWITCHER_ROW_HEIGHT, TOP_BAR_HEIGHT } from "../../ui/shell/geometry";
export const AREA_OUTLINE = 30;
const CHROME_LINE = 100;
@@ -80,14 +80,14 @@ export function drawLayout(d: Diagram, position: AppSwitcherPosition, band: Diag
switch (position) {
case "left":
case "right": {
const stripLeft = position === "left" ? 0 : G2_LENS_WIDTH - SIDEBAR_WIDTH;
const stripLeft = position === "left" ? 0 : screenWidth() - SIDEBAR_WIDTH;
const contentLeft = position === "left" ? SIDEBAR_WIDTH : 0;
const windowWidth = G2_LENS_WIDTH - SIDEBAR_WIDTH;
const windowWidth = screenWidth() - SIDEBAR_WIDTH;
drawStatusBar(d, contentLeft, top, windowWidth, TOP_BAR_HEIGHT - 1);
drawContent(d, contentLeft, top + TOP_BAR_HEIGHT, windowWidth, height - TOP_BAR_HEIGHT, 1);
// The strip keeps to the 288px band's height, even beside taller windows.
// The strip keeps to the min band's height (288px, or the whole short screen), even beside taller windows.
const separator = position === "left" ? SIDEBAR_WIDTH - 1 : stripLeft;
d.vline(separator, top + TOP_BAR_HEIGHT, MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT, CHROME_LINE);
d.vline(separator, top + TOP_BAR_HEIGHT, diagramBandHeight("left") - TOP_BAR_HEIGHT, CHROME_LINE);
// One column of icons against the separator.
const column = position === "left" ? SIDEBAR_WIDTH - 36 : stripLeft;
for (let slot = 0; slot < 4; slot++) drawIcon(d, column + 2, top + TOP_BAR_HEIGHT + 10 + slot * 40, slot === 0);
@@ -131,11 +131,11 @@ export function drawLayout(d: Diagram, position: AppSwitcherPosition, band: Diag
}
}
/** A bottom row or popup layout's window: centred at 576 wide and framed, or the panel's width without a frame. */
/** A bottom row or popup layout's window: centred, SIDEBAR_WIDTH narrower, framed; or the screen's width without a frame. */
function windowSpan(band: DiagramBand): { left: number; width: number; framed: boolean } {
return band.fullWidth
? { left: 0, width: G2_LENS_WIDTH, framed: false }
: { left: SIDEBAR_WIDTH / 2, width: G2_LENS_WIDTH - SIDEBAR_WIDTH, framed: true };
? { left: 0, width: screenWidth(), framed: false }
: { left: SIDEBAR_WIDTH / 2, width: screenWidth() - SIDEBAR_WIDTH, framed: true };
}
/**
@@ -173,5 +173,16 @@ function drawContent(d: Diagram, x: number, y: number, width: number, height: nu
}
}
/** Real-display rows the Layout page's diagrams cover: a 288px band and a bottom switcher row under it. */
export const LAYOUT_AREA_HEIGHT = MIN_WINDOW_HEIGHT + SWITCHER_ROW_HEIGHT;
/**
* Real-display rows the Layout page's diagrams cover: a 288px band and a
* bottom switcher row under it, or the whole screen where that is shorter
* (the RayNeo iO's 220 rows).
*/
export function layoutAreaHeight(): number {
return Math.min(MIN_WINDOW_HEIGHT + SWITCHER_ROW_HEIGHT, screenHeight());
}
/** A layout's min-height band within the diagram area: 288px, less a bottom row where the screen is short. */
export function diagramBandHeight(position: AppSwitcherPosition): number {
return Math.min(MIN_WINDOW_HEIGHT, layoutAreaHeight() - (position === "bottom" ? SWITCHER_ROW_HEIGHT : 0));
}
+26 -19
View File
@@ -1,9 +1,9 @@
import { G2_LENS_WIDTH, type GrayImage, type UiFont } from "../../graphics/image";
import { appSwitcherPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
import type { GrayImage, UiFont } from "../../graphics/image";
import { appSwitcherPositionSetting, glassesTypeSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
import type { InputEvent } from "../../ui/gestures";
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
import { MIN_WINDOW_HEIGHT } from "../../ui/shell/geometry";
import { AREA_OUTLINE, Diagram, drawLayout, LAYOUT_AREA_HEIGHT } from "./layout-diagram";
import { screenWidth } from "../../ui/shell/geometry";
import { AREA_OUTLINE, Diagram, diagramBandHeight, drawLayout, layoutAreaHeight } from "./layout-diagram";
import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
@@ -19,8 +19,13 @@ const ROW_GAP = 6;
const DEPTH_SUBTITLE = "Customizable Depth";
/** Grid order, in rows of two: the layouts with depth on top. */
const LAYOUT_ORDER: readonly AppSwitcherPosition[] = ["bottom", "popup", "left", "right"];
/** Selected on the first visit, and marked. */
const RECOMMENDED_LAYOUT: AppSwitcherPosition = "bottom";
/**
* Selected on the first visit, and marked: Bottom on the G2, whose 480 rows
* leave room for the row; a side strip on the RayNeo iO, whose 220 can't.
*/
export function recommendedLayout(): AppSwitcherPosition {
return glassesTypeSetting.get() === "rayneo-io" ? "left" : "bottom";
}
/** Whether a layout leaves the side margins the display's stereo depth shifts into (geometry.ts uiDepth). */
export function layoutHasDepth(position: AppSwitcherPosition): boolean {
@@ -29,7 +34,7 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
/**
* The app switcher position, as a 2×2 grid of captioned diagrams of each
* layout, Bottom (recommended, and selected at first) and Popup on top;
* layout, Bottom and Popup on top, the recommended one selected at first;
* swipes move through them in reading order, a tap saves the selected one.
* The page is immersive, so the diagrams get 40% of the display's width
* each. Choosing a layout reflows open windows (the dashboard controller
@@ -38,7 +43,7 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
export class LayoutPage implements OnboardingPage {
readonly immersive = true;
/** Kept across visits, so going back returns to the last choice. */
private selected = LAYOUT_ORDER.indexOf(RECOMMENDED_LAYOUT);
private selected = LAYOUT_ORDER.indexOf(recommendedLayout());
paint(image: GrayImage, focused: boolean): void {
const top = drawPageHeading(
@@ -53,11 +58,11 @@ export class LayoutPage implements OnboardingPage {
// Short of DIAGRAM_SCALE only where two rows of cells wouldn't fit.
const scale = Math.min(
DIAGRAM_SCALE,
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / LAYOUT_AREA_HEIGHT,
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / G2_LENS_WIDTH,
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / layoutAreaHeight(),
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / screenWidth(),
);
const diagramWidth = Math.round(G2_LENS_WIDTH * scale);
const diagramHeight = Math.round(LAYOUT_AREA_HEIGHT * scale);
const diagramWidth = Math.round(screenWidth() * scale);
const diagramHeight = Math.round(layoutAreaHeight() * scale);
const cellWidth = diagramWidth + 2 * CELL_PADDING;
const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight;
const left = Math.round((image.width - 2 * cellWidth - COLUMN_GAP) / 2);
@@ -75,7 +80,7 @@ export class LayoutPage implements OnboardingPage {
image.drawText(font, x + Math.round((cellWidth - font.measureText(text)) / 2), textY, text, value);
const captionTop = y + CELL_PADDING + diagramHeight + CAPTION_GAP;
const name = appSwitcherPositionSetting.displayValue(position);
const caption = position === RECOMMENDED_LAYOUT ? `${name} (Recommended)` : name;
const caption = position === recommendedLayout() ? `${name} (Recommended)` : name;
centre(caption, title, captionTop, selected ? 255 : 190);
if (layoutHasDepth(position)) {
centre(DEPTH_SUBTITLE, subtitle, captionTop + title.lineHeight, selected ? 210 : 150);
@@ -103,12 +108,14 @@ export class LayoutPage implements OnboardingPage {
}
/**
* A layout's diagram: the 288px band, with the popup switcher open. Only a
* bottom switcher row takes rows under the band; without one, the band sits
* centred in their place, as the band and row share the screen's slack.
* A layout's diagram: the min-height band, with the popup switcher open.
* Only a bottom switcher row takes rows under the band; without one, the
* band sits centred in their place, as the band and row share the screen's
* slack (none on a screen as short as the RayNeo iO's: the band fills it).
*/
function drawLayoutDiagram(d: Diagram, position: AppSwitcherPosition): void {
d.outline(0, 0, G2_LENS_WIDTH, LAYOUT_AREA_HEIGHT, AREA_OUTLINE, 12);
const top = position === "bottom" ? 0 : (LAYOUT_AREA_HEIGHT - MIN_WINDOW_HEIGHT) / 2;
drawLayout(d, position, { top, height: MIN_WINDOW_HEIGHT, fullWidth: false }, true);
d.outline(0, 0, screenWidth(), layoutAreaHeight(), AREA_OUTLINE, 12);
const height = diagramBandHeight(position);
const top = position === "bottom" ? 0 : (layoutAreaHeight() - height) / 2;
drawLayout(d, position, { top, height, fullWidth: false }, true);
}
+1 -4
View File
@@ -7,7 +7,6 @@ import { findSoundEffect, playSoundEffect } from "../../ui/sound-effects";
import { DataCollectionPage } from "./data-collection-page";
import { DepthPage } from "./depth-page";
import { DisplayModePage } from "./display-mode-page";
import { IosPrivacyPage } from "./ios-privacy-page";
import { LayoutPage } from "./layout-page";
import { markGlassesOnboardingFinished, ONBOARDING_APP_ID } from "./onboarding-progress";
import type { OnboardingPage } from "./onboarding-page";
@@ -26,9 +25,7 @@ export const ONBOARDING_SURFACE_ID = "window:onboarding";
*/
export function createOnboardingAppWindow(options: InProcessAppOptions): InProcessWindow {
const pages: OnboardingPage[] = [
new WelcomePage(), new TextSizePage(),
...(global.isIOS ? [new IosPrivacyPage()] : []),
new DataCollectionPage(), new LayoutPage(), new DepthPage(), new DisplayModePage(),
new WelcomePage(), new TextSizePage(), new DataCollectionPage(), new LayoutPage(), new DepthPage(), new DisplayModePage(),
];
const app = createInProcessWindow({
appId: ONBOARDING_APP_ID,
+5 -5
View File
@@ -3,6 +3,7 @@ import { installedFontPath } from "../../graphics/installed-fonts";
import { wrapText } from "../../graphics/textwrap";
import { TtfFont } from "../../graphics/ttf-font";
import {
defaultUiFontSize,
fontSelectionLabel,
getDefaultSmallFont,
getUiFontSelection,
@@ -25,8 +26,6 @@ const ROW_GAP = 2;
const NOTE_GAP = 8;
/** The sizes offered here; Settings has the full range. */
const SIZE_CHOICES = FONT_SIZE_CHOICES.filter((size) => size >= 12 && size <= 18);
/** Selected on the first visit, and marked. */
const RECOMMENDED_SIZE = 16;
const RECOMMENDED_NOTE = "Recommended";
/** Drawn while they fit, so smaller sizes visibly show more words. */
const PREVIEW_PARAGRAPHS = [
@@ -41,7 +40,8 @@ type Face =
| { kind: "fixed"; label: string };
/**
* The UI font's size, 12 to 18px (16 recommended, and selected at first),
* The UI font's size, 12 to 18px (the default size recommended, and
* selected at first: 16px, or 14px on the RayNeo iO),
* beside a preview of text in the selected size. The face and weight stay
* as they are (they live in the Settings font picker); a bitmap face has
* only one size, so the page just says so. The size is saved on tap, not
@@ -67,7 +67,7 @@ export class TextSizePage implements OnboardingPage {
if (sizes.length) {
this.face = { kind: "sized", file: selection.file, path, sizes };
// The recommended size the first time; on a return, what was left selected.
this.sizeMenu.setItems(sizes, nearestIndex(sizes, this.sizeMenu.selectedItem ?? RECOMMENDED_SIZE));
this.sizeMenu.setItems(sizes, nearestIndex(sizes, this.sizeMenu.selectedItem ?? defaultUiFontSize()));
return;
}
}
@@ -137,7 +137,7 @@ export class TextSizePage implements OnboardingPage {
const body = onboardingFont("body");
const label = sizeLabel(size);
image.drawText(body, x + 10, y + LIST_ROW_TEXT_INSET, label, selected ? 255 : 190);
if (size !== RECOMMENDED_SIZE) return;
if (size !== defaultUiFontSize()) return;
const detail = onboardingFont("detail");
const noteY = y + Math.round((height - detail.lineHeight) / 2);
image.drawText(detail, x + 10 + body.measureText(label) + NOTE_GAP, noteY, RECOMMENDED_NOTE, selected ? 210 : 150);
+171 -26
View File
@@ -6,9 +6,15 @@
* connected host's heading launches a shell there), and hosts the Manage
* Connections section
* where g2mirror:// connections are added, removed, and toggled.
* - "terminal:view:N": opened by selecting a session in the hub; each has
* its own websocket connection (the protocol allows one attached session
* per connection) and its own xterm emulator.
* - Selecting a session in the hub shows it in the hub's own window: a view
* takes the hub's place in `windows` under the same window id, and
* double-click puts the hub back. The window grows to the view's height
* meanwhile. Sessions already open in a window of their own focus it instead.
* - "terminal:view:N": a session in a window of its own, opened with "Open in
* new window" from the window menu (or by launching a session).
*
* Each view has its own websocket connection (the protocol allows one attached
* session per connection) and its own xterm emulator.
*
* Connections are g2mirror://<token>@<host>[:port] strings (g2mirrors:// for
* TLS), stored as JSON in the settings store (see connections.ts). Each
@@ -69,7 +75,7 @@ import { drawSubmenuIndicator, submenuItem, type MenuItem } from "../../ui/menu"
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { centeredTextY, lineStep, listRowHeight, textInkHeight } from "../../ui/metrics";
import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu";
import { appViewportSize } from "../../ui/shell/geometry";
import { appViewportSize, type WindowHeightMode } from "../../ui/shell/geometry";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
@@ -109,7 +115,10 @@ const LAUNCH_PRESETS_KEY = "terminal.launchPresets";
type BaseWindow = {
windowId: string;
surfaceId: string;
/** Shell-side window title, echoed back in the open-window message. */
/**
* Window menu title: the shell-side window title, echoed back in the
* open-window message, or the session's label for a view in the hub's window.
*/
title: string;
/** Content viewport from the shell's open-window message; grid = viewport / cell. */
viewportWidth: number;
@@ -155,6 +164,11 @@ type HubWindow = BaseWindow & {
type ViewWindow = BaseWindow & {
kind: "view";
/**
* Set when this view is showing in the hub's window rather than one of its
* own: the hub it replaced, which double-click restores.
*/
hub: HubWindow | null;
/** Grid font and integer cell pitch, captured at window creation. */
font: UiFont;
cellWidth: number;
@@ -202,8 +216,13 @@ type PendingView = {
options: G2MirrorClientOptions;
};
type Viewport = { width: number; height: number };
const windows = new Map<string, TerminalWindow>();
const pendingViews = new Map<string, PendingView>();
// Windows waiting on the shell's answer to a set-height-mode, by window id:
// what to do with the viewport it comes back with (see changeWindowHeight).
const pendingHeightChanges = new Map<string, (viewport: Viewport) => void>();
// The view an assistant tool acts on when the terminal isn't foregrounded:
// the last view to be foregrounded or receive input.
let activeViewId: string | null = null;
@@ -338,6 +357,12 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
openWindow(message.windowId, message.surfaceId, message.title, message.viewport);
break;
case "resize-window": {
const heightChange = pendingHeightChanges.get(message.windowId);
if (heightChange) {
pendingHeightChanges.delete(message.windowId);
heightChange(message.viewport);
break;
}
const window = windows.get(message.windowId);
if (!window || (window.viewportWidth === message.viewport.width && window.viewportHeight === message.viewport.height)) break;
window.viewportWidth = message.viewport.width;
@@ -543,18 +568,24 @@ function openWindow(windowId: string, surfaceId: string, title: string, viewport
updateHubAnimation();
}
/** Drop a view's connection for good: its window closed or the hub took its place. */
function stopViewConnection(window: ViewWindow): void {
for (const unsubscribe of window.unsubscribers.splice(0)) {
unsubscribe();
}
if (window.reconnectTimer) {
clearTimeout(window.reconnectTimer);
window.reconnectTimer = null;
}
window.client.stop();
}
function closeWindow(windowId: string): void {
const window = windows.get(windowId);
if (!window) return;
pendingHeightChanges.delete(windowId);
if (window.kind === "view") {
for (const unsubscribe of window.unsubscribers.splice(0)) {
unsubscribe();
}
if (window.reconnectTimer) {
clearTimeout(window.reconnectTimer);
window.reconnectTimer = null;
}
window.client.stop();
stopViewConnection(window);
}
if (window.kind === "hub" && window.mode === "add") {
// Window closed mid-add: shut the phone editor down.
@@ -759,10 +790,11 @@ function routeBell(connectionId: string, socket: string, lastBellAtMs: number):
}
}
if (terminalWakeOnBellSetting.get()) {
// Wake to the belling session's view window, or the hub if it has none.
// The shell drops the message unless the glasses are actually asleep.
// Wake to the belling session's view window, or the hub's window (whatever
// it is showing) if it has none. The shell drops the message unless the
// glasses are actually asleep.
const viewId = viewWindowIdForSocket(connectionId, socket);
const hubId = [...windows.values()].find((window) => window.kind === "hub")?.windowId ?? null;
const hubId = [...windows.values()].find((window) => window.kind === "hub" || window.hub)?.windowId ?? null;
const target = viewId ?? hubId;
if (target) post({ type: "wake-window", windowId: target });
}
@@ -895,6 +927,7 @@ function createViewWindow(
const client = new G2MirrorClient({ ...view.options, cols: gridCols, rows: gridRows });
const window: ViewWindow = {
kind: "view",
hub: null,
windowId,
surfaceId,
title,
@@ -1053,12 +1086,41 @@ function connectedControls(): ControlConnection[] {
return [...controls.values()].filter(isControlConnected);
}
/**
* What the window menu's "Open in new window" does here, if it applies: to the
* session selected in the hub's list, or the session showing in the hub's
* window (which gives way to the list, as a session has one window at a time).
*/
function openInNewWindowAction(window: TerminalWindow): (() => void) | null {
if (window.kind === "hub") {
const row = hubMenu(window).selectedItem?.sessionRow;
if (!row) return null;
return () => {
if (!focusSessionWindow(row.control, row.session)) openViewWindowFor(row.control, row.session);
};
}
const control = window.hub && controls.get(window.connectionId);
if (!control) return null;
return () => returnToHub(window, () => openViewWindow(control, window.socket, window.label));
}
function windowMenuItems(window: TerminalWindow): MenuItem[] {
const items: MenuItem[] = [
const items: MenuItem[] = [];
const openInNewWindow = openInNewWindowAction(window);
if (openInNewWindow) {
items.push({
label: "Open in new window",
onSelect: (ctx) => {
ctx.stack.pop();
openInNewWindow();
},
});
}
items.push(
submenuItem("Settings", (ctx) => {
ctx.stack.push(new WindowMenuLayer("Terminal settings", settingsMenuItems()));
}),
];
);
if (window.kind === "hub") {
const connected = connectedControls();
const multiHost = connected.length > 1;
@@ -1142,8 +1204,14 @@ function handleInput(window: TerminalWindow, event: InputEvent, frameId: number)
return;
}
if (event.type === "double-click") {
// Inside the hub's sub-sections, double-click backs out one level; at the
// top level (and in views) it yields focus to the sidebar as everywhere.
// Inside the hub's sub-sections and a session shown in its window,
// double-click backs out one level; at the top level (and in views with
// windows of their own) it yields focus to the sidebar as everywhere.
if (window.kind === "view" && window.hub) {
frameTimings.finishFrame(frameId, "discarded: terminal returning to the session list");
returnToHub(window);
return;
}
if (window.kind === "hub" && window.mode === "add") {
cancelAddConnection(window);
renderAndSubmit(window, frameId);
@@ -1233,6 +1301,8 @@ type HubItem = {
active?: boolean;
/** Glyph of the view window showing this session (the number column). */
openGlyph?: string | null;
/** The live session this row lists, for the window menu's "Open in new window". */
sessionRow?: { control: ControlConnection; session: G2MirrorSession };
onSelect?: () => void;
};
@@ -1371,13 +1441,9 @@ function hubSessionItems(window: HubWindow): HubItem[] {
label: sessionLabel(session),
active: isSessionActive(control.config.id, session.socket),
openGlyph: viewGlyphForSocket(control.config.id, session.socket),
sessionRow: { control, session },
onSelect: () => {
const windowId = viewWindowIdForSocket(control.config.id, session.socket);
if (windowId) {
post({ type: "focus-window", windowId });
} else {
openViewWindowFor(control, session);
}
if (!focusSessionWindow(control, session)) showSessionInHub(window, control, session);
},
});
}
@@ -1587,10 +1653,89 @@ function viewWindowIdForSocket(connectionId: string, socket: string): string | n
return null;
}
/** Focus the window already showing a session; false if it has none. */
function focusSessionWindow(control: ControlConnection, session: G2MirrorSession): boolean {
const windowId = viewWindowIdForSocket(control.config.id, session.socket);
if (!windowId) return false;
post({ type: "focus-window", windowId });
return true;
}
function openViewWindowFor(control: ControlConnection, session: G2MirrorSession): void {
openViewWindow(control, session.socket, sessionLabel(session));
}
/**
* Ask the shell to move a window to another height band, then run `apply` with
* the viewport it answers with: only the shell knows what a band comes to (the
* bottom switcher's height lives on the main thread), and a view's grid goes
* into its websocket handshake, so the size has to be right before it starts.
* Ignored if the window is already waiting on an answer (a repeated gesture).
*/
function changeWindowHeight(windowId: string, heightMode: WindowHeightMode, apply: (viewport: Viewport) => void): void {
if (pendingHeightChanges.has(windowId)) return;
pendingHeightChanges.set(windowId, apply);
post({ type: "set-height-mode", windowId, heightMode });
}
/** Make `incoming` what its window id shows, in place of `outgoing`. */
function replaceWindowContent(outgoing: TerminalWindow, incoming: TerminalWindow): void {
incoming.foreground = outgoing.foreground;
incoming.focused = outgoing.focused;
incoming.lastSubmittedFingerprint = "";
// Its pending timers and emulator callbacks must not paint over the surface.
outgoing.foreground = false;
windows.set(incoming.windowId, incoming);
updateHubAnimation();
renderAndSubmit(incoming, 0);
}
/** A session was selected in the list: show it in the hub's own window. */
function showSessionInHub(hub: HubWindow, control: ControlConnection, session: G2MirrorSession): void {
const options = clientOptionsFor(control.config);
if (!options) return;
const label = sessionLabel(session);
// Tall like a session in its own window (see openViewWindow).
changeWindowHeight(hub.windowId, "max", (viewport) => {
const view = createViewWindow(hub.windowId, hub.surfaceId, label, viewport, {
connectionId: control.config.id,
socket: session.socket,
label,
glyph: "",
options,
});
view.hub = hub;
if (hub.foreground) activeViewId = view.windowId;
replaceWindowContent(hub, view);
});
}
/**
* Back from a session in the hub's window to the list. The list keeps the order
* it had, with this session's row selected: viewing a session bumps its
* recency, and re-sorting on every return would shuffle the list while the user
* steps through it. `then` runs once the session's connection is gone.
*/
function returnToHub(view: ViewWindow, then?: () => void): void {
const hub = view.hub;
if (!hub) return;
changeWindowHeight(view.windowId, "min", (viewport) => {
stopViewConnection(view);
view.emulator.dispose();
if (activeViewId === view.windowId) activeViewId = null;
hub.viewportWidth = viewport.width;
hub.viewportHeight = viewport.height;
hub.menu?.resize(viewport);
const items = hubItems(hub);
const row = items.findIndex(
(item) => item.sessionRow?.control.config.id === view.connectionId && item.sessionRow.session.socket === view.socket,
);
hubMenu(hub).setItems(items, row >= 0 ? row : undefined);
replaceWindowContent(view, hub);
then?.();
});
}
/**
* Lowest unused sidebar-icon character for a new view window (its terminal
* icon shows ">N"). Glyphs free up when their window closes, since usage is
+12 -10
View File
@@ -5,11 +5,11 @@
* mirrors what the user can do from the launcher grid and the sidebar.
*
* The launchable set is the built-in launcher apps plus whatever EvenHub
* packages are installed right now, matching the launcher grid. Installs and
* uninstalls change that set at runtime, so the tools re-register (replacing
* themselves by name) whenever it changes to keep the id enums and
* descriptions current; register() fires the tools-changed broadcast that
* propagates the new specs to the assistant backends.
* packages are installed right now, matching the launcher grid. Installs,
* uninstalls and pairing different glasses change that set at runtime, so the
* tools re-register (replacing themselves by name) whenever it changes to keep
* the id enums and descriptions current; register() fires the tools-changed
* broadcast that propagates the new specs to the assistant backends.
*/
import { shell, type ShellWindow } from "../ui/shell/shell";
import type { AppDefinition } from "../apps/app-definition";
@@ -30,8 +30,8 @@ import { onAnySettingChanged } from "../ui/dashboard-settings";
import { toolRegistry, type ToolRegistry, type ToolResult } from "./tool-registry";
export type WindowToolsOptions = {
/** The built-in launcher apps; installed EvenHub apps are added dynamically. */
apps: readonly AppDefinition[];
/** The built-in launcher apps for the paired glasses; installed EvenHub apps are added dynamically. */
apps: () => readonly AppDefinition[];
/** Launch (or focus) an app exactly as the launcher grid would. */
launchApp: (appId: string) => Promise<void> | void;
/** Repaint the shell surface so the sidebar reflects a focus change. */
@@ -47,9 +47,11 @@ export function registerWindowTools(
if (registered) return;
registered = true;
registerTools(options, registry);
let fingerprint = getInstalledEvenHubFingerprint();
const launchableFingerprint = () =>
`${getInstalledEvenHubFingerprint()}\n${options.apps().map((app) => app.appId).join()}`;
let fingerprint = launchableFingerprint();
onAnySettingChanged(() => {
const current = getInstalledEvenHubFingerprint();
const current = launchableFingerprint();
if (current === fingerprint) return;
fingerprint = current;
registerTools(options, registry);
@@ -58,7 +60,7 @@ export function registerWindowTools(
function registerTools(options: WindowToolsOptions, registry: ToolRegistry): void {
const installedApps = getInstalledEvenHubApps();
const apps = new Map(options.apps.map((app) => [app.appId, app.title]));
const apps = new Map(options.apps().map((app) => [app.appId, app.title]));
for (const app of installedApps) {
apps.set(installedEvenHubAppId(app.packageId), app.name);
}
+37
View File
@@ -0,0 +1,37 @@
/** Keeping what's saved about a G1 current as an install changes its arms' addresses. */
import {
loadDeviceAddresses,
loadPairedGlassesIdentity,
saveDeviceAddresses,
savePairedGlassesIdentity,
} from "../g2/device-addresses";
import type { EvenAdvertisement } from "../g2/even-advertisement";
import type { GlassesPairCandidate } from "../g2/pairing-candidates";
import type { G1Side } from "./flash-plan";
export function saveG1Pair(pair: GlassesPairCandidate): void {
const stored = loadDeviceAddresses();
saveDeviceAddresses({ left: pair.left!.address, right: pair.right!.address, ring: stored.ring });
const identity = loadPairedGlassesIdentity();
savePairedGlassesIdentity({
serial: pair.serial ?? identity?.serial ?? "",
leftName: pair.left!.name,
rightName: pair.right!.name,
leftAddress: pair.left!.address,
rightAddress: pair.right!.address,
ringName: identity?.ringName ?? "",
ringAddress: stored.ring,
pairedAtMs: identity?.pairedAtMs ?? Date.now(),
});
}
/** Saved as soon as it's known: if anything stops the install after this, the next try and the session still find this arm. */
export function saveG1Arm(side: G1Side, arm: EvenAdvertisement): void {
saveDeviceAddresses({ ...loadDeviceAddresses(), [side]: arm.address });
const identity = loadPairedGlassesIdentity();
if (identity) {
savePairedGlassesIdentity(side === "left"
? { ...identity, leftName: arm.name, leftAddress: arm.address }
: { ...identity, rightName: arm.name, rightAddress: arm.address });
}
}
+86
View File
@@ -0,0 +1,86 @@
/**
* Finding a G1's arms by listening for them. That's how an install knows what each arm runs before connecting to it,
* and how it finds an arm again afterwards, when it advertises what it runs now (and, coming from g1v0 before 0.5.66, at
* a new address).
*/
import { classifyAdvertisement, type EvenAdvertisement } from "../g2/even-advertisement";
import { DiscoveryAggregator, type GlassesPairCandidate } from "../g2/pairing-candidates";
import { DeviceDiscoveryBridge } from "../native/device-discovery";
import { pickG1Pair, sameG1Serial, type G1Side, type G1Wanted } from "./flash-plan";
/** A serial should tell which arm is ours, but an arm that is the only one of its side around is good enough after this. */
const ACCEPT_ANY_SERIAL_AFTER_MS = 45_000;
export class G1ArmScanner {
private discovery: DeviceDiscoveryBridge | null = null;
private finish: (() => void) | null = null;
/** Resolves with the wanted pair once both arms have been heard, or null after [timeoutMs]. */
waitForPair(wanted: G1Wanted, timeoutMs: number): Promise<GlassesPairCandidate | null> {
const aggregator = new DiscoveryAggregator();
return this.listen<GlassesPairCandidate>(timeoutMs, (raw, done) => {
if (aggregator.ingest(raw)) {
const pair = pickG1Pair(aggregator.pairs(), wanted);
if (pair) done(pair);
}
});
}
/** Resolves when an arm of this side on g1v0 is heard, or null after [timeoutMs]. */
waitForG1v0Arm(side: G1Side, serial: string | null | undefined, timeoutMs: number): Promise<EvenAdvertisement | null> {
return this.waitForArm(side, serial, timeoutMs, (arm) => arm.g1Firmware !== "stock");
}
/** Resolves when an arm of this side is heard that [accept] takes, on any firmware, or null after [timeoutMs]. */
waitForArm(
side: G1Side,
serial: string | null | undefined,
timeoutMs: number,
accept: (arm: EvenAdvertisement) => boolean,
): Promise<EvenAdvertisement | null> {
const startedAt = Date.now();
const others = new Map<string, EvenAdvertisement>();
return this.listen<EvenAdvertisement>(timeoutMs, (raw, done) => {
const arm = classifyAdvertisement(raw);
if (!arm || arm.role !== side || !arm.g1Firmware || !accept(arm)) return;
if (!serial || sameG1Serial(arm.serial, serial)) {
done(arm);
return;
}
others.set(arm.address, arm);
if (others.size === 1 && Date.now() - startedAt >= ACCEPT_ANY_SERIAL_AFTER_MS) done(arm);
});
}
stop(): void {
this.finish?.();
}
private listen<T>(timeoutMs: number, onRaw: (raw: Parameters<DiscoveryAggregator["ingest"]>[0], done: (value: T) => void) => void): Promise<T | null> {
return new Promise((resolve, reject) => {
this.discovery ??= new DeviceDiscoveryBridge();
const discovery = this.discovery;
if (!discovery.bluetoothEnabled) {
reject(new Error("Bluetooth is off. Turn it on, then try again."));
return;
}
let settled = false;
const settle = (value: T | null, error?: Error) => {
if (settled) return;
settled = true;
clearTimeout(timer);
this.finish = null;
discovery.stopScan();
if (error) reject(error);
else resolve(value);
};
const timer = setTimeout(() => settle(null), timeoutMs);
this.finish = () => settle(null);
const started = discovery.startScan({
onAdvertisement: (raw) => onRaw(raw, (value) => settle(value)),
onScanFailed: (_code, message) => settle(null, new Error(`The Bluetooth scan failed: ${message}`)),
});
if (!started) settle(null, new Error("Could not start the Bluetooth scan. Check that Bluetooth is on."));
});
}
}
+21
View File
@@ -0,0 +1,21 @@
/**
* Even's official G1 firmware, which an uninstall puts back: both images of one public release, the application core's
* and the network core's (the Bluetooth controller), as Even's own update installs them, so the two always match.
* From Even's CDN, checked against these SHA-256 sums (scouter_kit g1_firmware/stock_images.txt). Every public image
* says 0.0.0 in its MCUboot header, so the hashes are the only way to tell releases apart.
*/
export type EvenG1Release = {
version: string;
zipUrl: string;
zipSha256: string;
appSha256: string;
netCoreSha256: string;
};
export const EVEN_G1_RESTORE: EvenG1Release = {
version: "1.6.6",
zipUrl: "https://cdn.evenreal.co/firmware/dcfa510c090e476c10a6f6c348a22415.zip",
zipSha256: "748836f2d9d092b0783cbb7672fdccec4f730051cad27f095bbb156ac3e5d316",
appSha256: "ae032838e27037156da98e19de90df78f5406715751f3b38adf50498db3010c1",
netCoreSha256: "c277749be97a2763742db399afeb10ca6916059abd60d41bbc05c8892c002c77",
};
+73
View File
@@ -0,0 +1,73 @@
/**
* Prepares the g1v0 image on the phone, as app/g2/firmware-builder.ts does for a G2: downloads Even's public firmware,
* checks it, and puts the parts this firmware embeds back into what the app ships. The result is byte for byte the
* image that was built, tested and signed, and it is checked to be. Also prepares Even's own images for an uninstall.
* It does not touch the glasses.
*/
import { knownFolders } from "@nativescript/core";
import { firmwareSha256, writeFirmwareFile } from "../native/firmware-files";
import { decodeBase64 } from "../util/base64";
import { fetchWithUserAgent } from "../util/http";
import { EVEN_G1_RESTORE } from "./even-firmware";
import { G1V0_IMAGE } from "./firmware/g1v0-image";
import { G1V0_OWN_BYTES_BASE64 } from "./firmware/g1v0-own-bytes";
import { assembleG1Image, decodeG1OwnBytes, extractEvenG1Images, G1FirmwareError, readZipEntry } from "./firmware-image";
export type G1BuildProgress = "downloading" | "verifying" | "assembling" | "writing";
export type BuiltG1Firmware = { path: string; bytes: number; version: string };
/** Even's release for an uninstall: the application core's image and the network core's. */
export type BuiltEvenG1Firmware = { appPath: string; netCorePath: string; bytes: number; version: string };
function sha256(bytes: Uint8Array): string {
return firmwareSha256(bytes.slice().buffer);
}
async function downloadStockZip(url: string): Promise<Uint8Array> {
let response: Response;
try {
response = await fetchWithUserAgent(url);
} catch (error) {
throw new G1FirmwareError(`Could not reach Even's firmware server: ${(error as Error)?.message ?? error}`);
}
if (!response.ok) throw new G1FirmwareError(`The firmware download failed (HTTP ${response.status}).`);
return new Uint8Array(await response.arrayBuffer());
}
export async function buildG1Firmware(onProgress?: (progress: G1BuildProgress) => void): Promise<BuiltG1Firmware> {
onProgress?.("downloading");
const zip = await downloadStockZip(G1V0_IMAGE.stockZipUrl);
onProgress?.("verifying");
const zipHash = sha256(zip);
if (zipHash !== G1V0_IMAGE.stockZipSha256) {
throw new G1FirmwareError(`Even's firmware download failed verification.\nexpected ${G1V0_IMAGE.stockZipSha256}\ngot ${zipHash}`);
}
onProgress?.("assembling");
const own = decodeG1OwnBytes(G1V0_OWN_BYTES_BASE64, decodeBase64);
const image = assembleG1Image(G1V0_IMAGE, own, (name) => readZipEntry(zip, name), sha256);
onProgress?.("writing");
const path = `${knownFolders.documents().path}/g1v0_${G1V0_IMAGE.version}.bin`;
writeFirmwareFile(path, image.slice().buffer);
return { path, bytes: image.length, version: G1V0_IMAGE.version };
}
export async function buildEvenG1Firmware(onProgress?: (progress: G1BuildProgress) => void): Promise<BuiltEvenG1Firmware> {
onProgress?.("downloading");
const zip = await downloadStockZip(EVEN_G1_RESTORE.zipUrl);
onProgress?.("verifying");
const { app, netCore } = extractEvenG1Images(zip, EVEN_G1_RESTORE, sha256);
onProgress?.("writing");
const folder = knownFolders.documents().path;
const appPath = `${folder}/even_g1_${EVEN_G1_RESTORE.version}_app.bin`;
const netCorePath = `${folder}/even_g1_${EVEN_G1_RESTORE.version}_net.bin`;
writeFirmwareFile(appPath, app.slice().buffer);
writeFirmwareFile(netCorePath, netCore.slice().buffer);
return { appPath, netCorePath, bytes: app.length + netCore.length, version: EVEN_G1_RESTORE.version };
}
+107
View File
@@ -0,0 +1,107 @@
/**
* Rebuilding the g1v0 image from what the app ships and Even's public firmware download. No I/O, so tests can run it
* on real or made-up files. tools/g1_firmware_bundle.py is the other half.
*/
import { inflate, inflateRaw } from "pako";
import type { EvenG1Release } from "./even-firmware";
import type { G1FirmwareImage } from "./firmware/g1v0-image";
export class G1FirmwareError extends Error {}
/** One file from a zip; throws when it's absent or in a form a firmware zip doesn't use. */
export function readZipEntry(zip: Uint8Array, name: string): Uint8Array {
const view = new DataView(zip.buffer, zip.byteOffset, zip.byteLength);
const END_OF_DIRECTORY = 0x06054b50;
const DIRECTORY_ENTRY = 0x02014b50;
const LOCAL_HEADER = 0x04034b50;
let end = zip.length - 22;
while (end >= 0 && view.getUint32(end, true) !== END_OF_DIRECTORY) end--;
if (end < 0) throw new G1FirmwareError("The firmware download is not a zip file.");
const count = view.getUint16(end + 10, true);
let at = view.getUint32(end + 16, true);
for (let i = 0; i < count; i++) {
if (at + 46 > zip.length || view.getUint32(at, true) !== DIRECTORY_ENTRY) break;
const method = view.getUint16(at + 10, true);
const packedSize = view.getUint32(at + 20, true);
const nameLength = view.getUint16(at + 28, true);
const extraLength = view.getUint16(at + 30, true);
const commentLength = view.getUint16(at + 32, true);
const headerAt = view.getUint32(at + 42, true);
const entryName = String.fromCharCode(...zip.subarray(at + 46, at + 46 + nameLength));
if (entryName === name || entryName.endsWith(`/${name}`)) {
if (view.getUint32(headerAt, true) !== LOCAL_HEADER) throw new G1FirmwareError(`Bad zip entry for ${name}.`);
const dataAt = headerAt + 30 + view.getUint16(headerAt + 26, true) + view.getUint16(headerAt + 28, true);
const packed = zip.subarray(dataAt, dataAt + packedSize);
if (method === 0) return packed.slice();
if (method === 8) return inflateRaw(packed);
throw new G1FirmwareError(`${name} uses zip method ${method}.`);
}
at += 46 + nameLength + extraLength + commentLength;
}
throw new G1FirmwareError(`The firmware download has no ${name}.`);
}
/**
* The two images of Even's release from its download, each checked by its own SHA-256 as well as the zip's, so what
* goes to the arms is byte for byte what Even published.
*/
export function extractEvenG1Images(
zip: Uint8Array,
release: EvenG1Release,
sha256: (bytes: Uint8Array) => string,
): { app: Uint8Array; netCore: Uint8Array } {
const zipHash = sha256(zip);
if (zipHash !== release.zipSha256) {
throw new G1FirmwareError(`Even's firmware download failed verification.\nexpected ${release.zipSha256}\ngot ${zipHash}`);
}
const checked = (name: string, want: string) => {
const bytes = readZipEntry(zip, name);
const got = sha256(bytes);
if (got !== want) throw new G1FirmwareError(`${name} in Even's download failed verification.\nexpected ${want}\ngot ${got}`);
return bytes;
};
return {
app: checked("app_update.bin", release.appSha256),
netCore: checked("net_core_app_update.bin", release.netCoreSha256),
};
}
export function decodeG1OwnBytes(base64: string, decode: (text: string) => Uint8Array): Uint8Array {
return inflate(decode(base64));
}
/**
* The finished image. [fileBytes] gives one of Even's unpacked files by name, [sha256] a lowercase hex digest. Each part
* and the result are checked, so a success is byte for byte the image that was built and signed.
*/
export function assembleG1Image(
manifest: G1FirmwareImage,
own: Uint8Array,
fileBytes: (name: string) => Uint8Array,
sha256: (bytes: Uint8Array) => string,
): Uint8Array {
const image = new Uint8Array(manifest.size);
let position = 0;
let ownAt = 0;
for (const part of [...manifest.parts].sort((a, b) => a.offset - b.offset)) {
const before = part.offset - position;
image.set(own.subarray(ownAt, ownAt + before), position);
ownAt += before;
const bytes = fileBytes(part.file).subarray(part.fileOffset, part.fileOffset + part.length);
if (bytes.length !== part.length || sha256(bytes) !== part.sha256) {
throw new G1FirmwareError(`${part.file} in Even's download is not the one this firmware was built with.`);
}
image.set(bytes, part.offset);
position = part.offset + part.length;
}
image.set(own.subarray(ownAt), position);
if (ownAt + (manifest.size - position) !== own.length) {
throw new G1FirmwareError("The firmware bundled with this app is damaged.");
}
const digest = sha256(image);
if (digest !== manifest.sha256) {
throw new G1FirmwareError(`The assembled firmware failed verification.\nexpected ${manifest.sha256}\ngot ${digest}`);
}
return image;
}
+41
View File
@@ -0,0 +1,41 @@
// AUTO-GENERATED by tools/g1_firmware_bundle.py -- do not edit by hand.
// What the app installs on a G1, and the parts of it that come from Even's own download.
export type G1FirmwarePart = { offset: number; length: number; file: string; fileOffset: number; sha256: string };
export type G1FirmwareImage = {
version: string;
sha256: string;
size: number;
source: string;
stockVersion: string;
stockZipUrl: string;
stockZipSha256: string;
parts: G1FirmwarePart[];
};
export const G1V0_IMAGE: G1FirmwareImage = {
"version": "0.5.66",
"sha256": "9861a5671ed2fab6a678feae1f22e57d0b41bbb5934d83b898c5108db3a474fd",
"size": 582992,
"source": "ceb74cce6945",
"stockVersion": "1.6.6",
"stockZipUrl": "https://cdn.evenreal.co/firmware/dcfa510c090e476c10a6f6c348a22415.zip",
"stockZipSha256": "748836f2d9d092b0783cbb7672fdccec4f730051cad27f095bbb156ac3e5d316",
"parts": [
{
"offset": 271264,
"length": 226020,
"file": "net_core_app_update.bin",
"fileOffset": 0,
"sha256": "c277749be97a2763742db399afeb10ca6916059abd60d41bbc05c8892c002c77"
},
{
"offset": 497312,
"length": 352,
"file": "app_update.bin",
"fileOffset": 531288,
"sha256": "92e73a6dd92da734bc21e8184d94d69e9a49e23056e378670b24334a305a953d"
}
]
};
+4
View File
@@ -0,0 +1,4 @@
// AUTO-GENERATED by tools/g1_firmware_bundle.py -- do not edit by hand.
// The built g1v0 image without Even's parts (g1v0-image.ts), deflated.
export const G1V0_OWN_BYTES_BASE64 = "eNrsfIl/U1X2+H1L1oY2XcB0AbNQTZsKoQUsFCFN2tclhbYsI+IyKaCmgGOgOnZxJCxKARcEEQQZ66DfQURpC4yUiqmAgzPqTMIyUlCpa2grnZe2kJf1/c59KcvM9/cX/D4/+Ly8c7dzzz33nHPPufe+3nd06HWE/5Hw/CAVQCQyoxv/+P//7//pf63/FKl3lNMooYFGkQvk/3pu//eo51bee+4Y/MSZ///894P5WtlXSLb7eizjXYeuoYxvfNGHRnUTLKqo7OsiK/qqHO0+VGnqX4ekLjVLIEdJIuus1HiSffmrPnZBPZOjpHDYmVjZN3fuCZ+KPOFTK5RBxZA6SLIqlwlaVPZ9qqvsO6ujgoqwqU+BdEFyqLLPQn3pXd23eJ7EU9VH5I1zVbJRk2nYBPgxTpOQQpBCLiekyR7kWsOiQjO60/XbvkJqax+VsLpPu2J1n27FMndlX9LiM/3JSz51nVEVmkpNhaajrgfNqYZml6NEyQL1gEnNrjYBPeZESBcOI0LDri5UucrMGNMs9598BFkYpMLKfgU66VNTRJDyIRZZyPNlZlu/CbVeQwnJZ1t9ztXisyZpZd8kgoQW0ezqM20Cd05Uxbhj6qOA5jJk6keImK534XZXz7QGneEDPqmivV9BoqCC3e9C0GKuWWX52OU2qSyOkq0sSlgDVIldTqCVyCUKjnhhXig8RpULj1LjxpTSblxT6pIyjpItfURChgupHSVJ7OpK2mNCeuA3no8kH1o1w4WuCfyDUVhuchPwLR4DrQHjEoIxk2LMTR3GZBp2QnkliygaeA1cs5QCt37bhxRS4KKFfd1CMFCKMnpgvkich+vKoe6NdKLAL5O5pr+Q+G0foSBd6xmCQWoL+xeL1LXX55y39xqiPg6+OCidvrf/xDzlJSJIhpcUIfgFqSE/Bk6C1Axa+smbskZCPjFSXtVXgTS3yvu+cThKmjpWdaCsT4ALQE2huEfqQvoM15MAV7K8EbH3H/0A+P5EL/0PlCW7hAxplxBbyX3L0T3f9pI6utVREqMXGdKhxHxbSSx/rnlJv4VylMTeiJ30v2rcKtPdVnaj3byOcqAvRhVQNClGleIWVaz0P6jB8n5PL1vyAvMiI2WkfxzNPMWkMshgYj91Pm9uD64dLO4ubwNuUJhr202vmSYEqSFLn0JR2Td6zr52neLjUJSLD6m+lIZQAPItbxTru/tVUh9/L33mjWKye5+PlBiK9vbLqHfaD4Wi4fhQRp4ihNiiPqqoxZzSnZOq8PF59JkWM9l9wEdSOUXj0yx9EtO4tnMmpJtsq7Mdv8JuKGG+9S5hfN6tnZZ0QoP7PtiuVtzCJ+FAEyw7i2ugb8BnpM/sLBbwIdy39D/6lvhx3382z77Z959v9v1TuqUPmbq8eMR4tGrQSzxi3OMW08F2ytIWw6NMVeBeC/tQYXOxtrt2pNfmkV6zit7ulxK720dqJ+JeLX2E5S1zfIzCSfSZt2K9EoaiS+kYzzavjfnRW8P44f0OjPaod51Z3D2mA2mkzLPev/ainoD3UHCd/5WOdWbi7Kpi6YVP+kna1k9RhPpNZhzUq/XmM0Fcs4Lznga72GmKD0quaYOK4QlBhe+YKcOiBkt51FTZl1JGWO4Mro8eCgU4WUhljFNIQ/FBGLtlV7Gp+0c8fzCaXbH5QzrgoZza2D5SOw/qRgv7qMKXi3O6a3Bd4OHLsbqUpghz8O3+eKIlRO4sLP4HY2HIs2LP7GL6DJHf0U/G2/tpCk34s/tIfzxZ008RBNhpbVAyFDBV9FEUUD/pDa+J+cxrYbq9So4wJHJEAZGtd+0y+93uNEcJxUCOgYIHZQc8OJ0swCGPKo3Id5SwRza2Pj4bHTzPLZ30hj2RJYg0j+k6ZZo+VseW8TSD9Ca201lvP2lPr3+wQ+Q7R529cnAiycrIs1f+fefJKz9NRDkBTw5LRZGmcJBCuN09I+3ecjbZq+dctJ/hCHSGEympv6qYHHYgomEKBwmhpmqk5iahh0X1z3MO9aLmd7lV6rSG57mV6kOcRP0u9xS8RcZ3ud8bc9h/Cq1JoXUgilsv93zN0V3fcAr1vIzC3MmMyv6AXZpHndpmvovxe2zQ45FIJvtVBNdd4NnObTLuEmecy7FWDq+vDtWQOkNpZ40E1sYCdktwO/es8UFx1bm7oXStUKq7Wbom+CSbRE/ukWhM1/NMOtYZFQNGxKrXSDQK431sd+RJlqYoh1LXxZGm9SuLHPRKLXPSMYmJ1f8TULuvg4DWkyBVM9KaWEMIrf8W0TK4Ji57SRjXUbeaGX/vcYY9vlON1EoNUs91yNBPl2nkhDfSmIHbEp+U1LFPC/W9nk77zv/F7XuBX2bgV6ymTah5xvOx/Uf7IY5Qv9pe1tZdP63tXY7WXKxPZMQ+PZrFruDV0DItAtywjWHVYpWHBKqfAMrEQnvE/o+TFKj+bYTQaRjKwThymViNiUKNt4HPbxrHSZLPYzozRnrXCGXbPEdhrs9C72dhVj/rzdflsD+Ft3MXjA+JE4X62SP1ZUL91cNNB3GLB0E61JNy2H+EpVCHQDrWJczpb91SgZZUoPeC0jRI6hJZE6zClI5kmiUVLgubgyysAm0Wb+e6jbBusiaUzMoStnN/MoLPMYxsFCum/iHBJUokNkghr8uBNAXstoCGQdpYXycjMVqmHMQycoSjE3eKM895OgoHRSPUto/UGH8QSid9bLd2xHiMeburObc0kZnFuqKYs0/ACEzXCeDWI9BmS8eTrJ2WelHWkCf7ptzpb8pdcQDkiuZ+iY3yfwROkUy3pMSV9ranFxGwtlaPKy1gZwjUxvCuGKHluw8JZvrYSiFvccR2aLQV48aSr7yJf3SggP0uGKv/1w/vYh8aadv14Xg2GqKZzl8ODiHnlmaI7Jzgz4ActsDzzogsKiH/NMBN9ieYb+ybWg9zhJEyvO4yl1vK5nI65TLmbE3lMKozlSavN1lP9IoIM6ecVTmcXD0TaP6ag/rqDxgy+zBHGUs9lIG5MK0ct3uC2dR6o+0UaDvpP9pOhLYd3AfMkob/aaAMO10Tyg9zkqpznAytYF5sfc2FMejKljEneiVTMYbL3IGubc9nYhyfnuiVVVUO11VjXGMBz3buXabensP+KYQ0lddJwfJ9GaYZVVua9XFvYlmHt96eOvsknkuwQZ+CDXoptB3eD0pWX1t8UMNUjljL9rC0TWmd460fkdUuqFkfqvIiVzhXhj5bJkP9wCcaHEjMt18hj14pQ9/AWwJ5ZQBjPV8F7wx4wM+onG59vvUsR+u2SuLOw1tjbkPak/CeUg6pScl2Ii/Zljcbjd/HVA47p06sBDuYJw7SgVTwRe9xE7q9pkuWnDLPlX9PJMHz/fTKrwngxSVc92iD9NAlCXXuLus8brzxZJuauY+t4yeArahk1eS/hxLXrR1KanYNPfmKtJ/O+KaXfL+qeGV/HCE/s24oUchXTklpE7WCr/EKMf6kF6nP96Kkt66OatLbRpVS2168SjaRW7u40m0YM8NTu2+0Q1nfu8ldDzJo61ymueQS8OZG/IiqiCrUS6vr7Ug9fIVWm6ohDf+wv3XPVXIzzbx1tWxz+Zz1rUAjBTRuWDdC4zmOq3qpg9TQ15ods9hxEaS3eJDupato8zSG3EZfc666rzSXtYZ+8J7jwmqDfbv5FMcZpa5TXNh4jlNOsrAkdQre/XYd2G8LS1D9tuX2DSMU65mdJSM9brzRY7/9DYmOJcjUc302jEE3gmHjSJtLogPnctnBwHte+tr6p5GW0OhB93ujSM952rxG6IeCPpC+x43uPsa4OdAr/UW32U4w281xHsK+o2OVfZJtrRl5VtpMnPT9Sey+yDTmKMxdnPsCh9QmJoHZwvzknWZbZV9rlrqesfV7zcyQF+vpDX5+Drx8zyRSKweU0/NYZFYewVwUewj18V/JzcevKE1TWZcLGUQXb6U/cx3y8ZXiS8YBtKl1oFSOS5THIe5MsJV1ui5ftTU+yapIpLUN3N141HXHwJbp/gHU+M3ok0NjqNUzUotSiohhRK5ln5tL93vmU74EIs0iGVBmzy2Xm+4deHxTe+eRAdMm34AymOBBOYh90SkZ2FL+1tUKOTyN3IC38e4B5ybJwIZNLm+hYNt4/2ruL9AH1JNLBj5vtA9Ioc7djSkd+QMlmw54cfvLV2csw20lA7803jtQuumtq9Ma7wAce7wstHzr6tRFl69OLZ9aXg/t0opOXrs/uXng7mW4JXVNW5dsgbbLLl81NiLDYwPiRZkD7wKmu6FNTmPxgATaGxYBRZDObiwZuBt6y2osGtjQ+Dg8xQOZjWnfYvr0UPNuoO0ZoeQFoA/G23jA+9bV0csYSOMUpu3y1aTGMQN/3lTprYecWM184EwJ1JQ3MgOnodbnm/ohlbjpPmE+Fwj/zs9Sh8qxOlSw/Grk8d9xr3PlpFmZedNnZr28ZKbxoX/yO5rvmJlZtnXm+/uzZ1W6M2Z+9eWXM3ED9kiiNbE8w/6amfYUXh+a/7D9XTPVnWYDS9JLaCFnAbqLuJsoagZpY48vss/PeMgGfuQXaUUHzGs5RVezC+o9/m8v+kGsnlRSWUGUTmM/7kSuw4ukiCgdx/Yej8FyLU7tP45h5RGqYoZGzdzLdvE9S5THUY9YzR6JrxQzX/cS81PacpjC68MLkBp+Hxprm1y0LvV9M3Fmi0CBTnUoFI4qQuPyCorSm+LmE8ZY39yRSrZKd5ZD83MqTsKvYY7Ofsic556hRZqs0lnsK/xdNr01qzzV/mpspNUL7c23jVRXMV5oIXJ/Ay200OL30CLVushO5EJ5JqFdVIe0u+ouNg22Edp0a5oDaROtF+uOX+FMvP91Fx6Pd/m97P38BvMpz5ImwiDy6Jp4wyk3kaer+9S7F3I+AbvDedObRAaym9TKrd94ScOFCxe9ePzG30wqoeF9g4/oe7E6dyHkwTt+D Line truncated
+120
View File
@@ -0,0 +1,120 @@
/** What installing firmware on a G1 has to decide. No I/O. */
import type { GlassesPairCandidate } from "../g2/pairing-candidates";
import { EVEN_G1_RESTORE } from "./even-firmware";
export type G1Side = "left" | "right";
/** Left first: a right arm on g1v0 next to a left arm on Even's firmware would leave the left eye dark. */
export const G1_SIDES: readonly G1Side[] = ["left", "right"];
/** Going back, right first, for the same reason: halfway, the pair is as halfway through an install. */
export const G1_UNINSTALL_SIDES: readonly G1Side[] = ["right", "left"];
export const G1_CASE_INSTRUCTIONS =
"Put the glasses in their charging case with the lid open, and plug the case in. Stay nearby, and leave Faceclaw open.";
/** An arm bonds only once it knows it's in the case, and a full case only says so about every 5 minutes. */
export const G1_CASE_DELAY_HINT =
"A fully charged arm can take up to 5 minutes to notice it's in the case, so this may take a while.";
export const G1_INSTALL_NOTICE =
"This replaces the firmware on both arms, about two minutes each. Faceclaw can put Even's firmware back later, but as version " +
`${EVEN_G1_RESTORE.version}, which may not be the version you have now. Installing custom firmware is not covered by warranty.`;
export const G1_UNINSTALL_NOTICE =
`This puts Even's official firmware ${EVEN_G1_RESTORE.version} back on both arms, Bluetooth controller included, a few minutes ` +
"each. It may not be the version they came with. Afterwards they work with Even's app again, and not with Faceclaw until you " +
"install its firmware again.";
/** What the native flow says when it finishes (G1ArmFlashFlow). */
export type G1FlashResult = {
flashed?: boolean;
firmware?: "g1v0" | "stock";
/** A restore erased g1v0's asset store, where Even's fonts and pictures were. */
wiped?: boolean;
version?: string;
safeMode?: boolean;
inCase?: boolean;
battery?: number | null;
};
export function parseG1FlashResult(detail: string): G1FlashResult {
try {
const parsed = JSON.parse(detail);
return parsed && typeof parsed === "object" ? (parsed as G1FlashResult) : {};
} catch {
return {};
}
}
/** Dotted versions, component by component; a missing component counts as 0. */
export function compareG1Versions(a: string, b: string): number {
const parts = (version: string) => version.split(".").map((part) => parseInt(part, 10) || 0);
const left = parts(a);
const right = parts(b);
for (let i = 0; i < Math.max(left.length, right.length); i++) {
const delta = (left[i] ?? 0) - (right[i] ?? 0);
if (delta !== 0) return delta;
}
return 0;
}
export type G1Wanted = { serial?: string | null; left?: string; right?: string };
const serialOf = (serial: string | null | undefined) => (serial ?? "").trim().toUpperCase();
export function sameG1Serial(a: string | null | undefined, b: string | null | undefined): boolean {
return serialOf(a) !== "" && serialOf(a) === serialOf(b);
}
/**
* The pair being installed on, among those heard, once both arms have been. Its serial decides, as a flash changes an arm's
* address; an address it was saved under also tells. Only with neither known does the only G1 around count: firmware
* must never go to someone else's glasses because the wanted ones weren't heard.
*/
export function pickG1Pair(pairs: readonly GlassesPairCandidate[], wanted: G1Wanted): GlassesPairCandidate | null {
const g1 = pairs.filter((pair) => pair.g1Firmware);
const complete = (pair: GlassesPairCandidate | undefined) => (pair?.left && pair.right ? pair : null);
const bySerial = g1.find((pair) => sameG1Serial(pair.serial, wanted.serial));
if (bySerial) return complete(bySerial);
const byAddress = g1.find((pair) =>
(!!wanted.left && pair.left?.address === wanted.left) || (!!wanted.right && pair.right?.address === wanted.right));
if (byAddress) return complete(byAddress);
if (serialOf(wanted.serial) || wanted.left || wanted.right) return null;
return g1.length === 1 ? complete(g1[0]) : null;
}
/**
* What a check of the two arms found: "stock", Even's firmware on an arm; "safe-mode", g1v0 restarted repeatedly and only
* updates work; "older", older than the app ships; "current", nothing to do.
*/
export type G1FirmwareState = "stock" | "safe-mode" | "older" | "current";
export function g1FirmwareState(arms: readonly G1FlashResult[], shipped: string): G1FirmwareState {
if (arms.some((arm) => arm.firmware === "stock")) return "stock";
if (arms.some((arm) => arm.safeMode)) return "safe-mode";
return arms.some((arm) => compareG1Versions(arm.version ?? "", shipped) < 0) ? "older" : "current";
}
/**
* What the arms' advertising alone says about their firmware, or null when an arm has to be asked: firmware before 0.5.66
* doesn't advertise its version.
*/
export function g1StateFromAdvertising(
pair: Pick<GlassesPairCandidate, "left" | "right">,
shipped: string,
): { state: G1FirmwareState; version: string } | null {
const arms = [pair.left, pair.right];
if (arms.some((arm) => arm?.g1Firmware === "stock")) return { state: "stock", version: "" };
if (arms.some((arm) => arm?.g1Firmware === "g1v0-safe")) return { state: "safe-mode", version: "" };
const versions = arms.map((arm) => arm?.g1Version);
if (!versions[0] || !versions[1]) return null;
const lowest = compareG1Versions(versions[0], versions[1]) <= 0 ? versions[0] : versions[1];
return { state: compareG1Versions(lowest, shipped) < 0 ? "older" : "current", version: lowest };
}
/** Each arm counts for half of the bar, in the order they're done. */
export function g1FlashPercent(side: G1Side, bytesSent: number, bytesTotal: number, order: readonly G1Side[] = G1_SIDES): number {
const within = bytesTotal > 0 ? Math.min(1, bytesSent / bytesTotal) : 0;
return ((order.indexOf(side) + within) / 2) * 100;
}
+4
View File
@@ -0,0 +1,4 @@
declare module "pako" {
export function inflate(data: Uint8Array): Uint8Array;
export function inflateRaw(data: Uint8Array): Uint8Array;
}
+3 -1
View File
@@ -152,8 +152,10 @@ export class AncsClient {
if (flags & 2) {
const data = new Uint8Array(this.fragments); this.fragments = []; this.packetKind = -1
if (kind === 0) {
if (data.length !== 1 || data[0] > 2) { this.recover(); return true }
if (data.length !== 1 || data[0] > 3) { this.recover(); return true }
if (data[0] === 2) { this.recover('Glasses reported a notification relay error. Retrying…'); return true }
// Only a G1's firmware looks for ANCS itself, so only it can say the phone isn't offering it.
if (data[0] === 3) { this.recover('iPhone is not sharing notifications with the glasses. Enable Share System Notifications in Settings → Bluetooth → right arm. Retrying…'); return true }
if (data[0] === 0) { this.resetReceived = true; this.log('Glasses accepted notification relay START; awaiting subscription') }
if (data[0] === 1) {
if (this.timer !== null) clearTimeout(this.timer)
+1 -14
View File
@@ -27,7 +27,7 @@
*
* It is **not** a measurement. A hand over the temple, a pocket, or a body
* between phone and glasses moves the estimate by metres. The wearer therefore
* only ever sees a coarse zone (glyph + label), never a number in metres they
* only ever sees a coarse zone (a signal-strength glyph), never a number in metres they
* might over-trust; the metres value exists purely to rank and bucket.
*
* This module is pure (no NativeScript imports) so it can run under node tests.
@@ -75,19 +75,6 @@ export function zoneFromMeters(meters: number): ProximityZone {
return "distant";
}
export function zoneLabel(zone: ProximityZone): string {
switch (zone) {
case "immediate":
return "In your hand";
case "near":
return "Nearby";
case "far":
return "Across the room";
case "distant":
return "Far away";
}
}
/** A glyph for the zone; SF Symbols have no Android equivalent, so plain text. */
export function zoneGlyph(zone: ProximityZone): string {
switch (zone) {
+13
View File
@@ -1,5 +1,18 @@
export const DEFAULT_BRIGHTNESS_CURVE = "0:0,0.2:7,1.5:33,5:100";
const PREVIOUS_DEFAULT_CURVE = "0:0,1:10,10:30,100:65,1000:100";
/**
* The RayNeo iO's sensor reads real lux, far above the G2's behind-the-lens values, so the
* G2's curve would sit at maximum in any lit room. These knots put the default 20–100 range on
* the stock firmware's own scene levels: 29, 41, 41, 53, 65, 76, 94 and 100 percent at 3, 10,
* 200, 300, 600, 1000, 4000 and 5000 lux.
*/
export const RAYNEO_IO_BRIGHTNESS_CURVE = "0:0,3:11,10:26,200:26,300:41,600:56,1000:70,4000:93,5000:100";
/**
* An Even G1's OPT3007 also reads lux (centilux on the wire). These knots are the stock firmware's table: levels 0, 10, 25,
* 41 and 42 of 42 at 0, 50, 200, 1000 and 2000 lux (g1_firmware/docs/VM.md §6.7).
*/
export const G1_BRIGHTNESS_CURVE = "0:0,50:24,200:60,1000:98,2000:100";
/** Percent of the configured range; defaults (20–100) give 20/26/46/100. */
export function brightnessCurveError(value: string): string | null {
+91 -44
View File
@@ -16,7 +16,6 @@ import { mediaControllerBridge } from "../native/media-controller";
import { nightscoutBridge } from "../native/nightscout-bridge";
import { weatherBridge } from "../native/weather";
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, onAndroidNotificationRemoved, readActiveNotifications } from "../native/notification-icons";
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
import { watchNotificationListenerBinding } from "../native/notification-access";
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
@@ -56,7 +55,7 @@ import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from "../apps/onb
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
import { voiceControlBridge } from "../native/voice-control";
import { voiceActivity } from "../ui/shell/voice-activity";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import { GrayImage } from "../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../graphics/plane";
import { prepareFrameDraws } from "../graphics/glyph-wire";
import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from "./lock-screen";
@@ -75,10 +74,10 @@ import { ALL_APPS } from "../apps/all-apps";
import { type AppContext, type AppDefinition, type AppLaunchParams, type TextEditorHost } from "../apps/app-definition";
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
import { appViewportRect, isOnSwitcherEdge, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
import { appViewportRect, isOnSwitcherEdge, screenHeight, screenWidth, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, getHeadUpPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, openAiTranscriptionModelSetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, getVoiceTranscriptionLanguage, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { appSwitcherPositionSetting, glassesModelName, glassesTypeSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, getHeadUpPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, openAiTranscriptionModelSetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, getVoiceTranscriptionLanguage, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, effectiveRingConnectionMode, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, shouldPopUpNewNotification, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
import {
getInstalledEvenHubAppById,
@@ -196,12 +195,12 @@ const LOW_BATTERY_PERCENT = 5;
const EVEN_APP_DETECTED_MESSAGE =
"The Even Realities app appears to be running. If Faceclaw has trouble connecting, open its app settings and force stop it.";
// The launcher grid's app list; also fixes the app ids apps.launch accepts.
const LAUNCHABLE_APPS = ALL_APPS.filter((app) => app.showInLauncher !== false);
// The launcher grid's app list for the paired glasses; also fixes the app ids apps.launch accepts.
const launchableApps = () => ALL_APPS.filter((app) => app.showInLauncher !== false && app.isSupported?.() !== false);
/**
* The global settings window viewport sizes depend on: the display mode's
* size (a band's position only moves windows), whether the app switcher
* The global settings window viewport sizes depend on: the paired glasses'
* screen, the display mode's size (a band's position only moves windows), whether the app switcher
* takes width beside windows, height below them or neither (a popup), and
* the chrome rows each window loses to it: below them, whether the status
* bar joins the row (dropping the top bar); with a popup, whether the
@@ -214,7 +213,7 @@ function viewportSizesKey(): string {
: position === "popup" ? `popup|${statusBarVisibilitySetting.get()}|${windowBorderSetting.get()}`
: "strip";
const layout = displayLayoutSetting.get();
return `${layout.startsWith("band-") ? "band" : layout}|${switcher}`;
return `${screenWidth()}x${screenHeight()}|${layout.startsWith("band-") ? "band" : layout}|${switcher}`;
}
/** The global settings that move window surfaces without resizing them. */
@@ -223,7 +222,7 @@ function windowPlacementKey(): string {
}
function createInitialDisplayPreview(): ImageSource | null {
return grayImageToPreviewSource(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0));
return grayImageToPreviewSource(new GrayImage(screenWidth(), screenHeight(), 0));
}
/** Echo the controller's appendLog() trace to the console. */
@@ -427,7 +426,7 @@ class DashboardController {
registerRoamTools((appId) => this.launchApp(appId));
// apps.* tools mirror the launcher grid and sidebar (launch, focus, close).
registerWindowTools({
apps: LAUNCHABLE_APPS,
apps: launchableApps,
launchApp: (appId) => this.launchApp(appId),
requestShellRender: () => this.requestShellRender(),
});
@@ -454,7 +453,8 @@ class DashboardController {
this.emit();
},
openNotificationsWindow: () =>
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID,
(options) => createNotificationsAppWindow(options, (section) => this.openSettings(section))),
onSwitcherBarHeightChanged: () => this.applySwitcherBarHeight(),
onWindowLayoutChanged: () => this.applySwitcherBarHeight(),
isLocked: () => this.glassesLocked,
@@ -485,6 +485,7 @@ class DashboardController {
this.pushBrightness();
this.pushHeadUpPreferences();
this.syncEvenHubScreenOffSetting();
this.syncVoiceWake();
// Display mode size first: a reflow repositions every surface too, so
// the band-position check after it then has nothing left to do.
this.applyDisplayModeIfChanged();
@@ -514,7 +515,7 @@ class DashboardController {
assistant: text => shell.sendToAssistant(text),
});
this.wearRemote = new WearRemote({
apps: LAUNCHABLE_APPS,
apps: launchableApps,
injectInput: (kind) => this.injectSyntheticRingInput(kind, "watch"),
launchApp: (appId) => this.launchApp(appId),
connect: () => this.connect(),
@@ -627,14 +628,28 @@ class DashboardController {
* are. Windows that can't resize keep the surface they have, the switcher
* covering any of it that it now overlaps, rather than being relaunched
* for it.
*
* A window is judged by its own size as well as its surface's rect: other
* paths (connect, a launch) configure surfaces from the geometry without
* resizing windows, so a window laid out before the row's height was known
* (restored at startup, at the default height) can sit behind a surface
* that already matches, and its frames would not fit it.
*/
private applySwitcherBarHeight(): void {
void (async () => {
for (const window of Array.from(shell.getWindows())) {
const rect = JSON.stringify(appViewportRect(window.heightMode, window.appId));
if (!window.relayout || this.windowSurfaceRects.get(window.surfaceId) === rect) continue;
window.relayout();
await this.configureWindowSurface(window.surfaceId, this.isForegroundWindow(window.windowId), window.heightMode);
if (!window.relayout) continue;
const rect = appViewportRect(window.heightMode, window.appId);
const size = window.layoutSize?.();
const resized = !!size && (size.width !== rect.width || size.height !== rect.height);
if (!resized && this.windowSurfaceRects.get(window.surfaceId) === JSON.stringify(rect)) continue;
try {
window.relayout();
await this.configureWindowSurface(window.surfaceId, this.isForegroundWindow(window.windowId), window.heightMode);
} catch (error) {
// The rest still need to follow the row.
this.appendLog(`switcher height change failed for ${window.windowId}: ${this.formatError(error)}`);
}
}
shell.foregroundWindow()?.requestRender();
this.requestShellRender();
@@ -825,8 +840,8 @@ class DashboardController {
await communicator.configureSurface(LOCK_SCREEN_SURFACE_ID, {
x: 0,
y: 0,
width: G2_LENS_WIDTH,
height: G2_LENS_HEIGHT,
width: screenWidth(),
height: screenHeight(),
zOrder: 1000,
transparency: "opaque",
});
@@ -934,6 +949,24 @@ class DashboardController {
return applied;
}
/** What the communicator was last told about the glasses' own wake word (null: not yet). */
private voiceWakeSent: boolean | null = null;
/**
* The glasses' own wake word follows the wake action: on a RayNeo iO, its
* "Hey RayNeo" switch (G2 glasses use the wake lease, syncFaceclawWakeLease).
*/
private syncVoiceWake(communicator = this.communicator): void {
if (!communicator) return;
const enabled = wakeWordActionSetting.get() !== "off";
if (this.voiceWakeSent === enabled) return;
this.voiceWakeSent = enabled;
void communicator.setVoiceWakeEnabled(enabled).catch((error) => {
this.voiceWakeSent = null;
this.appendLog(`wake word sync failed: ${this.formatError(error)}`);
});
}
private syncEvenHubScreenOffSetting(): void {
void this.syncFaceclawWakeLease().catch((error) => {
this.appendLog(`wake takeover lease sync failed: ${this.formatError(error)}`);
@@ -1051,9 +1084,11 @@ class DashboardController {
/**
* A Direct-mode session may have unpaired the R1 from the glasses (see
* GlassesSessionRing.releaseRingFromGlassesLocked). The first session in
* another mode asks the glasses to connect to it again; the ring's own
* glasses targets were cleared, so it accepts them. Called on connect.
* GlassesSessionRing.releaseRingFromGlassesLocked), and a RayNeo iO
* session (always Direct) may have cleared the ring's glasses targets.
* The first G2 session in another mode asks the glasses to connect to it
* again; the ring's own glasses targets were cleared, so it accepts them.
* Called on connect.
*/
private handRingBackToGlassesIfNeeded(): void {
if (this.ringModeAtConnect === "direct" || !getBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false)) return;
@@ -1094,7 +1129,7 @@ class DashboardController {
}
private pushHeadUpPreferences(force = false): void {
if (!global.isAndroid || !this.communicator) return;
if (!global.isAndroid || glassesTypeSetting.get() !== "g2" || !this.communicator) return;
const { enabled, angle } = getHeadUpPreferences();
if (enabled < 0 && angle < 0) return;
const value = JSON.stringify({ enabled, angle });
@@ -1292,6 +1327,7 @@ class DashboardController {
silentMode: this.silentMode,
screenOn: shell.isScreenOn(),
battery: this.lastHeadsetBattery,
glassesModel: glassesModelName(),
caseBattery: batteries.case,
caseCharging: batteries.caseCharging,
foregroundTitle: shell.getForegroundApp()?.title ?? null,
@@ -1464,12 +1500,12 @@ class DashboardController {
// is in place before any real render can reach the compositor.
this.previewTarget = target;
try {
await target.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
await target.configureCompositorScreen(screenWidth(), screenHeight());
await target.configureSurface(SHELL_SURFACE_ID, {
x: 0,
y: 0,
width: G2_LENS_WIDTH,
height: G2_LENS_HEIGHT,
width: screenWidth(),
height: screenHeight(),
zOrder: SHELL_SURFACE_Z_ORDER,
transparency: "color-key",
});
@@ -1552,17 +1588,21 @@ class DashboardController {
this.refreshEvenAppStatus();
this.setPhase("connecting");
this.setStatus("Connecting to the glasses...");
// "Only via glasses" (the default) means the phone never opens its own
// link to the ring: the glasses relay its gestures to us anyway. An empty
// address disables every direct-ring code path in the communicator.
const ringMode = ringConnectionModeSetting.get();
// "Only via glasses" (the G2's default) means the phone never opens its
// own link to the ring: the glasses relay its gestures to us anyway. An
// empty address disables every direct-ring code path in the communicator.
// A RayNeo iO (one link, its address in both arm slots) can't relay a
// ring, so with one the phone always takes the ring directly.
const ringMode = effectiveRingConnectionMode();
this.ringModeAtConnect = ringMode;
const glassesType = glassesTypeSetting.get();
const ringAddress = ringMode !== "glasses" ? addresses.ring : "";
// Direct mode may unpair the ring from the glasses; remember to hand it
// back once a later session runs in another mode.
if (ringMode === "direct" && ringAddress) setBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, true);
this.appendLog(
`Using configured arms: R=${addresses.right} L=${addresses.left}${ringAddress ? ` ring=${ringAddress}` : ""}`,
this.appendLog((glassesType === "rayneo-io"
? `Using configured RayNeo iO: ${addresses.right}`
: `Using configured arms: R=${addresses.right} L=${addresses.left}`) + (ringAddress ? ` ring=${ringAddress}` : ""),
);
let communicator: FaceclawCommunicatorBridge | null = null;
@@ -1584,6 +1624,7 @@ class DashboardController {
// sync needs the phone role, which the session borrows briefly for
// each pull (GlassesSessionRing.beginRingHealthWindowLocked).
ringRole: ringMode === "direct" ? "glasses" : "phone",
glassesType,
});
this.communicator = communicator;
// Size the compositor before anything else is awaited: windows opened
@@ -1591,9 +1632,12 @@ class DashboardController {
// configure their surfaces through this.communicator, and the Java call
// queue is FIFO, so enqueuing the screen size first guarantees it lands
// ahead of them. Mirrors ensurePreviewDisplay.
await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
// The paired glasses' screen: the G2's 640x480 or the RayNeo iO's 540x220.
await communicator.configureCompositorScreen(screenWidth(), screenHeight());
await communicator.configureBrightness(getBrightnessPreferences());
this.pushHeadUpPreferences(true);
this.voiceWakeSent = null;
this.syncVoiceWake(communicator);
this.offState = communicator.onStateChange((state) => {
if (state.phase !== "connected") resetRingInputFilter();
if (isHaltedSessionPhase(state.phase)) {
@@ -1784,8 +1828,8 @@ class DashboardController {
await communicator.configureSurface(SHELL_SURFACE_ID, {
x: 0,
y: 0,
width: G2_LENS_WIDTH,
height: G2_LENS_HEIGHT,
width: screenWidth(),
height: screenHeight(),
zOrder: SHELL_SURFACE_Z_ORDER,
transparency: "color-key",
});
@@ -2092,8 +2136,8 @@ class DashboardController {
return;
}
const at = mirrorToPanelFraction(this.displayPreviewCrop, nx, ny);
const x = Math.round(Math.min(1, Math.max(0, at.nx)) * G2_LENS_WIDTH);
const y = Math.round(Math.min(1, Math.max(0, at.ny)) * G2_LENS_HEIGHT);
const x = Math.round(Math.min(1, Math.max(0, at.nx)) * screenWidth());
const y = Math.round(Math.min(1, Math.max(0, at.ny)) * screenHeight());
const foreground = shell.foregroundWindow();
const stripShown = sidebarStripVisible(shell.getFocus(), foreground?.appId);
this.appendLog(`mirror tap at ${x},${y}`);
@@ -2661,11 +2705,7 @@ class DashboardController {
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
requestShellRender: () => this.requestShellRender(),
openSettings: (section) => {
void this.launchApp("settings", { section }).catch((error) => {
this.appendLog(`settings launch failed: ${this.formatError(error)}`);
});
},
openSettings: (section) => this.openSettings(section),
startTextSettingEdit: (settingId) => {
const setting = getStringSettingById(settingId);
if (setting) {
@@ -2749,6 +2789,13 @@ class DashboardController {
this.requestShellRender();
}
/** Open or focus the Settings app, optionally on a section (by label). */
private openSettings(section?: string): void {
void this.launchApp("settings", { section }).catch((error) => {
this.appendLog(`settings launch failed: ${this.formatError(error)}`);
});
}
/**
* Launch an app by id: the launcher grid, assistant tools, window-menu
* Settings item, and open-apps restore all come through here. Apps with an
@@ -2965,7 +3012,7 @@ class DashboardController {
// The tray shows the notification at once; its popup waits out a short
// delay, so one withdrawn right away (see NotificationPopupDelay) never shows.
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
if (notification && shouldShowNotificationOnGlasses(notification.packageName)) {
if (notification && shouldPopUpNewNotification(notification.packageName)) {
this.notificationPopups.post(notificationKey, notificationPopupDelayMs(notification));
}
this.requestShellRender();
@@ -2987,7 +3034,7 @@ class DashboardController {
private popUpAndroidNotification(notificationKey: string): void {
try {
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
if (!notification || !shouldShowNotificationOnGlasses(notification.packageName)) return;
if (!notification || !shouldPopUpNewNotification(notification.packageName)) return;
// New notifications open a shell modal over the app viewport; if the
// screen was off, wake for it and go back to sleep when it is closed.
// Waking while already on would steal focus, so only wake from sleep.
+114 -2
View File
@@ -30,7 +30,10 @@ export { bytesToHex, hexToBytes };
/** Even Realities' manufacturer-data company identifier (`"ER"` read little-endian). */
export const EVEN_COMPANY_IDENTIFIER = 0x5245;
export type EvenDeviceRole = "left" | "right" | "ring";
export type EvenDeviceRole = "left" | "right" | "ring" | "rayneo-io";
/** The firmware an Even G1 arm advertises: Even's, or Faceclaw's g1v0 (in safe mode: only updates work). */
export type G1Firmware = "stock" | "g1v0" | "g1v0-safe";
/** True when the manufacturer data opens with Even's `"ER"` marker. */
export function hasEvenManufacturerSignature(mfg: Uint8Array): boolean {
@@ -71,6 +74,61 @@ export function extractG2AdvertisementFlag(mfg: Uint8Array): number | null {
return mfg[22]!;
}
/**
* ## Even G1 arm
*
* On Even's firmware the name is `Even G1_<token>_<L|R>_<hex6>` and the manufacturer data `[01 right | 02 left]` +
* the ASCII serial, zero-padded (the first two bytes read as a "company id" that differs per arm). On g1v0 the name
* is `G1CFW_<L|R>_<hex6>` with the same digits and address as stock's, and the scan response holds company 0xFFFF, a
* format byte (2), a flags byte (bit 3: safe mode), the firmware's version in three bytes, and the pair ID in ASCII:
* the frame serial, the same on both arms. Before 0.5.66: `G1v0_L` or `G1v0_R` (`G1v0S_…` in safe mode), format 1, no
* version.
*/
export function g1FromName(name: string | null | undefined): { side: "left" | "right"; firmware: G1Firmware } | null {
if (!name) return null;
const custom = /^G1CFW_([LR])_[0-9A-F]{6}$/i.exec(name.trim());
if (custom) return { side: custom[1]!.toUpperCase() === "L" ? "left" : "right", firmware: "g1v0" };
const g1v0 = /^G1V0(S?)_([LR])$/i.exec(name.trim());
if (g1v0) {
return {
side: g1v0[2]!.toUpperCase() === "L" ? "left" : "right",
firmware: g1v0[1] ? "g1v0-safe" : "g1v0",
};
}
if (!/^EVEN G1_/i.test(name.trim())) return null;
const side = g2SideFromName(name);
return side ? { side, firmware: "stock" } : null;
}
/** What g1v0's pair record says beyond the serial; null when there is no record of a format that says it. */
export function parseG1Record(mfg: Uint8Array): { version: string; safeMode: boolean } | null {
if (mfg.length < 7 || mfg[0] !== 0xff || mfg[1] !== 0xff || mfg[2] !== 2) return null;
return { version: `${mfg[4]}.${mfg[5]}.${mfg[6]}`, safeMode: (mfg[3]! & 8) !== 0 };
}
/** The pair's serial from an arm's manufacturer data, on either firmware; null when absent. */
export function extractG1Serial(mfg: Uint8Array, firmware: G1Firmware): string | null {
const record = mfg.length >= 4 && mfg[0] === 0xff && mfg[1] === 0xff;
const start = firmware === "stock" ? 1 : record && mfg[2] === 2 ? 7 : record && mfg[2] === 1 ? 4 : -1;
if (start < 0 || mfg.length <= start) return null;
let serial = "";
for (let i = start; i < mfg.length; i++) {
const byte = mfg[i]!;
if (byte === 0) break;
if (byte < 0x20 || byte > 0x7e) return null;
serial += String.fromCharCode(byte);
}
return serial.length ? serial : null;
}
/** RayNeo iO manufacturer data (company 0x5716, little-endian first): `[07][MAC x6]...`, outside pairing mode. */
export const RAYNEO_COMPANY_IDENTIFIER = 0x5716;
export function extractRayNeoMac(mfg: Uint8Array): string | null {
if (mfg.length < 9 || mfg[0] !== 0x16 || mfg[1] !== 0x57 || mfg[2] !== 0x07) return null;
return Array.from(mfg.subarray(3, 9), (byte) => byte.toString(16).padStart(2, "0").toUpperCase()).join(":");
}
/**
* Which side a G2 temple advertisement belongs to, from the local name.
* Null when the name carries neither or both markers.
@@ -210,6 +268,10 @@ export type EvenAdvertisement = {
manufacturerData: string;
/** Why an otherwise Even-looking advertisement could not be fully parsed. */
note: string | null;
/** Set on an Even G1 arm (role left or right): its firmware. */
g1Firmware?: G1Firmware;
/** The version g1v0 advertises (0.5.66+); absent when it doesn't say. */
g1Version?: string;
};
/**
@@ -230,8 +292,58 @@ export function classifyAdvertisement(raw: RawAdvertisement): EvenAdvertisement
const hasSignature = hasEvenManufacturerSignature(mfg);
const looksLikeRing = /^EVEN R1([_ ]|$)/.test(upper);
const looksLikeG2 = upper.includes("G2");
const rayneoMac = extractRayNeoMac(mfg);
const looksLikeRayNeo = upper.startsWith("RAYNEO") || rayneoMac !== null;
if (!looksLikeRing && !looksLikeG2 && !hasSignature) return null;
const g1 = g1FromName(name);
if (g1) {
const serial = extractG1Serial(mfg, g1.firmware);
const record = g1.firmware === "stock" ? null : parseG1Record(mfg);
return {
address: normalizeMacAddress(raw.address),
name,
role: g1.side,
serial,
embeddedMac: null,
embeddedMacMismatch: false,
flag: null,
ringSerialSuffix: null,
rssi: raw.rssi,
txPower: raw.txPower,
connectable: raw.connectable,
bonded: raw.bonded,
source: raw.source,
seenAtMs: raw.seenAtMs,
manufacturerData: raw.manufacturerData ?? "",
note: serial ? null : "no serial in the advertisement (it may still be arriving)",
g1Firmware: record?.safeMode ? "g1v0-safe" : g1.firmware,
...(record ? { g1Version: record.version } : {}),
};
}
if (!looksLikeRing && !looksLikeG2 && !hasSignature && !looksLikeRayNeo) return null;
if (looksLikeRayNeo && !hasSignature) {
const address = normalizeMacAddress(raw.address);
return {
address,
name,
role: "rayneo-io",
serial: null,
embeddedMac: rayneoMac,
embeddedMacMismatch: !!rayneoMac && rayneoMac !== address,
flag: null,
ringSerialSuffix: null,
rssi: raw.rssi,
txPower: raw.txPower,
connectable: raw.connectable,
bonded: raw.bonded,
source: raw.source,
seenAtMs: raw.seenAtMs,
manufacturerData: raw.manufacturerData ?? "",
note: null,
};
}
const base = {
address: normalizeMacAddress(raw.address),
+5
View File
@@ -117,6 +117,11 @@ export function firmwareIncompatibilityMessage(info: FirmwareInfo): string | nul
const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`;
const required = `Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}`;
// A G1's session names what the arms run instead of a revision (GlassesSessionG1.kt).
if (extension.kind === "none" && reportedVersions.some((version) => /^(g1v0|Even's firmware)/.test(version))) {
return `These G1 glasses run ${versionsText}. This version of Faceclaw needs the firmware it comes with: install it to continue.`;
}
switch (extension.kind) {
case "faceclaw":
if (extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION) return null;
+10 -8
View File
@@ -3,6 +3,8 @@ export type GlassesDisplayState = {
silentMode: boolean;
screenOn: boolean;
battery: number | null;
/** The paired glasses' model, e.g. "G2" (glassesModelName). */
glassesModel: string;
/**
* The charging case's last-known level, and whether it is on USB (null
* while the glasses are out of the case). Shown only while charging, when
@@ -20,7 +22,7 @@ export function glassesDisplayLabel(state: GlassesDisplayState): string {
// Charging wins over every session-local state: the glasses are in their
// case, so neither the lock screen nor the foreground window is visible.
if (state.phase === "charging") {
return chargingDisplayLabel(state.battery);
return chargingDisplayLabel(state.battery, state.glassesModel);
}
// Preview mode has a live (simulated) screen despite the disconnected
// phase, so fall through to the screen-state/foreground labels.
@@ -63,8 +65,8 @@ export function glassesDisplayAsleep(state: GlassesDisplayState): boolean {
);
}
export function chargingDisplayLabel(battery: number | null): string {
return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging";
export function chargingDisplayLabel(battery: number | null, glassesModel: string): string {
return validBatteryLevel(battery) ? `Charging: ${glassesModel} ${battery}%` : "Charging";
}
/** The shell's last-known battery levels (ShellChromeState["battery"]), as far as the phone shows them. */
@@ -81,13 +83,13 @@ export type BatteryLevels = {
* The phone Settings tab's battery row: each device whose level is known,
* e.g. "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging), or "" when none
* is. Levels are the last known ones (the case only reports while the glasses
* are docked), so ⚡ appears only while it is live: G2 and Case only with a
* link to the glasses (`glassesLinked`: connected or charging), and Case only
* while they are docked (caseCharging is null otherwise).
* are docked), so ⚡ appears only while it is live: the glasses and Case only
* with a link to the glasses (`glassesLinked`: connected or charging), and Case
* only while they are docked (caseCharging is null otherwise).
*/
export function formatBatteryLine(levels: BatteryLevels, glassesLinked: boolean): string {
export function formatBatteryLine(levels: BatteryLevels, glassesLinked: boolean, glassesModel: string): string {
const devices: Array<[string, number | null, boolean | null]> = [
["G2", levels.headset, glassesLinked && levels.headsetCharging],
[glassesModel, levels.headset, glassesLinked && levels.headsetCharging],
["Case", levels.case, glassesLinked && levels.caseCharging],
["R1", levels.ring, levels.ringCharging],
];
+15 -1
View File
@@ -1,12 +1,26 @@
import { classifyAdvertisement, hasEvenManufacturerSignature, type EvenAdvertisement } from './even-advertisement'
import { classifyAdvertisement, g1FromName, hasEvenManufacturerSignature, type EvenAdvertisement } from './even-advertisement'
import { hexToBytes } from '../util/hex-util'
export type IosAdvertisement = { identifier: string; name: string; manufacturerData: string; rssi: number; connectable: boolean }
export type IosDevice = EvenAdvertisement & { identifier: string }
/**
* A G1 arm advertises no full MAC, and CoreBluetooth hides the real one. Faceclaw's addresses are MAC-shaped everywhere, so its
* address on this phone is made from the peripheral identifier. It's stable as long as the identifier is, which on firmware
* 0.5.66 and later is across installs too, and it only has to mean something on this phone: nobody types it in.
*/
export function g1IosAddress(identifier: string): string {
return identifier.replace(/-/g, '').slice(0, 12).toUpperCase().replace(/(..)(?=.)/g, '$1:')
}
/** Only a full vendor-advertised MAC may bind a manually entered address. */
export function identifyIosPeripheral(raw: IosAdvertisement): IosDevice | null {
if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(raw.identifier)) return null
if (g1FromName(raw.name)) {
const arm = classifyAdvertisement({ ...raw, address: g1IosAddress(raw.identifier), source: 'scan', bonded: false,
txPower: null, seenAtMs: Date.now() })
return arm && { ...arm, identifier: raw.identifier.toUpperCase() }
}
if (!hasEvenManufacturerSignature(hexToBytes(raw.manufacturerData))) return null
const candidate = classifyAdvertisement({ ...raw, address: '', source: 'scan', bonded: false,
txPower: null, seenAtMs: Date.now() })
+16 -8
View File
@@ -2,7 +2,6 @@ import { startRemoteInput } from "../remote/service"
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup, readActiveNotifications } from '../native/notification-icons.ios'
import { shouldShowNotificationOnGlasses } from '../native/notification-sources'
import { launcherEntries } from '../apps/launcher'
import { discardZeroedEvenHubPackage, getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
import { isInstalledPackagePresent } from '../apps/evenhub/updates'
@@ -23,6 +22,7 @@ import { weatherBridge } from '../native/weather'
import { FaceclawCommunicatorBridge, resolveIosPeripherals, type CommunicatorState, type RawInputEvent } from '../native/faceclaw-communicator.ios'
import { PreviewDisplayTarget, type DisplayTarget } from '../native/preview-display.ios'
import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client'
import { G1V0_IMAGE } from '../g1/firmware/g1v0-image'
import { GlanceHost, type GlanceDisplay } from './glance-host'
import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from './lock-screen'
import { OsEventTypeList } from './events'
@@ -53,7 +53,7 @@ import { onAnySettingChanged,
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
openAiApiKeySetting, openAiTranscriptionModelSetting, sonioxApiKeySetting, whisperServerApiKeySetting, getVoiceTranscriptionLanguage,
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting } from '../ui/dashboard-settings'
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting, glassesTypeSetting, shouldPopUpNewNotification } from '../ui/dashboard-settings'
import { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
import type { PhoneGesture } from '../phone-ui/phone-gestures'
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
@@ -215,7 +215,8 @@ export class IosPreviewController {
requestShellRender: () => this.requestShellRender(),
onWindowsChanged: () => { this.requestShellRender(); this.syncEvenHubPhoneUi(); this.wearRemote?.schedulePublish() },
openNotificationsWindow: () =>
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID,
options => createNotificationsAppWindow(options, section => { void this.launchApp('settings', { section }) })),
onSwitcherBarHeightChanged: () => {
this.relayout()
shell.foregroundWindow()?.requestRender()
@@ -253,7 +254,7 @@ export class IosPreviewController {
shell.focusWindow(launcher.windowId)
onIosNotificationPopup(key => {
const notification = readActiveNotifications(128).find(n => n.key === key)
if (this.glassesLocked || !notification || !shouldShowNotificationOnGlasses(notification.packageName)) return
if (this.glassesLocked || !notification || !shouldPopUpNewNotification(notification.packageName)) return
const woke = !shell.isScreenOn() && shell.wake('sidebar')
shell.openNotificationModal(key, woke)
this.requestShellRender()
@@ -278,7 +279,7 @@ export class IosPreviewController {
// The header's EvenHub phone-UI button hides while that UI is showing.
onPhoneShownChanged(() => this.syncEvenHubPhoneUi())
registerSystemTools()
registerWindowTools({ apps: ALL_APPS.filter(app => !iosAppUnavailableReason(app.appId)),
registerWindowTools({ apps: () => ALL_APPS.filter(app => app.isSupported?.() !== false && !iosAppUnavailableReason(app.appId)),
launchApp: id => this.launchApp(id), requestShellRender: () => this.requestShellRender() })
registerNavigateTools(id => this.launchApp(id))
registerRoamTools(id => this.launchApp(id))
@@ -286,7 +287,7 @@ export class IosPreviewController {
iosVoiceInput.onSpeechEnd(() => this.syncContinuousCapture())
for (const app of ALL_APPS) if (app.appId !== 'launcher' && !iosAppUnavailableReason(app.appId)) app.boot?.(this.buildAppContext(app))
this.wearRemote = new WearRemote({
apps: ALL_APPS.filter(app => app.showInLauncher !== false && !iosAppUnavailableReason(app.appId)),
apps: () => ALL_APPS.filter(app => app.showInLauncher !== false && app.isSupported?.() !== false && !iosAppUnavailableReason(app.appId)),
injectInput: kind => this.injectWatchInput(kind),
launchApp: id => this.launchApp(id),
// The watch's Connect/Disconnect are explicit user choices, like the phone's own buttons.
@@ -808,7 +809,7 @@ export class IosPreviewController {
const display = this.display
if (!display) return
await display.configureSurface(id, { ...appViewportRect(heightMode, appId), zOrder: 0, transparency: 'opaque' })
await display.setSurfaceVisible(id, visible)
await display.setSurfaceVisible(id, typeof visible === 'function' ? visible() : visible)
},
setSurfaceVisible: (id, visible) => this.setWindowSurfaceVisible(id, visible),
removeSurface: id => this.removeWindowSurface(id),
@@ -887,7 +888,7 @@ export class IosPreviewController {
return
}
if (this.communicator) await this.closeCommunicator()
const communicator = new FaceclawCommunicatorBridge(identifiers)
const communicator = new FaceclawCommunicatorBridge({ ...identifiers, glassesType: glassesTypeSetting.get() })
this.teardownPreviewDisplay()
this.communicator = communicator
this.wearDetectionRequested = false
@@ -991,6 +992,8 @@ export class IosPreviewController {
// (or re-pairs / installs the custom firmware, which lift the suppression).
if (isHaltedSessionPhase(state.phase)) suppressAutoReconnect()
const phase: SessionPhase = state.phase === 'charging' ? 'connected' : isHaltedSessionPhase(state.phase) ? 'error' : state.phase
// The relay ends with the link, so a reconnected session has to ask for it again (syncNotifications).
if (phase !== 'connected' && this.notifications && this.notifications.state !== 'disconnected') this.notifications.stop()
// Wear state is a per-transport snapshot: ask again on every new session.
if (phase !== 'connected') this.wearDetectionRequested = false
this.update(phase, state.status)
@@ -1034,6 +1037,11 @@ export class IosPreviewController {
if (this.state.capabilities) notifications.stop(`Update glasses to Faceclaw firmware ${ANCS_FIRMWARE_VERSION} or newer for iPhone notifications.`)
return
}
// A G1 reports no revision that says so: its session knows from what the right arm answered.
if (!communicator.ancsRelayAvailable()) {
notifications.stop(`Update the glasses to Faceclaw's firmware ${G1V0_IMAGE.version} for iPhone notifications, then reconnect.`)
return
}
if (notifications.state !== 'disconnected') return
notifications.start((Date.now() ^ Math.floor(Math.random() * 0xffffffff)) >>> 0, communicator.rightWriteLimit())
}
+8 -5
View File
@@ -1,23 +1,26 @@
import { GrayImage, G2_LENS_WIDTH, G2_LENS_HEIGHT } from "../graphics/image";
import { GrayImage } from "../graphics/image";
import { screenHeight, screenWidth } from "../graphics/screen-size";
import { getDefaultMediumFont } from "../graphics/ui-fonts";
import { wrapText } from "../graphics/textwrap";
export const LOCK_SCREEN_SURFACE_ID = "lock-screen";
const LOCK_SCREEN_MESSAGE = "Glasses locked; unlock the phone to unlock the glasses.";
/** The paired glasses' whole screen, black, with the message in a box at its centre. */
export function createLockScreenImage(): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const width = screenWidth(), height = screenHeight();
const image = new GrayImage(width, height, 0);
const font = getDefaultMediumFont();
const boxWidth = 480;
const boxHeight = 150;
const boxX = Math.round((G2_LENS_WIDTH - boxWidth) / 2);
const boxY = Math.round((G2_LENS_HEIGHT - boxHeight) / 2);
const boxX = Math.round((width - boxWidth) / 2);
const boxY = Math.round((height - boxHeight) / 2);
image.drawRoundedRect(boxX, boxY, boxWidth, boxHeight, 150, 12);
const lines = wrapText(font, LOCK_SCREEN_MESSAGE, boxWidth - 64);
const textHeight = lines.length * font.lineHeight;
const firstY = boxY + Math.round((boxHeight - textHeight) / 2);
lines.forEach((line, index) => {
const x = Math.round((G2_LENS_WIDTH - font.measureText(line)) / 2);
const x = Math.round((width - font.measureText(line)) / 2);
image.drawText(font, x, firstY + index * font.lineHeight, line, 230);
});
return image;
+104 -10
View File
@@ -16,12 +16,11 @@ import {
RING_CALIBRATION,
sortedByProximity,
zoneGlyph,
zoneLabel,
type ProximityEstimate,
type ProximityZone,
} from "./ble-proximity";
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type RawAdvertisement } from "./even-advertisement";
import { glassesImagePath, R1_IMAGE_PATH } from "./glasses-artwork";
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type G1Firmware, type RawAdvertisement } from "./even-advertisement";
import { GENERIC_G2_IMAGE_PATH, glassesImagePath, R1_IMAGE_PATH } from "./glasses-artwork";
import {
colorwayDisplayName,
colorwaySwatchHex,
@@ -48,6 +47,8 @@ export type GlassesPairCandidate = {
rssi: number | null;
proximity: ProximityEstimate | null;
lastSeenMs: number;
/** An Even G1 pair: the arms' firmware, the "lower" of the two (stock, then safe mode). Absent on a G2. */
g1Firmware?: G1Firmware;
/**
* Set when this lone arm and a lone arm of the other side carry different
* serials — the mixed-pair situation the serial check exists to name.
@@ -56,6 +57,15 @@ export type GlassesPairCandidate = {
mismatchWarning: string | null;
};
/** A RayNeo iO: one device, one address (no arms to join). */
export type RayNeoCandidate = {
id: string;
advertisement: EvenAdvertisement;
rssi: number | null;
proximity: ProximityEstimate | null;
lastSeenMs: number;
};
export type RingCandidate = {
id: string;
advertisement: EvenAdvertisement;
@@ -176,9 +186,10 @@ export class DiscoveryAggregator {
pairs(): GlassesPairCandidate[] {
const groups = new Map<string, { left: (EvenAdvertisement & { smoothedRssi: number | null }) | null; right: (EvenAdvertisement & { smoothedRssi: number | null }) | null }>();
for (const record of this.byAddress.values()) {
if (record.role === "ring") continue;
if (record.role === "ring" || record.role === "rayneo-io") continue;
const canonical = serialKey(record.serial);
const key = canonical ? `serial:${canonical}` : `arm:${record.address}`;
const family = record.g1Firmware ? "g1:" : "";
const key = canonical ? `${family}serial:${canonical}` : `arm:${record.address}`;
const group = groups.get(key) ?? { left: null, right: null };
const slot = record.role === "left" ? "left" : "right";
const incumbent = group[slot];
@@ -199,7 +210,9 @@ export class DiscoveryAggregator {
pairs.push({
id: serialKey(serial) ?? `arm:${any.address}`,
serial,
identity: GlassesHardwareIdentity.decode(serial),
// Even's G2 serial scheme; a G1's says nothing to it.
identity: any.g1Firmware ? null : GlassesHardwareIdentity.decode(serial),
...(any.g1Firmware ? { g1Firmware: g1PairFirmware(left, right) } : {}),
left: left ? stripSmoothing(left) : null,
right: right ? stripSmoothing(right) : null,
completeness: left && right ? "complete" : left ? "left-only" : "right-only",
@@ -225,6 +238,22 @@ export class DiscoveryAggregator {
}
/** Every R1 ring seen, closest first. */
rayneos(): RayNeoCandidate[] {
const found: RayNeoCandidate[] = [];
for (const record of this.byAddress.values()) {
if (record.role !== "rayneo-io") continue;
const rssi = record.smoothedRssi != null ? Math.round(record.smoothedRssi) : null;
found.push({
id: `rayneo:${record.address}`,
advertisement: stripSmoothing(record),
rssi,
proximity: estimateProximity(rssi, GLASSES_CALIBRATION),
lastSeenMs: record.seenAtMs,
});
}
return sortedByProximity(found, (candidate) => candidate.proximity, (candidate) => candidate.id);
}
rings(): RingCandidate[] {
const rings: RingCandidate[] = [];
for (const record of this.byAddress.values()) {
@@ -281,7 +310,7 @@ export function isPreviouslyPaired(name: string | null | undefined, pairedSerial
export type PairingRowPresentation = {
id: string;
kind: "glasses" | "ring";
kind: "glasses" | "ring" | "rayneo-io";
/** "Even G2 B" / "Even R1" / fallback product name. */
modelTitle: string;
/** The serial (glasses) or local name (ring). */
@@ -299,7 +328,6 @@ export type PairingRowPresentation = {
isPreviouslyPaired: boolean;
/** "Yours" / "Closest" / "". */
badge: string;
proximitySummary: string;
proximityGlyph: string;
zone: ProximityZone | null;
/** "Left + right arms found", "Only the left arm has been seen", …; "" when there is nothing worth a line (an unbonded ring). */
@@ -325,12 +353,11 @@ function presentationBase(
isNearest: boolean,
isPaired: boolean,
warnings: readonly string[],
): Pick<PairingRowPresentation, "isNearest" | "isPreviouslyPaired" | "badge" | "proximitySummary" | "proximityGlyph" | "zone" | "warning"> {
): Pick<PairingRowPresentation, "isNearest" | "isPreviouslyPaired" | "badge" | "proximityGlyph" | "zone" | "warning"> {
return {
isNearest,
isPreviouslyPaired: isPaired,
badge: isPaired ? "Yours" : isNearest ? "Closest" : "",
proximitySummary: proximity ? zoneLabel(proximity.zone) : "Signal unknown",
proximityGlyph: proximity ? zoneGlyph(proximity.zone) : "○○○○",
zone: proximity?.zone ?? null,
warning: warnings.join(" "),
@@ -342,7 +369,52 @@ function embeddedMacMismatchWarning(subject: string, ad: EvenAdvertisement | nul
return `${subject} advertised address ${ad.embeddedMac} differs from its radio address ${ad.address}.`;
}
/** The pair can only do what its less capable arm can. */
function g1PairFirmware(left: EvenAdvertisement | null, right: EvenAdvertisement | null): G1Firmware {
const firmwares = [left?.g1Firmware, right?.g1Firmware];
if (firmwares.includes("stock")) return "stock";
return firmwares.includes("g1v0-safe") ? "g1v0-safe" : "g1v0";
}
export function g1Row(pair: GlassesPairCandidate, context: RowContext = {}): PairingRowPresentation {
const isPreviouslyPairedRow = isPreviouslyPaired(pair.serial, context.pairedSerial);
const isNearest = !!context.nearestId && context.nearestId === pair.id;
const warnings: string[] = [];
if (pair.mismatchWarning) warnings.push(pair.mismatchWarning);
let armsSummary: string;
let canSelect = false;
if (pair.completeness !== "complete") {
armsSummary = pair.completeness === "left-only"
? "Only the left arm has been seen — waiting for the right"
: "Only the right arm has been seen — waiting for the left";
} else if (pair.g1Firmware === "stock") {
armsSummary = "Runs Even's firmware. Faceclaw will install its own, with the glasses in the case";
canSelect = true;
} else if (pair.g1Firmware === "g1v0-safe") {
armsSummary = "In safe mode: the firmware restarted repeatedly. Faceclaw can install it again, with the glasses in the case";
canSelect = true;
} else {
armsSummary = "Left + right arms found. To pair, keep them in the case with the lid open";
canSelect = true;
}
return {
id: pair.id,
kind: "glasses",
modelTitle: "Even Realities G1",
deviceName: pair.serial ?? (pair.left ?? pair.right)!.name,
variantSummary: null,
colorway: null,
swatchHex: null,
imagePath: GENERIC_G2_IMAGE_PATH,
hasVariantImage: false,
...presentationBase(pair.proximity, isNearest, isPreviouslyPairedRow, warnings),
armsSummary,
canSelect,
};
}
export function glassesRow(pair: GlassesPairCandidate, context: RowContext = {}): PairingRowPresentation {
if (pair.g1Firmware) return g1Row(pair, context);
const identity = pair.identity;
const imagePath = glassesImagePath(identity);
const isPreviouslyPairedRow = isPreviouslyPaired(pair.serial, context.pairedSerial);
@@ -416,6 +488,28 @@ export function ringRow(ring: RingCandidate, context: RowContext = {}): PairingR
};
}
export function rayneoRow(candidate: RayNeoCandidate, context: { pairedAddress?: string; nearestId?: string | null } = {}): PairingRowPresentation {
const ad = candidate.advertisement;
const isPaired = !!context.pairedAddress && normalizeMacAddress(context.pairedAddress) === ad.address;
const isNearest = !!context.nearestId && context.nearestId === candidate.id;
const warnings: string[] = [];
if (ad.embeddedMacMismatch) warnings.push(`It advertises ${ad.embeddedMac} but was heard as ${ad.address}.`);
return {
id: candidate.id,
kind: "rayneo-io",
modelTitle: "RayNeo iO",
deviceName: ad.name || ad.address,
variantSummary: null,
colorway: null,
swatchHex: null,
imagePath: GENERIC_G2_IMAGE_PATH,
hasVariantImage: false,
...presentationBase(candidate.proximity, isNearest, isPaired, warnings),
armsSummary: "Needs the Faceclaw custom firmware. First time: put it in pairing mode (on the charger, hold the button ~5 s until the light blinks blue).",
canSelect: true,
};
}
/** Convenience: a colourway's display text, for rows that show the swatch alone. */
export function colorwayLabel(colorway: GlassesColorway | null): string {
return colorway ? colorwayDisplayName(colorway) : "";
+4 -5
View File
@@ -1,6 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
import { previewScalingSetting } from "../ui/dashboard-settings";
import { phonePreviewRect, usedScreenRect, type ScreenRect } from "../ui/shell/geometry";
import { phonePreviewRect, screenHeight, screenWidth, usedScreenRect, type ScreenRect } from "../ui/shell/geometry";
import { shell } from "../ui/shell/shell";
/**
@@ -14,7 +13,7 @@ export function phonePreviewCrop(locked: boolean, glanceRect: ScreenRect | null)
if (locked || previewScalingSetting.get() === "raw") return null;
const window = shell.foregroundWindow();
const crop = phonePreviewRect(glanceRect ?? usedScreenRect(window?.heightMode ?? "min", window?.appId));
const wholePanel = crop.x === 0 && crop.y === 0 && crop.width === G2_LENS_WIDTH && crop.height === G2_LENS_HEIGHT;
const wholePanel = crop.x === 0 && crop.y === 0 && crop.width === screenWidth() && crop.height === screenHeight();
return wholePanel ? null : crop;
}
@@ -27,7 +26,7 @@ export function phonePreviewCrop(locked: boolean, glanceRect: ScreenRect | null)
export function mirrorToPanelFraction(crop: ScreenRect | null, nx: number, ny: number): { nx: number; ny: number } {
if (!crop) return { nx, ny };
return {
nx: (crop.x + nx * crop.width) / G2_LENS_WIDTH,
ny: (crop.y + ny * crop.height) / G2_LENS_HEIGHT,
nx: (crop.x + nx * crop.width) / screenWidth(),
ny: (crop.y + ny * crop.height) / screenHeight(),
};
}
+5 -3
View File
@@ -32,6 +32,7 @@ import { type AppDefinition } from "../apps/app-definition";
import { getInstalledEvenHubApps, installedEvenHubAppId } from "../apps/evenhub/installed-apps";
import { WEAR_PATHS, wearBridge, type WearMessage } from "../native/wear-bridge";
import {
glassesModelName,
onAnySettingChanged,
watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
@@ -115,8 +116,8 @@ const WATCH_BATTERY_MAX_AGE_MS = 4 * 60 * 60_000;
/** What the dashboard controller lends the watch remote. */
export type WearRemoteHost = {
/** The launcher-grid apps; installed EvenHub packages are added dynamically. */
apps: readonly AppDefinition[];
/** The launcher-grid apps for the paired glasses; installed EvenHub packages are added dynamically. */
apps: () => readonly AppDefinition[];
injectInput: (kind: WearRemoteInputKind) => Promise<void>;
launchApp: (appId: string) => Promise<void>;
connect: () => Promise<void>;
@@ -294,6 +295,7 @@ export class WearRemote {
worn: state.glassesWorn,
listening: voiceActivity.isActive(),
battery: state.lastHeadsetBattery,
glassesModel: glassesModelName(),
charging: state.phase === "charging" || battery.headsetCharging === true,
caseBattery: battery.case,
caseCharging: battery.caseCharging,
@@ -320,7 +322,7 @@ export class WearRemote {
/** Launchable apps, matching the launcher grid and the apps.launch tool. */
private listApps(): Array<{ appId: string; title: string }> {
const apps = this.host.apps.map((app) => ({ appId: app.appId, title: app.title }));
const apps = this.host.apps().map((app) => ({ appId: app.appId, title: app.title }));
for (const installed of getInstalledEvenHubApps()) {
apps.push({ appId: installedEvenHubAppId(installed.packageId), title: installed.name });
}
+6 -61
View File
@@ -12,7 +12,8 @@
* - Text SIZING / KERNING / WRAPPING: @evenrealities/pretext, whose advance
* tables the bitmaps were validated against. Using pretext for measurement
* means our line breaks match exactly where EvenHub apps (which measure
* with the same library) expect them.
* with the same library) expect them. The one exception is leading spaces
* after a '\n', which stock keeps and pretext drops (see lvgl-wrap.ts).
*
* Bitmaps are 4bpp, high-nibble-first, row stride floor(boxW/2)+1. The UI
* fonts are effectively 1-bit (nibbles 0 or 0xF); we keep the nibble value so
@@ -23,6 +24,7 @@ import { File, knownFolders } from "@nativescript/core";
import { getTextWidth } from "@evenrealities/pretext";
import { EVENHUB_RUNTIME_FONT_FILENAME, isEvenHubFontAsset } from "../g2/firmware-fonts";
import { lvglMetrics, lvglGlyph } from "../native/lvgl-font";
import { wrapLvglText } from "./lvgl-wrap";
import { GrayImage, grayToNibble, type FwTextFont, type PlacedFwText, type PlacedFwTextGlyph } from "./image";
import { TtfFont } from "./ttf-font";
import { decodeBase64 } from "../util/base64";
@@ -200,63 +202,11 @@ export class EvenHubFont implements FwTextFont {
}
/**
* Wrap text to a pixel width, returning the actual line strings. Ports
* pretext's measureTextWrap (LVGL lv_text_get_next_line semantics) so the
* breaks land exactly where the measurement library reports them.
* Wrap text to a pixel width, returning the actual line strings: pretext's
* breaks, but keeping leading spaces after a '\n' (see lvgl-wrap.ts).
*/
wrap(text: string, maxWidth: number): string[] {
if (!text) return [""];
const cps = Array.from(text).map((c) => c.codePointAt(0)!);
const lines: string[] = [];
let line: number[] = [];
let lineWidth = 0;
let lastBreak = -1; // index within `line` after which we may wrap
for (let i = 0; i < cps.length; i++) {
const cp = cps[i]!;
if (cp === 10) {
lines.push(String.fromCodePoint(...line));
line = [];
lineWidth = 0;
lastBreak = -1;
continue;
}
// LVGL drops leading spaces at the start of a wrapped line.
if (line.length === 0 && cp === 32) continue;
const adv = this.advanceOf(cp, cps[i + 1] ?? 0);
if (lineWidth + adv > maxWidth) {
if (cp === 32) {
// The overflowing char is a space: break here, discard it.
lines.push(String.fromCodePoint(...line));
line = [];
lineWidth = 0;
lastBreak = -1;
} else if (lastBreak !== -1) {
// Wrap at the last break opportunity; carry the remainder forward.
const carry = line.slice(lastBreak + 1);
line = line.slice(0, lastBreak + 1);
const trimmed = line[line.length - 1] === 32 ? line.slice(0, -1) : line;
lines.push(String.fromCodePoint(...trimmed));
line = carry;
lineWidth = carry.reduce((sum, c, j) => sum + this.advanceOf(c, carry[j + 1] ?? 0), 0);
lastBreak = -1;
line.push(cp);
lineWidth += adv;
} else {
// No break opportunity: hard break before the overflowing char.
lines.push(String.fromCodePoint(...line));
line = [cp];
lineWidth = adv;
lastBreak = -1;
}
} else {
line.push(cp);
lineWidth += adv;
if (isBreakable(cp)) lastBreak = line.length - 1;
}
}
lines.push(String.fromCodePoint(...line));
return lines;
return wrapLvglText(text, maxWidth, kernedAdvance);
}
/**
@@ -446,8 +396,3 @@ export class EvenHubFont implements FwTextFont {
}
}
function isBreakable(cp: number): boolean {
if (cp === 32 || cp === 45) return true; // space, hyphen
// CJK ranges (pretext parity) — breakable between any two ideographs.
return (cp >= 0x2e80 && cp <= 0x9fff) || (cp >= 0xf900 && cp <= 0xfaff) || (cp >= 0xac00 && cp <= 0xd7af);
}
+63 -3
View File
@@ -4,8 +4,14 @@ import type { MenuHighlightAnimation } from "../ui/menu-highlight-motion";
import { Glyph } from "./bdffont";
import { wrapText } from "./textwrap";
// This file is also built by tests/tsconfig.json, which has no DOM or Node types.
declare const console: { warn(message: string): void };
export const G2_LENS_WIDTH = 640;
export const G2_LENS_HEIGHT = 480;
/** RayNeo iO screen (per eye) with the Faceclaw firmware: 540x220. */
export const RAYNEO_IO_WIDTH = 540;
export const RAYNEO_IO_HEIGHT = 220;
const DEFAULT_CORNER_RADIUS = 8;
/**
@@ -156,9 +162,15 @@ export class GrayImage {
private memoizedSourceHash: number | null = null;
constructor(width: number, height: number, fill = 0) {
this.width = width;
this.height = height;
this.pixels = new Uint8Array(width * height);
// A fractional width would put most rows' `y * width + x` between pixels,
// silently losing them. TTF text measures fractionally, so this is easy to
// hit; the stack is there because the size alone doesn't identify the caller.
if (!Number.isInteger(width) || !Number.isInteger(height)) {
console.warn(`GrayImage: rounding up non-integer size ${width}x${height}\n${new Error().stack}`);
}
this.width = Math.ceil(width);
this.height = Math.ceil(height);
this.pixels = new Uint8Array(this.width * this.height);
if (fill !== 0) {
this.clear(fill);
}
@@ -584,6 +596,25 @@ export class GrayImage {
}
}
/**
* bakeDeferredDrawsInPlace, but only for the draws whose ink may fall inside
* `rect`; the rest stay deferred. For covering part of the image with later
* raster (the EvenHub compositor painting an image container over text)
* without giving up the deferred wire path for everything else.
*/
bakeDeferredDrawsWithin(rect: { x: number; y: number; width: number; height: number }): void {
if (!this.drawList.length) return;
const covered = (b: { x: number; y: number; width: number; height: number } | null) =>
!b || (b.x < rect.x + rect.width && rect.x < b.x + b.width && b.y < rect.y + rect.height && rect.y < b.y + b.height);
const bake: DeferredDraw[] = [];
const keep: DeferredDraw[] = [];
for (const placed of this.drawList) (covered(placedDrawBounds(placed)) ? bake : keep).push(placed);
if (!bake.length) return;
this.drawList.splice(0, this.drawList.length, ...bake);
this.bakeDeferredDrawsInPlace();
this.drawList.push(...keep);
}
/**
* A copy of this image with its brightness scaled by `factor` (0..1):
* raster and glyph / firmware-text draws alike, keeping the draws deferred
@@ -693,6 +724,35 @@ export function grayToNibble(value: number): number {
/** Where rasterizeGlyph writes: an image, or a clipped buffer (paintReplayDraws). */
type PixelSink = { setPixel(x: number, y: number, value: number): void };
/** A deferred draw's ink rectangle, or null when it can't be bounded (treat as anywhere). */
function placedDrawBounds(placed: DeferredDraw): { x: number; y: number; width: number; height: number } | null {
if (placed.kind === "glyph") {
const { glyph } = placed;
return {
x: placed.x + glyph.bbxX,
y: placed.y + placed.font.ascent - (glyph.bbxHeight + glyph.bbxY),
width: glyph.bbxWidth,
height: glyph.bbxHeight,
};
}
if (placed.kind === "image") {
return placed.presentation ? null : { x: placed.x, y: placed.y, width: placed.source.width, height: placed.source.height };
}
let left = Infinity, top = Infinity, right = -Infinity, bottom = -Infinity;
for (const member of placed.glyphs) {
if (!member.ink) continue;
const wire = placed.font.fwGlyphWireData(member.cp);
if (!wire) return null;
const x = placed.x + member.dx + wire.ofsX;
const y = placed.y + wire.inkTop;
left = Math.min(left, x);
top = Math.min(top, y);
right = Math.max(right, x + wire.boxW);
bottom = Math.max(bottom, y + wire.boxH);
}
return right < left ? { x: placed.x, y: placed.y, width: 0, height: 0 } : { x: left, y: top, width: right - left, height: bottom - top };
}
/** Bake one glyph into an image's pixel buffer (y is the top of the line). */
function rasterizeGlyph(
target: PixelSink,
+76
View File
@@ -0,0 +1,76 @@
/**
* Word wrap for EvenHub text containers, matching the stock firmware's LVGL
* labels as measured by running firmware 2.2.9.22 in the g2-firmware-emulator:
*
* - Spaces are kept wherever they fall: at the start of the text, after a
* '\n', and on soft-wrapped lines. A space that doesn't fit at the end of a
* line starts the next one, so "HHHHHHHH EEEE" in 100px (8 H = 96px,
* 5px spaces) wraps with all four spaces indenting the second line.
* - A line otherwise breaks after its last space, hyphen or CJK ideograph,
* or, with none, before the character that overflows.
*
* @evenrealities/pretext's measureTextWrap, which apps measure with, differs
* in one way: it drops spaces at the start of every line. Apps rely on stock's
* behavior, though: Iris Pro indents a line 11 spaces past a 40px glyph placed
* beside it, and stripping the indent slid the text under the icon.
*/
/** Wrap opportunities: space, hyphen, and between CJK ideographs. */
export function isLvglBreakable(cp: number): boolean {
if (cp === 32 || cp === 45) return true;
return (cp >= 0x2e80 && cp <= 0x9fff) || (cp >= 0xf900 && cp <= 0xfaff) || (cp >= 0xac00 && cp <= 0xd7af);
}
/**
* Split text into display lines no wider than maxWidth.
* `advanceOf(cp, next)` is the kerned pixel advance of cp before next (0 at the end).
*/
export function wrapLvglText(text: string, maxWidth: number, advanceOf: (cp: number, next: number) => number): string[] {
if (!text) return [""];
const cps = Array.from(text).map((c) => c.codePointAt(0)!);
const lines: string[] = [];
let line: number[] = [];
let lineWidth = 0;
// The last break opportunity on this line, as an index into cps, and how
// many of `line`'s codepoints end at it.
let lastBreak = -1;
let lastBreakKeep = 0;
const endLine = (keep: number[]) => {
lines.push(String.fromCodePoint(...keep));
line = [];
lineWidth = 0;
lastBreak = -1;
};
let i = 0;
while (i < cps.length) {
const cp = cps[i]!;
if (cp === 10) {
endLine(line);
i++;
continue;
}
const adv = advanceOf(cp, cps[i + 1] ?? 0);
if (lineWidth + adv <= maxWidth || line.length === 0) {
// A character wider than the whole line still takes one to itself.
line.push(cp);
lineWidth += adv;
if (isLvglBreakable(cp)) {
lastBreak = i;
lastBreakKeep = line.length;
}
i++;
} else if (cp !== 32 && lastBreak !== -1) {
// Wrap after the last break opportunity and rescan from there.
const restart = lastBreak + 1;
endLine(line.slice(0, lastBreakKeep));
i = restart;
} else {
// An overflowing space, or no break opportunity: this character starts the next line.
endLine(line);
}
}
lines.push(String.fromCodePoint(...line));
return lines;
}
+27
View File
@@ -0,0 +1,27 @@
/**
* The paired glasses' screen (per eye), which the shell and UI lay out in:
* the G2's 640x480, or the RayNeo iO's 540x220 with the Faceclaw firmware.
*
* Read straight from the settings store (the key dashboard-settings.ts's
* glassesTypeSetting writes), so this stays a leaf that UI primitives can
* import without pulling in the settings module, and every isolate (the
* main one, app workers, the phone preview) agrees with the session.
*/
import { getStringSetting } from "../native/settings-store";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, RAYNEO_IO_HEIGHT, RAYNEO_IO_WIDTH } from "./image";
/** Settings key of the paired glasses' type: "g2" (default) or "rayneo-io". */
export const GLASSES_TYPE_KEY = "deviceType";
/** Whether the paired glasses are a RayNeo iO. */
export function isRayNeoIoConfigured(): boolean {
return getStringSetting(GLASSES_TYPE_KEY, "g2") === "rayneo-io";
}
export function screenWidth(): number {
return isRayNeoIoConfigured() ? RAYNEO_IO_WIDTH : G2_LENS_WIDTH;
}
export function screenHeight(): number {
return isRayNeoIoConfigured() ? RAYNEO_IO_HEIGHT : G2_LENS_HEIGHT;
}
+16 -4
View File
@@ -13,6 +13,7 @@ import type { UiFont } from "./image";
import { TtfFont } from "./ttf-font";
import { ensurePreinstalledFonts, getInstalledFont, installedFontPath } from "./installed-fonts";
import { getStringSetting, onSettingsStoreChanged, setStringSetting } from "../native/settings-store";
import { GLASSES_TYPE_KEY, isRayNeoIoConfigured } from "./screen-size";
export type BitmapFace = "terminus" | "terminusv";
@@ -72,8 +73,18 @@ export function parseFontSelection(raw: string): UiFontSelection | null {
return null;
}
/** Default UI font when the user has never picked one. */
const DEFAULT_UI_FONT: UiFontSelection = { kind: "ttf", file: "Roboto-Light.ttf", size: 16 };
/**
* The default UI font's size, which onboarding recommends: 16, or 14 on the
* RayNeo iO, whose 540x220 screen fits fewer rows.
*/
export function defaultUiFontSize(): number {
return isRayNeoIoConfigured() ? 14 : 16;
}
/** Default UI font when the user has never picked one: Roboto Light at the default size. */
function defaultUiFont(): UiFontSelection {
return { kind: "ttf", file: "Roboto-Light.ttf", size: defaultUiFontSize() };
}
export function getUiFontSelection(): UiFontSelection {
const parsed = parseFontSelection(getStringSetting(UI_FONT_SELECTION_KEY, ""));
@@ -84,7 +95,7 @@ export function getUiFontSelection(): UiFontSelection {
if (legacy === "terminus" || legacy === "terminusv") {
return { kind: "bitmap", face: legacy };
}
return DEFAULT_UI_FONT;
return defaultUiFont();
}
export function setUiFontSelection(selection: UiFontSelection): void {
@@ -113,7 +124,8 @@ export function fontSelectionLabel(selection: UiFontSelection): string {
type UiFontRole = "small" | "medium" | "large";
const UI_FONT_KEYS: readonly string[] = [UI_FONT_SELECTION_KEY, LEGACY_UI_FONT_KEY];
/** Keys whose change re-resolves the UI fonts (the glasses type picks the default size). */
const UI_FONT_KEYS: readonly string[] = [UI_FONT_SELECTION_KEY, LEGACY_UI_FONT_KEY, GLASSES_TYPE_KEY];
/**
* The three role fonts for one selection source, resolved lazily and cached
+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
+489
View File
@@ -0,0 +1,489 @@
import { Frame, Observable } from "@nativescript/core";
import { G1ArmScanner } from "../g1/arm-scanner";
import { EVEN_G1_RESTORE } from "../g1/even-firmware";
import { G1V0_IMAGE } from "../g1/firmware/g1v0-image";
import {
buildEvenG1Firmware,
buildG1Firmware,
type BuiltEvenG1Firmware,
type BuiltG1Firmware,
type G1BuildProgress,
} from "../g1/firmware-builder";
import { saveG1Arm, saveG1Pair } from "../g1/addresses";
import {
G1_CASE_DELAY_HINT,
G1_CASE_INSTRUCTIONS,
G1_INSTALL_NOTICE,
G1_SIDES,
G1_UNINSTALL_NOTICE,
G1_UNINSTALL_SIDES,
g1FlashPercent,
type G1FlashResult,
type G1Side,
} from "../g1/flash-plan";
import { loadDeviceAddresses, loadPairedGlassesIdentity } from "../g2/device-addresses";
import { downloadAndExtractEvenHubFonts, hasExtractedEvenHubFonts } from "../g2/firmware-builder";
import { type GlassesPairCandidate } from "../g2/pairing-candidates";
import { resumeAutoReconnect, suppressAutoReconnect } from "../g2/reconnect-policy";
import { ensureBlePermissions } from "../native/ble-permissions";
import { forgetG1Pairing, G1Flasher, type G1FlasherOptions } from "../native/g1-flasher";
import { formatErrorMessage } from "../util/format-error";
import { finishOnboardingNavigation } from "./onboarding-navigation";
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
type Phase = "intro" | "preparing" | "flashing" | "flashed" | "error";
const LOCATE_MS = 45_000;
/** An arm takes about 20 s to copy the image, and a hung boot resets itself within two minutes. */
const RETURN_MS = 240_000;
/** Even's image is larger than g1v0, and MCUboot first installs the network core's. */
const RESTORE_RETURN_MS = 300_000;
/**
* Just after its reset an arm may still be heard on g1v0. Later than this, one heard on g1v0 has booted it again:
* MCUboot didn't take Even's firmware.
*/
const OLD_FIRMWARE_GRACE_MS = 15_000;
const CONNECT_MS = 60_000;
/** A new arm pairs only once it knows it's in the case, which a full case can take a while to tell it. */
const FIRST_PAIRING_MS = 120_000;
/**
* The install and uninstall page on a G1, in place of OnboardingFlashViewModel. The two arms are separate devices that
* each take the image over MCUmgr (G1ArmFlashFlow), left first; an uninstall goes right first and puts back both of
* Even's images, the network core's too. There is nothing on the lens to confirm with while an arm runs Even's
* firmware, so the confirmation is on the phone: the page before, or this one's intro.
*
* Every run starts by listening for what each arm runs now, so a retry picks up wherever the last one stopped. An arm's
* new address is saved as soon as it's known.
*/
export class G1FlashViewModel extends Observable {
private phase: Phase = "intro";
private readonly fromOnboarding: boolean;
private readonly uninstalling: boolean;
private readonly scanner = new G1ArmScanner();
private image: BuiltG1Firmware | null = null;
private evenImage: BuiltEvenG1Firmware | null = null;
private flasher: G1Flasher | null = null;
private generation = 0;
private disposed = false;
private unpairedArm = false;
/** An uninstall's outcome, for the last page: an arm's store erased, a pairing this phone couldn't remove, an arm done. */
private wiped = false;
private pairingLeft = false;
private restoredArm = false;
headline = "Install Faceclaw's Firmware";
status = "";
log = "";
busy = false;
progress = 0;
constructor(options?: { mode?: "install" | "uninstall"; fromOnboarding?: boolean; autoStart?: boolean }) {
super();
this.fromOnboarding = options?.fromOnboarding ?? true;
this.uninstalling = options?.mode === "uninstall";
suppressAutoReconnect();
if (this.uninstalling) {
this.headline = "Back to Even's Firmware";
this.status = `${G1_CASE_INSTRUCTIONS}\n\n${G1_UNINSTALL_NOTICE}`;
} else {
this.status = `${G1_CASE_INSTRUCTIONS}\n\n${G1_INSTALL_NOTICE}`;
}
if (options?.autoStart) void this.run();
}
// --- what the page binds --------------------------------------------------
get logVisibility(): "visible" | "collapse" {
return this.log ? "visible" : "collapse";
}
get busyVisibility(): "visible" | "collapse" {
return this.busy ? "visible" : "collapse";
}
get progressVisibility(): "visible" | "collapse" {
return this.phase === "flashing" ? "visible" : "collapse";
}
get primaryLabel(): string {
switch (this.phase) {
case "intro":
return this.uninstalling ? "Uninstall" : "Install";
case "flashed":
return "Finish";
case "error":
return "Retry";
default:
return "";
}
}
get primaryVisibility(): "visible" | "collapse" {
return this.primaryLabel ? "visible" : "collapse";
}
get secondaryLabel(): string {
return "Back";
}
get secondaryVisibility(): "visible" | "collapse" {
// No way out mid-install, or after one.
return this.phase === "preparing" || this.phase === "flashing" || this.phase === "flashed" ? "collapse" : "visible";
}
onPrimaryTap(): void {
if (this.phase === "intro" || this.phase === "error") void this.run();
else if (this.phase === "flashed") this.finish();
}
onSecondaryTap(): void {
if (this.phase === "intro" || this.phase === "error") this.leave();
}
// --- the install ----------------------------------------------------------
private async run(): Promise<void> {
const generation = ++this.generation;
const live = () => !this.disposed && generation === this.generation;
this.setPhase("preparing");
this.setBusy(true);
this.setText("Preparing Firmware", this.uninstalling ? "Getting Even's firmware ready..." : "Getting the firmware ready...");
try {
await ensureBlePermissions();
if (!live()) return;
if (this.uninstalling) {
if (!this.evenImage) {
this.evenImage = await buildEvenG1Firmware((progress) => {
if (live()) this.setStatus(describeEvenBuild(progress));
});
this.appendLog(`Even's firmware ${this.evenImage.version} downloaded and verified (${this.evenImage.bytes.toLocaleString()} bytes)`);
}
} else {
if (!this.image) {
this.image = await buildG1Firmware((progress) => {
if (live()) this.setStatus(describeBuild(progress));
});
this.appendLog(`firmware ${this.image.version} prepared and verified (${this.image.bytes.toLocaleString()} bytes)`);
}
await this.prepareFonts(live);
}
if (!live()) return;
this.setPhase("flashing");
this.setText(this.uninstalling ? "Restoring Even's Firmware" : "Installing Firmware", "Listening for your glasses...");
const identity = loadPairedGlassesIdentity();
const stored = loadDeviceAddresses();
const pair = await this.scanner.waitForPair({ serial: identity?.serial, left: stored.left, right: stored.right }, LOCATE_MS);
if (!live()) return;
if (!pair) {
throw new Error("Couldn't hear both arms of your glasses. Make sure they're in the case with the lid open, and that no other app " +
"or phone is connected to them, then retry.");
}
saveG1Pair(pair);
if (this.uninstalling) {
for (const side of G1_UNINSTALL_SIDES) {
await this.restoreArm(side, pair, live);
if (!live()) return;
}
this.restored();
return;
}
this.unpairedArm = false;
for (const side of G1_SIDES) {
await this.installArm(side, pair, live);
if (!live()) return;
}
this.finished();
} catch (error) {
if (live()) this.failed(formatErrorMessage(error));
}
}
private async installArm(side: G1Side, pair: GlassesPairCandidate, live: () => boolean): Promise<void> {
const arm = pair[side]!;
const fromStock = arm.g1Firmware === "stock";
this.setProgress(g1FlashPercent(side, 0, 1));
this.setStatus(`Connecting to the ${side} arm...`);
const installed = await this.flash({
address: arm.address,
side,
firmwarePath: this.image!.path,
mode: fromStock ? "stock" : "update",
connectWindowMs: CONNECT_MS,
}, (state) => {
if (state === "pairing") this.setStatus(`Pairing with the ${side} arm. If your phone asks, accept it.`);
else if (state === "checking") this.setStatus(`Checking the ${side} arm...`);
else if (state === "flashing") this.setStatus(`Sending the firmware to the ${side} arm. Nothing has changed yet.`);
else if (state === "committing") this.setStatus(`Installing on the ${side} arm. Keep the glasses in the case.`);
}, (sent, total) => this.setProgress(g1FlashPercent(side, sent, total)));
if (!live()) return;
this.setProgress(g1FlashPercent(side, 1, 1));
if (!installed.flashed) {
this.appendLog(`${side} arm already runs ${installed.version}`);
return;
}
this.setStatus(`The ${side} arm is restarting into the new firmware. This takes about 20 seconds; keep it in the case.`);
const identity = loadPairedGlassesIdentity();
const back = await this.scanner.waitForG1v0Arm(side, identity?.serial ?? pair.serial, RETURN_MS);
if (!live()) return;
if (!back) {
throw new Error(`The ${side} arm hasn't come back yet. Leave the glasses in the plugged-in case for a few minutes, with the lid ` +
"open: an interrupted install finishes by itself. Then retry.");
}
saveG1Arm(side, back);
// Coming from firmware before 0.5.66, which had an address of its own: the phone needn't remember that one.
if (back.address !== arm.address) forgetG1Pairing(arm.address);
if (back.g1Firmware === "g1v0-safe") {
throw new Error(`The ${side} arm came back in safe mode: the new firmware restarted repeatedly. Retry to install it again.`);
}
this.setStatus(`Checking the ${side} arm. If your phone asks to pair, accept it. ${G1_CASE_DELAY_HINT}`);
// An arm at a new address has no bond yet (coming from Even's firmware the address is kept from 0.5.66 on, and so is the
// bond). It may refuse one for a while: it's installed either way, and the session pairs it later.
const newAddress = back.address !== arm.address;
let running: G1FlashResult;
try {
running = await this.flash({
address: back.address,
side,
firmwarePath: "",
mode: "probe",
connectWindowMs: newAddress ? FIRST_PAIRING_MS : RETURN_MS,
});
} catch (error) {
if (!newAddress || !live()) throw error;
// Installed, as its advertising shows; it just won't pair yet. The next connection pairs it.
this.appendLog(`${side} arm not paired yet: ${formatErrorMessage(error)}`);
this.unpairedArm = true;
return;
}
if (!live()) return;
if (running.version !== installed.version) {
throw new Error(`The ${side} arm runs ${running.version}, not ${installed.version}: it didn't take the new firmware. Retry to try again.`);
}
this.appendLog(`${side} arm runs ${running.version}`);
}
/**
* Even's firmware back on one arm, then a wait for it to advertise as Even's. An arm already on Even's firmware is
* left alone: a retry goes on from there.
*/
private async restoreArm(side: G1Side, pair: GlassesPairCandidate, live: () => boolean): Promise<void> {
const arm = pair[side]!;
if (arm.g1Firmware === "stock") {
this.appendLog(`${side} arm already runs Even's firmware`);
this.setProgress(g1FlashPercent(side, 1, 1, G1_UNINSTALL_SIDES));
return;
}
const even = this.evenImage!;
this.setProgress(g1FlashPercent(side, 0, 1, G1_UNINSTALL_SIDES));
this.setStatus(`Connecting to the ${side} arm...`);
const result = await this.flash({
address: arm.address,
side,
firmwarePath: even.appPath,
netCorePath: even.netCorePath,
mode: "restore",
connectWindowMs: CONNECT_MS,
}, (state) => {
if (state === "pairing") this.setStatus(`Pairing with the ${side} arm. If your phone asks, accept it.`);
else if (state === "checking") this.setStatus(`Checking the ${side} arm...`);
else if (state === "wiping") {
this.setStatus(`Erasing Faceclaw's storage on the ${side} arm, where Even's fonts were. This can take several minutes; keep the ` +
"glasses in the case. Nothing else has changed yet.");
} else if (state === "flashing") this.setStatus(`Sending Even's firmware to the ${side} arm. Its firmware hasn't changed yet.`);
else if (state === "committing") this.setStatus(`Installing on the ${side} arm. Keep the glasses in the case.`);
}, (sent, total) => this.setProgress(g1FlashPercent(side, sent, total, G1_UNINSTALL_SIDES)));
if (!live()) return;
if (result.wiped) this.wiped = true;
this.setProgress(g1FlashPercent(side, 1, 1, G1_UNINSTALL_SIDES));
this.setStatus(`The ${side} arm is restarting into Even's firmware. This takes a minute or two; keep it in the case.`);
const resetAt = Date.now();
const identity = loadPairedGlassesIdentity();
const back = await this.scanner.waitForArm(side, identity?.serial ?? pair.serial, RESTORE_RETURN_MS,
(heard) => heard.g1Firmware === "stock" || Date.now() - resetAt >= OLD_FIRMWARE_GRACE_MS);
if (!live()) return;
if (!back) {
throw new Error(`The ${side} arm hasn't come back yet. Leave the glasses in the plugged-in case for a few minutes, with the lid ` +
"open: an interrupted install finishes by itself. Then retry.");
}
if (back.g1Firmware !== "stock") {
throw new Error(`The ${side} arm came back on Faceclaw's firmware: it didn't take Even's. Retry to try again.`);
}
saveG1Arm(side, back);
this.restoredArm = true;
// Even's app makes its own pairing with Even's firmware; the one this phone made with g1v0 would only be in its way.
this.forgetPairing(back.address);
if (back.address !== arm.address) this.forgetPairing(arm.address);
this.appendLog(`${side} arm runs Even's firmware`);
}
private forgetPairing(address: string): void {
if (!forgetG1Pairing(address)) this.pairingLeft = true;
}
private async flash(
options: G1FlasherOptions,
onState?: (state: string) => void,
onProgress?: (sent: number, total: number) => void,
) {
const flasher = new G1Flasher(options);
this.flasher = flasher;
flasher.onLog((line) => this.appendLog(line));
if (onState) flasher.onState(onState);
if (onProgress) flasher.onProgress(onProgress);
try {
return await flasher.run();
} finally {
if (this.flasher === flasher) this.flasher = null;
flasher.close();
}
}
/** A G2's install gets these from the same download; Faceclaw's fonts are a phone-side matter, so a failure here is no reason to stop. */
private async prepareFonts(live: () => boolean): Promise<void> {
if (hasExtractedEvenHubFonts()) return;
if (live()) this.setStatus("Preparing fonts...");
try {
await downloadAndExtractEvenHubFonts();
} catch (error) {
this.appendLog(`fonts not prepared: ${formatErrorMessage(error)}`);
}
}
private finished(): void {
// The glasses are ready for the main page to connect to.
resumeAutoReconnect();
this.setBusy(false);
this.setProgress(100);
this.setPhase("flashed");
this.setText("All Done", `Both arms run Faceclaw's firmware ${G1V0_IMAGE.version}.` + (this.unpairedArm
? " Keep the glasses in the case with the lid open until Faceclaw has connected: they only pair in the case."
: ""));
}
private restored(): void {
// Stays manually disconnected: Faceclaw would only find firmware it can't run.
this.setBusy(false);
this.setProgress(100);
this.setPhase("flashed");
if (!this.restoredArm) {
this.setText("All Done", "Both arms already run Even's firmware.");
return;
}
const steps = [`Both arms run Even's firmware ${EVEN_G1_RESTORE.version}.`];
if (this.pairingLeft) {
steps.push("Before pairing them in Even's app, remove both arms in this phone's Bluetooth settings (\"Forget This Device\"): " +
"Faceclaw's firmware made that pairing, and Even's firmware makes its own.");
} else {
steps.push("To use them, pair them in Even's app.");
}
if (this.wiped) {
steps.push("Even's Chinese, Japanese and Korean text and its demo pictures were erased with Faceclaw's storage, and don't come back.");
}
this.setText("All Done", steps.join("\n\n"));
}
private failed(message: string): void {
this.setBusy(false);
this.setPhase("error");
this.setText("Something Went Wrong", message);
}
private finish(): void {
if (!this.uninstalling) {
setPreviewOnlyMode(false);
setOnboardingCompleted(true);
}
this.teardown();
finishOnboardingNavigation();
}
private leave(): void {
this.teardown();
const frame = Frame.topmost();
if (this.fromOnboarding && frame?.canGoBack()) {
frame.goBack();
return;
}
if (!this.fromOnboarding) {
finishOnboardingNavigation();
return;
}
frame?.navigate({ moduleName: "phone-ui/onboarding-page", clearHistory: true });
}
dispose(): void {
this.disposed = true;
this.teardown();
}
private teardown(): void {
++this.generation;
this.scanner.stop();
this.flasher?.close();
this.flasher = null;
}
// --- page state -----------------------------------------------------------
private setText(headline: string, status: string): void {
this.set("headline", headline);
this.set("status", status);
}
private setStatus(status: string): void {
this.set("status", status);
}
private setBusy(busy: boolean): void {
this.set("busy", busy);
this.notifyPropertyChange("busyVisibility", this.busyVisibility);
}
private setProgress(percent: number): void {
this.set("progress", Math.max(0, Math.min(100, Math.round(percent))));
}
private setPhase(phase: Phase): void {
this.phase = phase;
for (const property of ["primaryLabel", "primaryVisibility", "secondaryVisibility", "progressVisibility"] as const) {
this.notifyPropertyChange(property, this[property]);
}
}
private appendLog(line: string): void {
const stamp = new Date().toISOString().slice(11, 19);
this.set("log", this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`);
this.notifyPropertyChange("logVisibility", this.logVisibility);
}
}
function describeEvenBuild(progress: G1BuildProgress): string {
switch (progress) {
case "downloading":
return "Downloading Even's firmware from Even's firmware server...";
case "verifying":
return "Verifying the download...";
default:
return "Saving the firmware...";
}
}
function describeBuild(progress: G1BuildProgress): string {
switch (progress) {
case "downloading":
return "Downloading the parts it needs from Even's firmware server...";
case "verifying":
return "Verifying the download...";
case "assembling":
return "Assembling the firmware...";
default:
return "Saving the firmware...";
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ import { IosPreviewController } from '../g2/ios-preview-controller'
import { PhoneGestureRecognizer } from './phone-gestures'
import { BleBandwidthMeter } from './ble-bandwidth-meter'
import { sampleBleTraffic } from '../native/ble-traffic'
import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
import { glassesModelName, onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
import { loadDeviceAddresses } from '../g2/device-addresses'
import { deviceAddressError } from '../g2/ios-peripheral-identity'
import { formatBatteryLine } from '../g2/glasses-display-state'
@@ -75,7 +75,7 @@ export function createMainPage(): Page {
// The Settings tab's battery row. iOS reports charging sessions as
// connected, so "connected" is the whole live-link condition here.
let glassesLinked = false
const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked) }
const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked, glassesModelName()) }
const keyboardField = () => keyboardPanel.getViewById<TextView>('keyboardInputField')
const controller = new IosPreviewController((image, label) => {
mirror.imageSource = image; model.set('padFocusLine', label)
+1
View File
@@ -15,6 +15,7 @@
<ActionItem text="Conversations" tap="{{ onConversationsTap }}" android.position="popup" />
<ActionItem text="Take screenshot" tap="{{ onTakeScreenshotTap }}" android.position="popup" />
<ActionItem text="Record screen" tap="{{ onRecordScreenTap }}" android.position="popup" />
<ActionItem text="Check firmware" tap="{{ onCheckFirmwareTap }}" isEnabled="{{ canRun }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
<ActionItem text="Uninstall custom firmware" tap="{{ onUninstallFirmwareTap }}" isEnabled="{{ canRun }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
</ActionBar>
+21 -7
View File
@@ -17,6 +17,7 @@ import {
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
import { formatBatteryLine } from "../g2/glasses-display-state";
import {
glassesModelName,
mirrorTouchSetting,
onAnySettingChanged,
showBleBandwidthSetting,
@@ -26,10 +27,13 @@ import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-policy";
import { isPreviewOnlyMode } from "./onboarding-state";
import { formatErrorMessage } from "../util/format-error";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
import { screenHeight, screenWidth } from "../ui/shell/geometry";
import { type PhoneUiButton } from "../apps/evenhub/manager";
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
/** The paired glasses' screen aspect (4:3 on the G2, 27:11 on the RayNeo iO). */
function lensAspectRatio(): number {
return screenWidth() / screenHeight();
}
type LayoutOrientation = "portrait" | "landscape";
@@ -96,6 +100,7 @@ export class MainViewModel extends RemoteControlsViewModel {
this.batteryLine = formatBatteryLine(
snapshot.batteries,
snapshot.phase === "connected" || snapshot.phase === "charging",
glassesModelName(),
);
this.activeTextSettingId = snapshot.activeTextSettingId;
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
@@ -246,7 +251,7 @@ export class MainViewModel extends RemoteControlsViewModel {
}
get displayPreviewHeight(): number {
return Screen.mainScreen.widthDIPs / LENS_ASPECT_RATIO;
return Screen.mainScreen.widthDIPs / lensAspectRatio();
}
get landscapeDisplayPreviewWidth(): number {
@@ -262,8 +267,8 @@ export class MainViewModel extends RemoteControlsViewModel {
// and controls, and updates for rotation, split-screen, and the keyboard.
const { width, height } = args.object.getActualSize();
if (width <= 0 || height <= 0) return;
const previewHeight = Math.min(height, width / LENS_ASPECT_RATIO);
const previewWidth = previewHeight * LENS_ASPECT_RATIO;
const previewHeight = Math.min(height, width / lensAspectRatio());
const previewWidth = previewHeight * lensAspectRatio();
if (previewWidth === this._landscapePreviewWidth && previewHeight === this._landscapePreviewHeight) return;
this._landscapePreviewWidth = previewWidth;
this._landscapePreviewHeight = previewHeight;
@@ -672,6 +677,14 @@ export class MainViewModel extends RemoteControlsViewModel {
* auto-reconnect suppression right away.
*/
async onPrepareFontsTap(): Promise<void> {
await this.openFirmwareCheck();
}
async onCheckFirmwareTap(): Promise<void> {
await this.openFirmwareCheck();
}
private async openFirmwareCheck(): Promise<void> {
this.setWarningsModalVisible(false);
if (this.phase === "connected" || this.phase === "charging" || this.phase === "connecting") {
try {
@@ -919,8 +932,9 @@ export class MainViewModel extends RemoteControlsViewModel {
}
private async openFlashPage(mode: "install" | "uninstall"): Promise<void> {
// The flasher needs the glasses to itself, so drop the main connection first.
if (this.phase === "connected" || this.phase === "charging") {
// The flasher needs the glasses to itself, so drop the main connection first. That includes a session
// still retrying: an install brings arms back at the addresses it is dialling.
if (this.phase === "connected" || this.phase === "charging" || this.phase === "connecting") {
try {
await dashboardController.disconnect();
} catch {
+10
View File
@@ -0,0 +1,10 @@
import { EventData, Page } from "@nativescript/core";
import { OnboardingDevicesViewModel } from "./onboarding-devices-view-model";
export function navigatingTo(args: EventData): void {
const page = args.object as Page;
if (!page.bindingContext) {
page.bindingContext = new OnboardingDevicesViewModel();
}
}
+43
View File
@@ -0,0 +1,43 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
<GridLayout rows="*,auto" class="p-20">
<ScrollView row="0">
<StackLayout>
<Label text="Your Devices" class="h1 text-center m-t-24" textWrap="true" />
<Label
text="Which devices do you have?"
class="body-text m-t-24" textWrap="true" />
<Label text="Glasses" class="h2 pairing-section m-t-24" />
<Repeater items="{{ glassesOptions }}">
<Repeater.itemsLayout>
<StackLayout />
</Repeater.itemsLayout>
<Repeater.itemTemplate>
<GridLayout columns="*,auto" rows="auto" class="{{ rowClass }}" tap="{{ onRowTap }}">
<StackLayout col="0" verticalAlignment="center">
<Label text="{{ label }}" class="pairing-title" />
<Label text="{{ note }}" class="permissions-description" textWrap="true" visibility="{{ noteVisibility }}" />
</StackLayout>
<Label col="1" text="✓" class="permissions-check" verticalAlignment="center" visibility="{{ checkVisibility }}" />
</GridLayout>
</Repeater.itemTemplate>
</Repeater>
<Label text="Accessories" class="h2 pairing-section m-t-16" />
<GridLayout columns="*,auto" rows="auto" class="pairing-row">
<Label col="0" text="Even R1 ring" class="pairing-title" verticalAlignment="center" />
<Switch col="1" checked="{{ hasRing }}" verticalAlignment="center" margin="0" />
</GridLayout>
<GridLayout columns="*,auto" rows="auto" class="pairing-row">
<Label col="0" text="{{ watchLabel }}" class="pairing-title" verticalAlignment="center" />
<Switch col="1" checked="{{ hasWatch }}" verticalAlignment="center" margin="0" />
</GridLayout>
</StackLayout>
</ScrollView>
<GridLayout row="1" columns="*,*" class="m-t-20">
<Button col="0" text="Back" tap="{{ onBackTap }}" />
<Button col="1" text="Next" tap="{{ onNextTap }}" class="-primary" isEnabled="{{ nextEnabled }}" />
</GridLayout>
</GridLayout>
</Page>
@@ -0,0 +1,124 @@
import { EventData, Frame, Observable, View } from "@nativescript/core";
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
import { ownsRing, ownsWatch, setOwnsRing, setOwnsWatch, setPreviewOnlyMode } from "./onboarding-state";
/** A row in the glasses list: a kind of glasses, or no glasses at all. */
type GlassesChoice = GlassesType | "preview";
const GLASSES_OPTIONS: { choice: GlassesChoice; label: string; description?: string }[] = [
{ choice: "preview", label: "Preview Only", description: "No glasses: explore Faceclaw on your phone's screen" },
{ choice: "g1", label: "Even G1" },
{ choice: "g2", label: "Even G2" },
{ choice: "rayneo-io", label: "RayNeo iO" },
];
/** RayNeo iO support isn't ready to offer in a release yet; set this to show its row again. */
const OFFER_RAYNEO_IO = false;
/** Why this choice can't be made on this phone, or "" when it can. */
function unavailableReason(choice: GlassesChoice): string {
// FaceclawCommunicatorBridge refuses to start a session with one on iOS.
return choice === "rayneo-io" && global.isIOS ? "Not supported on iOS yet" : "";
}
export type GlassesOptionItem = {
choice: GlassesChoice;
label: string;
selectable: boolean;
note: string;
noteVisibility: "visible" | "collapse";
rowClass: string;
/** Hidden, not collapsed: the check is what sets a row's height, so collapsing it would shift the list on every selection. */
checkVisibility: "visible" | "hidden";
onRowTap: (args: EventData) => void;
};
/**
* The Your Devices onboarding page, between the splash and the disclaimer: one
* kind of glasses (or Preview Only) plus any accessories, which later setup
* pages tailor themselves to. Pairing still has the last word on the glasses,
* since it can tell what it heard.
*
* Nothing starts out selected, whatever an earlier run stored, and Next waits
* for a choice. A tap stores it straight away: Preview Only sets the persisted
* preview-only flag and leaves the glasses type alone, so the Permissions page
* finishes onboarding instead of moving on to the firmware step.
*/
export class OnboardingDevicesViewModel extends Observable {
/** This visit's choice; the page keeps this model when you come Back to it. */
private selected: GlassesChoice | null = null;
get glassesOptions(): GlassesOptionItem[] {
const selected = this.selected;
const options = OFFER_RAYNEO_IO ? GLASSES_OPTIONS : GLASSES_OPTIONS.filter(({ choice }) => choice !== "rayneo-io");
return options.map(({ choice, label, description }) => {
const reason = unavailableReason(choice);
const note = reason || description || "";
const isSelected = choice === selected;
return {
choice,
label,
selectable: !reason,
note,
noteVisibility: note ? "visible" : "collapse",
rowClass: isSelected ? "pairing-row pairing-row-selected" : reason ? "pairing-row pairing-row-incomplete" : "pairing-row",
checkVisibility: isSelected ? "visible" : "hidden",
onRowTap: this.onGlassesRowTap,
};
});
}
// Arrow property: NativeScript fires XML event handlers with `this` bound to
// the tapped view's bindingContext (the row item), not the view model.
readonly onGlassesRowTap = (args: EventData): void => {
const item = (args.object as View).bindingContext as GlassesOptionItem | undefined;
if (!item?.selectable) return;
this.selected = item.choice;
setPreviewOnlyMode(item.choice === "preview");
if (item.choice !== "preview") glassesTypeSetting.set(item.choice);
this.notifyPropertyChange("glassesOptions", this.glassesOptions);
this.notifyPropertyChange("nextEnabled", this.nextEnabled);
};
get nextEnabled(): boolean {
return this.selected !== null;
}
get hasRing(): boolean {
return ownsRing();
}
set hasRing(value: boolean) {
setOwnsRing(value);
}
get hasWatch(): boolean {
return ownsWatch();
}
set hasWatch(value: boolean) {
setOwnsWatch(value);
}
get watchLabel(): string {
return global.isIOS ? "Apple Watch" : "Wear OS watch";
}
onNextTap(): void {
if (!this.nextEnabled) return;
Frame.topmost()?.navigate({
moduleName: "phone-ui/onboarding-page",
context: { step: 2 },
});
}
onBackTap(): void {
const frame = Frame.topmost();
if (frame?.canGoBack()) {
frame.goBack();
return;
}
frame?.navigate({ moduleName: "phone-ui/onboarding-page", clearHistory: true });
}
}
@@ -18,11 +18,29 @@ import {
type OnboardingFirmwareKind,
} from "../g2/firmware-compat";
import { DeviceInfoProbe, DeviceInfoState } from "../native/device-info-probe";
import { G1Flasher } from "../native/g1-flasher";
import { saveG1Pair } from "../g1/addresses";
import { G1ArmScanner } from "../g1/arm-scanner";
import { G1V0_IMAGE } from "../g1/firmware/g1v0-image";
import {
G1_CASE_DELAY_HINT,
G1_CASE_INSTRUCTIONS,
G1_INSTALL_NOTICE,
g1FirmwareState,
g1StateFromAdvertising,
type G1FlashResult,
type G1Side,
} from "../g1/flash-plan";
import { loadPairedGlassesIdentity } from "../g2/device-addresses";
import { glassesTypeSetting } from "../ui/dashboard-settings";
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
import { formatErrorMessage } from "../util/format-error";
type CheckPhase = "checking" | "fonts" | "custom" | "flashable" | "newer-validated" | "newer" | "error";
const G1_LOCATE_MS = 30_000;
const G1_CHECK_CONNECT_MS = 45_000;
export class OnboardingFirmwareCheckViewModel extends Observable {
private _phase: CheckPhase = "checking";
private _headline = "Checking Firmware";
@@ -31,7 +49,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
private generation = 0;
private probeInstance: DeviceInfoProbe | null = null;
private probeInstance: { close(): void } | null = null;
constructor() {
super();
@@ -175,6 +193,10 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
try {
await ensureBlePermissions();
if (generation !== this.generation) return;
if (glassesTypeSetting.get() === "g1") {
await this.checkG1(generation);
return;
}
const stored = loadDeviceAddresses();
if (!isValidMacAddress(stored.right)) {
this.toError("No glasses address is configured. Go back and set the device addresses.");
@@ -194,11 +216,71 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
this.applyClassification(kind, version, extension);
} catch (error) {
if (generation !== this.generation) return;
this.probeInstance = null;
this.toError(this.formatError(error));
}
}
/**
* What the arms advertise first, as that needs no connection or pairing. Only firmware from before it advertised its
* version (0.5.66) has to be asked.
*/
private async checkG1(generation: number): Promise<void> {
this.status = "Listening for your glasses...";
const scanner = new G1ArmScanner();
this.probeInstance = { close: () => scanner.stop() };
const stored = loadDeviceAddresses();
const pair = await scanner.waitForPair({ serial: loadPairedGlassesIdentity()?.serial, left: stored.left, right: stored.right }, G1_LOCATE_MS);
if (generation !== this.generation) return;
this.probeInstance = null;
if (!pair) {
this.toError(`Couldn't hear both arms of your glasses. ${G1_CASE_INSTRUCTIONS} Make sure no other app or phone is connected to them, then retry.`);
return;
}
saveG1Pair(pair);
const advertised = g1StateFromAdvertising(pair, G1V0_IMAGE.version);
if (advertised) {
if (advertised.state === "current") this.applyClassification("custom", advertised.version, { kind: "none" });
else if (advertised.state === "stock") this.showG1Install({ firmware: "stock" });
else if (advertised.state === "safe-mode") this.showG1Install({ safeMode: true });
else this.showG1Install({ version: advertised.version });
return;
}
const arms: G1FlashResult[] = [];
for (const side of ["left", "right"] as G1Side[]) {
const flasher = new G1Flasher({ address: pair[side]!.address, side, firmwarePath: "", mode: "probe", connectWindowMs: G1_CHECK_CONNECT_MS });
this.probeInstance = flasher;
flasher.onState((state) => {
if (generation !== this.generation) return;
if (state === "pairing") {
this.status = `Pairing with the ${side} arm. If your phone asks, accept it. A G1 pairs only in its case, with the lid open. ${G1_CASE_DELAY_HINT}`;
} else {
this.status = `Checking the ${side} arm...`;
}
});
arms.push(await flasher.run());
if (generation !== this.generation) return;
this.disposeProbe();
}
const state = g1FirmwareState(arms, G1V0_IMAGE.version);
if (state === "current") this.applyClassification("custom", arms[0]!.version ?? "", { kind: "none" });
else this.showG1Install(state === "stock" ? { firmware: "stock" } : state === "safe-mode" ? { safeMode: true } : arms.find((arm) => arm.version) ?? {});
}
private showG1Install(found: G1FlashResult): void {
this.busy = false;
this.setPhase("flashable");
if (found.firmware === "stock") {
this.headline = "Ready to Install";
this.status = `Your glasses run Even's firmware.\n\n${G1_CASE_INSTRUCTIONS}\n\n${G1_INSTALL_NOTICE}`;
} else if (found.safeMode) {
this.headline = "Firmware Needs Reinstalling";
this.status = `An arm of your glasses is in safe mode: its firmware restarted repeatedly. Installing it again usually fixes this.\n\n${G1_CASE_INSTRUCTIONS}`;
} else {
this.headline = "Firmware Update Available";
this.status = `Your glasses run Faceclaw's firmware ${found.version ?? ""}, and this version of Faceclaw comes with ${G1V0_IMAGE.version}.\n\n${G1_CASE_INSTRUCTIONS}`;
}
}
private reportProbeState(state: DeviceInfoState, detail: string): void {
// The probe brings up the right lens, then the left, and pairs with each
// in turn (they are separate Bluetooth devices with separate bonds).
@@ -326,7 +408,7 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
this.busy = false;
this.setPhase("custom");
this.headline = extractedFonts ? "Fonts Ready" : "Custom Firmware Detected";
const details = [
const details = glassesTypeSetting.get() === "g1" ? [version].filter(Boolean) : [
extension.kind === "faceclaw" ? `revision ${extension.version}` : "",
version ? `based on stock ${version}` : "",
].filter(Boolean);
+6 -3
View File
@@ -1,5 +1,7 @@
import { NavigatedData, Page } from "@nativescript/core";
import { glassesTypeSetting } from "../ui/dashboard-settings";
import { G1FlashViewModel } from "./g1-flash-view-model";
import { FlashMode, OnboardingFlashViewModel } from "./onboarding-flash-view-model";
export function navigatingTo(args: NavigatedData): void {
@@ -7,16 +9,17 @@ export function navigatingTo(args: NavigatedData): void {
if (!page.bindingContext) {
const context =
(args.context as { mode?: FlashMode; fromOnboarding?: boolean; autoStart?: boolean } | undefined) ?? undefined;
page.bindingContext = new OnboardingFlashViewModel({
const options = {
mode: context?.mode ?? "install",
fromOnboarding: context?.fromOnboarding ?? true,
autoStart: context?.autoStart ?? false,
});
};
page.bindingContext = glassesTypeSetting.get() === "g1" ? new G1FlashViewModel(options) : new OnboardingFlashViewModel(options);
}
}
export function navigatingFrom(args: NavigatedData): void {
const page = args.object as Page;
(page.bindingContext as OnboardingFlashViewModel | undefined)?.dispose();
(page.bindingContext as OnboardingFlashViewModel | G1FlashViewModel | undefined)?.dispose();
page.bindingContext = null;
}
+2
View File
@@ -2,6 +2,8 @@ require('@nativescript/core/bundle-entry-points');
// iOS reuses Android's NativeScript XML forms and view models.
global.registerModule('phone-ui/onboarding-page', () => require('./onboarding-page'));
global.registerModule('phone-ui/onboarding-page.xml', () => require('./onboarding-page.xml'));
global.registerModule('phone-ui/onboarding-devices-page', () => require('./onboarding-devices-page'));
global.registerModule('phone-ui/onboarding-devices-page.xml', () => require('./onboarding-devices-page.xml'));
global.registerModule('phone-ui/onboarding-unpair-page', () => require('./onboarding-unpair-page'));
global.registerModule('phone-ui/onboarding-unpair-page.xml', () => require('./onboarding-unpair-page.xml'));
global.registerModule('phone-ui/pairing-page', () => require('./pairing-page'));
+27
View File
@@ -1,7 +1,13 @@
import { ApplicationSettings } from "@nativescript/core";
import { getBooleanSetting, setBooleanSetting } from "../native/settings-store";
const ONBOARDING_COMPLETE_KEY = "onboarding.complete";
const PREVIEW_ONLY_KEY = "onboarding.previewOnly";
// The "onboarding." prefix keeps these on this phone in config transfers and
// lets scripts/resetOnboarding.sh clear them.
const OWNS_RING_KEY = "onboarding.ownsRing";
const OWNS_WATCH_KEY = "onboarding.ownsWatch";
export function hasCompletedOnboarding(): boolean {
return ApplicationSettings.getBoolean(ONBOARDING_COMPLETE_KEY, false);
@@ -27,3 +33,24 @@ export function isPreviewOnlyMode(): boolean {
export function setPreviewOnlyMode(previewOnly: boolean): void {
ApplicationSettings.setBoolean(PREVIEW_ONLY_KEY, previewOnly);
}
/**
* Accessories chosen on the Your Devices onboarding page, for tailoring the
* rest of setup. The glasses chosen there go in glassesTypeSetting instead.
*/
export function ownsRing(): boolean {
return getBooleanSetting(OWNS_RING_KEY, false);
}
export function setOwnsRing(owns: boolean): void {
setBooleanSetting(OWNS_RING_KEY, owns);
}
/** An Apple Watch on iOS, a Wear OS watch on Android. */
export function ownsWatch(): boolean {
return getBooleanSetting(OWNS_WATCH_KEY, false);
}
export function setOwnsWatch(owns: boolean): void {
setBooleanSetting(OWNS_WATCH_KEY, owns);
}
+2 -1
View File
@@ -4,10 +4,11 @@
<StackLayout>
<Label text="Disconnect Other Apps" class="h1 text-center m-t-24" textWrap="true" />
<Label
text="Your glasses can only be connected to one app or phone at a time. If they're connected to another app (such as Even Realities or MentraOS) or another phone, disconnect them there before continuing. If nothing else is connected, you can continue."
text="{{ otherAppsInstructions }}"
class="body-text m-t-24" textWrap="true" />
<Label
text="{{ evenAppInstructions }}"
visibility="{{ evenAppVisibility }}"
class="body-text m-t-16" textWrap="true" />
<Button text="Open Even App Settings" tap="{{ onOpenEvenAppSettingsTap }}" visibility="{{ settingsButtonVisibility }}" width="{{ settingsButtonWidth }}" horizontalAlignment="center" class="-primary m-t-24" />
</StackLayout>
+19 -1
View File
@@ -1,10 +1,28 @@
import { Frame, Observable, Screen } from "@nativescript/core";
import { openEvenAppSettings } from "../native/even-app-conflict";
import { glassesTypeSetting } from "../ui/dashboard-settings";
import { hasCompletedOnboarding } from "./onboarding-state";
export class OnboardingUnpairViewModel extends Observable {
/**
* Setting up a RayNeo iO, so the Even app doesn't apply. Only during first-run
* setup: "Pair glasses" in the main menu also opens this page, and you may be
* pairing something other than the glasses you paired before.
*/
private readonly settingUpIo = !hasCompletedOnboarding() && glassesTypeSetting.get() === "rayneo-io";
get otherAppsInstructions(): string {
const apps = this.settingUpIo ? "another app" : "another app (such as Even Realities or MentraOS)";
return `Your glasses can only be connected to one app or phone at a time. If they're connected to ${apps} or another phone, disconnect them there before continuing. If nothing else is connected, you can continue.`;
}
get evenAppVisibility(): "visible" | "collapse" {
return this.settingUpIo ? "collapse" : "visible";
}
get settingsButtonVisibility(): "visible" | "collapse" {
return global.isAndroid ? "visible" : "collapse";
return global.isAndroid && !this.settingUpIo ? "visible" : "collapse";
}
get evenAppInstructions(): string {
+86 -74
View File
@@ -1,9 +1,10 @@
import { finishOnboardingNavigation } from "./onboarding-navigation";
import { Frame, Observable, Screen } from "@nativescript/core";
import { IOS_PRIVACY_NOTICE } from "../analytics/privacy-disclosure";
import { EVEN_G1_RESTORE } from "../g1/even-firmware";
import { glassesTypeSetting, type GlassesType } from "../ui/dashboard-settings";
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
import { isPreviewOnlyMode } from "./onboarding-state";
/** Steps are separate pages in the flow; the devices page follows the splash. */
type OnboardingStep = 1 | 2 | 3;
type StepContent = {
@@ -17,52 +18,84 @@ type StepContent = {
showSecondary: boolean;
};
const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
1: {
headline: "Faceclaw",
tagline: "Perching on the faces of giants",
body: "",
primaryLabel: "Next",
secondaryLabel: "",
splash: true,
showSecondary: false,
},
2: {
headline: "Before You Continue",
tagline: "",
body: "This software provides a custom user interface and functionality for the Even Realities G2 smart glasses. It is not created or supported by Even Realities. If this software somehow breaks your headset, this is not Even's fault and is not covered by the hardware's warranty. If this software doesn't break you headset, using this software may void the hardware's warranty anyways, at the sole discretion of Even Realities. This software is beta; don't rely on it for anything critically important." +
(global.isIOS ? "\n\niOS / TestFlight privacy\n\n" + IOS_PRIVACY_NOTICE : ""),
primaryLabel: "Agree",
secondaryLabel: "Back",
splash: false,
showSecondary: true,
},
3: {
headline: "Custom Firmware Required",
tagline: "",
body: "Faceclaw only runs on Even Realities G2 glasses that have Faceclaw's custom firmware installed. You have two choices:\n\n• Preview Only — explore Faceclaw's interface on your phone's screen without pairing any glasses. Nothing is written to a headset.\n\n• Flash Firmware — install the custom firmware on your glasses now, then use Faceclaw for real.\n\nFlashing replaces the official firmware. You can uninstall and return to the official firmware later, by reconnecting the official Even Realities app. Installing custom firmware is not covered by warranty.",
primaryLabel: "Flash Firmware",
secondaryLabel: "Preview Only",
splash: false,
showSecondary: true,
},
type Makers = { product: string; maker: string; makerPossessive: string };
const GLASSES_MAKER: Record<GlassesType, Makers> = {
g1: { product: "Even Realities G1", maker: "Even Realities", makerPossessive: "Even's" },
g2: { product: "Even Realities G2", maker: "Even Realities", makerPossessive: "Even's" },
"rayneo-io": { product: "RayNeo iO", maker: "RayNeo", makerPossessive: "RayNeo's" },
};
/** Preview Only: no particular glasses yet, so the disclaimer covers every kind Faceclaw supports. */
const ANY_GLASSES_MAKER: Makers = { product: "Even Realities G1 and G2 and RayNeo iO", maker: "Even Realities or RayNeo", makerPossessive: "their" };
const WARRANTY_NOTE = "Installing custom firmware is not covered by warranty.";
// Preview Only is chosen on Your Devices, which is three pages back from here.
const PREVIEW_HINT = "Not ready? Go back to Your Devices and choose Preview Only to explore Faceclaw on your phone's screen instead.";
function firmwareBody(glasses: GlassesType): string {
// Pairing skips the firmware pages for an iO: the app has no flasher for it.
if (glasses === "rayneo-io") {
return `Faceclaw only runs on a RayNeo iO that has Faceclaw's custom firmware installed. This app can't install it on an iO, so that has to be done separately before you pair your glasses. ${WARRANTY_NOTE}\n\n${PREVIEW_HINT}`;
}
const restore = glasses === "g1"
? `You can return to the official firmware later from Faceclaw, as version ${EVEN_G1_RESTORE.version}.`
: "You can uninstall and return to the official firmware later, by reconnecting the official Even Realities app.";
return `Faceclaw only runs on ${GLASSES_MAKER[glasses].product} glasses that have Faceclaw's custom firmware installed. Next, Faceclaw will pair with your glasses, check their firmware, and install the custom firmware if it isn't there yet.\n\nFlashing replaces the official firmware. ${restore} ${WARRANTY_NOTE}\n\n${PREVIEW_HINT}`;
}
function stepContent(step: OnboardingStep, glasses: GlassesType, previewOnly: boolean): StepContent {
const { product, maker, makerPossessive } = previewOnly ? ANY_GLASSES_MAKER : GLASSES_MAKER[glasses];
switch (step) {
case 1:
return {
headline: "Faceclaw",
tagline: "Perching on the faces of giants",
body: "",
primaryLabel: "Next",
secondaryLabel: "",
splash: true,
showSecondary: false,
};
case 2:
return {
headline: "Before You Continue",
tagline: "",
body: `This software provides a custom user interface and functionality for the ${product} smart glasses. It is not created or supported by ${maker}. If this software somehow breaks your headset, this is not ${makerPossessive} fault and is not covered by the hardware's warranty. If this software doesn't break your headset, using this software may void the hardware's warranty anyways, at the sole discretion of ${maker}. This software is beta; don't rely on it for anything critically important.`,
primaryLabel: "Agree",
secondaryLabel: "Back",
splash: false,
showSecondary: true,
};
case 3:
return {
headline: "Custom Firmware Required",
tagline: "",
body: firmwareBody(glasses),
primaryLabel: glasses === "rayneo-io" ? "Pair Glasses" : "Flash Firmware",
secondaryLabel: "Back",
splash: false,
showSecondary: true,
};
}
}
export class OnboardingViewModel extends Observable {
private _step: OnboardingStep = 1;
private readonly step: OnboardingStep;
private readonly content: StepContent;
constructor(initialStep?: number) {
super();
if (initialStep === 2 || initialStep === 3) this._step = initialStep;
this.publish();
this.step = initialStep === 2 || initialStep === 3 ? initialStep : 1;
this.content = stepContent(this.step, glassesTypeSetting.get(), isPreviewOnlyMode());
}
onPrimaryTap(): void {
if (this._step === 1) {
this.setStep(2);
if (this.step === 1) {
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-devices-page" });
return;
}
if (this._step === 2) {
if (this.step === 2) {
// The Permissions screen sits between the disclaimer and the firmware
// step; it navigates forward to a fresh onboarding page at step 3.
Frame.topmost()?.navigate({
@@ -93,49 +126,47 @@ export class OnboardingViewModel extends Observable {
});
}
/** Back, on the disclaimer and firmware steps. */
onSecondaryTap(): void {
if (this._step === 2) {
this.setStep(1);
const frame = Frame.topmost();
if (frame?.canGoBack()) {
frame.goBack();
return;
}
if (this._step === 3) {
// Step 3 secondary: skip flashing, use the on-phone preview only.
setPreviewOnlyMode(true);
setOnboardingCompleted(true);
finishOnboardingNavigation();
}
// The disconnect page's Back can open step 3 on a fresh history.
frame?.navigate({ moduleName: "phone-ui/onboarding-devices-page", clearHistory: true });
}
get headline(): string {
return STEP_CONTENT[this._step].headline;
return this.content.headline;
}
get tagline(): string {
return STEP_CONTENT[this._step].tagline;
return this.content.tagline;
}
get body(): string {
return STEP_CONTENT[this._step].body;
return this.content.body;
}
get primaryLabel(): string {
return STEP_CONTENT[this._step].primaryLabel;
return this.content.primaryLabel;
}
get secondaryLabel(): string {
return STEP_CONTENT[this._step].secondaryLabel;
return this.content.secondaryLabel;
}
get showSecondary(): boolean {
return STEP_CONTENT[this._step].showSecondary;
return this.content.showSecondary;
}
get splashVisibility(): "visible" | "collapse" {
return STEP_CONTENT[this._step].splash ? "visible" : "collapse";
return this.content.splash ? "visible" : "collapse";
}
get contentVisibility(): "visible" | "collapse" {
return STEP_CONTENT[this._step].splash ? "collapse" : "visible";
return this.content.splash ? "collapse" : "visible";
}
/**
@@ -153,25 +184,6 @@ export class OnboardingViewModel extends Observable {
/** License and privacy-policy links, shown only under the disclaimer step. */
get footerVisibility(): "visible" | "collapse" {
return this._step === 2 ? "visible" : "collapse";
}
private setStep(step: OnboardingStep): void {
if (this._step === step) return;
this._step = step;
this.publish();
}
private publish(): void {
this.notifyPropertyChange("headline", this.headline);
this.notifyPropertyChange("tagline", this.tagline);
this.notifyPropertyChange("body", this.body);
this.notifyPropertyChange("primaryLabel", this.primaryLabel);
this.notifyPropertyChange("secondaryLabel", this.secondaryLabel);
this.notifyPropertyChange("showSecondary", this.showSecondary);
this.notifyPropertyChange("splashVisibility", this.splashVisibility);
this.notifyPropertyChange("contentVisibility", this.contentVisibility);
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
this.notifyPropertyChange("footerVisibility", this.footerVisibility);
return this.step === 2 ? "visible" : "collapse";
}
}
+25 -23
View File
@@ -45,29 +45,31 @@
</Repeater.itemTemplate>
</Repeater>
<Label text="Ring (optional)" class="h2 pairing-section m-t-16" />
<Label text="{{ emptyRingMessage }}" class="pairing-empty" textWrap="true" visibility="{{ emptyRingVisibility }}" />
<Repeater items="{{ ringRows }}">
<Repeater.itemsLayout>
<StackLayout />
</Repeater.itemsLayout>
<Repeater.itemTemplate>
<GridLayout columns="84,*,auto" rows="auto" class="{{ rowClass }}" tap="{{ onRowTap }}">
<Image col="0" src="{{ imagePath }}" stretch="aspectFit" width="56" height="30" class="pairing-art" />
<StackLayout col="1" class="m-l-8">
<GridLayout columns="auto,auto">
<Label col="0" text="{{ modelTitle }}" class="pairing-title" />
<Label col="1" text="{{ badge }}" class="pairing-badge m-l-6" visibility="{{ badgeVisibility }}" />
</GridLayout>
<Label text="{{ proximityLine }}" class="{{ proximityClass }}" />
<Label text="{{ deviceName }}" class="pairing-serial" />
<Label text="{{ armsSummary }}" class="pairing-arms" textWrap="true" visibility="{{ armsVisibility }}" />
<Label text="{{ warning }}" class="pairing-warning" textWrap="true" visibility="{{ warningVisibility }}" />
</StackLayout>
<Label col="2" text="{{ chevron }}" class="pairing-chevron" verticalAlignment="center" />
</GridLayout>
</Repeater.itemTemplate>
</Repeater>
<StackLayout visibility="{{ ringSectionVisibility }}">
<Label text="Ring (optional)" class="h2 pairing-section m-t-16" />
<Label text="{{ emptyRingMessage }}" class="pairing-empty" textWrap="true" visibility="{{ emptyRingVisibility }}" />
<Repeater items="{{ ringRows }}">
<Repeater.itemsLayout>
<StackLayout />
</Repeater.itemsLayout>
<Repeater.itemTemplate>
<GridLayout columns="84,*,auto" rows="auto" class="{{ rowClass }}" tap="{{ onRowTap }}">
<Image col="0" src="{{ imagePath }}" stretch="aspectFit" width="56" height="30" class="pairing-art" />
<StackLayout col="1" class="m-l-8">
<GridLayout columns="auto,auto">
<Label col="0" text="{{ modelTitle }}" class="pairing-title" />
<Label col="1" text="{{ badge }}" class="pairing-badge m-l-6" visibility="{{ badgeVisibility }}" />
</GridLayout>
<Label text="{{ proximityLine }}" class="{{ proximityClass }}" />
<Label text="{{ deviceName }}" class="pairing-serial" />
<Label text="{{ armsSummary }}" class="pairing-arms" textWrap="true" visibility="{{ armsVisibility }}" />
<Label text="{{ warning }}" class="pairing-warning" textWrap="true" visibility="{{ warningVisibility }}" />
</StackLayout>
<Label col="2" text="{{ chevron }}" class="pairing-chevron" verticalAlignment="center" />
</GridLayout>
</Repeater.itemTemplate>
</Repeater>
</StackLayout>
<StackLayout class="pairing-selection m-t-16" visibility="{{ selectionVisibility }}">
<Label text="Selected" class="h2 pairing-section" />
Loaded 100 of 234 files, more files were not shown because too many files have changed in this diff. Show more