forked from Blendman974/faceclaw
Compare commits
94
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a263a055d7 | ||
|
|
9ddc864b0d | ||
|
|
35b02aef52 | ||
|
|
c3d1b5f3d3 | ||
|
|
309f05547b | ||
|
|
22df4d76d9 | ||
|
|
6150a1ac57 | ||
|
|
b4a2b2931b | ||
|
|
70ec2a0d6a | ||
|
|
5e3f58764c | ||
|
|
bf66c5a53c | ||
|
|
fa663804de | ||
|
|
4759c55fb8 | ||
|
|
2b29c9e551 | ||
|
|
479308f4a6 | ||
|
|
e103b89510 | ||
|
|
ac68ba5991 | ||
|
|
b866224909 | ||
|
|
43738b181d | ||
|
|
10a9c85f27 | ||
|
|
448a057d2d | ||
|
|
c713815694 | ||
|
|
9ba5c1988d | ||
|
|
3a0908fde2 | ||
|
|
d1f9f76abb | ||
|
|
16fe517b34
|
||
|
|
d2f846e2ba
|
||
|
|
a575db8e27
|
||
|
|
86b78d45a5
|
||
|
|
26e570f0e1
|
||
|
|
dbcdb1e3f6
|
||
|
|
69bb92da7b
|
||
|
|
2a607b32d0
|
||
|
|
a80d6697b5
|
||
|
|
ca05030857
|
||
|
|
8d57b7c1d0
|
||
|
|
c6fa3647ae | ||
|
|
d01fe585bc
|
||
|
|
693c442faf
|
||
|
|
f0bb727a80
|
||
|
|
3677a77a52
|
||
|
|
9b30105996 | ||
|
|
8591fb5039 | ||
|
|
41ef3b88a0 | ||
|
|
1eee926cbe
|
||
|
|
0f62573b1c
|
||
|
|
b353483ac2 | ||
|
|
595b462b2e | ||
|
|
e1a3e80b3d | ||
|
|
32fa5c0e6e | ||
|
|
6e4515afa5 | ||
|
|
0cc263c5d2 | ||
|
|
f9d3edf58c
|
||
|
|
799bdc153f
|
||
|
|
1997258b25
|
||
|
|
fe87e75fc2
|
||
|
|
fe0cf5b777
|
||
|
|
f029e3ce91
|
||
|
|
38c52ebc31 | ||
|
|
3aeed72f5d
|
||
|
|
02dba88131
|
||
|
|
345ba36c33 | ||
|
|
67aff19923 | ||
|
|
19944c7855
|
||
|
|
428142aef7
|
||
|
|
53391a310e
|
||
|
|
cfda10d47f
|
||
|
|
46cc5c5e5b
|
||
|
|
c9151710dc
|
||
|
|
5ae06c1818
|
||
|
|
bac1c8a239
|
||
|
|
883fe6bee9
|
||
|
|
cb4635d959
|
||
|
|
3f392712ec
|
||
|
|
ec6fc8d40e
|
||
|
|
675c051461
|
||
|
|
f060deaf6f
|
||
|
|
6f80ca75bd
|
||
|
|
acd114370b
|
||
|
|
5929259d84
|
||
|
|
55bd5f891c
|
||
|
|
0b9e4cb367
|
||
|
|
1959e57d02
|
||
|
|
9e6bb8473a
|
||
|
|
75bceb3b92
|
||
|
|
1b2095aa5b
|
||
|
|
f803f4212c | ||
|
|
739e81c8a6 | ||
|
|
b2b6c5c8d8 | ||
|
|
dff8608a63 | ||
|
|
9ddd4c4d03 | ||
|
|
fde847a31a | ||
|
|
dee60bbcd2 | ||
|
|
4d101eefe1 |
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
watch_file devenv.nix devenv.yaml devenv.lock
|
||||||
|
eval "$(devenv direnvrc)"
|
||||||
|
use devenv
|
||||||
@@ -49,6 +49,11 @@ faceclaw_settings.xml
|
|||||||
faceclaw_settings*.json
|
faceclaw_settings*.json
|
||||||
|
|
||||||
# Developer configs
|
# Developer configs
|
||||||
|
.devenv*
|
||||||
|
.direnv/
|
||||||
|
.android/
|
||||||
|
devenv.local.nix
|
||||||
|
local.properties
|
||||||
build_paths.sh
|
build_paths.sh
|
||||||
**/xcuserdata/
|
**/xcuserdata/
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
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
|
iPhone notification icons are Pebble's notification and timeline icons, from
|
||||||
https://github.com/pebble-dev/iconography: the original Pebble Technology icons
|
https://github.com/pebble-dev/iconography: the original Pebble Technology icons
|
||||||
and Rebble community additions. They are licensed under the Apache License 2.0;
|
and Rebble community additions. They are licensed under the Apache License 2.0;
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ dependencies {
|
|||||||
// app's captions (translation models download on demand, per language).
|
// app's captions (translation models download on demand, per language).
|
||||||
implementation 'com.google.mlkit:language-id:17.0.6'
|
implementation 'com.google.mlkit:language-id:17.0.6'
|
||||||
implementation 'com.google.mlkit:translate:17.0.3'
|
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"
|
def faceclawSherpaOnnxVersion = "1.13.0"
|
||||||
@@ -162,6 +165,14 @@ tasks.register("prepareFaceclawNativeLibs") {
|
|||||||
def faceclawLlamaCppTag = "b10333"
|
def faceclawLlamaCppTag = "b10333"
|
||||||
|
|
||||||
def faceclawFindSdkCmakeDir = {
|
def faceclawFindSdkCmakeDir = {
|
||||||
|
// NixOS and other managed environments can provide patched host tools.
|
||||||
|
def explicitCmake = System.getenv("ANDROID_CMAKE_HOME")
|
||||||
|
if (explicitCmake != null) {
|
||||||
|
def explicitDir = file(explicitCmake)
|
||||||
|
if (faceclawHostExecutable(file("$explicitDir/bin"), "cmake").exists()
|
||||||
|
&& faceclawHostExecutable(file("$explicitDir/bin"), "ninja").exists()) return explicitDir
|
||||||
|
throw new GradleException("ANDROID_CMAKE_HOME must contain bin/cmake and bin/ninja: $explicitDir")
|
||||||
|
}
|
||||||
def sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
|
def sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
|
||||||
if (sdkRoot == null) return null
|
if (sdkRoot == null) return null
|
||||||
def cmakeRoot = file("$sdkRoot/cmake")
|
def cmakeRoot = file("$sdkRoot/cmake")
|
||||||
|
|||||||
@@ -46,6 +46,15 @@ class AndroidSessionLink(private val bleManager: FaceclawBleManager) : SessionLi
|
|||||||
|
|
||||||
override fun isBonded(address: String): Boolean = bleManager.isBonded(address)
|
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 prepareBenchmarkLink(address: String, mode: Int) = bleManager.prepareBenchmarkLink(address, mode)
|
||||||
|
|
||||||
override fun recordDisplayFrameSent() = FaceclawBleManager.recordDisplayFrameSent()
|
override fun recordDisplayFrameSent() = FaceclawBleManager.recordDisplayFrameSent()
|
||||||
|
|||||||
@@ -25,18 +25,21 @@ internal object AndroidSpeechEngines {
|
|||||||
private const val FEATURE_DIM = 80
|
private const val FEATURE_DIM = 80
|
||||||
|
|
||||||
/** Sherpa-onnx configuration for the on-device model files in [modelDir]. */
|
/** Sherpa-onnx configuration for the on-device model files in [modelDir]. */
|
||||||
fun recognizerConfig(modelDir: File, kind: VoiceModelKind): OfflineRecognizerConfig {
|
fun recognizerConfig(
|
||||||
|
modelDir: File, kind: VoiceModelKind,
|
||||||
|
whisper: WhisperModelFiles = WhisperModelFiles.forLanguage(null),
|
||||||
|
): OfflineRecognizerConfig {
|
||||||
val modelConfig = OfflineModelConfig.builder()
|
val modelConfig = OfflineModelConfig.builder()
|
||||||
.setNumThreads(1)
|
.setNumThreads(1)
|
||||||
if (kind == VoiceModelKind.WHISPER) {
|
if (kind == VoiceModelKind.WHISPER) {
|
||||||
modelConfig
|
modelConfig
|
||||||
.setWhisper(OfflineWhisperModelConfig.builder()
|
.setWhisper(OfflineWhisperModelConfig.builder()
|
||||||
.setEncoder(File(modelDir, "base.en-encoder.int8.onnx").absolutePath)
|
.setEncoder(File(modelDir, whisper.encoder).absolutePath)
|
||||||
.setDecoder(File(modelDir, "base.en-decoder.int8.onnx").absolutePath)
|
.setDecoder(File(modelDir, whisper.decoder).absolutePath)
|
||||||
.setLanguage("en")
|
.setLanguage(whisper.language)
|
||||||
.setTask("transcribe")
|
.setTask("transcribe")
|
||||||
.build())
|
.build())
|
||||||
.setTokens(File(modelDir, "base.en-tokens.txt").absolutePath)
|
.setTokens(File(modelDir, whisper.tokens).absolutePath)
|
||||||
} else {
|
} else {
|
||||||
modelConfig
|
modelConfig
|
||||||
.setMoonshine(OfflineMoonshineModelConfig.builder()
|
.setMoonshine(OfflineMoonshineModelConfig.builder()
|
||||||
@@ -94,6 +97,44 @@ internal object AndroidSpeechEngines {
|
|||||||
override fun close() = decoder.close()
|
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
|
* 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
|
* 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
|
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 disconnect(address: String) = bleManager.disconnect(address)
|
||||||
|
|
||||||
override fun close() = bleManager.close()
|
override fun close() = bleManager.close()
|
||||||
|
|||||||
@@ -189,6 +189,28 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
|
|||||||
|
|
||||||
fun setRequiredFirmwareRevision(revision: Int) = core.setRequiredFirmwareRevision(revision)
|
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() {
|
fun start() {
|
||||||
if (core.start()) {
|
if (core.start()) {
|
||||||
activeInstance = this
|
activeInstance = this
|
||||||
@@ -235,6 +257,9 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
|
|||||||
|
|
||||||
fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean = core.setFaceclawWakeLeaseEnabled(enabled)
|
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 awaitEvenHubSessionReady(timeoutMs: Int): Boolean = core.awaitEvenHubSessionReady(timeoutMs)
|
||||||
|
|
||||||
fun setImuReportEnabled(enable: Boolean, reportFrq: Int) = core.setImuReportEnabled(enable, reportFrq)
|
fun setImuReportEnabled(enable: Boolean, reportFrq: Int) = core.setImuReportEnabled(enable, reportFrq)
|
||||||
@@ -249,6 +274,8 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
|
|||||||
|
|
||||||
fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState()
|
fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState()
|
||||||
|
|
||||||
|
fun configureHeadUpWake(enabled: Int, angle: Int) = core.configureHeadUpWake(enabled, angle)
|
||||||
|
|
||||||
fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean =
|
fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean =
|
||||||
core.startBandwidthBenchmark(messageSize, windowSize, durationMs)
|
core.startBandwidthBenchmark(messageSize, windowSize, durationMs)
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ import java.util.concurrent.atomic.AtomicLong
|
|||||||
class FaceclawBleManager(context: Context) {
|
class FaceclawBleManager(context: Context) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "FaceclawBle"
|
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)
|
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
|
// 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 /
|
* Android's bond state for this address (BluetoothDevice.BOND_NONE /
|
||||||
* BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined.
|
* BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined.
|
||||||
@@ -364,6 +399,31 @@ class FaceclawBleManager(context: Context) {
|
|||||||
return status == BluetoothGatt.GATT_SUCCESS
|
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 {
|
fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean {
|
||||||
synchronized(bluetoothApiLock) {
|
synchronized(bluetoothApiLock) {
|
||||||
val gatt = requireGatt(address)
|
val gatt = requireGatt(address)
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
* boundaries the provider stores them as.
|
* boundaries the provider stores them as.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long): String {
|
@JvmOverloads
|
||||||
|
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long, selectedCalendarIdsJson: String = "null"): String {
|
||||||
if (context == null || maxEvents <= 0) {
|
if (context == null || maxEvents <= 0) {
|
||||||
return "[]"
|
return "[]"
|
||||||
}
|
}
|
||||||
@@ -73,11 +74,21 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
|
// Filter instances before the cutoff/limit so excluded calendars
|
||||||
|
// cannot crowd out selected calendars, including recurrences.
|
||||||
|
val ids = if (selectedCalendarIdsJson == "null") null else JSONArray(selectedCalendarIdsJson)
|
||||||
|
if (ids != null && ids.length() == 0) return "[]"
|
||||||
|
val args = ids?.let { values -> Array(values.length()) { index ->
|
||||||
|
values.getString(index).also { require(it.matches(Regex("[0-9]+"))) }
|
||||||
|
} }
|
||||||
|
val selection = args?.let {
|
||||||
|
CalendarContract.Instances.CALENDAR_ID + " IN (" + it.joinToString(",") { "?" } + ")"
|
||||||
|
}
|
||||||
cursor = context.contentResolver.query(
|
cursor = context.contentResolver.query(
|
||||||
uri,
|
uri,
|
||||||
PROJECTION,
|
PROJECTION,
|
||||||
null,
|
selection,
|
||||||
null,
|
args,
|
||||||
CalendarContract.Instances.BEGIN + " ASC")
|
CalendarContract.Instances.BEGIN + " ASC")
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||||
@@ -118,6 +129,33 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
return out.toString()
|
return out.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getCalendarsJson(context: Context?): String {
|
||||||
|
if (context == null) return "[]"
|
||||||
|
val out = JSONArray()
|
||||||
|
try {
|
||||||
|
context.contentResolver.query(
|
||||||
|
CalendarContract.Calendars.CONTENT_URI,
|
||||||
|
arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
|
||||||
|
CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.ACCOUNT_TYPE),
|
||||||
|
null, null, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME + " ASC",
|
||||||
|
)?.use { cursor ->
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
out.put(JSONObject().apply {
|
||||||
|
put("id", cursor.getLong(0).toString())
|
||||||
|
put("name", cursor.getString(1) ?: "")
|
||||||
|
put("accountName", cursor.getString(2) ?: "")
|
||||||
|
put("accountType", cursor.getString(3) ?: "")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.w(TAG, "failed to read calendars", t)
|
||||||
|
return "[]"
|
||||||
|
}
|
||||||
|
return out.toString()
|
||||||
|
}
|
||||||
|
|
||||||
private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event {
|
private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event {
|
||||||
val allDay = cursor.getInt(4) != 0
|
val allDay = cursor.getInt(4) != 0
|
||||||
var startMs = cursor.getLong(2)
|
var startMs = cursor.getLong(2)
|
||||||
|
|||||||
@@ -129,13 +129,21 @@ class FaceclawDeviceDiscovery(context: Context) {
|
|||||||
&& manufacturerData[0] == 0x45.toByte() && manufacturerData[1] == 0x52.toByte()) {
|
&& manufacturerData[0] == 0x45.toByte() && manufacturerData[1] == 0x52.toByte()) {
|
||||||
return true
|
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) {
|
if (name == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val upper = name.uppercase()
|
val upper = name.uppercase()
|
||||||
// A bare "R1" substring also matches unrelated hardware ("Oppo Enco
|
// A bare "R1" substring also matches unrelated hardware ("Oppo Enco
|
||||||
// R1"), and TS only classifies rings from the stock name prefix.
|
// 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(
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.faceclaw.app
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.security.keystore.KeyGenParameterSpec
|
||||||
|
import android.security.keystore.KeyProperties
|
||||||
|
import android.util.AtomicFile
|
||||||
|
import java.io.File
|
||||||
|
import java.security.KeyStore
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.KeyGenerator
|
||||||
|
import javax.crypto.SecretKey
|
||||||
|
import javax.crypto.spec.GCMParameterSpec
|
||||||
|
|
||||||
|
/** This credential cannot be restored onto a device lacking its Keystore key. */
|
||||||
|
object FaceclawHealthExportSecret {
|
||||||
|
private const val ALIAS = "faceclaw.health.export"
|
||||||
|
private fun file(context: Context) = AtomicFile(File(context.noBackupFilesDir, "health-export-key"))
|
||||||
|
private fun key(): SecretKey {
|
||||||
|
val store = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
|
||||||
|
(store.getKey(ALIAS, null) as? SecretKey)?.let { return it }
|
||||||
|
return KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore").apply {
|
||||||
|
init(KeyGenParameterSpec.Builder(ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
|
||||||
|
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
|
||||||
|
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE).build())
|
||||||
|
}.generateKey()
|
||||||
|
}
|
||||||
|
@JvmStatic @Synchronized fun read(context: Context): String {
|
||||||
|
val held = file(context)
|
||||||
|
if (!held.baseFile.exists()) return ""
|
||||||
|
return try {
|
||||||
|
val bytes = held.readFully()
|
||||||
|
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, key(), GCMParameterSpec(128, bytes.copyOfRange(0, 12)))
|
||||||
|
String(cipher.doFinal(bytes.copyOfRange(12, bytes.size)), Charsets.UTF_8)
|
||||||
|
} catch (_: Exception) { "" } // Require re-entry after key loss; never log the credential.
|
||||||
|
}
|
||||||
|
@JvmStatic @Synchronized fun write(context: Context, value: String) {
|
||||||
|
val held = file(context)
|
||||||
|
if (value.isEmpty()) { held.delete(); return }
|
||||||
|
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, key())
|
||||||
|
val bytes = cipher.iv + cipher.doFinal(value.toByteArray(Charsets.UTF_8))
|
||||||
|
val stream = held.startWrite()
|
||||||
|
try { stream.write(bytes); held.finishWrite(stream) }
|
||||||
|
catch (error: Exception) { held.failWrite(stream); throw error }
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -504,6 +504,18 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun dismissAllNotifications(): Boolean {
|
||||||
|
val service = activeService ?: return false
|
||||||
|
return try {
|
||||||
|
service.cancelAllNotifications()
|
||||||
|
true
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.w(TAG, "failed to dismiss all notifications", t)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun emitNotificationPosted(key: String?) {
|
private fun emitNotificationPosted(key: String?) {
|
||||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,17 +32,6 @@ class FaceclawVoiceController(context: Context) {
|
|||||||
"decoder_model_merged.ort",
|
"decoder_model_merged.ort",
|
||||||
"tokens.txt"
|
"tokens.txt"
|
||||||
)
|
)
|
||||||
// Second on-device model: sherpa-onnx's offline Whisper backend (base.en,
|
|
||||||
// int8-quantized -- see the model-choice note in asr-model.ts). Directory
|
|
||||||
// shared with the TS-side download flow, same convention as ASR_MODEL_DIR.
|
|
||||||
// Whisper re-encodes the whole buffer on every call, so the shared session
|
|
||||||
// skips live partials for it; see VoiceCaptureSession.processRecognizer.
|
|
||||||
private const val ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8"
|
|
||||||
private val ASR_WHISPER_MODEL_FILES = arrayOf(
|
|
||||||
"base.en-encoder.int8.onnx",
|
|
||||||
"base.en-decoder.int8.onnx",
|
|
||||||
"base.en-tokens.txt"
|
|
||||||
)
|
|
||||||
// 50 ms chunks match the G2 packet cadence the rest of the pipeline
|
// 50 ms chunks match the G2 packet cadence the rest of the pipeline
|
||||||
// (endpointing, transcript pacing) is tuned for.
|
// (endpointing, transcript pacing) is tuned for.
|
||||||
private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20
|
private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20
|
||||||
@@ -84,6 +73,7 @@ class FaceclawVoiceController(context: Context) {
|
|||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
@Volatile
|
@Volatile
|
||||||
private var communicator: FaceclawBleCommunicator? = null
|
private var communicator: FaceclawBleCommunicator? = null
|
||||||
|
private var whisperModel = WhisperModelFiles.forLanguage(null)
|
||||||
|
|
||||||
private val host = object : VoiceCaptureHost {
|
private val host = object : VoiceCaptureHost {
|
||||||
override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } }
|
override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } }
|
||||||
@@ -114,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)
|
override fun openPhoneMic(): PcmAudioSource? = AndroidSpeechEngines.openPhoneMic(PHONE_MIC_CHUNK_SAMPLES)
|
||||||
|
|
||||||
@@ -122,7 +114,7 @@ class FaceclawVoiceController(context: Context) {
|
|||||||
|
|
||||||
override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber {
|
override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber {
|
||||||
val modelDir = findAsrModelDir(kind) ?: throw IllegalStateException("voice model missing")
|
val modelDir = findAsrModelDir(kind) ?: throw IllegalStateException("voice model missing")
|
||||||
return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind))
|
return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind, whisperModel))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun speakerEmbedder(modelPath: String): SpeakerEmbedder {
|
override fun speakerEmbedder(modelPath: String): SpeakerEmbedder {
|
||||||
@@ -168,6 +160,11 @@ class FaceclawVoiceController(context: Context) {
|
|||||||
session.setOnboardModelKind(kind)
|
session.setOnboardModelKind(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Language for the next on-device Whisper capture; empty enables auto-detection. */
|
||||||
|
fun setOnboardLanguage(language: String?) {
|
||||||
|
whisperModel = WhisperModelFiles.forLanguage(language)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When true, watch the decoded PCM and fire {@code onSpeechEnd} once the
|
* When true, watch the decoded PCM and fire {@code onSpeechEnd} once the
|
||||||
* speaker stops. Used by hands-free ("Hey Even") capture, which has no
|
* speaker stops. Used by hands-free ("Hey Even") capture, which has no
|
||||||
@@ -263,8 +260,8 @@ class FaceclawVoiceController(context: Context) {
|
|||||||
*/
|
*/
|
||||||
private fun findAsrModelDir(kind: VoiceModelKind): File? {
|
private fun findAsrModelDir(kind: VoiceModelKind): File? {
|
||||||
val whisper = kind == VoiceModelKind.WHISPER
|
val whisper = kind == VoiceModelKind.WHISPER
|
||||||
val dirName = if (whisper) ASR_WHISPER_MODEL_DIR else ASR_MODEL_DIR
|
val dirName = if (whisper) whisperModel.dirName else ASR_MODEL_DIR
|
||||||
val fileNames = if (whisper) ASR_WHISPER_MODEL_FILES else ASR_MODEL_FILES
|
val fileNames = if (whisper) whisperModel.files else ASR_MODEL_FILES.toList()
|
||||||
val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName)
|
val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName)
|
||||||
for (fileName in fileNames) {
|
for (fileName in fileNames) {
|
||||||
val file = File(modelDir, fileName)
|
val file = File(modelDir, fileName)
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ class FontFileRenderer private constructor() {
|
|||||||
* [width u16][height u16]
|
* [width u16][height u16]
|
||||||
* [width*height coverage bytes, gamma-mapped]
|
* [width*height coverage bytes, gamma-mapped]
|
||||||
* An ink-free glyph (space) has width = height = 0 but a valid advance.
|
* 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.
|
* Empty array when the font cannot be loaded or the render fails.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -196,11 +197,16 @@ class FontFileRenderer private constructor() {
|
|||||||
}
|
}
|
||||||
val penX = pad - bounds.left
|
val penX = pad - bounds.left
|
||||||
val baselineY = pad - bounds.top
|
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)
|
val canvas = Canvas(bitmap)
|
||||||
canvas.drawText(text, penX.toFloat(), baselineY.toFloat(), paint)
|
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()
|
bitmap.recycle()
|
||||||
|
val pixels = ColorGlyphArt.coverage(argb)
|
||||||
|
|
||||||
// Trim to the tight ink box; bearing/inkTop become pen- and
|
// Trim to the tight ink box; bearing/inkTop become pen- and
|
||||||
// line-relative inside the shared packer.
|
// 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,
|
* Scale a bitmap to fit within maxWidth x maxHeight (preserving aspect,
|
||||||
* never upscaling) and convert it to the grayscale packet format.
|
* never upscaling) and convert it to the grayscale packet format.
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ add_subdirectory(${LLAMA_CPP_SOURCE_DIR} llama.cpp-build EXCLUDE_FROM_ALL)
|
|||||||
|
|
||||||
add_library(faceclaw_llama SHARED faceclaw_llama.cpp)
|
add_library(faceclaw_llama SHARED faceclaw_llama.cpp)
|
||||||
target_link_libraries(faceclaw_llama PRIVATE llama android log)
|
target_link_libraries(faceclaw_llama PRIVATE llama android log)
|
||||||
|
# NDK r27 defaults to 4 KiB. Align both LOAD segments and RELRO boundaries
|
||||||
|
# for Android devices using 16 KiB pages, including debug APKs.
|
||||||
|
target_link_options(faceclaw_llama PRIVATE
|
||||||
|
"-Wl,-z,max-page-size=16384"
|
||||||
|
"-Wl,-z,common-page-size=16384")
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>Faceclaw</string>
|
<string>Faceclaw</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.8.6</string>
|
<string>0.9.0</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>1</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#import "FaceclawFontRenderer.h"
|
#import "FaceclawFontRenderer.h"
|
||||||
#import <CoreText/CoreText.h>
|
#import <CoreText/CoreText.h>
|
||||||
#import <CoreGraphics/CoreGraphics.h>
|
#import <CoreGraphics/CoreGraphics.h>
|
||||||
|
#import <FaceclawKit/FaceclawKit.h>
|
||||||
#import <math.h>
|
#import <math.h>
|
||||||
|
|
||||||
// Immutable font descriptors may be shared; layout objects never cross threads.
|
// 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
|
// 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
|
// (▶ 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
|
// emoji is a tile (▶ becomes a rounded square: a silhouette in the alpha-only
|
||||||
// rounded square). Request text presentation (U+FE0E) for each lone codepoint
|
// 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
|
// that fell back to a color font, wherever a text font can supply it. Returns
|
||||||
// `text` itself when nothing changes.
|
// `text` itself when nothing changes.
|
||||||
static NSString *PreferTextPresentation(CTFontRef font, NSString *text, CTLineRef line, BOOL glyphLayout) {
|
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) {
|
static BOOL ValidRaster(NSInteger width, NSInteger height) {
|
||||||
return width > 0 && height > 0 && width <= 65535 && height <= 65535 && width * height <= 4000000;
|
return width > 0 && height > 0 && width <= 65535 && height <= 65535 && width * height <= 4000000;
|
||||||
}
|
}
|
||||||
static CGContextRef CreateContext(NSMutableData *pixels, NSInteger width, NSInteger height) CF_RETURNS_RETAINED {
|
static void ConfigureTextContext(CGContextRef ctx) {
|
||||||
CGContextRef ctx = CGBitmapContextCreate(pixels.mutableBytes, width, height, 8, width, NULL, (CGBitmapInfo)kCGImageAlphaOnly);
|
|
||||||
if (ctx) {
|
|
||||||
CGContextSetShouldAntialias(ctx, true);
|
CGContextSetShouldAntialias(ctx, true);
|
||||||
CGContextSetShouldSmoothFonts(ctx, false); // Grayscale coverage, never LCD subpixel color.
|
CGContextSetShouldSmoothFonts(ctx, false); // Grayscale coverage, never LCD subpixel color.
|
||||||
CGContextSetShouldSubpixelPositionFonts(ctx, true);
|
CGContextSetShouldSubpixelPositionFonts(ctx, true);
|
||||||
CGContextSetShouldSubpixelQuantizeFonts(ctx, false);
|
CGContextSetShouldSubpixelQuantizeFonts(ctx, false);
|
||||||
CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
|
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) {
|
||||||
|
ConfigureTextContext(ctx);
|
||||||
CGContextSetGrayFillColor(ctx, 1, 1);
|
CGContextSetGrayFillColor(ctx, 1, 1);
|
||||||
}
|
}
|
||||||
return ctx;
|
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 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) {
|
static void GammaCopy(uint8_t *dst, const uint8_t *src, NSInteger count, double gamma) {
|
||||||
if (!isfinite(gamma) || gamma <= 0) gamma = 1;
|
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 bottom = floor(CGRectGetMinY(bounds)) - 2;
|
||||||
NSInteger width = ceil(CGRectGetMaxX(bounds)) + 2 - left, height = top - bottom;
|
NSInteger width = ceil(CGRectGetMaxX(bounds)) + 2 - left, height = top - bottom;
|
||||||
if (!ValidRaster(width, height)) { CFRelease(line); CFRelease(font); return [NSData data]; }
|
if (!ValidRaster(width, height)) { CFRelease(line); CFRelease(font); return [NSData data]; }
|
||||||
NSMutableData *pixels = [NSMutableData dataWithLength:width * height];
|
BOOL color = HasColorRun(line);
|
||||||
CGContextRef ctx = CreateContext(pixels, width, height);
|
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]; }
|
if (!ctx) { CFRelease(line); CFRelease(font); return [NSData data]; }
|
||||||
CGContextSetTextPosition(ctx, -left, -bottom); CTLineDraw(line, ctx); CGContextRelease(ctx);
|
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;
|
const uint8_t *src = pixels.bytes;
|
||||||
NSInteger x0 = width, y0 = height, x1 = -1, y1 = -1;
|
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]) {
|
for (NSInteger y = 0; y < height; y++) for (NSInteger x = 0; x < width; x++) if (src[y * width + x]) {
|
||||||
|
|||||||
@@ -14,4 +14,10 @@
|
|||||||
+ (NSData *)bgraPacket:(CGImageRef)image maxSize:(NSInteger)maxSize;
|
+ (NSData *)bgraPacket:(CGImageRef)image maxSize:(NSInteger)maxSize;
|
||||||
/** bgraPacket of encoded image bytes (JPEG, PNG, ...); nil when undecodable. */
|
/** bgraPacket of encoded image bytes (JPEG, PNG, ...); nil when undecodable. */
|
||||||
+ (NSData *)bgraPacketFromImageData:(NSData *)data maxSize:(NSInteger)maxSize;
|
+ (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
|
@end
|
||||||
@@ -158,4 +158,26 @@
|
|||||||
CGImageRelease(image);
|
CGImageRelease(image);
|
||||||
return packet;
|
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
|
@end
|
||||||
@@ -1,5 +1,26 @@
|
|||||||
# Changelog
|
# 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
|
## 0.8.6 - 2026-11-01
|
||||||
|
|
||||||
* Connect directly to the R1 ring rather than indirectly via the glasses
|
* Connect directly to the R1 ring rather than indirectly via the glasses
|
||||||
|
|||||||
@@ -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
|
This Android app uses a modded firmware for the G2 smart glasses. Source code
|
||||||
to the corresponding firmware modifications lives in
|
to the corresponding firmware modifications lives in
|
||||||
https://github.com/jimrandomh/g2flash; there is a compiled version of the
|
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
|
firmware patch-set in app/g2/firmware/cfw-patches.ts, regenerated by
|
||||||
changes to the Android app over making changes to changes to the firmware, as
|
scripts/update_deltas.sh. Even G1 glasses run g1v0, a firmware from ScouterKit
|
||||||
firmware development is considerably more fraught.
|
(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.
|
||||||
|
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
/** Conditional wording: also shown on self-built iOS apps, where TestFlight does not apply. */
|
/**
|
||||||
export const IOS_PRIVACY_NOTICE = [
|
* One-line pointer for iOS. The full TestFlight disclosure lives only in the
|
||||||
"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.",
|
* PRIVACY file (shown in-app as Settings > Privacy > Privacy policy).
|
||||||
"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");
|
|
||||||
|
|
||||||
export const IOS_PRIVACY_SUMMARY =
|
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.";
|
||||||
@@ -81,12 +81,6 @@ Button.-primary {
|
|||||||
font-size: 18;
|
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
|
/* License / privacy-policy links in the onboarding disclaimer footer. The
|
||||||
* padding widens the tap target beyond the small text. */
|
* padding widens the tap target beyond the small text. */
|
||||||
.footer-link {
|
.footer-link {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
.body-text { font-size: 18; }
|
.body-text { font-size: 18; }
|
||||||
.h1 { font-size: 28; font-weight: bold; }
|
.h1 { font-size: 28; font-weight: bold; }
|
||||||
.footer-link { color: #285c45; padding: 4 8; text-decoration: underline; }
|
.footer-link { color: #285c45; padding: 4 8; text-decoration: underline; }
|
||||||
|
.ns-dark .footer-link { color: #7bc47f; }
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
background-color: #f5f5f2;
|
background-color: #f5f5f2;
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ export type AppDefinition = {
|
|||||||
boot?: (ctx: AppContext) => void;
|
boot?: (ctx: AppContext) => void;
|
||||||
/** False for apps that must not appear in the launcher grid (the launcher itself). */
|
/** False for apps that must not appear in the launcher grid (the launcher itself). */
|
||||||
showInLauncher?: boolean;
|
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. */
|
/** Present on the app that handles text shared via the Android share intent. */
|
||||||
openSharedText?: (ctx: AppContext, title: string, text: string) => void;
|
openSharedText?: (ctx: AppContext, title: string, text: string) => void;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { invalidateCalendarCache, onCalendarChanged } from "../../native/calenda
|
|||||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||||
import { CalendarLayer } from "./calendar";
|
import { CalendarLayer } from "./calendar";
|
||||||
import { renderCalendarDateIcon } from "./calendar-icon";
|
import { renderCalendarDateIcon } from "./calendar-icon";
|
||||||
|
import { calendarSelectionMenuItems } from "./calendar-filter";
|
||||||
import {
|
import {
|
||||||
createInProcessWindow,
|
createInProcessWindow,
|
||||||
YieldAtRootLayer,
|
YieldAtRootLayer,
|
||||||
@@ -44,6 +45,10 @@ export function createCalendarAppWindow(options: InProcessAppOptions): InProcess
|
|||||||
icon: "calendar",
|
icon: "calendar",
|
||||||
drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")),
|
drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")),
|
||||||
closeable: true,
|
closeable: true,
|
||||||
|
menuItems: () => calendarSelectionMenuItems().map(item => ({ ...item, onSelect: (ctx, menu) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
return item.onSelect(ctx, menu);
|
||||||
|
} })),
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||||
|
import { type GrayImage } from "../../graphics/image";
|
||||||
|
import { truncateText } from "../../graphics/textwrap";
|
||||||
|
import { readCalendarSelection, setCalendarSelection } from "../../native/calendar-selection";
|
||||||
|
import { readAvailableCalendars } from "../../native/calendar-sources";
|
||||||
|
import { hasCalendarPermission } from "../../native/calendar-permissions";
|
||||||
|
import { type InputEvent } from "../../ui/gestures";
|
||||||
|
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||||
|
import { drawToggleMenuItem, MenuLayer, type MenuItem } from "../../ui/menu";
|
||||||
|
|
||||||
|
/** Shared preference for every Android calendar reader. */
|
||||||
|
export class CalendarFilterLayer implements Layer {
|
||||||
|
private menu: MenuLayer | null = null;
|
||||||
|
private width = 0;
|
||||||
|
private keys: string[] = [];
|
||||||
|
|
||||||
|
private currentMenu(ctx: LayerContext): MenuLayer {
|
||||||
|
const calendars = readAvailableCalendars().sort((a, b) =>
|
||||||
|
a.name.localeCompare(b.name) || a.accountName.localeCompare(b.accountName) || a.id.localeCompare(b.id));
|
||||||
|
const selection = readCalendarSelection();
|
||||||
|
const known = new Set(calendars.map(calendar => calendar.id));
|
||||||
|
const keys = ["all", "none"];
|
||||||
|
const toggle = (id: string) => {
|
||||||
|
// Leaving all mode snapshots the current calendars. Newly added calendars
|
||||||
|
// then stay excluded until selected individually or all mode is restored.
|
||||||
|
const ids = new Set(readCalendarSelection() ?? calendars.map(calendar => calendar.id));
|
||||||
|
if (ids.has(id)) ids.delete(id); else ids.add(id);
|
||||||
|
setCalendarSelection(Array.from(ids));
|
||||||
|
};
|
||||||
|
const items: MenuItem[] = [{
|
||||||
|
label: "All calendars",
|
||||||
|
description: "Include all calendars, including calendars added later.",
|
||||||
|
onSelect: () => setCalendarSelection(null),
|
||||||
|
render: ({ image, x, y, width, selected }) => drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width,
|
||||||
|
"All calendars", readCalendarSelection() === null, selected),
|
||||||
|
}, {
|
||||||
|
label: "No calendars",
|
||||||
|
onSelect: () => setCalendarSelection([]),
|
||||||
|
render: ({ image, x, y, width, selected }) => drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width,
|
||||||
|
"No calendars", readCalendarSelection()?.length === 0, selected),
|
||||||
|
}];
|
||||||
|
const rows = [
|
||||||
|
...calendars.map(calendar => ({ id: calendar.id,
|
||||||
|
label: `${calendar.name || "(unnamed)"} / ${calendar.accountName || "Local"} (${calendar.accountType || "local"}) #${calendar.id}` })),
|
||||||
|
...(selection ?? []).filter(id => !known.has(id)).map(id => ({ id, label: `Unavailable calendar #${id}` })),
|
||||||
|
];
|
||||||
|
for (const row of rows) {
|
||||||
|
keys.push(`calendar:${row.id}`);
|
||||||
|
items.push({
|
||||||
|
label: row.label,
|
||||||
|
description: row.label,
|
||||||
|
onSelect: () => toggle(row.id),
|
||||||
|
render: ({ image, x, y, width, selected }) => {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
|
const ids = readCalendarSelection();
|
||||||
|
drawToggleMenuItem(image, font, x, y, width, truncateText(font, row.label, width - 48),
|
||||||
|
ids === null || ids.includes(row.id), selected);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!calendars.length) items.push({
|
||||||
|
label: hasCalendarPermission() ? "No calendars available" : "Grant calendar permission on your phone",
|
||||||
|
disabled: true, onSelect: () => {},
|
||||||
|
});
|
||||||
|
const key = this.menu?.selectedIndex != null ? this.keys[this.menu.selectedIndex] : "all";
|
||||||
|
const index = Math.max(0, keys.indexOf(key ?? "all"));
|
||||||
|
this.keys = keys;
|
||||||
|
const width = ctx.stack.getBaseSize().width;
|
||||||
|
if (!this.menu || this.width !== width) {
|
||||||
|
this.width = width;
|
||||||
|
this.menu = new MenuLayer("Calendars displayed", items, {
|
||||||
|
x: 8, y: 8, width: width - 16, opaque: true, showBorder: false,
|
||||||
|
footer: "Shared by Calendar and Glanceboard",
|
||||||
|
}).selectItem(index);
|
||||||
|
} else this.menu.setItems(items, index);
|
||||||
|
return this.menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||||
|
return this.currentMenu(ctx).paint(ctx, paintBelow);
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
|
await this.currentMenu(ctx).handleInput(event, ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function calendarSelectionMenuItems(): MenuItem[] {
|
||||||
|
return global.isAndroid ? [{
|
||||||
|
label: "Calendars displayed",
|
||||||
|
description: "Choose the calendars used by Calendar, Glanceboard and other calendar views.",
|
||||||
|
onSelect: ctx => ctx.stack.push(new CalendarFilterLayer()),
|
||||||
|
}] : [];
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
type CompassDiagnostics,
|
type CompassDiagnostics,
|
||||||
} from "../../native/compass";
|
} from "../../native/compass";
|
||||||
import { wrapText } from "../../graphics/textwrap";
|
import { wrapText } from "../../graphics/textwrap";
|
||||||
|
import { glassesHaveCompass } from "../../ui/dashboard-settings";
|
||||||
import { type InputEvent } from "../../ui/gestures";
|
import { type InputEvent } from "../../ui/gestures";
|
||||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||||
import { lineStep } from "../../ui/metrics";
|
import { lineStep } from "../../ui/metrics";
|
||||||
@@ -151,6 +152,7 @@ class CompassLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private statusText(): string {
|
private statusText(): string {
|
||||||
|
if (!glassesHaveCompass()) return "These glasses have no compass sensor";
|
||||||
if (this.firmwareStatus !== null) return this.firmwareStatus;
|
if (this.firmwareStatus !== null) return this.firmwareStatus;
|
||||||
if (!this.enabled) return "Compass paused";
|
if (!this.enabled) return "Compass paused";
|
||||||
if (this.rawHeading === null) return "Waiting for compass data…";
|
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);
|
image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125);
|
||||||
y += smallStep;
|
y += smallStep;
|
||||||
}
|
}
|
||||||
|
if (glassesHaveCompass()) {
|
||||||
const accuracyText = magneticAccuracyText(this.diagnostics);
|
const accuracyText = magneticAccuracyText(this.diagnostics);
|
||||||
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175);
|
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175);
|
||||||
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -216,7 +220,7 @@ class CompassLayer implements Layer {
|
|||||||
// "Uncalibrated" prompt advertises, and re-calibrating is a normal thing to
|
// "Uncalibrated" prompt advertises, and re-calibrating is a normal thing to
|
||||||
// want once the glasses have been taken off and put back on.
|
// want once the glasses have been taken off and put back on.
|
||||||
handleInput(event: InputEvent, ctx: LayerContext): void {
|
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",
|
icon: "compass",
|
||||||
closeable: true,
|
closeable: true,
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
menuItems: () => [
|
menuItems: () => !glassesHaveCompass() ? [] : [
|
||||||
{
|
{
|
||||||
label: "Calibrate",
|
label: "Calibrate",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { glassesHaveCompass } from "../../ui/dashboard-settings";
|
||||||
import { type AppDefinition } from "../app-definition";
|
import { type AppDefinition } from "../app-definition";
|
||||||
import { COMPASS_SURFACE_ID, COMPASS_WINDOW_ID, createCompassAppWindow } from "./compass-app";
|
import { COMPASS_SURFACE_ID, COMPASS_WINDOW_ID, createCompassAppWindow } from "./compass-app";
|
||||||
|
|
||||||
@@ -5,6 +6,7 @@ const compassApp: AppDefinition = {
|
|||||||
appId: "compass",
|
appId: "compass",
|
||||||
title: "Compass",
|
title: "Compass",
|
||||||
icon: "compass",
|
icon: "compass",
|
||||||
|
isSupported: glassesHaveCompass,
|
||||||
launch: (ctx) => ctx.launchInProcessApp(COMPASS_WINDOW_ID, COMPASS_SURFACE_ID, createCompassAppWindow),
|
launch: (ctx) => ctx.launchInProcessApp(COMPASS_WINDOW_ID, COMPASS_SURFACE_ID, createCompassAppWindow),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { type InputEvent } from "../../ui/gestures";
|
|||||||
import { Layer, type LayerContext } from "../../ui/layers";
|
import { Layer, type LayerContext } from "../../ui/layers";
|
||||||
import { shell } from "../../ui/shell/shell";
|
import { shell } from "../../ui/shell/shell";
|
||||||
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
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 { loadDeviceAddresses } from "../../g2/device-addresses";
|
||||||
import {
|
import {
|
||||||
getRingSessionStatus,
|
getRingSessionStatus,
|
||||||
@@ -146,7 +146,7 @@ export class RingStatusLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!s.directEnabled) {
|
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 });
|
rows.push({ label: "Direct link", value: pending ? "on after glasses reconnect" : "off (only via glasses)", dim: true });
|
||||||
} else {
|
} else {
|
||||||
const state = s.directNotificationsReady ? "subscribed"
|
const state = s.directNotificationsReady ? "subscribed"
|
||||||
|
|||||||
+128
-47
@@ -7,16 +7,23 @@
|
|||||||
* match what apps expect. Extended layouts may pick other fonts per container
|
* match what apps expect. Extended layouts may pick other fonts per container
|
||||||
* (fonts.ts), which wrap with Faceclaw's own text wrapping.
|
* (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:
|
* Known deviations from stock, acceptable for now:
|
||||||
* - List rendering is a plain vertical list. A non-zero itemWidth sets the
|
* - 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;
|
* 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.
|
* whether stock also lays narrow items out side by side is unknown.
|
||||||
* - Lists scroll with our menus' animation and bounce (see list-menu.ts).
|
* - 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 { GrayImage } from "../../graphics/image";
|
||||||
import { containerFace } from "./fonts";
|
import { containerFace } from "./fonts";
|
||||||
import {
|
import {
|
||||||
type EvenHubContainer,
|
borderGrey,
|
||||||
|
paintOrder,
|
||||||
type EvenHubImageContainer,
|
type EvenHubImageContainer,
|
||||||
type EvenHubListContainer,
|
type EvenHubListContainer,
|
||||||
type EvenHubPage,
|
type EvenHubPage,
|
||||||
@@ -30,35 +37,122 @@ export const EVENHUB_SCREEN_HEIGHT = 288;
|
|||||||
const TEXT_WHITE = 255;
|
const TEXT_WHITE = 255;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SDK 0.0.14 textColor levels 0..4 as grey values. Level 4 is the default and
|
* SDK 0.0.14 textColor levels 0..4 as the greys stock draws them (measured
|
||||||
* the only one apps got before 0.0.14, so it must stay exactly TEXT_WHITE.
|
* in the firmware emulator): level 0 is dim, not off. A missing or
|
||||||
* Level 0 is the firmware's "fully dim" step, which over the black page
|
* out-of-range level draws white, the only colour before 0.0.14.
|
||||||
* background means the text is effectively not shown.
|
|
||||||
*/
|
*/
|
||||||
const TEXT_BRIGHTNESS_GREYS = [0, 64, 128, 191, 255];
|
const TEXT_BRIGHTNESS_GREYS = [51, 102, 153, 204, 255];
|
||||||
|
|
||||||
function textGrey(level: number | undefined): number {
|
function textGrey(level: number | undefined): number {
|
||||||
return level === undefined ? TEXT_WHITE : (TEXT_BRIGHTNESS_GREYS[level] ?? TEXT_WHITE);
|
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. */
|
* The scrollbar stock draws on any text container whose text overflows
|
||||||
function paintTextContainer(image: GrayImage, container: EvenHubTextContainer): void {
|
* (LV_SCROLLBAR_MODE_AUTO), whether or not it captures input: 4px wide, 10px
|
||||||
// Only the text dims: textColor is a text-brightness level, and stock draws
|
* in from the right edge, in a track 6px in from top and bottom, with its
|
||||||
// the container's border at full brightness regardless.
|
* corner pixels cut. Measured in the firmware emulator.
|
||||||
paintBorder(image, container);
|
*/
|
||||||
|
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 inset = container.borderWidth + container.paddingLength;
|
||||||
const face = containerFace(container.font);
|
const face = containerFace(container.font);
|
||||||
const lines = face.wrap(container.content, Math.max(1, container.width - 2 * inset));
|
const lines = face.wrap(container.content, Math.max(1, container.width - 2 * container.paddingLength));
|
||||||
for (let i = 0; i < lines.length; i++) {
|
const viewportHeight = Math.max(0, container.height - 2 * inset);
|
||||||
face.drawText(image, container.x + inset, container.y + inset + i * face.lineHeight, lines[i]!, textGrey(container.textColor));
|
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(
|
function paintBorder(
|
||||||
image: GrayImage,
|
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 {
|
): void {
|
||||||
|
const grey = borderGrey(container.borderColor);
|
||||||
for (let i = 0; i < container.borderWidth; i++) {
|
for (let i = 0; i < container.borderWidth; i++) {
|
||||||
if (container.borderRadius > 0) {
|
if (container.borderRadius > 0) {
|
||||||
image.drawRoundedRect(
|
image.drawRoundedRect(
|
||||||
@@ -66,65 +160,52 @@ function paintBorder(
|
|||||||
container.y + i,
|
container.y + i,
|
||||||
container.width - 2 * i,
|
container.width - 2 * i,
|
||||||
container.height - 2 * i,
|
container.height - 2 * i,
|
||||||
TEXT_WHITE,
|
grey,
|
||||||
Math.max(0, container.borderRadius - i),
|
Math.max(0, container.borderRadius - i),
|
||||||
);
|
);
|
||||||
} else {
|
} 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 {
|
function paintImageContainer(image: GrayImage, container: EvenHubImageContainer): void {
|
||||||
if (!container.pixels || container.pixelsWidth <= 0 || container.pixelsHeight <= 0) return;
|
if (!container.pixels || container.pixelsWidth <= 0 || container.pixelsHeight <= 0) return;
|
||||||
const source = new GrayImage(container.pixelsWidth, container.pixelsHeight, 0);
|
const source = new GrayImage(container.pixelsWidth, container.pixelsHeight, 0);
|
||||||
source.pixels.set(container.pixels);
|
source.pixels.set(container.pixels);
|
||||||
// Stock quirk: raw data smaller than the container tiles/repeats to fill it.
|
image.bitBlt(source, container.x, container.y, {
|
||||||
for (let ty = 0; ty < container.height; ty += container.pixelsHeight) {
|
width: Math.min(container.pixelsWidth, container.width),
|
||||||
for (let tx = 0; tx < container.width; tx += container.pixelsWidth) {
|
height: Math.min(container.pixelsHeight, container.height),
|
||||||
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),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function paintListContainer(image: GrayImage, container: EvenHubListContainer, focused: boolean): void {
|
function paintListContainer(image: GrayImage, container: EvenHubListContainer, focused: boolean): void {
|
||||||
paintBorder(image, container);
|
paintBorder(image, container);
|
||||||
paintListItems(image, container, containerFace(container.font), focused);
|
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). */
|
/** 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 {
|
export function compositePage(page: EvenHubPage | null, size: { width: number; height: number }, focused: boolean): GrayImage {
|
||||||
const image = new GrayImage(size.width, size.height, 0);
|
const image = new GrayImage(size.width, size.height, 0);
|
||||||
if (!page) return image;
|
if (!page) return image;
|
||||||
for (const container of paintOrder(page.containers)) {
|
for (const container of paintOrder(page.containers)) {
|
||||||
switch (container.kind) {
|
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
|
// Text painted so far is deferred draws (firmware-text runs), which
|
||||||
// would otherwise render above this container's raster. Stock puts a
|
// would otherwise render above this container's raster. The image is
|
||||||
// later image container OVER earlier text, so bake the pending draws
|
// opaque and covers what's under it, so bake the draws it overlaps
|
||||||
// first; text painted after this container stays deferred (and above).
|
// first; the others, and text painted later, stay deferred.
|
||||||
image.bakeDeferredDrawsInPlace();
|
const box: Rect = { x: container.x, y: container.y, width: container.width, height: container.height };
|
||||||
|
image.bakeDeferredDrawsWithin(box);
|
||||||
paintImageContainer(image, container);
|
paintImageContainer(image, container);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "text":
|
case "text":
|
||||||
paintTextContainer(image, container);
|
paintTextContainer(image, container);
|
||||||
break;
|
break;
|
||||||
|
|||||||
+130
-13
@@ -6,6 +6,7 @@
|
|||||||
* reads go through loose key matching (the SDK's pickLoose behavior).
|
* reads go through loose key matching (the SDK's pickLoose behavior).
|
||||||
*/
|
*/
|
||||||
import { mergeFontSpecs, parseFontSpec, type EvenHubFontSpec } from "./font-spec";
|
import { mergeFontSpecs, parseFontSpec, type EvenHubFontSpec } from "./font-spec";
|
||||||
|
import { inStockImageRange } from "./image-pipeline";
|
||||||
|
|
||||||
export type EvenHubTextContainer = {
|
export type EvenHubTextContainer = {
|
||||||
kind: "text";
|
kind: "text";
|
||||||
@@ -16,6 +17,8 @@ export type EvenHubTextContainer = {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
borderWidth: number;
|
borderWidth: number;
|
||||||
|
/** Firmware border color index 0..16; see borderGrey. */
|
||||||
|
borderColor: number;
|
||||||
borderRadius: number;
|
borderRadius: number;
|
||||||
paddingLength: number;
|
paddingLength: number;
|
||||||
isEventCapture: boolean;
|
isEventCapture: boolean;
|
||||||
@@ -27,6 +30,11 @@ export type EvenHubTextContainer = {
|
|||||||
textColor: number | undefined;
|
textColor: number | undefined;
|
||||||
/** Extended-layout font (merged with the layout's default); undefined is the stock font. */
|
/** Extended-layout font (merged with the layout's default); undefined is the stock font. */
|
||||||
font: EvenHubFontSpec | undefined;
|
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 = {
|
export type EvenHubImageContainer = {
|
||||||
@@ -54,6 +62,8 @@ export type EvenHubListContainer = {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
borderWidth: number;
|
borderWidth: number;
|
||||||
|
/** Firmware border color index 0..16; see borderGrey. */
|
||||||
|
borderColor: number;
|
||||||
borderRadius: number;
|
borderRadius: number;
|
||||||
paddingLength: number;
|
paddingLength: number;
|
||||||
isEventCapture: boolean;
|
isEventCapture: boolean;
|
||||||
@@ -80,7 +90,7 @@ export type EvenHubMenuItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type EvenHubPage = {
|
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[];
|
containers: EvenHubContainer[];
|
||||||
/**
|
/**
|
||||||
* The page's contextual-menu entries (SDK 0.0.14 `menuObject`). Empty when
|
* 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. */
|
/** Stock draws at most a 5px border; wider requests are clamped. */
|
||||||
const MAX_BORDER_WIDTH = 5;
|
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. */
|
/** Firmware brightness levels for text; 4 is the device default. */
|
||||||
const MIN_TEXT_BRIGHTNESS = 0;
|
const MIN_TEXT_BRIGHTNESS = 0;
|
||||||
const MAX_TEXT_BRIGHTNESS = 4;
|
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)));
|
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. */
|
/** A container's font: its own `font` over the layout-wide default. */
|
||||||
function readFont(json: Record<string, unknown>, layoutFont: EvenHubFontSpec | undefined): EvenHubFontSpec | undefined {
|
function readFont(json: Record<string, unknown>, layoutFont: EvenHubFontSpec | undefined): EvenHubFontSpec | undefined {
|
||||||
return mergeFontSpecs(layoutFont, parseFontSpec(pickLoose(json, "font")));
|
return mergeFontSpecs(layoutFont, parseFontSpec(pickLoose(json, "font")));
|
||||||
@@ -169,6 +204,7 @@ function parseTextContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
|
|||||||
width: readNumber(json, "width", 0),
|
width: readNumber(json, "width", 0),
|
||||||
height: readNumber(json, "height", 0),
|
height: readNumber(json, "height", 0),
|
||||||
borderWidth: readBorderWidth(json),
|
borderWidth: readBorderWidth(json),
|
||||||
|
borderColor: readBorderColor(json),
|
||||||
borderRadius: readNumber(json, "borderRadius", 0),
|
borderRadius: readNumber(json, "borderRadius", 0),
|
||||||
paddingLength: readNumber(json, "paddingLength", 0),
|
paddingLength: readNumber(json, "paddingLength", 0),
|
||||||
isEventCapture: readFlag(json, "isEventCapture"),
|
isEventCapture: readFlag(json, "isEventCapture"),
|
||||||
@@ -177,6 +213,7 @@ function parseTextContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
|
|||||||
content: readString(json, "content", ""),
|
content: readString(json, "content", ""),
|
||||||
textColor: readTextBrightness(json),
|
textColor: readTextBrightness(json),
|
||||||
font: readFont(json, layoutFont),
|
font: readFont(json, layoutFont),
|
||||||
|
scrollY: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,6 +299,7 @@ function parseListContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
|
|||||||
width: readNumber(json, "width", 0),
|
width: readNumber(json, "width", 0),
|
||||||
height: readNumber(json, "height", 0),
|
height: readNumber(json, "height", 0),
|
||||||
borderWidth: readBorderWidth(json),
|
borderWidth: readBorderWidth(json),
|
||||||
|
borderColor: readBorderColor(json),
|
||||||
borderRadius: readNumber(json, "borderRadius", 0),
|
borderRadius: readNumber(json, "borderRadius", 0),
|
||||||
paddingLength: readNumber(json, "paddingLength", 0),
|
paddingLength: readNumber(json, "paddingLength", 0),
|
||||||
isEventCapture: readFlag(json, "isEventCapture"),
|
isEventCapture: readFlag(json, "isEventCapture"),
|
||||||
@@ -277,9 +315,8 @@ function parseListContainer(json: Record<string, unknown>, layoutFont: EvenHubFo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a CreateStartUpPageContainer / RebuildPageContainer payload into a
|
* Parse a CreateStartUpPageContainer / RebuildPageContainer payload into a
|
||||||
* page. Containers keep declaration order within and across the three arrays
|
* page. Containers are kept in stock's container-list order: lists, then
|
||||||
* (lists, then images, then texts — texts last so info panels and capture
|
* texts, then images, each in declaration order (evenhub_build_container_list).
|
||||||
* containers sit above image tiles when no zOrderIndex is given).
|
|
||||||
*
|
*
|
||||||
* The whole page is replaced on rebuild, which is also what gives an omitted
|
* The whole page is replaced on rebuild, which is also what gives an omitted
|
||||||
* menuObject its documented meaning: the previous contextual menu goes away.
|
* 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)) {
|
if (Array.isArray(lists)) {
|
||||||
for (const item of lists) containers.push(parseListContainer(asRecord(item), layoutFont));
|
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");
|
const texts = pickLoose(data, "textObject");
|
||||||
if (Array.isArray(texts)) {
|
if (Array.isArray(texts)) {
|
||||||
for (const item of texts) containers.push(parseTextContainer(asRecord(item), layoutFont));
|
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) };
|
return { containers, menuItems: parseMenuItems(data) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The container that owns gesture events (exactly one per valid page). */
|
/**
|
||||||
export function eventCaptureContainer(page: EvenHubPage): EvenHubContainer | undefined {
|
* Clamp a stock page's containers the way the firmware does when it creates
|
||||||
return page.containers.find(
|
* them: positions and sizes to the 576x288 screen (images keep their size,
|
||||||
(container) => container.kind !== "image" && container.isEventCapture,
|
* 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.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* makes the content area exactly the 576x288 surface EvenHub apps expect.
|
* makes the content area exactly the 576x288 surface EvenHub apps expect.
|
||||||
*/
|
*/
|
||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
import { EVENHUB_SCREEN_WIDTH } from "./compositor";
|
import { EVENHUB_SCREEN_WIDTH, EVENHUB_SCREEN_HEIGHT } from "./compositor";
|
||||||
import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures";
|
import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures";
|
||||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||||
import {
|
import {
|
||||||
@@ -16,6 +16,8 @@ import { shell } from "../../ui/shell/shell";
|
|||||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||||
import { EvenHubSession } from "./session";
|
import { EvenHubSession } from "./session";
|
||||||
import { renderInstalledEvenHubIcon } from "./installed-apps";
|
import { renderInstalledEvenHubIcon } from "./installed-apps";
|
||||||
|
import { markDisplayWarningShown, needsDisplayWarning } from "./glasses-compat";
|
||||||
|
import { EvenHubDisplayWarningLayer } from "./display-warning-dialog";
|
||||||
|
|
||||||
class EvenHubAppLayer implements Layer {
|
class EvenHubAppLayer implements Layer {
|
||||||
/**
|
/**
|
||||||
@@ -24,22 +26,27 @@ class EvenHubAppLayer implements Layer {
|
|||||||
* extension's source field should see that they came from the watch.
|
* extension's source field should see that they came from the watch.
|
||||||
*/
|
*/
|
||||||
readonly acceptsDirectional = true;
|
readonly acceptsDirectional = true;
|
||||||
|
private tallCanvas = false;
|
||||||
|
|
||||||
constructor(private readonly session: EvenHubSession) {}
|
constructor(private readonly session: EvenHubSession) {}
|
||||||
|
|
||||||
|
setTallCanvas(tall: boolean): void {
|
||||||
|
this.tallCanvas = tall;
|
||||||
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
const size = ctx.stack.getBaseSize();
|
const size = ctx.stack.getBaseSize();
|
||||||
// EvenHub apps lay out for the stock 576-wide surface. In the Full
|
// Host full screen hides chrome; it does not enlarge the stock app canvas.
|
||||||
// Screen display mode the window is 640 wide; paint at stock width and
|
// Only the app's explicit Faceclaw extended-layout request opts into height.
|
||||||
// centre it rather than leaving all the slack on the right.
|
const canvas = { width: EVENHUB_SCREEN_WIDTH, height: this.tallCanvas ? size.height : EVENHUB_SCREEN_HEIGHT };
|
||||||
if (size.width > EVENHUB_SCREEN_WIDTH) {
|
const content = this.session.paint(canvas, ctx.stack.isFocused());
|
||||||
const content = this.session.paint({ width: EVENHUB_SCREEN_WIDTH, height: size.height }, ctx.stack.isFocused());
|
if (size.width === canvas.width && size.height === canvas.height) return content;
|
||||||
const image = new GrayImage(size.width, size.height, 0);
|
const image = new GrayImage(size.width, size.height, 0);
|
||||||
content.composeInto(image, Math.floor((size.width - EVENHUB_SCREEN_WIDTH) / 2), 0);
|
// Clip text to its logical canvas before placing it in the larger host window.
|
||||||
|
image.bitBlt(content.withDrawsBaked(), Math.max(0, Math.floor((size.width - canvas.width) / 2)),
|
||||||
|
Math.max(0, Math.floor((size.height - canvas.height) / 2)));
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
return this.session.paint(size, ctx.stack.isFocused());
|
|
||||||
}
|
|
||||||
|
|
||||||
handleInput(event: InputEvent): void {
|
handleInput(event: InputEvent): void {
|
||||||
// Everything goes to the app; the menu gestures never reach here (the
|
// Everything goes to the app; the menu gestures never reach here (the
|
||||||
@@ -60,6 +67,7 @@ export function createEvenHubWindow(
|
|||||||
requestShellRender: () => void,
|
requestShellRender: () => void,
|
||||||
): InProcessWindow {
|
): InProcessWindow {
|
||||||
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
|
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
|
||||||
|
const appLayer = new EvenHubAppLayer(session);
|
||||||
const created = createInProcessWindow({
|
const created = createInProcessWindow({
|
||||||
appId,
|
appId,
|
||||||
windowId,
|
windowId,
|
||||||
@@ -91,7 +99,7 @@ export function createEvenHubWindow(
|
|||||||
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } },
|
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } },
|
||||||
],
|
],
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
baseLayer: new EvenHubAppLayer(session),
|
baseLayer: appLayer,
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
setSurfaceVisible: options.setSurfaceVisible,
|
setSurfaceVisible: options.setSurfaceVisible,
|
||||||
removeSurface: options.removeSurface,
|
removeSurface: options.removeSurface,
|
||||||
@@ -109,7 +117,10 @@ export function createEvenHubWindow(
|
|||||||
pushOverlay: (layer) => created.stack.push(layer),
|
pushOverlay: (layer) => created.stack.push(layer),
|
||||||
// The extended layout uses the full 576x452 app area ("max"); stock apps
|
// The extended layout uses the full 576x452 app area ("max"); stock apps
|
||||||
// stay in the 576x288 band ("medium").
|
// stay in the 576x288 band ("medium").
|
||||||
setTallCanvas: (tall) => created.setHeightMode(tall ? "max" : "medium"),
|
setTallCanvas: (tall) => {
|
||||||
|
appLayer.setTallCanvas(tall);
|
||||||
|
created.setHeightMode(tall ? "max" : "medium");
|
||||||
|
},
|
||||||
setAttention: (attention) => shell.setWindowAttention(windowId, attention),
|
setAttention: (attention) => shell.setWindowAttention(windowId, attention),
|
||||||
// Only while the app listens for text: otherwise the shell's Type Into App
|
// Only while the app listens for text: otherwise the shell's Type Into App
|
||||||
// destinations (voice dialog, phone keyboard, watch) would send into a void.
|
// destinations (voice dialog, phone keyboard, watch) would send into a void.
|
||||||
@@ -149,5 +160,16 @@ export function createEvenHubWindow(
|
|||||||
session.setScreenOn(on);
|
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;
|
return created;
|
||||||
}
|
}
|
||||||
@@ -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 [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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: "" };
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@
|
|||||||
* a phone WebView (its runtime + phone UI) and a 576x288 glasses window
|
* a phone WebView (its runtime + phone UI) and a 576x288 glasses window
|
||||||
* composited by Faceclaw instead of the stock firmware.
|
* 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.
|
* Design notes: notes/evenhub_compatibility.txt.
|
||||||
*/
|
*/
|
||||||
import { type AppContext, type AppDefinition } from "../app-definition";
|
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 { renderEvenRealitiesLogo } from "../../graphics/even-realities-logo";
|
||||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||||
import { type InstalledEvenHubApp } from "./installed-apps";
|
import { type InstalledEvenHubApp } from "./installed-apps";
|
||||||
|
import { isEvenHubStoreAvailable } from "./glasses-compat";
|
||||||
|
|
||||||
const EVENHUB_STORE_WINDOW_ID = "evenhub:store";
|
const EVENHUB_STORE_WINDOW_ID = "evenhub:store";
|
||||||
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
|
const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store";
|
||||||
@@ -104,8 +108,17 @@ const evenhubApp: AppDefinition = {
|
|||||||
title: "EvenHub",
|
title: "EvenHub",
|
||||||
icon: "package",
|
icon: "package",
|
||||||
renderIcon: renderEvenRealitiesLogo,
|
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) => {
|
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();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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)}`;
|
||||||
|
}
|
||||||
@@ -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, "");
|
||||||
|
}
|
||||||
@@ -1,17 +1,11 @@
|
|||||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
|
||||||
import { GrayImage } from "../../graphics/image";
|
|
||||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||||
import { type InputEvent } from "../../ui/gestures";
|
import { type LayerContext } from "../../ui/layers";
|
||||||
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
|
||||||
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
|
|
||||||
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
||||||
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
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 DIALOG_WIDTH = 320;
|
||||||
const PADDING = 10;
|
|
||||||
const PERM_GAP = 4;
|
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
|
* 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.
|
* 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
|
* A long list scrolls a page at a time, and Allow stays inert until the
|
||||||
* through the content row by row, and only once the bottom is fully visible do
|
* bottom has been reached (see ScrollingDialogLayer), so the user can't
|
||||||
* further scrolls move the action selection. The actions are inert until then
|
* Allow without having had the whole list on screen.
|
||||||
* (a click just scrolls), so the user can't Allow without having had the whole
|
|
||||||
* list on screen.
|
|
||||||
*/
|
*/
|
||||||
export class EvenHubPermissionDialogLayer implements Layer {
|
export class EvenHubPermissionDialogLayer extends ScrollingDialogLayer {
|
||||||
/** 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;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly appName: string,
|
private readonly appName: string,
|
||||||
private readonly permissions: EvenHubPermission[],
|
private readonly permissions: EvenHubPermission[],
|
||||||
private readonly privacyPolicyUrl: string,
|
private readonly privacyPolicyUrl: string,
|
||||||
private readonly onConfirm: () => void,
|
private readonly onConfirm: () => void,
|
||||||
private readonly onCancel: () => void,
|
private readonly onCancel: () => void,
|
||||||
) {}
|
) {
|
||||||
|
super(DIALOG_WIDTH);
|
||||||
/** 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 {
|
protected bodyRows({ image, font, left, textWidth }: DialogBody): DialogRow[] {
|
||||||
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;
|
|
||||||
|
|
||||||
const headerStep = lineStep(font) + 2;
|
const headerStep = lineStep(font) + 2;
|
||||||
const permLabelStep = lineStep(font) + 1;
|
const permLabelStep = lineStep(font) + 1;
|
||||||
const permDetailStep = lineStep(font) - 1;
|
const permDetailStep = lineStep(font) - 1;
|
||||||
const actionRowH = listRowHeight(font);
|
const rows: DialogRow[] = [];
|
||||||
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 heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
||||||
rows.push({
|
rows.push({
|
||||||
height: headerStep + 6,
|
height: headerStep + 6,
|
||||||
@@ -98,113 +62,28 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let index = 0; index < actions.length; index++) {
|
return rows;
|
||||||
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);
|
protected actions(): string[] {
|
||||||
const height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_MARGIN);
|
return this.privacyPolicyUrl ? ["Allow", "Privacy policy", "Cancel"] : ["Allow", "Cancel"];
|
||||||
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) {
|
protected activate(action: string, ctx: LayerContext): void {
|
||||||
drawListScrollbar(
|
if (action === "Privacy policy") {
|
||||||
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.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);
|
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
|
||||||
|
} else if (action === "Allow") {
|
||||||
|
this.close(ctx, () => this.onConfirm());
|
||||||
} else {
|
} else {
|
||||||
this.resolve(ctx, actions[this.selectedIndex] === "Allow");
|
this.close(ctx, () => this.onCancel());
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "double-click":
|
|
||||||
this.resolve(ctx, false);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemoved(): void {
|
protected backedOut(): void {
|
||||||
// Dismissed some other way (window closed, back button): treat as cancel.
|
this.onCancel();
|
||||||
if (!this.resolved) {
|
}
|
||||||
this.resolved = true;
|
|
||||||
|
protected abandoned(): void {
|
||||||
this.onCancel();
|
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[] {
|
|
||||||
return this.privacyPolicyUrl ? ["Allow", "Privacy policy", "Cancel"] : ["Allow", "Cancel"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
+190
-218
@@ -38,7 +38,11 @@ import {
|
|||||||
import { EvenHubApiKeyDialogLayer } from "./api-key-dialog";
|
import { EvenHubApiKeyDialogLayer } from "./api-key-dialog";
|
||||||
import {
|
import {
|
||||||
asRecord,
|
asRecord,
|
||||||
|
clampToStockLimits,
|
||||||
|
containerById,
|
||||||
declaredMenuItems,
|
declaredMenuItems,
|
||||||
|
PAGE_CREATE_INVALID,
|
||||||
|
stockPageFailure,
|
||||||
eventCaptureContainer,
|
eventCaptureContainer,
|
||||||
parsePage,
|
parsePage,
|
||||||
readNumber,
|
readNumber,
|
||||||
@@ -50,8 +54,13 @@ import {
|
|||||||
type EvenHubContainer,
|
type EvenHubContainer,
|
||||||
type EvenHubMenuItem,
|
type EvenHubMenuItem,
|
||||||
type EvenHubPage,
|
type EvenHubPage,
|
||||||
|
type EvenHubTextContainer,
|
||||||
} from "./containers";
|
} 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 { stepListSelection } from "./list-menu";
|
||||||
import { type EvenHubManifest } from "./ehpk";
|
import { type EvenHubManifest } from "./ehpk";
|
||||||
import { permissionsIncludeMicrophone, permissionsInclude } from "./permissions";
|
import { permissionsIncludeMicrophone, permissionsInclude } from "./permissions";
|
||||||
@@ -74,7 +83,15 @@ import { parseWindowIcon, WindowIconRenderer } from "./window-icon";
|
|||||||
import { availableFontFamilies, containerFace, measureContainerText } from "./fonts";
|
import { availableFontFamilies, containerFace, measureContainerText } from "./fonts";
|
||||||
import { parseFontSpec } from "./font-spec";
|
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). */
|
/** OsEventTypeList values (PB ordinals). */
|
||||||
const CLICK_EVENT = 0;
|
const CLICK_EVENT = 0;
|
||||||
@@ -83,12 +100,20 @@ const SCROLL_BOTTOM_EVENT = 2;
|
|||||||
const DOUBLE_CLICK_EVENT = 3;
|
const DOUBLE_CLICK_EVENT = 3;
|
||||||
const FOREGROUND_ENTER_EVENT = 4;
|
const FOREGROUND_ENTER_EVENT = 4;
|
||||||
const FOREGROUND_EXIT_EVENT = 5;
|
const FOREGROUND_EXIT_EVENT = 5;
|
||||||
|
const ABNORMAL_EXIT_EVENT = 6;
|
||||||
const SYSTEM_EXIT_EVENT = 7;
|
const SYSTEM_EXIT_EVENT = 7;
|
||||||
const IMU_DATA_REPORT_EVENT = 8;
|
const IMU_DATA_REPORT_EVENT = 8;
|
||||||
/** SDK 0.0.14: the press gesture, delivered like any other list/text/sys event. */
|
/** SDK 0.0.14: the press gesture, delivered like any other list/text/sys event. */
|
||||||
const LONG_PRESS_EVENT = 9;
|
const LONG_PRESS_EVENT = 9;
|
||||||
const LONG_PRESS_RELEASE_EVENT = 10;
|
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
|
* Injected into every served HTML document at document start (before any app
|
||||||
* JS): (1) the promise-returning flutter_inappwebview.callHandler the EvenHub
|
* 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 page: EvenHubPage | null = null;
|
||||||
private pageCreated = false;
|
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 webViewHandle: EvenHubWebViewHandle | null = null;
|
||||||
private windowHooks: EvenHubWindowHooks | null = null;
|
private windowHooks: EvenHubWindowHooks | null = null;
|
||||||
private closed = false;
|
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;
|
const eventType = event.type === "scroll-up" ? SCROLL_TOP_EVENT : SCROLL_BOTTOM_EVENT;
|
||||||
if (capture?.kind === "list") {
|
if (capture?.kind === "list") {
|
||||||
this.scrollList(capture, eventType, inputSource);
|
this.scrollList(capture, eventType, inputSource);
|
||||||
|
} else if (capture?.kind === "text") {
|
||||||
|
this.scrollText(capture, eventType, inputSource);
|
||||||
} else {
|
} else {
|
||||||
this.emitSysEvent(eventType, 0, inputSource);
|
this.emitSysEvent(eventType, 0, inputSource);
|
||||||
}
|
}
|
||||||
@@ -620,6 +649,25 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
|
|||||||
this.pushMessage("evenHubEvent", { type: "menuItemClickEvent", jsonData: { itemID } });
|
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 {
|
private scrollList(list: EvenHubListContainer, eventType: number, inputSource?: ExtensionInputSource): void {
|
||||||
// Swipe up selects the previous item, swipe down the next (stock direction).
|
// Swipe up selects the previous item, swipe down the next (stock direction).
|
||||||
const delta = eventType === SCROLL_TOP_EVENT ? -1 : 1;
|
const delta = eventType === SCROLL_TOP_EVENT ? -1 : 1;
|
||||||
@@ -808,7 +856,8 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
|
|||||||
deliverImu(reading: ImuReading): void {
|
deliverImu(reading: ImuReading): void {
|
||||||
this.pushEvenHubEvent("sysEvent", {
|
this.pushEvenHubEvent("sysEvent", {
|
||||||
eventType: IMU_DATA_REPORT_EVENT,
|
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 first = args[0];
|
||||||
const message = asRecord(typeof first === "string" ? JSON.parse(first) : first);
|
const message = asRecord(typeof first === "string" ? JSON.parse(first) : first);
|
||||||
const method = readString(message, "method", "");
|
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);
|
result = await this.dispatch(method, data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.log(`evenhub bridge call failed: ${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> {
|
private async createStartUpPage(data: Record<string, unknown>): Promise<number> {
|
||||||
if (this.pageCreated) {
|
if (this.pageCreated) {
|
||||||
// One-shot per session on stock: a second call blocks ~2s, then fails.
|
// 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);
|
await delay(DUPLICATE_CREATE_DELAY_MS);
|
||||||
return 1;
|
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);
|
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.page = page;
|
||||||
this.pageCreated = true;
|
this.pageCreated = true;
|
||||||
|
this.extendedLayout = false;
|
||||||
// The launch focus arrived before the page existed; deliver the ENTER now.
|
// The launch focus arrived before the page existed; deliver the ENTER now.
|
||||||
if (this.foreground && !this.launchEnterSent) {
|
if (this.foreground && !this.launchEnterSent) {
|
||||||
this.launchEnterSent = true;
|
this.launchEnterSent = true;
|
||||||
@@ -933,16 +999,39 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
|
|||||||
}
|
}
|
||||||
|
|
||||||
private rebuildPage(data: Record<string, unknown>): boolean {
|
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);
|
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.page = page;
|
||||||
this.pageCreated = true;
|
this.extendedLayout = false;
|
||||||
this.windowHooks?.requestRender();
|
this.windowHooks?.requestRender();
|
||||||
return true;
|
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;
|
const declaredMenuCount = declaredMenuItems(data).length;
|
||||||
if (declaredMenuCount > page.menuItems.length) {
|
if (declaredMenuCount > page.menuItems.length) {
|
||||||
this.log(
|
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)",
|
"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 {
|
private textUpgrade(data: Record<string, unknown>): boolean {
|
||||||
const id = readNumber(data, "containerID", -1);
|
const id = readNumber(data, "containerID", 0);
|
||||||
// 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 name = readString(data, "containerName", "");
|
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 content = readString(data, "content", "");
|
||||||
const offset = readOptionalNumber(data, "contentOffset");
|
const offset = readOptionalNumber(data, "contentOffset");
|
||||||
// (contentLength is intentionally ignored — see below.)
|
const payloadError = stockPayloadError("textUpgrade", data);
|
||||||
// Stock semantics are "write `content` at contentOffset and truncate the
|
if (payloadError) {
|
||||||
// rest" (a null-terminating strcpy(buf+offset, content)), NOT a splice that
|
this.layoutLog(() => [`textContainerUpgrade refused, as the Even app would: ${payloadError}`]);
|
||||||
// keeps the old tail after offset+contentLength. Keeping the tail left stray
|
return false;
|
||||||
// trailing text when an app (e.g. g2oom) shrank a string with an
|
}
|
||||||
// under-sized contentLength; dropping it matches stock and still supports
|
// The firmware finds the container by id alone (its first container with
|
||||||
// suffix rewrites (offset>0) and full replaces (offset 0 / omitted).
|
// that id, of any kind); the name isn't checked anywhere.
|
||||||
if (offset !== undefined && offset > 0) {
|
const target = containerById(this.page, id);
|
||||||
container.content = container.content.slice(0, offset) + content;
|
if (!target) {
|
||||||
} else {
|
this.layoutLog(() => [describeTextUpgrade(id, name, null, offset, content.length)]);
|
||||||
container.content = content;
|
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
|
// SDK 0.0.14: textColor on an incremental update sets the container's
|
||||||
// brightness; omitting it keeps whatever level the container has.
|
// brightness; omitting it keeps whatever level the container has.
|
||||||
const brightness = readTextBrightness(data);
|
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();
|
this.windowHooks?.requestRender();
|
||||||
return true;
|
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 {
|
private updateImage(data: Record<string, unknown>): number {
|
||||||
const id = readNumber(data, "containerID", -1);
|
const id = readNumber(data, "containerID", 0);
|
||||||
const container = this.page?.containers.find((c) => c.kind === "image" && c.id === id);
|
const name = readString(data, "containerName", "");
|
||||||
if (!container || container.kind !== "image") return 3;
|
const raw = data.imageData;
|
||||||
const bytes = imagePayloadBytes(data.imageData ?? data.rawData ?? asRecord(data).mapRawData);
|
// Before the page exists (and after shutdown) the Even app fails it outright.
|
||||||
if (!bytes || bytes.length === 0) return 1;
|
if (!this.pageCreated || !this.page) {
|
||||||
const decoded = decodeImageBytes(bytes, container);
|
this.layoutLog(() => [`updateImageRawData id=${id}: no page yet, sendFailed`]);
|
||||||
if (!decoded) return 1;
|
return IMAGE_SEND_FAILED;
|
||||||
container.pixels = decoded.pixels;
|
}
|
||||||
container.pixelsWidth = decoded.width;
|
// The Even app sizes the bitmap from the image container it finds by id,
|
||||||
container.pixelsHeight = decoded.height;
|
// 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.windowHooks?.requestRender();
|
||||||
return 0;
|
}
|
||||||
|
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 {
|
private shutDown(exitMode: number): boolean {
|
||||||
|
this.layoutLog(() => [`shutDownPageContainer exitMode=${exitMode}`]);
|
||||||
if (exitMode === 1) {
|
if (exitMode === 1) {
|
||||||
// The app asked to quit (stock would pop an on-glasses confirm). We
|
// 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
|
// 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 });
|
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 {
|
private emitListEvent(list: EvenHubListContainer, eventType: number, inputSource?: ExtensionInputSource): void {
|
||||||
this.pushEvenHubEvent("listEvent", {
|
this.pushEvenHubEvent("listEvent", {
|
||||||
containerID: list.id,
|
containerID: list.id,
|
||||||
@@ -1252,8 +1392,10 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
|
|||||||
for (const container of page.containers) {
|
for (const container of page.containers) {
|
||||||
if (container.preserve) preserveContent(container, previous);
|
if (container.preserve) preserveContent(container, previous);
|
||||||
}
|
}
|
||||||
|
this.layoutLog(() => describePage("extension layout", page, data));
|
||||||
this.page = page;
|
this.page = page;
|
||||||
this.pageCreated = true;
|
this.pageCreated = true;
|
||||||
|
this.extendedLayout = true;
|
||||||
// The extended layout uses the taller app area.
|
// The extended layout uses the taller app area.
|
||||||
this.windowHooks?.setTallCanvas(true);
|
this.windowHooks?.setTallCanvas(true);
|
||||||
if (this.foreground && !this.launchEnterSent) {
|
if (this.foreground && !this.launchEnterSent) {
|
||||||
@@ -1559,82 +1701,6 @@ function normalizeBuzzerSteps(raw: unknown[]): Step[] {
|
|||||||
return out;
|
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
|
* Input-device names in the extension API: the touchDown event's source, and
|
||||||
* the `faceclawInputSource` field added to stock gesture events.
|
* the `faceclawInputSource` field added to stock gesture events.
|
||||||
@@ -1686,97 +1752,3 @@ function elideZeroFields(obj: Record<string, unknown>): Record<string, unknown>
|
|||||||
return out;
|
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
@@ -1,7 +1,7 @@
|
|||||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
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 { type Layer, type LayerActions, type LayerContext, type LayerStack } from "../../ui/layers";
|
||||||
import { drawSelectionHighlight, type MenuItem } from "../../ui/menu";
|
import { drawSelectionHighlight, type MenuItem } from "../../ui/menu";
|
||||||
import { Menu } from "../../ui/menu-core";
|
import { Menu } from "../../ui/menu-core";
|
||||||
@@ -14,6 +14,7 @@ import { EvenHubStoreDetailLayer, type EvenHubStoreDetailOptions } from "./store
|
|||||||
import { cleanError, installStoreApp } from "./store-install";
|
import { cleanError, installStoreApp } from "./store-install";
|
||||||
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
|
import { checkForEvenHubUpdates, describeUpdate, type EvenHubAppUpdate } from "./updates";
|
||||||
import { lineStep } from "../../ui/metrics";
|
import { lineStep } from "../../ui/metrics";
|
||||||
|
import { isEvenHubStoreAvailable } from "./glasses-compat";
|
||||||
|
|
||||||
const LIST_X = 18;
|
const LIST_X = 18;
|
||||||
/** Horizontal gap between tab labels. */
|
/** 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. */
|
/** The Search tab's first row: shows the query and opens the phone editor. */
|
||||||
| { kind: "search-query" }
|
| { kind: "search-query" }
|
||||||
/** A registry entry whose package is gone and which the store no longer lists. */
|
/** 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 = {
|
type TabState = {
|
||||||
rows: StoreRow[];
|
rows: StoreRow[];
|
||||||
@@ -118,10 +144,18 @@ export type EvenHubStoreLayerOptions = {
|
|||||||
* The EvenHub storefront: Top (leaderboard), New (by first publication),
|
* The EvenHub storefront: Top (leaderboard), New (by first publication),
|
||||||
* Search, and Updates (installed apps that are stale or whose package is
|
* 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
|
* 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
|
* in the list focuses the tabs, scrolling (or a watch swipe in any direction)
|
||||||
* returns to the list.
|
* 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 {
|
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> = {
|
private readonly tabs: Record<StoreTab, TabState> = {
|
||||||
top: emptyTab(),
|
top: emptyTab(),
|
||||||
new: emptyTab(),
|
new: emptyTab(),
|
||||||
@@ -140,12 +174,15 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
private updatingAll = false;
|
private updatingAll = false;
|
||||||
/** An app page requested while the login form was up; opened once signed in. */
|
/** An app page requested while the login form was up; opened once signed in. */
|
||||||
private pendingPackage: InstalledEvenHubApp | null = null;
|
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) {
|
constructor(private readonly options: EvenHubStoreLayerOptions) {
|
||||||
if (this.showingLogin) resetEvenHubLoginForm();
|
if (this.showingLogin) resetEvenHubLoginForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
if (!isEvenHubStoreAvailable()) return this.paintUnavailable(ctx);
|
||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
this.started = true;
|
this.started = true;
|
||||||
// Do NOT open the phone credential editor here. This runs on the first
|
// Do NOT open the phone credential editor here. This runs on the first
|
||||||
@@ -205,6 +242,23 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
return image;
|
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. */
|
/** Tab labels to the right of the title; the active one is bright and underlined. */
|
||||||
private paintTabs(image: GrayImage, font: UiFont, ctx: LayerContext): void {
|
private paintTabs(image: GrayImage, font: UiFont, ctx: LayerContext): void {
|
||||||
const tabsFocused = ctx.stack.isFocused() && this.focus === "tabs";
|
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;
|
const label = TABS.find((entry) => entry.id === tab)!.label;
|
||||||
if (tab !== "updates") return label;
|
if (tab !== "updates") return label;
|
||||||
const updates = this.tabs.updates;
|
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;
|
return updates.loaded && count > 0 ? `${label} (${count})` : label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,9 +299,11 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
if (!state.query) return "Search public apps";
|
if (!state.query) return "Search public apps";
|
||||||
return results === 1 ? `1 result for "${state.query}"` : `${results} results for "${state.query}"`;
|
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";
|
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 (this.showingLogin) {
|
||||||
if (event.type === "click" && !this.loginBusy) {
|
if (event.type === "click" && !this.loginBusy) {
|
||||||
this.openCredentialEditor(ctx);
|
this.openCredentialEditor(ctx);
|
||||||
@@ -301,9 +364,11 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
const index = TABS.findIndex((tab) => tab.id === this.activeTab);
|
const index = TABS.findIndex((tab) => tab.id === this.activeTab);
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case "scroll-up":
|
case "scroll-up":
|
||||||
|
case "swipe-left":
|
||||||
this.switchTab(ctx, TABS[Math.max(0, index - 1)]!.id);
|
this.switchTab(ctx, TABS[Math.max(0, index - 1)]!.id);
|
||||||
return;
|
return;
|
||||||
case "scroll-down":
|
case "scroll-down":
|
||||||
|
case "swipe-right":
|
||||||
this.switchTab(ctx, TABS[Math.min(TABS.length - 1, index + 1)]!.id);
|
this.switchTab(ctx, TABS[Math.min(TABS.length - 1, index + 1)]!.id);
|
||||||
return;
|
return;
|
||||||
case "click":
|
case "click":
|
||||||
@@ -333,6 +398,9 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
case "search-query":
|
case "search-query":
|
||||||
this.openSearchEditor(ctx);
|
this.openSearchEditor(ctx);
|
||||||
return;
|
return;
|
||||||
|
case "update-all":
|
||||||
|
void this.updateAll(ctx);
|
||||||
|
return;
|
||||||
case "orphan": {
|
case "orphan": {
|
||||||
// Nothing can be reinstalled; the only useful action is to drop the
|
// Nothing can be reinstalled; the only useful action is to drop the
|
||||||
// dead registry entry so the launcher stops offering it.
|
// 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.
|
* placeholder built from the registry entry stands in.
|
||||||
*/
|
*/
|
||||||
showInstalledPackage(stack: LayerStack, installed: InstalledEvenHubApp): void {
|
showInstalledPackage(stack: LayerStack, installed: InstalledEvenHubApp): void {
|
||||||
|
if (!isEvenHubStoreAvailable()) {
|
||||||
|
this.unavailablePackageName = installed.name;
|
||||||
|
stack.clearToBase();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.unavailablePackageName = null;
|
||||||
if (this.showingLogin) {
|
if (this.showingLogin) {
|
||||||
this.pendingPackage = installed;
|
this.pendingPackage = installed;
|
||||||
return;
|
return;
|
||||||
@@ -369,7 +443,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
|
|
||||||
/** Dictated text becomes a search (the shell's "Type Into App" / voice input). */
|
/** Dictated text becomes a search (the shell's "Type Into App" / voice input). */
|
||||||
receiveTextInput(text: string, ctx: LayerContext): void {
|
receiveTextInput(text: string, ctx: LayerContext): void {
|
||||||
if (this.showingLogin) return;
|
if (this.showingLogin || !isEvenHubStoreAvailable()) return;
|
||||||
const query = evenHubSearchQuerySetting.set(text);
|
const query = evenHubSearchQuerySetting.set(text);
|
||||||
if (!query) return;
|
if (!query) return;
|
||||||
this.closePhoneEditor(ctx.actions, "search");
|
this.closePhoneEditor(ctx.actions, "search");
|
||||||
@@ -379,7 +453,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildMenuItems(): MenuItem[] {
|
buildMenuItems(): MenuItem[] {
|
||||||
if (this.showingLogin) return [];
|
if (this.showingLogin || !isEvenHubStoreAvailable()) return [];
|
||||||
const items: MenuItem[] = [];
|
const items: MenuItem[] = [];
|
||||||
if (this.activeTab === "search") {
|
if (this.activeTab === "search") {
|
||||||
items.push({
|
items.push({
|
||||||
@@ -532,8 +606,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
const rows: StoreRow[] = updates.map((update) =>
|
const rows: StoreRow[] = updates.map((update) =>
|
||||||
update.latest ? { kind: "app", app: update.latest, update } : { kind: "orphan", update },
|
update.latest ? { kind: "app", app: update.latest, update } : { kind: "orphan", update },
|
||||||
);
|
);
|
||||||
state.rows = rows;
|
this.setUpdateRows(state, rows, 0);
|
||||||
state.menu.setItems(rows, 0);
|
|
||||||
state.menu.scrollTop = 0;
|
state.menu.scrollTop = 0;
|
||||||
state.status = "";
|
state.status = "";
|
||||||
state.exhausted = true;
|
state.exhausted = true;
|
||||||
@@ -548,10 +621,20 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private updatableRows(): Extract<StoreRow, { kind: "app" }>[] {
|
private updatableRows(): AppRow[] {
|
||||||
return this.tabs.updates.rows.filter(
|
return this.tabs.updates.rows.filter(isUpdatableRow);
|
||||||
(row): row is Extract<StoreRow, { kind: "app" }> => row.kind === "app" && row.update !== undefined,
|
}
|
||||||
);
|
|
||||||
|
/**
|
||||||
|
* 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. */
|
/** 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;
|
if (this.updatingAll) return;
|
||||||
this.updatingAll = true;
|
this.updatingAll = true;
|
||||||
const state = this.tabs.updates;
|
const state = this.tabs.updates;
|
||||||
|
this.setUpdateRows(state, state.rows);
|
||||||
const pending = this.updatableRows();
|
const pending = this.updatableRows();
|
||||||
let installed = 0;
|
let installed = 0;
|
||||||
const failures: string[] = [];
|
const failures: string[] = [];
|
||||||
@@ -593,6 +677,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
: installed === 1 ? "Updated 1 app." : `Updated ${installed} apps.`;
|
: installed === 1 ? "Updated 1 app." : `Updated ${installed} apps.`;
|
||||||
} finally {
|
} finally {
|
||||||
this.updatingAll = false;
|
this.updatingAll = false;
|
||||||
|
this.setUpdateRows(this.tabs.updates, this.tabs.updates.rows);
|
||||||
if (!this.closed) ctx.actions.requestRender();
|
if (!this.closed) ctx.actions.requestRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -609,10 +694,7 @@ export class EvenHubStoreLayer implements Layer {
|
|||||||
|
|
||||||
private removeUpdateRow(packageId: string): void {
|
private removeUpdateRow(packageId: string): void {
|
||||||
const state = this.tabs.updates;
|
const state = this.tabs.updates;
|
||||||
state.rows = state.rows.filter((row) =>
|
this.setUpdateRows(state, state.rows.filter((row) => rowPackageId(row) !== packageId));
|
||||||
row.kind === "search-query" ? true : row.kind === "app" ? row.app.packageId !== packageId : row.update.installed.packageId !== packageId,
|
|
||||||
);
|
|
||||||
state.menu.setItems(state.rows);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- login and phone editors --------------------------------------------
|
// ---- login and phone editors --------------------------------------------
|
||||||
@@ -751,6 +833,14 @@ function rowText(row: StoreRow): { title: string; detail: string; titleValue: nu
|
|||||||
titleValue: 200,
|
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":
|
case "orphan":
|
||||||
return {
|
return {
|
||||||
title: row.update.installed.name,
|
title: row.update.installed.name,
|
||||||
|
|||||||
@@ -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 { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout";
|
||||||
import { type GlanceWidgetId } from "./widget";
|
import { type GlanceWidgetId } from "./widget";
|
||||||
import { glanceWidgetSpans } from "./widgets";
|
import { glanceWidgetSpans } from "./widgets";
|
||||||
@@ -23,6 +23,11 @@ export function glanceSlotChoiceLabel(choice: GlanceSlotChoice): string {
|
|||||||
return SLOT_CHOICE_LABELS[choice] ?? choice;
|
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
|
* Slot order follows QUADRANT_LAYOUT: top left, top right, bottom left, bottom
|
||||||
* right. Calendar in both right slots merges into one double-height region.
|
* 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.",
|
"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
|
* 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",
|
label: "Show on tap",
|
||||||
storageKey: "glanceboard.tapDuration",
|
storageKey: "glanceboard.tapDuration",
|
||||||
defaultValue: DEFAULT_TAP_DURATION,
|
defaultValue: DEFAULT_TAP_DURATION,
|
||||||
values: ["off", "3s", "5s", "7s", "10s"],
|
values: TAP_DURATION_VALUES,
|
||||||
formatValue: (value) => (value === "off" ? "Disabled" : value.replace("s", " s")),
|
formatValue: formatTapDuration,
|
||||||
description:
|
description:
|
||||||
"How long a single tap (or a head-tilt) keeps the Glanceboard on screen. Disabled: a single tap does not show the Glanceboard.",
|
"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 {
|
export function glanceTapTimeoutMs(): number {
|
||||||
const duration = glanceTapDurationSetting.get();
|
const duration = glanceTapDurationSetting.get();
|
||||||
const seconds = duration === "off" ? DEFAULT_TAP_DURATION : duration;
|
return TAP_DURATION_SECONDS[duration === "off" ? DEFAULT_TAP_DURATION : duration] * 1000;
|
||||||
return Number.parseInt(seconds, 10) * 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A long-press holds the board up until the press is released. */
|
/** 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>[] {
|
export function glanceSlotSettings(layout: GlanceLayout = glanceLayout()): ConfigSettingEnum<GlanceSlotChoice>[] {
|
||||||
const grid = layout === QUADRANT_LAYOUT || layout === SIX_SLOT_LAYOUT;
|
const grid = layout === QUADRANT_LAYOUT || layout === SIX_SLOT_LAYOUT;
|
||||||
const storageId = grid ? QUADRANT_LAYOUT.id : layout.id;
|
const storageId = grid ? QUADRANT_LAYOUT.id : layout.id;
|
||||||
return layout.slots.map(
|
return layout.slots.map((slot, index) => {
|
||||||
(slot, index) =>
|
const defaultValue: GlanceSlotChoice = (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none";
|
||||||
new ConfigSettingEnum<GlanceSlotChoice>({
|
return new ConfigSettingEnum<GlanceSlotChoice>({
|
||||||
id: `glanceboard-${layout.id}-slot-${index}`,
|
id: `glanceboard-${layout.id}-slot-${index}`,
|
||||||
label: slot.label,
|
label: slot.label,
|
||||||
storageKey: `glanceboard.${storageId}.slot.${index}`,
|
storageKey: `glanceboard.${storageId}.slot.${index}`,
|
||||||
defaultValue: (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none",
|
defaultValue,
|
||||||
values: SLOT_CHOICES,
|
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,
|
formatValue: glanceSlotChoiceLabel,
|
||||||
description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`,
|
description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`,
|
||||||
}),
|
});
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget";
|
import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget";
|
||||||
import { CalendarWidget } from "./calendar-widget";
|
import { CalendarWidget } from "./calendar-widget";
|
||||||
|
import { calendarSelectionMenuItems } from "../../calendar/calendar-filter";
|
||||||
import { CompassWidget } from "./compass-widget";
|
import { CompassWidget } from "./compass-widget";
|
||||||
import { MusicWidget, musicSettingsMenuItems } from "./music-widget";
|
import { MusicWidget, musicSettingsMenuItems } from "./music-widget";
|
||||||
import { NightscoutWidget } from "./nightscout-widget";
|
import { NightscoutWidget } from "./nightscout-widget";
|
||||||
@@ -11,7 +12,7 @@ import { HealthWidget } from "./health-widget";
|
|||||||
/** Every widget a board slot can hold. */
|
/** Every widget a board slot can hold. */
|
||||||
export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
|
export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
|
||||||
{ id: "system-card", label: "System card", settingsMenuItems: systemCardSettingsMenuItems, create: () => new SystemCardWidget() },
|
{ id: "system-card", label: "System card", settingsMenuItems: systemCardSettingsMenuItems, create: () => new SystemCardWidget() },
|
||||||
{ id: "calendar", label: "Calendar", tall: true, create: () => new CalendarWidget() },
|
{ id: "calendar", label: "Calendar", tall: true, settingsMenuItems: calendarSelectionMenuItems, create: () => new CalendarWidget() },
|
||||||
{ id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() },
|
{ id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() },
|
||||||
{ id: "t3code", label: "T3 Code", tall: true, create: () => new T3CodeWidget() },
|
{ id: "t3code", label: "T3 Code", tall: true, create: () => new T3CodeWidget() },
|
||||||
{ id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() },
|
{ id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() },
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
batteryIndicatorVisible,
|
batteryIndicatorVisible,
|
||||||
ConfigSettingBoolean,
|
ConfigSettingBoolean,
|
||||||
glassesBatteryVisibilitySetting,
|
glassesBatteryVisibilitySetting,
|
||||||
|
glassesModelName,
|
||||||
onAnySettingChanged,
|
onAnySettingChanged,
|
||||||
phoneBatteryVisibilitySetting,
|
phoneBatteryVisibilitySetting,
|
||||||
ringBatteryVisibilitySetting,
|
ringBatteryVisibilitySetting,
|
||||||
@@ -328,7 +329,7 @@ function collectBatteryItems(): BatteryItem[] {
|
|||||||
push(phoneBatteryVisibilitySetting.get(), "Phone", "phone", phone.battery, phone.charging);
|
push(phoneBatteryVisibilitySetting.get(), "Phone", "phone", phone.battery, phone.charging);
|
||||||
const levels = shell.getBatteryLevels();
|
const levels = shell.getBatteryLevels();
|
||||||
push(watchBatteryVisibilitySetting.get(), "Watch", "watch", levels.watch, levels.watchCharging);
|
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) {
|
if (levels.ring !== null && Number.isInteger(levels.ring) && levels.ring >= 0 && levels.ring <= 100) {
|
||||||
push(ringBatteryVisibilitySetting.get(), "R1", "ring", levels.ring, levels.ringCharging);
|
push(ringBatteryVisibilitySetting.get(), "R1", "ring", levels.ring, levels.ringCharging);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
export function launcherEntries(apps: readonly AppDefinition[]) {
|
export function launcherEntries(apps: readonly AppDefinition[]) {
|
||||||
return [
|
return [
|
||||||
...apps
|
...apps
|
||||||
.filter((app) => app.showInLauncher !== false)
|
.filter((app) => app.showInLauncher !== false && app.isSupported?.() !== false)
|
||||||
.map((app) => ({
|
.map((app) => ({
|
||||||
appId: app.appId,
|
appId: app.appId,
|
||||||
label: app.title,
|
label: app.title,
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ function buildNightscoutTrayIcon(state: NightscoutState): GrayImage {
|
|||||||
const font = getDefaultSmallFont();
|
const font = getDefaultSmallFont();
|
||||||
const nowMs = Date.now();
|
const nowMs = Date.now();
|
||||||
const label = state.latest ? `${state.latest.sgv}` : "--";
|
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 warning = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs).any;
|
||||||
const graphEnd = labelWidth + 4 + TRAY_GRAPH_WIDTH;
|
const graphEnd = labelWidth + 4 + TRAY_GRAPH_WIDTH;
|
||||||
const image = new GrayImage(graphEnd + (warning ? 24 : 0), TRAY_HEIGHT, 0);
|
const image = new GrayImage(graphEnd + (warning ? 24 : 0), TRAY_HEIGHT, 0);
|
||||||
|
|||||||
@@ -14,7 +14,12 @@ const notificationsApp: AppDefinition = {
|
|||||||
if (listenerState === "no-access" || listenerState === "stuck") {
|
if (listenerState === "no-access" || listenerState === "stuck") {
|
||||||
requestNotificationListenerAccess();
|
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}`);
|
||||||
|
});
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { NotificationsListLayer } from "../../ui/notifications";
|
import { NotificationsListLayer } from "../../ui/notifications";
|
||||||
import { NotificationFilterLayer } from "../../ui/notification-filter";
|
import { NOTIFICATIONS_SETTINGS_SECTION } from "../../ui/dashboard/settings-menus";
|
||||||
import { onAndroidNotificationsChanged } from "../../native/notification-icons";
|
import { ALL_NOTIFICATIONS, dismissAllNotifications, onAndroidNotificationsChanged, readActiveNotifications } from "../../native/notification-icons";
|
||||||
import {
|
import {
|
||||||
createInProcessWindow,
|
createInProcessWindow,
|
||||||
YieldAtRootLayer,
|
YieldAtRootLayer,
|
||||||
@@ -14,9 +14,13 @@ export const NOTIFICATIONS_SURFACE_ID = "window:notifications";
|
|||||||
/**
|
/**
|
||||||
* The Notifications app: the Android-notification list (previously a
|
* The Notifications app: the Android-notification list (previously a
|
||||||
* dashboard page) in its own in-process window; selecting a notification
|
* 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.
|
// Newly posted notifications repaint the list while the window is open.
|
||||||
let offNotificationsChanged: (() => void) | null = null;
|
let offNotificationsChanged: (() => void) | null = null;
|
||||||
const created = createInProcessWindow({
|
const created = createInProcessWindow({
|
||||||
@@ -27,10 +31,19 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
|
|||||||
icon: "bell",
|
icon: "bell",
|
||||||
closeable: true,
|
closeable: true,
|
||||||
menuItems: () => [{
|
menuItems: () => [{
|
||||||
label: "Notification filter",
|
label: "Settings",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
ctx.stack.push(new NotificationFilterLayer());
|
openSettings(NOTIFICATIONS_SETTINGS_SECTION);
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
label: "Dismiss all notifications",
|
||||||
|
description: "Dismiss notifications on the phone and glasses. System-protected notifications may remain.",
|
||||||
|
disabled: () => readActiveNotifications(ALL_NOTIFICATIONS).length === 0,
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
dismissAllNotifications();
|
||||||
|
created.requestRender();
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
* page: to scale in real-display pixels, simplified, and drawn brighter
|
* page: to scale in real-display pixels, simplified, and drawn brighter
|
||||||
* than the real chrome, which they shrink to a few pixels.
|
* 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 { 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;
|
export const AREA_OUTLINE = 30;
|
||||||
const CHROME_LINE = 100;
|
const CHROME_LINE = 100;
|
||||||
@@ -80,14 +80,14 @@ export function drawLayout(d: Diagram, position: AppSwitcherPosition, band: Diag
|
|||||||
switch (position) {
|
switch (position) {
|
||||||
case "left":
|
case "left":
|
||||||
case "right": {
|
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 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);
|
drawStatusBar(d, contentLeft, top, windowWidth, TOP_BAR_HEIGHT - 1);
|
||||||
drawContent(d, contentLeft, top + TOP_BAR_HEIGHT, windowWidth, height - 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;
|
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.
|
// One column of icons against the separator.
|
||||||
const column = position === "left" ? SIDEBAR_WIDTH - 36 : stripLeft;
|
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);
|
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 } {
|
function windowSpan(band: DiagramBand): { left: number; width: number; framed: boolean } {
|
||||||
return band.fullWidth
|
return band.fullWidth
|
||||||
? { left: 0, width: G2_LENS_WIDTH, framed: false }
|
? { left: 0, width: screenWidth(), framed: false }
|
||||||
: { left: SIDEBAR_WIDTH / 2, width: G2_LENS_WIDTH - SIDEBAR_WIDTH, framed: true };
|
: { 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));
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { G2_LENS_WIDTH, type GrayImage, type UiFont } from "../../graphics/image";
|
import type { GrayImage, UiFont } from "../../graphics/image";
|
||||||
import { appSwitcherPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
|
import { appSwitcherPositionSetting, glassesTypeSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
|
||||||
import type { InputEvent } from "../../ui/gestures";
|
import type { InputEvent } from "../../ui/gestures";
|
||||||
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
|
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
|
||||||
import { MIN_WINDOW_HEIGHT } from "../../ui/shell/geometry";
|
import { screenWidth } from "../../ui/shell/geometry";
|
||||||
import { AREA_OUTLINE, Diagram, drawLayout, LAYOUT_AREA_HEIGHT } from "./layout-diagram";
|
import { AREA_OUTLINE, Diagram, diagramBandHeight, drawLayout, layoutAreaHeight } from "./layout-diagram";
|
||||||
import { onboardingFont } from "./onboarding-fonts";
|
import { onboardingFont } from "./onboarding-fonts";
|
||||||
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||||
|
|
||||||
@@ -19,8 +19,13 @@ const ROW_GAP = 6;
|
|||||||
const DEPTH_SUBTITLE = "Customizable Depth";
|
const DEPTH_SUBTITLE = "Customizable Depth";
|
||||||
/** Grid order, in rows of two: the layouts with depth on top. */
|
/** Grid order, in rows of two: the layouts with depth on top. */
|
||||||
const LAYOUT_ORDER: readonly AppSwitcherPosition[] = ["bottom", "popup", "left", "right"];
|
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). */
|
/** Whether a layout leaves the side margins the display's stereo depth shifts into (geometry.ts uiDepth). */
|
||||||
export function layoutHasDepth(position: AppSwitcherPosition): boolean {
|
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
|
* 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.
|
* 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
|
* The page is immersive, so the diagrams get 40% of the display's width
|
||||||
* each. Choosing a layout reflows open windows (the dashboard controller
|
* 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 {
|
export class LayoutPage implements OnboardingPage {
|
||||||
readonly immersive = true;
|
readonly immersive = true;
|
||||||
/** Kept across visits, so going back returns to the last choice. */
|
/** 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 {
|
paint(image: GrayImage, focused: boolean): void {
|
||||||
const top = drawPageHeading(
|
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.
|
// Short of DIAGRAM_SCALE only where two rows of cells wouldn't fit.
|
||||||
const scale = Math.min(
|
const scale = Math.min(
|
||||||
DIAGRAM_SCALE,
|
DIAGRAM_SCALE,
|
||||||
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / LAYOUT_AREA_HEIGHT,
|
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / layoutAreaHeight(),
|
||||||
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / G2_LENS_WIDTH,
|
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / screenWidth(),
|
||||||
);
|
);
|
||||||
const diagramWidth = Math.round(G2_LENS_WIDTH * scale);
|
const diagramWidth = Math.round(screenWidth() * scale);
|
||||||
const diagramHeight = Math.round(LAYOUT_AREA_HEIGHT * scale);
|
const diagramHeight = Math.round(layoutAreaHeight() * scale);
|
||||||
const cellWidth = diagramWidth + 2 * CELL_PADDING;
|
const cellWidth = diagramWidth + 2 * CELL_PADDING;
|
||||||
const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight;
|
const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight;
|
||||||
const left = Math.round((image.width - 2 * cellWidth - COLUMN_GAP) / 2);
|
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);
|
image.drawText(font, x + Math.round((cellWidth - font.measureText(text)) / 2), textY, text, value);
|
||||||
const captionTop = y + CELL_PADDING + diagramHeight + CAPTION_GAP;
|
const captionTop = y + CELL_PADDING + diagramHeight + CAPTION_GAP;
|
||||||
const name = appSwitcherPositionSetting.displayValue(position);
|
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);
|
centre(caption, title, captionTop, selected ? 255 : 190);
|
||||||
if (layoutHasDepth(position)) {
|
if (layoutHasDepth(position)) {
|
||||||
centre(DEPTH_SUBTITLE, subtitle, captionTop + title.lineHeight, selected ? 210 : 150);
|
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
|
* A layout's diagram: the min-height band, with the popup switcher open.
|
||||||
* bottom switcher row takes rows under the band; without one, the band sits
|
* Only a bottom switcher row takes rows under the band; without one, the
|
||||||
* centred in their place, as the band and row share the screen's slack.
|
* 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 {
|
function drawLayoutDiagram(d: Diagram, position: AppSwitcherPosition): void {
|
||||||
d.outline(0, 0, G2_LENS_WIDTH, LAYOUT_AREA_HEIGHT, AREA_OUTLINE, 12);
|
d.outline(0, 0, screenWidth(), layoutAreaHeight(), AREA_OUTLINE, 12);
|
||||||
const top = position === "bottom" ? 0 : (LAYOUT_AREA_HEIGHT - MIN_WINDOW_HEIGHT) / 2;
|
const height = diagramBandHeight(position);
|
||||||
drawLayout(d, position, { top, height: MIN_WINDOW_HEIGHT, fullWidth: false }, true);
|
const top = position === "bottom" ? 0 : (layoutAreaHeight() - height) / 2;
|
||||||
|
drawLayout(d, position, { top, height, fullWidth: false }, true);
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import { findSoundEffect, playSoundEffect } from "../../ui/sound-effects";
|
|||||||
import { DataCollectionPage } from "./data-collection-page";
|
import { DataCollectionPage } from "./data-collection-page";
|
||||||
import { DepthPage } from "./depth-page";
|
import { DepthPage } from "./depth-page";
|
||||||
import { DisplayModePage } from "./display-mode-page";
|
import { DisplayModePage } from "./display-mode-page";
|
||||||
import { IosPrivacyPage } from "./ios-privacy-page";
|
|
||||||
import { LayoutPage } from "./layout-page";
|
import { LayoutPage } from "./layout-page";
|
||||||
import { markGlassesOnboardingFinished, ONBOARDING_APP_ID } from "./onboarding-progress";
|
import { markGlassesOnboardingFinished, ONBOARDING_APP_ID } from "./onboarding-progress";
|
||||||
import type { OnboardingPage } from "./onboarding-page";
|
import type { OnboardingPage } from "./onboarding-page";
|
||||||
@@ -26,9 +25,7 @@ export const ONBOARDING_SURFACE_ID = "window:onboarding";
|
|||||||
*/
|
*/
|
||||||
export function createOnboardingAppWindow(options: InProcessAppOptions): InProcessWindow {
|
export function createOnboardingAppWindow(options: InProcessAppOptions): InProcessWindow {
|
||||||
const pages: OnboardingPage[] = [
|
const pages: OnboardingPage[] = [
|
||||||
new WelcomePage(), new TextSizePage(),
|
new WelcomePage(), new TextSizePage(), new DataCollectionPage(), new LayoutPage(), new DepthPage(), new DisplayModePage(),
|
||||||
...(global.isIOS ? [new IosPrivacyPage()] : []),
|
|
||||||
new DataCollectionPage(), new LayoutPage(), new DepthPage(), new DisplayModePage(),
|
|
||||||
];
|
];
|
||||||
const app = createInProcessWindow({
|
const app = createInProcessWindow({
|
||||||
appId: ONBOARDING_APP_ID,
|
appId: ONBOARDING_APP_ID,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { installedFontPath } from "../../graphics/installed-fonts";
|
|||||||
import { wrapText } from "../../graphics/textwrap";
|
import { wrapText } from "../../graphics/textwrap";
|
||||||
import { TtfFont } from "../../graphics/ttf-font";
|
import { TtfFont } from "../../graphics/ttf-font";
|
||||||
import {
|
import {
|
||||||
|
defaultUiFontSize,
|
||||||
fontSelectionLabel,
|
fontSelectionLabel,
|
||||||
getDefaultSmallFont,
|
getDefaultSmallFont,
|
||||||
getUiFontSelection,
|
getUiFontSelection,
|
||||||
@@ -25,8 +26,6 @@ const ROW_GAP = 2;
|
|||||||
const NOTE_GAP = 8;
|
const NOTE_GAP = 8;
|
||||||
/** The sizes offered here; Settings has the full range. */
|
/** The sizes offered here; Settings has the full range. */
|
||||||
const SIZE_CHOICES = FONT_SIZE_CHOICES.filter((size) => size >= 12 && size <= 18);
|
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";
|
const RECOMMENDED_NOTE = "Recommended";
|
||||||
/** Drawn while they fit, so smaller sizes visibly show more words. */
|
/** Drawn while they fit, so smaller sizes visibly show more words. */
|
||||||
const PREVIEW_PARAGRAPHS = [
|
const PREVIEW_PARAGRAPHS = [
|
||||||
@@ -41,7 +40,8 @@ type Face =
|
|||||||
| { kind: "fixed"; label: string };
|
| { 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
|
* 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
|
* 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
|
* 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) {
|
if (sizes.length) {
|
||||||
this.face = { kind: "sized", file: selection.file, path, sizes };
|
this.face = { kind: "sized", file: selection.file, path, sizes };
|
||||||
// The recommended size the first time; on a return, what was left selected.
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ export class TextSizePage implements OnboardingPage {
|
|||||||
const body = onboardingFont("body");
|
const body = onboardingFont("body");
|
||||||
const label = sizeLabel(size);
|
const label = sizeLabel(size);
|
||||||
image.drawText(body, x + 10, y + LIST_ROW_TEXT_INSET, label, selected ? 255 : 190);
|
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 detail = onboardingFont("detail");
|
||||||
const noteY = y + Math.round((height - detail.lineHeight) / 2);
|
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);
|
image.drawText(detail, x + 10 + body.measureText(label) + NOTE_GAP, noteY, RECOMMENDED_NOTE, selected ? 210 : 150);
|
||||||
|
|||||||
@@ -6,9 +6,15 @@
|
|||||||
* connected host's heading launches a shell there), and hosts the Manage
|
* connected host's heading launches a shell there), and hosts the Manage
|
||||||
* Connections section
|
* Connections section
|
||||||
* where g2mirror:// connections are added, removed, and toggled.
|
* where g2mirror:// connections are added, removed, and toggled.
|
||||||
* - "terminal:view:N": opened by selecting a session in the hub; each has
|
* - Selecting a session in the hub shows it in the hub's own window: a view
|
||||||
* its own websocket connection (the protocol allows one attached session
|
* takes the hub's place in `windows` under the same window id, and
|
||||||
* per connection) and its own xterm emulator.
|
* 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
|
* Connections are g2mirror://<token>@<host>[:port] strings (g2mirrors:// for
|
||||||
* TLS), stored as JSON in the settings store (see connections.ts). Each
|
* 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 { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
||||||
import { centeredTextY, lineStep, listRowHeight, textInkHeight } from "../../ui/metrics";
|
import { centeredTextY, lineStep, listRowHeight, textInkHeight } from "../../ui/metrics";
|
||||||
import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu";
|
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 { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
|
||||||
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
||||||
|
|
||||||
@@ -109,7 +115,10 @@ const LAUNCH_PRESETS_KEY = "terminal.launchPresets";
|
|||||||
type BaseWindow = {
|
type BaseWindow = {
|
||||||
windowId: string;
|
windowId: string;
|
||||||
surfaceId: 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;
|
title: string;
|
||||||
/** Content viewport from the shell's open-window message; grid = viewport / cell. */
|
/** Content viewport from the shell's open-window message; grid = viewport / cell. */
|
||||||
viewportWidth: number;
|
viewportWidth: number;
|
||||||
@@ -155,6 +164,11 @@ type HubWindow = BaseWindow & {
|
|||||||
|
|
||||||
type ViewWindow = BaseWindow & {
|
type ViewWindow = BaseWindow & {
|
||||||
kind: "view";
|
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. */
|
/** Grid font and integer cell pitch, captured at window creation. */
|
||||||
font: UiFont;
|
font: UiFont;
|
||||||
cellWidth: number;
|
cellWidth: number;
|
||||||
@@ -202,8 +216,13 @@ type PendingView = {
|
|||||||
options: G2MirrorClientOptions;
|
options: G2MirrorClientOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Viewport = { width: number; height: number };
|
||||||
|
|
||||||
const windows = new Map<string, TerminalWindow>();
|
const windows = new Map<string, TerminalWindow>();
|
||||||
const pendingViews = new Map<string, PendingView>();
|
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 view an assistant tool acts on when the terminal isn't foregrounded:
|
||||||
// the last view to be foregrounded or receive input.
|
// the last view to be foregrounded or receive input.
|
||||||
let activeViewId: string | null = null;
|
let activeViewId: string | null = null;
|
||||||
@@ -338,6 +357,12 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
|||||||
openWindow(message.windowId, message.surfaceId, message.title, message.viewport);
|
openWindow(message.windowId, message.surfaceId, message.title, message.viewport);
|
||||||
break;
|
break;
|
||||||
case "resize-window": {
|
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);
|
const window = windows.get(message.windowId);
|
||||||
if (!window || (window.viewportWidth === message.viewport.width && window.viewportHeight === message.viewport.height)) break;
|
if (!window || (window.viewportWidth === message.viewport.width && window.viewportHeight === message.viewport.height)) break;
|
||||||
window.viewportWidth = message.viewport.width;
|
window.viewportWidth = message.viewport.width;
|
||||||
@@ -543,10 +568,8 @@ function openWindow(windowId: string, surfaceId: string, title: string, viewport
|
|||||||
updateHubAnimation();
|
updateHubAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeWindow(windowId: string): void {
|
/** Drop a view's connection for good: its window closed or the hub took its place. */
|
||||||
const window = windows.get(windowId);
|
function stopViewConnection(window: ViewWindow): void {
|
||||||
if (!window) return;
|
|
||||||
if (window.kind === "view") {
|
|
||||||
for (const unsubscribe of window.unsubscribers.splice(0)) {
|
for (const unsubscribe of window.unsubscribers.splice(0)) {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
@@ -556,6 +579,14 @@ function closeWindow(windowId: string): void {
|
|||||||
}
|
}
|
||||||
window.client.stop();
|
window.client.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeWindow(windowId: string): void {
|
||||||
|
const window = windows.get(windowId);
|
||||||
|
if (!window) return;
|
||||||
|
pendingHeightChanges.delete(windowId);
|
||||||
|
if (window.kind === "view") {
|
||||||
|
stopViewConnection(window);
|
||||||
|
}
|
||||||
if (window.kind === "hub" && window.mode === "add") {
|
if (window.kind === "hub" && window.mode === "add") {
|
||||||
// Window closed mid-add: shut the phone editor down.
|
// Window closed mid-add: shut the phone editor down.
|
||||||
endAddConnection(window);
|
endAddConnection(window);
|
||||||
@@ -759,10 +790,11 @@ function routeBell(connectionId: string, socket: string, lastBellAtMs: number):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (terminalWakeOnBellSetting.get()) {
|
if (terminalWakeOnBellSetting.get()) {
|
||||||
// Wake to the belling session's view window, or the hub if it has none.
|
// Wake to the belling session's view window, or the hub's window (whatever
|
||||||
// The shell drops the message unless the glasses are actually asleep.
|
// it is showing) if it has none. The shell drops the message unless the
|
||||||
|
// glasses are actually asleep.
|
||||||
const viewId = viewWindowIdForSocket(connectionId, socket);
|
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;
|
const target = viewId ?? hubId;
|
||||||
if (target) post({ type: "wake-window", windowId: target });
|
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 client = new G2MirrorClient({ ...view.options, cols: gridCols, rows: gridRows });
|
||||||
const window: ViewWindow = {
|
const window: ViewWindow = {
|
||||||
kind: "view",
|
kind: "view",
|
||||||
|
hub: null,
|
||||||
windowId,
|
windowId,
|
||||||
surfaceId,
|
surfaceId,
|
||||||
title,
|
title,
|
||||||
@@ -1053,12 +1086,41 @@ function connectedControls(): ControlConnection[] {
|
|||||||
return [...controls.values()].filter(isControlConnected);
|
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[] {
|
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) => {
|
submenuItem("Settings", (ctx) => {
|
||||||
ctx.stack.push(new WindowMenuLayer("Terminal settings", settingsMenuItems()));
|
ctx.stack.push(new WindowMenuLayer("Terminal settings", settingsMenuItems()));
|
||||||
}),
|
}),
|
||||||
];
|
);
|
||||||
if (window.kind === "hub") {
|
if (window.kind === "hub") {
|
||||||
const connected = connectedControls();
|
const connected = connectedControls();
|
||||||
const multiHost = connected.length > 1;
|
const multiHost = connected.length > 1;
|
||||||
@@ -1142,8 +1204,14 @@ function handleInput(window: TerminalWindow, event: InputEvent, frameId: number)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.type === "double-click") {
|
if (event.type === "double-click") {
|
||||||
// Inside the hub's sub-sections, double-click backs out one level; at the
|
// Inside the hub's sub-sections and a session shown in its window,
|
||||||
// top level (and in views) it yields focus to the sidebar as everywhere.
|
// 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") {
|
if (window.kind === "hub" && window.mode === "add") {
|
||||||
cancelAddConnection(window);
|
cancelAddConnection(window);
|
||||||
renderAndSubmit(window, frameId);
|
renderAndSubmit(window, frameId);
|
||||||
@@ -1233,6 +1301,8 @@ type HubItem = {
|
|||||||
active?: boolean;
|
active?: boolean;
|
||||||
/** Glyph of the view window showing this session (the number column). */
|
/** Glyph of the view window showing this session (the number column). */
|
||||||
openGlyph?: string | null;
|
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;
|
onSelect?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1371,13 +1441,9 @@ function hubSessionItems(window: HubWindow): HubItem[] {
|
|||||||
label: sessionLabel(session),
|
label: sessionLabel(session),
|
||||||
active: isSessionActive(control.config.id, session.socket),
|
active: isSessionActive(control.config.id, session.socket),
|
||||||
openGlyph: viewGlyphForSocket(control.config.id, session.socket),
|
openGlyph: viewGlyphForSocket(control.config.id, session.socket),
|
||||||
|
sessionRow: { control, session },
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
const windowId = viewWindowIdForSocket(control.config.id, session.socket);
|
if (!focusSessionWindow(control, session)) showSessionInHub(window, control, session);
|
||||||
if (windowId) {
|
|
||||||
post({ type: "focus-window", windowId });
|
|
||||||
} else {
|
|
||||||
openViewWindowFor(control, session);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1587,10 +1653,89 @@ function viewWindowIdForSocket(connectionId: string, socket: string): string | n
|
|||||||
return null;
|
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 {
|
function openViewWindowFor(control: ControlConnection, session: G2MirrorSession): void {
|
||||||
openViewWindow(control, session.socket, sessionLabel(session));
|
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
|
* 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
|
* icon shows ">N"). Glyphs free up when their window closes, since usage is
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import {
|
|||||||
resolveTranslateLanguage,
|
resolveTranslateLanguage,
|
||||||
resolveTranslateProvider,
|
resolveTranslateProvider,
|
||||||
translateLanguageSetting,
|
translateLanguageSetting,
|
||||||
|
translateModelSetting,
|
||||||
|
translateTargetLanguageSetting,
|
||||||
translateProviderSetting,
|
translateProviderSetting,
|
||||||
translateShowOriginalSetting,
|
translateShowOriginalSetting,
|
||||||
} from "./translate-settings";
|
} from "./translate-settings";
|
||||||
@@ -11,7 +13,7 @@ import { MIC_ICON } from "../transcribe/transcribe-app";
|
|||||||
import { transcriptTimestamp } from "../transcribe/transcribe";
|
import { transcriptTimestamp } from "../transcribe/transcribe";
|
||||||
import { type ContinuousCaptureOptions } from "../../ui/layers";
|
import { type ContinuousCaptureOptions } from "../../ui/layers";
|
||||||
import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel";
|
import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel";
|
||||||
import { enumSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
import { enumSettingMenuItem, textSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||||
import {
|
import {
|
||||||
createInProcessWindow,
|
createInProcessWindow,
|
||||||
YieldAtRootLayer,
|
YieldAtRootLayer,
|
||||||
@@ -28,8 +30,8 @@ const TRAY_ICON_ID = "translate";
|
|||||||
const NO_PROVIDER_PROBLEM =
|
const NO_PROVIDER_PROBLEM =
|
||||||
"Translate needs a transcription provider that understands any language: add an ElevenLabs, OpenAI, or Soniox API key (Settings > API Keys), or a Whisper server URL (Settings > Voice).";
|
"Translate needs a transcription provider that understands any language: add an ElevenLabs, OpenAI, or Soniox API key (Settings > API Keys), or a Whisper server URL (Settings > Voice).";
|
||||||
const NO_MODEL_PROBLEM = global.isIOS
|
const NO_MODEL_PROBLEM = global.isIOS
|
||||||
? "Translate needs a language model: configure a cloud or OpenAI-compatible model in Settings > Assistant."
|
? "Translate needs a language model: set an OpenAI model in Translate settings and add its API key, or configure a cloud or OpenAI-compatible model in Settings > Assistant."
|
||||||
: "Translate needs a language model: configure one in Settings > Assistant, or download the on-phone model.";
|
: "Translate needs a language model: set an OpenAI model in Translate settings and add its API key, or configure one in Settings > Assistant, or download the on-phone model.";
|
||||||
|
|
||||||
export type TranslateAppOptions = InProcessAppOptions & {
|
export type TranslateAppOptions = InProcessAppOptions & {
|
||||||
/** Begin (or retarget) continuous mic capture, kept on while the window is open. */
|
/** Begin (or retarget) continuous mic capture, kept on while the window is open. */
|
||||||
@@ -38,7 +40,7 @@ export type TranslateAppOptions = InProcessAppOptions & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Translate app: live speech in any language, translated into English by
|
* The Translate app: live speech in any language, translated into the selected output language by
|
||||||
* the assistant's model, in its own window. Like Transcribe it holds
|
* the assistant's model, in its own window. Like Transcribe it holds
|
||||||
* continuous mic capture while open, but always with a multilingual cloud
|
* continuous mic capture while open, but always with a multilingual cloud
|
||||||
* provider (Translate settings), which a shared capture switches to.
|
* provider (Translate settings), which a shared capture switches to.
|
||||||
@@ -84,6 +86,8 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
|
|||||||
openSettingsSubMenu(ctx, "Translate settings", [
|
openSettingsSubMenu(ctx, "Translate settings", [
|
||||||
enumSettingMenuItem(translateLanguageSetting, { onChange: startCapture }),
|
enumSettingMenuItem(translateLanguageSetting, { onChange: startCapture }),
|
||||||
enumSettingMenuItem(translateProviderSetting, { onChange: startCapture }),
|
enumSettingMenuItem(translateProviderSetting, { onChange: startCapture }),
|
||||||
|
enumSettingMenuItem(translateTargetLanguageSetting),
|
||||||
|
textSettingMenuItem(translateModelSetting),
|
||||||
toggleSettingMenuItem(translateShowOriginalSetting),
|
toggleSettingMenuItem(translateShowOriginalSetting),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Streamed translation against the assistant's configured model (Settings >
|
* Streamed translation against Translate's OpenAI override, or the assistant's
|
||||||
* Assistant). Each call translates one stretch of speech into English; see
|
* configured model when no override is set. Each call translates one stretch of speech into the selected output language; see
|
||||||
* TranslationModel for how stretches are batched and given context.
|
* TranslationModel for how stretches are batched and given context.
|
||||||
*/
|
*/
|
||||||
import { streamAnthropicMessage } from "../../native/anthropic";
|
import { streamAnthropicMessage } from "../../native/anthropic";
|
||||||
@@ -13,7 +13,8 @@ import {
|
|||||||
anthropicApiKeySetting, assistantModelSetting, assistantOpenAiCompatibleKeySetting,
|
anthropicApiKeySetting, assistantModelSetting, assistantOpenAiCompatibleKeySetting,
|
||||||
assistantOpenAiCompatibleModelSetting, assistantOpenAiCompatibleUrlSetting, openAiApiKeySetting,
|
assistantOpenAiCompatibleModelSetting, assistantOpenAiCompatibleUrlSetting, openAiApiKeySetting,
|
||||||
} from "../../ui/dashboard-settings";
|
} from "../../ui/dashboard-settings";
|
||||||
import { TRANSLATE_SYSTEM_PROMPT, buildTranslateUserMessage } from "../../prompts";
|
import { buildTranslateSystemPrompt, buildTranslateUserMessage } from "../../prompts";
|
||||||
|
import { translateModelSetting, translateTargetLanguageSetting, spokenLanguageName } from "./translate-settings";
|
||||||
import { type TranslationTurn } from "./translation-model";
|
import { type TranslationTurn } from "./translation-model";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +24,11 @@ import { type TranslationTurn } from "./translation-model";
|
|||||||
* for whichever API key is set, else the on-phone model.
|
* for whichever API key is set, else the on-phone model.
|
||||||
*/
|
*/
|
||||||
export function resolveTranslationModel(): ResolvedAssistantModel | null {
|
export function resolveTranslationModel(): ResolvedAssistantModel | null {
|
||||||
|
const translationModel = translateModelSetting.get().trim();
|
||||||
|
if (translationModel) {
|
||||||
|
const apiKey = openAiApiKeySetting.get().trim();
|
||||||
|
return apiKey ? { selection: "auto", provider: "openai", model: translationModel, apiKey } : null;
|
||||||
|
}
|
||||||
const selection = assistantModelSetting.get();
|
const selection = assistantModelSetting.get();
|
||||||
return resolveAssistantModel(selection === "hermes" ? "auto" : selection, {
|
return resolveAssistantModel(selection === "hermes" ? "auto" : selection, {
|
||||||
anthropic: anthropicApiKeySetting.get(),
|
anthropic: anthropicApiKeySetting.get(),
|
||||||
@@ -44,13 +50,14 @@ export type TranslationRequest = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function streamTranslation(model: ResolvedAssistantModel, request: TranslationRequest): LlmStreamHandle {
|
export function streamTranslation(model: ResolvedAssistantModel, request: TranslationRequest): LlmStreamHandle {
|
||||||
|
const targetLanguage = spokenLanguageName(translateTargetLanguageSetting.get());
|
||||||
const options: LlmStreamOptions = {
|
const options: LlmStreamOptions = {
|
||||||
apiKey: model.apiKey,
|
apiKey: model.apiKey,
|
||||||
model: model.model,
|
model: model.model,
|
||||||
system: TRANSLATE_SYSTEM_PROMPT,
|
system: buildTranslateSystemPrompt(targetLanguage),
|
||||||
effort: model.effort,
|
effort: model.effort,
|
||||||
maxTokens: 1024,
|
maxTokens: 1024,
|
||||||
messages: [{ role: "user", content: buildTranslateUserMessage(request.speech, request.context, request.language) }],
|
messages: [{ role: "user", content: buildTranslateUserMessage(request.speech, request.context, request.language, targetLanguage) }],
|
||||||
onTextDelta: (_delta, textSoFar) => request.onProgress(cleanTranslation(textSoFar)),
|
onTextDelta: (_delta, textSoFar) => request.onProgress(cleanTranslation(textSoFar)),
|
||||||
onDone: (result) => {
|
onDone: (result) => {
|
||||||
if (result.stopReason === "refusal") request.onError("The model declined to translate this.");
|
if (result.stopReason === "refusal") request.onError("The model declined to translate this.");
|
||||||
@@ -70,7 +77,7 @@ export function streamTranslation(model: ResolvedAssistantModel, request: Transl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The context turns are tagged <english>; a model may echo the tag around its reply. */
|
/** The context turns are tagged <translation>; a model may echo the tag around its reply. */
|
||||||
function cleanTranslation(text: string): string {
|
function cleanTranslation(text: string): string {
|
||||||
return text.replace(/^\s*<english>/i, "").replace(/<\/english>\s*$/i, "").trim();
|
return text.replace(/^\s*<(?:translation|english)>/i, "").replace(/<\/(?:translation|english)>\s*$/i, "").trim();
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ConfigSettingBoolean, ConfigSettingEnum, voiceProviderSetting, type VoiceProvider } from "../../ui/dashboard-settings";
|
import { ConfigSettingBoolean, ConfigSettingEnum, ConfigSettingString, voiceProviderSetting, type VoiceProvider } from "../../ui/dashboard-settings";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The transcription providers that recognize any spoken language, in picker
|
* The transcription providers that recognize any spoken language, in picker
|
||||||
@@ -52,6 +52,7 @@ export const translateProviderSetting = new ConfigSettingEnum<TranslateProvider>
|
|||||||
* form every multilingual provider accepts), in picker order.
|
* form every multilingual provider accepts), in picker order.
|
||||||
*/
|
*/
|
||||||
const SPOKEN_LANGUAGES = {
|
const SPOKEN_LANGUAGES = {
|
||||||
|
en: "English",
|
||||||
ar: "Arabic",
|
ar: "Arabic",
|
||||||
zh: "Chinese",
|
zh: "Chinese",
|
||||||
nl: "Dutch",
|
nl: "Dutch",
|
||||||
@@ -106,3 +107,24 @@ export const translateShowOriginalSetting = new ConfigSettingBoolean({
|
|||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
description: "Show what was said, dimmed, above each translation.",
|
description: "Show what was said, dimmed, above each translation.",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Empty preserves the existing Assistant-based routing. */
|
||||||
|
export const translateModelSetting = new ConfigSettingString({
|
||||||
|
id: "translate-model",
|
||||||
|
label: "Translation model (OpenAI)",
|
||||||
|
storageKey: "translate.model",
|
||||||
|
defaultValue: "",
|
||||||
|
inputKind: "text",
|
||||||
|
normalize: (value) => value.trim(),
|
||||||
|
description: "OpenAI model ID used only by Translate, for example gpt-4o-mini. Uses the OpenAI key from Settings > API Keys. Leave empty to use the Assistant model. Changes apply to subsequent translation requests; Assistant settings are unchanged.",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const translateTargetLanguageSetting = new ConfigSettingEnum<SpokenLanguage>({
|
||||||
|
id: "translate-target-language",
|
||||||
|
label: "Output language",
|
||||||
|
storageKey: "translate.targetLanguage",
|
||||||
|
defaultValue: "en",
|
||||||
|
values: Object.keys(SPOKEN_LANGUAGES) as SpokenLanguage[],
|
||||||
|
formatValue: (value) => SPOKEN_LANGUAGES[value],
|
||||||
|
description: "Language of subsequent translations. Independent of the spoken language and Assistant settings. Existing translations stay unchanged.",
|
||||||
|
});
|
||||||
@@ -18,7 +18,7 @@ const NO_MODEL_NOTICE = "No language model is set up.";
|
|||||||
* Live translation view. Continuous mic capture is owned by the app wrapper
|
* Live translation view. Continuous mic capture is owned by the app wrapper
|
||||||
* (createTranslateAppWindow); this layer feeds speech to the assistant's
|
* (createTranslateAppWindow); this layer feeds speech to the assistant's
|
||||||
* model one block at a time (provisionally while a block is still being
|
* model one block at a time (provisionally while a block is still being
|
||||||
* spoken), shows the English as it streams in, and saves the session to
|
* spoken), shows the translation as it streams in, and saves the session to
|
||||||
* Downloads from the app menu.
|
* Downloads from the app menu.
|
||||||
*/
|
*/
|
||||||
export class TranslateLayer implements Layer {
|
export class TranslateLayer implements Layer {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { wrapTranscribeText } from "../transcribe/transcript-model";
|
|||||||
type TranscriptEvent = { text: string; isFinal: boolean };
|
type TranscriptEvent = { text: string; isFinal: boolean };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One block of speech (up to a pause) and its English translation. The last
|
* One block of speech (up to a pause) and its translation. The last
|
||||||
* block may still be live, its transcript revising; it is translated
|
* block may still be live, its transcript revising; it is translated
|
||||||
* provisionally as it grows, then again once final if its text changed.
|
* provisionally as it grows, then again once final if its text changed.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
* mirrors what the user can do from the launcher grid and the sidebar.
|
* 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
|
* The launchable set is the built-in launcher apps plus whatever EvenHub
|
||||||
* packages are installed right now, matching the launcher grid. Installs and
|
* packages are installed right now, matching the launcher grid. Installs,
|
||||||
* uninstalls change that set at runtime, so the tools re-register (replacing
|
* uninstalls and pairing different glasses change that set at runtime, so the
|
||||||
* themselves by name) whenever it changes to keep the id enums and
|
* tools re-register (replacing themselves by name) whenever it changes to keep
|
||||||
* descriptions current; register() fires the tools-changed broadcast that
|
* the id enums and descriptions current; register() fires the tools-changed
|
||||||
* propagates the new specs to the assistant backends.
|
* broadcast that propagates the new specs to the assistant backends.
|
||||||
*/
|
*/
|
||||||
import { shell, type ShellWindow } from "../ui/shell/shell";
|
import { shell, type ShellWindow } from "../ui/shell/shell";
|
||||||
import type { AppDefinition } from "../apps/app-definition";
|
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";
|
import { toolRegistry, type ToolRegistry, type ToolResult } from "./tool-registry";
|
||||||
|
|
||||||
export type WindowToolsOptions = {
|
export type WindowToolsOptions = {
|
||||||
/** The built-in launcher apps; installed EvenHub apps are added dynamically. */
|
/** The built-in launcher apps for the paired glasses; installed EvenHub apps are added dynamically. */
|
||||||
apps: readonly AppDefinition[];
|
apps: () => readonly AppDefinition[];
|
||||||
/** Launch (or focus) an app exactly as the launcher grid would. */
|
/** Launch (or focus) an app exactly as the launcher grid would. */
|
||||||
launchApp: (appId: string) => Promise<void> | void;
|
launchApp: (appId: string) => Promise<void> | void;
|
||||||
/** Repaint the shell surface so the sidebar reflects a focus change. */
|
/** Repaint the shell surface so the sidebar reflects a focus change. */
|
||||||
@@ -47,9 +47,11 @@ export function registerWindowTools(
|
|||||||
if (registered) return;
|
if (registered) return;
|
||||||
registered = true;
|
registered = true;
|
||||||
registerTools(options, registry);
|
registerTools(options, registry);
|
||||||
let fingerprint = getInstalledEvenHubFingerprint();
|
const launchableFingerprint = () =>
|
||||||
|
`${getInstalledEvenHubFingerprint()}\n${options.apps().map((app) => app.appId).join()}`;
|
||||||
|
let fingerprint = launchableFingerprint();
|
||||||
onAnySettingChanged(() => {
|
onAnySettingChanged(() => {
|
||||||
const current = getInstalledEvenHubFingerprint();
|
const current = launchableFingerprint();
|
||||||
if (current === fingerprint) return;
|
if (current === fingerprint) return;
|
||||||
fingerprint = current;
|
fingerprint = current;
|
||||||
registerTools(options, registry);
|
registerTools(options, registry);
|
||||||
@@ -58,7 +60,7 @@ export function registerWindowTools(
|
|||||||
|
|
||||||
function registerTools(options: WindowToolsOptions, registry: ToolRegistry): void {
|
function registerTools(options: WindowToolsOptions, registry: ToolRegistry): void {
|
||||||
const installedApps = getInstalledEvenHubApps();
|
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) {
|
for (const app of installedApps) {
|
||||||
apps.set(installedEvenHubAppId(app.packageId), app.name);
|
apps.set(installedEvenHubAppId(app.packageId), app.name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { startHealthExport } from "./health/health-export"
|
||||||
import { Application } from '@nativescript/core'
|
import { Application } from '@nativescript/core'
|
||||||
import { registerShareIntentHandler } from './native/share-intents'
|
import { registerShareIntentHandler } from './native/share-intents'
|
||||||
import { installNativeUserAgent } from './util/http'
|
import { installNativeUserAgent } from './util/http'
|
||||||
@@ -18,6 +19,7 @@ Application.on(Application.launchEvent, () => {
|
|||||||
// they are closed would be lost if the process restarted first, so this keeps
|
// they are closed would be lost if the process restarted first, so this keeps
|
||||||
// them reaching disk regardless. No-op when there is nothing new.
|
// them reaching disk regardless. No-op when there is nothing new.
|
||||||
startLiveHealthSync()
|
startLiveHealthSync()
|
||||||
|
startHealthExport()
|
||||||
|
|
||||||
// Collect from the ring on a wall-clock cadence (:01 and :31). Without this
|
// Collect from the ring on a wall-clock cadence (:01 and :31). Without this
|
||||||
// nothing drives a pull on a timer at all - only onRingReady() on reconnect -
|
// nothing drives a pull on a timer at all - only onRingReady() on reconnect -
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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."));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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",
|
||||||
|
};
|
||||||
@@ -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 };
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
@@ -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
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
declare module "pako" {
|
||||||
|
export function inflate(data: Uint8Array): Uint8Array;
|
||||||
|
export function inflateRaw(data: Uint8Array): Uint8Array;
|
||||||
|
}
|
||||||
@@ -152,8 +152,10 @@ export class AncsClient {
|
|||||||
if (flags & 2) {
|
if (flags & 2) {
|
||||||
const data = new Uint8Array(this.fragments); this.fragments = []; this.packetKind = -1
|
const data = new Uint8Array(this.fragments); this.fragments = []; this.packetKind = -1
|
||||||
if (kind === 0) {
|
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 }
|
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] === 0) { this.resetReceived = true; this.log('Glasses accepted notification relay START; awaiting subscription') }
|
||||||
if (data[0] === 1) {
|
if (data[0] === 1) {
|
||||||
if (this.timer !== null) clearTimeout(this.timer)
|
if (this.timer !== null) clearTimeout(this.timer)
|
||||||
|
|||||||
+1
-14
@@ -27,7 +27,7 @@
|
|||||||
*
|
*
|
||||||
* It is **not** a measurement. A hand over the temple, a pocket, or a body
|
* 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
|
* 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.
|
* 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.
|
* 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";
|
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. */
|
/** A glyph for the zone; SF Symbols have no Android equivalent, so plain text. */
|
||||||
export function zoneGlyph(zone: ProximityZone): string {
|
export function zoneGlyph(zone: ProximityZone): string {
|
||||||
switch (zone) {
|
switch (zone) {
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
export const DEFAULT_BRIGHTNESS_CURVE = "0:0,0.2:7,1.5:33,5:100";
|
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";
|
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. */
|
/** Percent of the configured range; defaults (20–100) give 20/26/46/100. */
|
||||||
export function brightnessCurveError(value: string): string | null {
|
export function brightnessCurveError(value: string): string | null {
|
||||||
|
|||||||
+158
-47
@@ -16,7 +16,6 @@ import { mediaControllerBridge } from "../native/media-controller";
|
|||||||
import { nightscoutBridge } from "../native/nightscout-bridge";
|
import { nightscoutBridge } from "../native/nightscout-bridge";
|
||||||
import { weatherBridge } from "../native/weather";
|
import { weatherBridge } from "../native/weather";
|
||||||
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, onAndroidNotificationRemoved, readActiveNotifications } from "../native/notification-icons";
|
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, onAndroidNotificationRemoved, readActiveNotifications } from "../native/notification-icons";
|
||||||
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
|
||||||
import { watchNotificationListenerBinding } from "../native/notification-access";
|
import { watchNotificationListenerBinding } from "../native/notification-access";
|
||||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||||
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
|
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 { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||||
import { voiceControlBridge } from "../native/voice-control";
|
import { voiceControlBridge } from "../native/voice-control";
|
||||||
import { voiceActivity } from "../ui/shell/voice-activity";
|
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 { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../graphics/plane";
|
||||||
import { prepareFrameDraws } from "../graphics/glyph-wire";
|
import { prepareFrameDraws } from "../graphics/glyph-wire";
|
||||||
import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from "./lock-screen";
|
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 AppContext, type AppDefinition, type AppLaunchParams, type TextEditorHost } from "../apps/app-definition";
|
||||||
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
|
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
|
||||||
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
|
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 ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
|
||||||
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
|
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
|
||||||
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, 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 { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||||
import {
|
import {
|
||||||
getInstalledEvenHubAppById,
|
getInstalledEvenHubAppById,
|
||||||
@@ -121,6 +120,7 @@ export type DashboardSnapshot = {
|
|||||||
* glasses, and this says which harmless thing is actually going on.
|
* glasses, and this says which harmless thing is actually going on.
|
||||||
*/
|
*/
|
||||||
displayPreviewMessage: string;
|
displayPreviewMessage: string;
|
||||||
|
silentModeFeedback: string;
|
||||||
activeTextSettingId: string | null;
|
activeTextSettingId: string | null;
|
||||||
activeTextEditorTitle: string;
|
activeTextEditorTitle: string;
|
||||||
activeTextSettingTitle: string;
|
activeTextSettingTitle: string;
|
||||||
@@ -195,12 +195,12 @@ const LOW_BATTERY_PERCENT = 5;
|
|||||||
const EVEN_APP_DETECTED_MESSAGE =
|
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 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.
|
// The launcher grid's app list for the paired glasses; also fixes the app ids apps.launch accepts.
|
||||||
const LAUNCHABLE_APPS = ALL_APPS.filter((app) => app.showInLauncher !== false);
|
const launchableApps = () => ALL_APPS.filter((app) => app.showInLauncher !== false && app.isSupported?.() !== false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global settings window viewport sizes depend on: the display mode's
|
* The global settings window viewport sizes depend on: the paired glasses'
|
||||||
* size (a band's position only moves windows), whether the app switcher
|
* 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
|
* 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
|
* 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
|
* bar joins the row (dropping the top bar); with a popup, whether the
|
||||||
@@ -213,7 +213,7 @@ function viewportSizesKey(): string {
|
|||||||
: position === "popup" ? `popup|${statusBarVisibilitySetting.get()}|${windowBorderSetting.get()}`
|
: position === "popup" ? `popup|${statusBarVisibilitySetting.get()}|${windowBorderSetting.get()}`
|
||||||
: "strip";
|
: "strip";
|
||||||
const layout = displayLayoutSetting.get();
|
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. */
|
/** The global settings that move window surfaces without resizing them. */
|
||||||
@@ -222,7 +222,7 @@ function windowPlacementKey(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createInitialDisplayPreview(): ImageSource | null {
|
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. */
|
/** Echo the controller's appendLog() trace to the console. */
|
||||||
@@ -294,8 +294,12 @@ class DashboardController {
|
|||||||
/** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */
|
/** The screen area displayPreview shows (Preview scaling), or null for the whole panel. */
|
||||||
private displayPreviewCrop: ScreenRect | null = null;
|
private displayPreviewCrop: ScreenRect | null = null;
|
||||||
private silentMode = false;
|
private silentMode = false;
|
||||||
|
private silentModeFeedback = "";
|
||||||
|
private silentModeFeedbackGeneration = 0;
|
||||||
|
private silentModeFeedbackTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
// Brightness value last pushed to the glasses; see pushBrightness.
|
// Brightness value last pushed to the glasses; see pushBrightness.
|
||||||
private lastPushedBrightness: string | null = null;
|
private lastPushedBrightness: string | null = null;
|
||||||
|
private lastPushedHeadUp: string | null = null;
|
||||||
// Last battery level the glasses reported, kept across disconnects so a
|
// Last battery level the glasses reported, kept across disconnects so a
|
||||||
// drop-off right after a low reading can be explained as a flat battery.
|
// drop-off right after a low reading can be explained as a flat battery.
|
||||||
private lastHeadsetBattery: number | null = null;
|
private lastHeadsetBattery: number | null = null;
|
||||||
@@ -422,7 +426,7 @@ class DashboardController {
|
|||||||
registerRoamTools((appId) => this.launchApp(appId));
|
registerRoamTools((appId) => this.launchApp(appId));
|
||||||
// apps.* tools mirror the launcher grid and sidebar (launch, focus, close).
|
// apps.* tools mirror the launcher grid and sidebar (launch, focus, close).
|
||||||
registerWindowTools({
|
registerWindowTools({
|
||||||
apps: LAUNCHABLE_APPS,
|
apps: launchableApps,
|
||||||
launchApp: (appId) => this.launchApp(appId),
|
launchApp: (appId) => this.launchApp(appId),
|
||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
});
|
});
|
||||||
@@ -449,8 +453,11 @@ class DashboardController {
|
|||||||
this.emit();
|
this.emit();
|
||||||
},
|
},
|
||||||
openNotificationsWindow: () =>
|
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(),
|
onSwitcherBarHeightChanged: () => this.applySwitcherBarHeight(),
|
||||||
|
onWindowLayoutChanged: () => this.applySwitcherBarHeight(),
|
||||||
|
isLocked: () => this.glassesLocked,
|
||||||
onScreenStateChanged: (on) => {
|
onScreenStateChanged: (on) => {
|
||||||
// Any wake of the regular UI replaces a showing Glanceboard.
|
// Any wake of the regular UI replaces a showing Glanceboard.
|
||||||
if (on) this.glance.dismiss();
|
if (on) this.glance.dismiss();
|
||||||
@@ -476,13 +483,16 @@ class DashboardController {
|
|||||||
// Apply a firmware-debug-flags toggle live while connected (Java dedups).
|
// Apply a firmware-debug-flags toggle live while connected (Java dedups).
|
||||||
this.pushFirmwareDebugFlags();
|
this.pushFirmwareDebugFlags();
|
||||||
this.pushBrightness();
|
this.pushBrightness();
|
||||||
|
this.pushHeadUpPreferences();
|
||||||
this.syncEvenHubScreenOffSetting();
|
this.syncEvenHubScreenOffSetting();
|
||||||
|
this.syncVoiceWake();
|
||||||
// Display mode size first: a reflow repositions every surface too, so
|
// Display mode size first: a reflow repositions every surface too, so
|
||||||
// the band-position check after it then has nothing left to do.
|
// the band-position check after it then has nothing left to do.
|
||||||
this.applyDisplayModeIfChanged();
|
this.applyDisplayModeIfChanged();
|
||||||
this.applyVerticalPositionIfChanged();
|
this.applyVerticalPositionIfChanged();
|
||||||
this.applyAppLayoutsIfChanged();
|
this.applyAppLayoutsIfChanged();
|
||||||
this.syncAssistantBridgeIfChanged();
|
this.syncAssistantBridgeIfChanged();
|
||||||
|
this.retargetContinuousCapture();
|
||||||
this.syncLockScreenSettingIfChanged();
|
this.syncLockScreenSettingIfChanged();
|
||||||
// A Preview color or scaling change should show on the mirror at once,
|
// A Preview color or scaling change should show on the mirror at once,
|
||||||
// not at the next composited frame (cheap: floor-limited, dedup'd on
|
// not at the next composited frame (cheap: floor-limited, dedup'd on
|
||||||
@@ -505,7 +515,7 @@ class DashboardController {
|
|||||||
assistant: text => shell.sendToAssistant(text),
|
assistant: text => shell.sendToAssistant(text),
|
||||||
});
|
});
|
||||||
this.wearRemote = new WearRemote({
|
this.wearRemote = new WearRemote({
|
||||||
apps: LAUNCHABLE_APPS,
|
apps: launchableApps,
|
||||||
injectInput: (kind) => this.injectSyntheticRingInput(kind, "watch"),
|
injectInput: (kind) => this.injectSyntheticRingInput(kind, "watch"),
|
||||||
launchApp: (appId) => this.launchApp(appId),
|
launchApp: (appId) => this.launchApp(appId),
|
||||||
connect: () => this.connect(),
|
connect: () => this.connect(),
|
||||||
@@ -618,14 +628,28 @@ class DashboardController {
|
|||||||
* are. Windows that can't resize keep the surface they have, the switcher
|
* 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
|
* covering any of it that it now overlaps, rather than being relaunched
|
||||||
* for it.
|
* 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 {
|
private applySwitcherBarHeight(): void {
|
||||||
void (async () => {
|
void (async () => {
|
||||||
for (const window of Array.from(shell.getWindows())) {
|
for (const window of Array.from(shell.getWindows())) {
|
||||||
const rect = JSON.stringify(appViewportRect(window.heightMode, window.appId));
|
if (!window.relayout) continue;
|
||||||
if (!window.relayout || this.windowSurfaceRects.get(window.surfaceId) === rect) 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();
|
window.relayout();
|
||||||
await this.configureWindowSurface(window.surfaceId, this.isForegroundWindow(window.windowId), window.heightMode);
|
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();
|
shell.foregroundWindow()?.requestRender();
|
||||||
this.requestShellRender();
|
this.requestShellRender();
|
||||||
@@ -816,8 +840,8 @@ class DashboardController {
|
|||||||
await communicator.configureSurface(LOCK_SCREEN_SURFACE_ID, {
|
await communicator.configureSurface(LOCK_SCREEN_SURFACE_ID, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: G2_LENS_WIDTH,
|
width: screenWidth(),
|
||||||
height: G2_LENS_HEIGHT,
|
height: screenHeight(),
|
||||||
zOrder: 1000,
|
zOrder: 1000,
|
||||||
transparency: "opaque",
|
transparency: "opaque",
|
||||||
});
|
});
|
||||||
@@ -925,6 +949,24 @@ class DashboardController {
|
|||||||
return applied;
|
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 {
|
private syncEvenHubScreenOffSetting(): void {
|
||||||
void this.syncFaceclawWakeLease().catch((error) => {
|
void this.syncFaceclawWakeLease().catch((error) => {
|
||||||
this.appendLog(`wake takeover lease sync failed: ${this.formatError(error)}`);
|
this.appendLog(`wake takeover lease sync failed: ${this.formatError(error)}`);
|
||||||
@@ -1042,9 +1084,11 @@ class DashboardController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A Direct-mode session may have unpaired the R1 from the glasses (see
|
* A Direct-mode session may have unpaired the R1 from the glasses (see
|
||||||
* GlassesSessionRing.releaseRingFromGlassesLocked). The first session in
|
* GlassesSessionRing.releaseRingFromGlassesLocked), and a RayNeo iO
|
||||||
* another mode asks the glasses to connect to it again; the ring's own
|
* session (always Direct) may have cleared the ring's glasses targets.
|
||||||
* glasses targets were cleared, so it accepts them. Called on connect.
|
* 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 {
|
private handRingBackToGlassesIfNeeded(): void {
|
||||||
if (this.ringModeAtConnect === "direct" || !getBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false)) return;
|
if (this.ringModeAtConnect === "direct" || !getBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false)) return;
|
||||||
@@ -1084,6 +1128,19 @@ class DashboardController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private pushHeadUpPreferences(force = false): void {
|
||||||
|
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 });
|
||||||
|
if (!force && value === this.lastPushedHeadUp) return;
|
||||||
|
this.lastPushedHeadUp = value;
|
||||||
|
void this.communicator.configureHeadUpWake(enabled, angle).catch(error => {
|
||||||
|
this.lastPushedHeadUp = null;
|
||||||
|
this.appendLog(`head-up configuration failed: ${this.formatError(error)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Save the occupied part of the composited screen as a 4-bit grayscale PNG. */
|
/** Save the occupied part of the composited screen as a 4-bit grayscale PNG. */
|
||||||
saveScreenshot(): string {
|
saveScreenshot(): string {
|
||||||
const path = this.display?.saveScreenshot(shell.screenshotCropRect()) ?? "";
|
const path = this.display?.saveScreenshot(shell.screenshotCropRect()) ?? "";
|
||||||
@@ -1142,6 +1199,7 @@ class DashboardController {
|
|||||||
status: this.status,
|
status: this.status,
|
||||||
displayPreview: this.displayPreview,
|
displayPreview: this.displayPreview,
|
||||||
displayPreviewMessage: this.displayPreviewMessage(),
|
displayPreviewMessage: this.displayPreviewMessage(),
|
||||||
|
silentModeFeedback: this.silentModeFeedback,
|
||||||
activeTextSettingId: primaryTextSetting?.id ?? null,
|
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||||
activeTextEditorTitle: this.activeTextEditorTitle,
|
activeTextEditorTitle: this.activeTextEditorTitle,
|
||||||
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
|
activeTextSettingTitle: primaryTextSetting?.editorTitle ?? "",
|
||||||
@@ -1181,6 +1239,43 @@ class DashboardController {
|
|||||||
* charging and silent mode both make the display unavailable while BLE stays
|
* charging and silent mode both make the display unavailable while BLE stays
|
||||||
* up, and a battery that just ran out simply stops answering.
|
* up, and a battery that just ran out simply stops answering.
|
||||||
*/
|
*/
|
||||||
|
private handleSilentMode(silent: boolean): void {
|
||||||
|
if (this.silentMode === silent) return;
|
||||||
|
this.silentMode = silent;
|
||||||
|
const generation = ++this.silentModeFeedbackGeneration;
|
||||||
|
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||||
|
this.silentModeFeedbackTimer = null;
|
||||||
|
this.silentModeFeedback = silent
|
||||||
|
? "Silent mode enabled — hold both touchpads to exit"
|
||||||
|
: "Silent mode disabled";
|
||||||
|
if (!silent) {
|
||||||
|
void this.showSilentModeExit(generation).catch(error => {
|
||||||
|
this.appendLog(`silent-mode exit feedback failed: ${this.formatError(error)}`);
|
||||||
|
});
|
||||||
|
this.silentModeFeedbackTimer = setTimeout(() => {
|
||||||
|
this.silentModeFeedbackTimer = null;
|
||||||
|
this.silentModeFeedback = "";
|
||||||
|
this.emit();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
this.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async showSilentModeExit(generation: number): Promise<void> {
|
||||||
|
if (this.phase !== "connected" || this.silentMode || this.glassesLocked) return;
|
||||||
|
// The firmware powered the lenses down, and Faceclaw may have gone to
|
||||||
|
// sleep/suspended EvenHub meanwhile. Reusing the ordinary wake barrier is
|
||||||
|
// essential: rendering an alert into the retained surface alone is invisible.
|
||||||
|
this.cancelEvenHubSuspendTimer();
|
||||||
|
shell.wake("sidebar");
|
||||||
|
const ready = await this.ensureEvenHubSessionActive();
|
||||||
|
if (!ready || generation !== this.silentModeFeedbackGeneration || this.silentMode ||
|
||||||
|
this.phase !== "connected" || this.glassesLocked) return;
|
||||||
|
shell.showAlert("Silent mode disabled");
|
||||||
|
shell.foregroundWindow()?.requestRender();
|
||||||
|
this.requestShellRender();
|
||||||
|
}
|
||||||
|
|
||||||
private displayPreviewMessage(): string {
|
private displayPreviewMessage(): string {
|
||||||
if (this.phase === "charging") {
|
if (this.phase === "charging") {
|
||||||
return chargingPreviewMessage(this.glassesDisplayState());
|
return chargingPreviewMessage(this.glassesDisplayState());
|
||||||
@@ -1232,6 +1327,7 @@ class DashboardController {
|
|||||||
silentMode: this.silentMode,
|
silentMode: this.silentMode,
|
||||||
screenOn: shell.isScreenOn(),
|
screenOn: shell.isScreenOn(),
|
||||||
battery: this.lastHeadsetBattery,
|
battery: this.lastHeadsetBattery,
|
||||||
|
glassesModel: glassesModelName(),
|
||||||
caseBattery: batteries.case,
|
caseBattery: batteries.case,
|
||||||
caseCharging: batteries.caseCharging,
|
caseCharging: batteries.caseCharging,
|
||||||
foregroundTitle: shell.getForegroundApp()?.title ?? null,
|
foregroundTitle: shell.getForegroundApp()?.title ?? null,
|
||||||
@@ -1404,12 +1500,12 @@ class DashboardController {
|
|||||||
// is in place before any real render can reach the compositor.
|
// is in place before any real render can reach the compositor.
|
||||||
this.previewTarget = target;
|
this.previewTarget = target;
|
||||||
try {
|
try {
|
||||||
await target.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
|
await target.configureCompositorScreen(screenWidth(), screenHeight());
|
||||||
await target.configureSurface(SHELL_SURFACE_ID, {
|
await target.configureSurface(SHELL_SURFACE_ID, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: G2_LENS_WIDTH,
|
width: screenWidth(),
|
||||||
height: G2_LENS_HEIGHT,
|
height: screenHeight(),
|
||||||
zOrder: SHELL_SURFACE_Z_ORDER,
|
zOrder: SHELL_SURFACE_Z_ORDER,
|
||||||
transparency: "color-key",
|
transparency: "color-key",
|
||||||
});
|
});
|
||||||
@@ -1492,17 +1588,21 @@ class DashboardController {
|
|||||||
this.refreshEvenAppStatus();
|
this.refreshEvenAppStatus();
|
||||||
this.setPhase("connecting");
|
this.setPhase("connecting");
|
||||||
this.setStatus("Connecting to the glasses...");
|
this.setStatus("Connecting to the glasses...");
|
||||||
// "Only via glasses" (the default) means the phone never opens its own
|
// "Only via glasses" (the G2's default) means the phone never opens its
|
||||||
// link to the ring: the glasses relay its gestures to us anyway. An empty
|
// own link to the ring: the glasses relay its gestures to us anyway. An
|
||||||
// address disables every direct-ring code path in the communicator.
|
// empty address disables every direct-ring code path in the communicator.
|
||||||
const ringMode = ringConnectionModeSetting.get();
|
// 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;
|
this.ringModeAtConnect = ringMode;
|
||||||
|
const glassesType = glassesTypeSetting.get();
|
||||||
const ringAddress = ringMode !== "glasses" ? addresses.ring : "";
|
const ringAddress = ringMode !== "glasses" ? addresses.ring : "";
|
||||||
// Direct mode may unpair the ring from the glasses; remember to hand it
|
// Direct mode may unpair the ring from the glasses; remember to hand it
|
||||||
// back once a later session runs in another mode.
|
// back once a later session runs in another mode.
|
||||||
if (ringMode === "direct" && ringAddress) setBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, true);
|
if (ringMode === "direct" && ringAddress) setBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, true);
|
||||||
this.appendLog(
|
this.appendLog((glassesType === "rayneo-io"
|
||||||
`Using configured arms: R=${addresses.right} L=${addresses.left}${ringAddress ? ` ring=${ringAddress}` : ""}`,
|
? `Using configured RayNeo iO: ${addresses.right}`
|
||||||
|
: `Using configured arms: R=${addresses.right} L=${addresses.left}`) + (ringAddress ? ` ring=${ringAddress}` : ""),
|
||||||
);
|
);
|
||||||
|
|
||||||
let communicator: FaceclawCommunicatorBridge | null = null;
|
let communicator: FaceclawCommunicatorBridge | null = null;
|
||||||
@@ -1524,6 +1624,7 @@ class DashboardController {
|
|||||||
// sync needs the phone role, which the session borrows briefly for
|
// sync needs the phone role, which the session borrows briefly for
|
||||||
// each pull (GlassesSessionRing.beginRingHealthWindowLocked).
|
// each pull (GlassesSessionRing.beginRingHealthWindowLocked).
|
||||||
ringRole: ringMode === "direct" ? "glasses" : "phone",
|
ringRole: ringMode === "direct" ? "glasses" : "phone",
|
||||||
|
glassesType,
|
||||||
});
|
});
|
||||||
this.communicator = communicator;
|
this.communicator = communicator;
|
||||||
// Size the compositor before anything else is awaited: windows opened
|
// Size the compositor before anything else is awaited: windows opened
|
||||||
@@ -1531,8 +1632,12 @@ class DashboardController {
|
|||||||
// configure their surfaces through this.communicator, and the Java call
|
// configure their surfaces through this.communicator, and the Java call
|
||||||
// queue is FIFO, so enqueuing the screen size first guarantees it lands
|
// queue is FIFO, so enqueuing the screen size first guarantees it lands
|
||||||
// ahead of them. Mirrors ensurePreviewDisplay.
|
// 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());
|
await communicator.configureBrightness(getBrightnessPreferences());
|
||||||
|
this.pushHeadUpPreferences(true);
|
||||||
|
this.voiceWakeSent = null;
|
||||||
|
this.syncVoiceWake(communicator);
|
||||||
this.offState = communicator.onStateChange((state) => {
|
this.offState = communicator.onStateChange((state) => {
|
||||||
if (state.phase !== "connected") resetRingInputFilter();
|
if (state.phase !== "connected") resetRingInputFilter();
|
||||||
if (isHaltedSessionPhase(state.phase)) {
|
if (isHaltedSessionPhase(state.phase)) {
|
||||||
@@ -1570,6 +1675,7 @@ class DashboardController {
|
|||||||
// mode-7 control message once the dashboard container is warmed up.
|
// mode-7 control message once the dashboard container is warmed up.
|
||||||
this.pushFirmwareDebugFlags();
|
this.pushFirmwareDebugFlags();
|
||||||
this.pushBrightness(true);
|
this.pushBrightness(true);
|
||||||
|
this.pushHeadUpPreferences(true);
|
||||||
this.handRingBackToGlassesIfNeeded();
|
this.handRingBackToGlassesIfNeeded();
|
||||||
}
|
}
|
||||||
if (mappedPhase !== "connected" && mappedPhase !== "charging") {
|
if (mappedPhase !== "connected" && mappedPhase !== "charging") {
|
||||||
@@ -1604,9 +1710,7 @@ class DashboardController {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.offSilentMode = communicator.onSilentMode((silent) => {
|
this.offSilentMode = communicator.onSilentMode((silent) => {
|
||||||
if (this.silentMode === silent) return;
|
this.handleSilentMode(silent);
|
||||||
this.silentMode = silent;
|
|
||||||
this.emit();
|
|
||||||
});
|
});
|
||||||
this.offWearState = communicator.onWearState((wearing) => {
|
this.offWearState = communicator.onWearState((wearing) => {
|
||||||
this.handleWearState(wearing);
|
this.handleWearState(wearing);
|
||||||
@@ -1724,8 +1828,8 @@ class DashboardController {
|
|||||||
await communicator.configureSurface(SHELL_SURFACE_ID, {
|
await communicator.configureSurface(SHELL_SURFACE_ID, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
width: G2_LENS_WIDTH,
|
width: screenWidth(),
|
||||||
height: G2_LENS_HEIGHT,
|
height: screenHeight(),
|
||||||
zOrder: SHELL_SURFACE_Z_ORDER,
|
zOrder: SHELL_SURFACE_Z_ORDER,
|
||||||
transparency: "color-key",
|
transparency: "color-key",
|
||||||
});
|
});
|
||||||
@@ -2032,8 +2136,8 @@ class DashboardController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const at = mirrorToPanelFraction(this.displayPreviewCrop, nx, ny);
|
const at = mirrorToPanelFraction(this.displayPreviewCrop, nx, ny);
|
||||||
const x = Math.round(Math.min(1, Math.max(0, at.nx)) * G2_LENS_WIDTH);
|
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)) * G2_LENS_HEIGHT);
|
const y = Math.round(Math.min(1, Math.max(0, at.ny)) * screenHeight());
|
||||||
const foreground = shell.foregroundWindow();
|
const foreground = shell.foregroundWindow();
|
||||||
const stripShown = sidebarStripVisible(shell.getFocus(), foreground?.appId);
|
const stripShown = sidebarStripVisible(shell.getFocus(), foreground?.appId);
|
||||||
this.appendLog(`mirror tap at ${x},${y}`);
|
this.appendLog(`mirror tap at ${x},${y}`);
|
||||||
@@ -2197,16 +2301,16 @@ class DashboardController {
|
|||||||
private voiceCaptureOptions(communicator: FaceclawCommunicatorBridge | null) {
|
private voiceCaptureOptions(communicator: FaceclawCommunicatorBridge | null) {
|
||||||
// A window that needs its own provider and language sets them for every
|
// A window that needs its own provider and language sets them for every
|
||||||
// capture while it is open, so push-to-talk still shares its stream.
|
// capture while it is open, so push-to-talk still shares its stream.
|
||||||
// Otherwise only Whisper server is told a language (its own setting).
|
// Otherwise use the shared transcription-language preference.
|
||||||
const choice = this.transcriptionChoice();
|
const choice = this.transcriptionChoice();
|
||||||
const provider = choice?.provider ?? voiceProviderSetting.get();
|
const provider = choice?.provider ?? voiceProviderSetting.get();
|
||||||
return {
|
return {
|
||||||
communicator: communicator?.getNativeCommunicator() ?? null,
|
communicator: communicator?.getNativeCommunicator() ?? null,
|
||||||
usePhoneMic: communicator === null,
|
usePhoneMic: communicator === null,
|
||||||
provider,
|
provider,
|
||||||
language: choice ? choice.language : provider === "whisper-server" ? whisperServerLanguageSetting.get() : "",
|
language: choice ? choice.language : getVoiceTranscriptionLanguage(provider),
|
||||||
elevenLabsApiKey: elevenLabsApiKeySetting.get(),
|
elevenLabsApiKey: elevenLabsApiKeySetting.get(),
|
||||||
openAiApiKey: openAiApiKeySetting.get(),
|
openAiApiKey: openAiApiKeySetting.get(), openAiTranscriptionModel: openAiTranscriptionModelSetting.get(),
|
||||||
sonioxApiKey: sonioxApiKeySetting.get(),
|
sonioxApiKey: sonioxApiKeySetting.get(),
|
||||||
whisperServerUrl: whisperServerUrlSetting.get(),
|
whisperServerUrl: whisperServerUrlSetting.get(),
|
||||||
whisperServerModel: whisperServerModelSetting.get(),
|
whisperServerModel: whisperServerModelSetting.get(),
|
||||||
@@ -2601,11 +2705,7 @@ class DashboardController {
|
|||||||
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
|
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
|
||||||
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
|
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
|
||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
openSettings: (section) => {
|
openSettings: (section) => this.openSettings(section),
|
||||||
void this.launchApp("settings", { section }).catch((error) => {
|
|
||||||
this.appendLog(`settings launch failed: ${this.formatError(error)}`);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
startTextSettingEdit: (settingId) => {
|
startTextSettingEdit: (settingId) => {
|
||||||
const setting = getStringSettingById(settingId);
|
const setting = getStringSettingById(settingId);
|
||||||
if (setting) {
|
if (setting) {
|
||||||
@@ -2689,6 +2789,13 @@ class DashboardController {
|
|||||||
this.requestShellRender();
|
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
|
* 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
|
* Settings item, and open-apps restore all come through here. Apps with an
|
||||||
@@ -2905,7 +3012,7 @@ class DashboardController {
|
|||||||
// The tray shows the notification at once; its popup waits out a short
|
// The tray shows the notification at once; its popup waits out a short
|
||||||
// delay, so one withdrawn right away (see NotificationPopupDelay) never shows.
|
// delay, so one withdrawn right away (see NotificationPopupDelay) never shows.
|
||||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
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.notificationPopups.post(notificationKey, notificationPopupDelayMs(notification));
|
||||||
}
|
}
|
||||||
this.requestShellRender();
|
this.requestShellRender();
|
||||||
@@ -2927,7 +3034,7 @@ class DashboardController {
|
|||||||
private popUpAndroidNotification(notificationKey: string): void {
|
private popUpAndroidNotification(notificationKey: string): void {
|
||||||
try {
|
try {
|
||||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
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
|
// 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.
|
// 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.
|
// Waking while already on would steal focus, so only wake from sleep.
|
||||||
@@ -2984,6 +3091,10 @@ class DashboardController {
|
|||||||
// Kept across "connecting": silent mode blocks app launches, so it can
|
// Kept across "connecting": silent mode blocks app launches, so it can
|
||||||
// itself cause the reconnect churn, and Java re-reports it either way.
|
// itself cause the reconnect churn, and Java re-reports it either way.
|
||||||
this.silentMode = false;
|
this.silentMode = false;
|
||||||
|
this.silentModeFeedbackGeneration++;
|
||||||
|
if (this.silentModeFeedbackTimer !== null) clearTimeout(this.silentModeFeedbackTimer);
|
||||||
|
this.silentModeFeedbackTimer = null;
|
||||||
|
this.silentModeFeedback = "";
|
||||||
}
|
}
|
||||||
this.emit();
|
this.emit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ export { bytesToHex, hexToBytes };
|
|||||||
/** Even Realities' manufacturer-data company identifier (`"ER"` read little-endian). */
|
/** Even Realities' manufacturer-data company identifier (`"ER"` read little-endian). */
|
||||||
export const EVEN_COMPANY_IDENTIFIER = 0x5245;
|
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. */
|
/** True when the manufacturer data opens with Even's `"ER"` marker. */
|
||||||
export function hasEvenManufacturerSignature(mfg: Uint8Array): boolean {
|
export function hasEvenManufacturerSignature(mfg: Uint8Array): boolean {
|
||||||
@@ -71,6 +74,61 @@ export function extractG2AdvertisementFlag(mfg: Uint8Array): number | null {
|
|||||||
return mfg[22]!;
|
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.
|
* Which side a G2 temple advertisement belongs to, from the local name.
|
||||||
* Null when the name carries neither or both markers.
|
* Null when the name carries neither or both markers.
|
||||||
@@ -210,6 +268,10 @@ export type EvenAdvertisement = {
|
|||||||
manufacturerData: string;
|
manufacturerData: string;
|
||||||
/** Why an otherwise Even-looking advertisement could not be fully parsed. */
|
/** Why an otherwise Even-looking advertisement could not be fully parsed. */
|
||||||
note: string | null;
|
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 hasSignature = hasEvenManufacturerSignature(mfg);
|
||||||
const looksLikeRing = /^EVEN R1([_ ]|$)/.test(upper);
|
const looksLikeRing = /^EVEN R1([_ ]|$)/.test(upper);
|
||||||
const looksLikeG2 = upper.includes("G2");
|
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 = {
|
const base = {
|
||||||
address: normalizeMacAddress(raw.address),
|
address: normalizeMacAddress(raw.address),
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ export function firmwareIncompatibilityMessage(info: FirmwareInfo): string | nul
|
|||||||
const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`;
|
const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`;
|
||||||
const required = `Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}`;
|
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) {
|
switch (extension.kind) {
|
||||||
case "faceclaw":
|
case "faceclaw":
|
||||||
if (extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION) return null;
|
if (extension.version >= REQUIRED_FACECLAW_FIRMWARE_VERSION) return null;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ export type GlassesDisplayState = {
|
|||||||
silentMode: boolean;
|
silentMode: boolean;
|
||||||
screenOn: boolean;
|
screenOn: boolean;
|
||||||
battery: number | null;
|
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
|
* 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
|
* 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
|
// Charging wins over every session-local state: the glasses are in their
|
||||||
// case, so neither the lock screen nor the foreground window is visible.
|
// case, so neither the lock screen nor the foreground window is visible.
|
||||||
if (state.phase === "charging") {
|
if (state.phase === "charging") {
|
||||||
return chargingDisplayLabel(state.battery);
|
return chargingDisplayLabel(state.battery, state.glassesModel);
|
||||||
}
|
}
|
||||||
// Preview mode has a live (simulated) screen despite the disconnected
|
// Preview mode has a live (simulated) screen despite the disconnected
|
||||||
// phase, so fall through to the screen-state/foreground labels.
|
// 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 {
|
export function chargingDisplayLabel(battery: number | null, glassesModel: string): string {
|
||||||
return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging";
|
return validBatteryLevel(battery) ? `Charging: ${glassesModel} ${battery}%` : "Charging";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The shell's last-known battery levels (ShellChromeState["battery"]), as far as the phone shows them. */
|
/** 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,
|
* 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
|
* 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
|
* 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
|
* are docked), so ⚡ appears only while it is live: the glasses and Case only
|
||||||
* link to the glasses (`glassesLinked`: connected or charging), and Case only
|
* with a link to the glasses (`glassesLinked`: connected or charging), and Case
|
||||||
* while they are docked (caseCharging is null otherwise).
|
* 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]> = [
|
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],
|
["Case", levels.case, glassesLinked && levels.caseCharging],
|
||||||
["R1", levels.ring, levels.ringCharging],
|
["R1", levels.ring, levels.ringCharging],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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'
|
import { hexToBytes } from '../util/hex-util'
|
||||||
|
|
||||||
export type IosAdvertisement = { identifier: string; name: string; manufacturerData: string; rssi: number; connectable: boolean }
|
export type IosAdvertisement = { identifier: string; name: string; manufacturerData: string; rssi: number; connectable: boolean }
|
||||||
export type IosDevice = EvenAdvertisement & { identifier: string }
|
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. */
|
/** Only a full vendor-advertised MAC may bind a manually entered address. */
|
||||||
export function identifyIosPeripheral(raw: IosAdvertisement): IosDevice | null {
|
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 (!/^[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
|
if (!hasEvenManufacturerSignature(hexToBytes(raw.manufacturerData))) return null
|
||||||
const candidate = classifyAdvertisement({ ...raw, address: '', source: 'scan', bonded: false,
|
const candidate = classifyAdvertisement({ ...raw, address: '', source: 'scan', bonded: false,
|
||||||
txPower: null, seenAtMs: Date.now() })
|
txPower: null, seenAtMs: Date.now() })
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { startRemoteInput } from "../remote/service"
|
|||||||
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
||||||
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
|
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
|
||||||
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup, readActiveNotifications } from '../native/notification-icons.ios'
|
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup, readActiveNotifications } from '../native/notification-icons.ios'
|
||||||
import { shouldShowNotificationOnGlasses } from '../native/notification-sources'
|
|
||||||
import { launcherEntries } from '../apps/launcher'
|
import { launcherEntries } from '../apps/launcher'
|
||||||
import { discardZeroedEvenHubPackage, getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
|
import { discardZeroedEvenHubPackage, getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
|
||||||
import { isInstalledPackagePresent } from '../apps/evenhub/updates'
|
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 { FaceclawCommunicatorBridge, resolveIosPeripherals, type CommunicatorState, type RawInputEvent } from '../native/faceclaw-communicator.ios'
|
||||||
import { PreviewDisplayTarget, type DisplayTarget } from '../native/preview-display.ios'
|
import { PreviewDisplayTarget, type DisplayTarget } from '../native/preview-display.ios'
|
||||||
import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client'
|
import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client'
|
||||||
|
import { G1V0_IMAGE } from '../g1/firmware/g1v0-image'
|
||||||
import { GlanceHost, type GlanceDisplay } from './glance-host'
|
import { GlanceHost, type GlanceDisplay } from './glance-host'
|
||||||
import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from './lock-screen'
|
import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from './lock-screen'
|
||||||
import { OsEventTypeList } from './events'
|
import { OsEventTypeList } from './events'
|
||||||
@@ -52,8 +52,8 @@ import { mirrorToPanelFraction, phonePreviewCrop } from './phone-preview-crop'
|
|||||||
import { onAnySettingChanged,
|
import { onAnySettingChanged,
|
||||||
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
|
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
|
||||||
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
|
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
|
||||||
openAiApiKeySetting, sonioxApiKeySetting, whisperServerApiKeySetting, whisperServerLanguageSetting,
|
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 { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
|
||||||
import type { PhoneGesture } from '../phone-ui/phone-gestures'
|
import type { PhoneGesture } from '../phone-ui/phone-gestures'
|
||||||
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
|
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
|
||||||
@@ -215,12 +215,19 @@ export class IosPreviewController {
|
|||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
onWindowsChanged: () => { this.requestShellRender(); this.syncEvenHubPhoneUi(); this.wearRemote?.schedulePublish() },
|
onWindowsChanged: () => { this.requestShellRender(); this.syncEvenHubPhoneUi(); this.wearRemote?.schedulePublish() },
|
||||||
openNotificationsWindow: () =>
|
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: () => {
|
onSwitcherBarHeightChanged: () => {
|
||||||
this.relayout()
|
this.relayout()
|
||||||
shell.foregroundWindow()?.requestRender()
|
shell.foregroundWindow()?.requestRender()
|
||||||
this.requestShellRender()
|
this.requestShellRender()
|
||||||
},
|
},
|
||||||
|
onWindowLayoutChanged: () => {
|
||||||
|
this.relayout()
|
||||||
|
shell.foregroundWindow()?.requestRender()
|
||||||
|
this.requestShellRender()
|
||||||
|
},
|
||||||
|
isLocked: () => this.glassesLocked,
|
||||||
onScreenStateChanged: on => {
|
onScreenStateChanged: on => {
|
||||||
if (on) this.glance.dismiss()
|
if (on) this.glance.dismiss()
|
||||||
// A wake unblanks only once the next shell render has staged an awake
|
// A wake unblanks only once the next shell render has staged an awake
|
||||||
@@ -247,7 +254,7 @@ export class IosPreviewController {
|
|||||||
shell.focusWindow(launcher.windowId)
|
shell.focusWindow(launcher.windowId)
|
||||||
onIosNotificationPopup(key => {
|
onIosNotificationPopup(key => {
|
||||||
const notification = readActiveNotifications(128).find(n => n.key === 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')
|
const woke = !shell.isScreenOn() && shell.wake('sidebar')
|
||||||
shell.openNotificationModal(key, woke)
|
shell.openNotificationModal(key, woke)
|
||||||
this.requestShellRender()
|
this.requestShellRender()
|
||||||
@@ -272,7 +279,7 @@ export class IosPreviewController {
|
|||||||
// The header's EvenHub phone-UI button hides while that UI is showing.
|
// The header's EvenHub phone-UI button hides while that UI is showing.
|
||||||
onPhoneShownChanged(() => this.syncEvenHubPhoneUi())
|
onPhoneShownChanged(() => this.syncEvenHubPhoneUi())
|
||||||
registerSystemTools()
|
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() })
|
launchApp: id => this.launchApp(id), requestShellRender: () => this.requestShellRender() })
|
||||||
registerNavigateTools(id => this.launchApp(id))
|
registerNavigateTools(id => this.launchApp(id))
|
||||||
registerRoamTools(id => this.launchApp(id))
|
registerRoamTools(id => this.launchApp(id))
|
||||||
@@ -280,7 +287,7 @@ export class IosPreviewController {
|
|||||||
iosVoiceInput.onSpeechEnd(() => this.syncContinuousCapture())
|
iosVoiceInput.onSpeechEnd(() => this.syncContinuousCapture())
|
||||||
for (const app of ALL_APPS) if (app.appId !== 'launcher' && !iosAppUnavailableReason(app.appId)) app.boot?.(this.buildAppContext(app))
|
for (const app of ALL_APPS) if (app.appId !== 'launcher' && !iosAppUnavailableReason(app.appId)) app.boot?.(this.buildAppContext(app))
|
||||||
this.wearRemote = new WearRemote({
|
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),
|
injectInput: kind => this.injectWatchInput(kind),
|
||||||
launchApp: id => this.launchApp(id),
|
launchApp: id => this.launchApp(id),
|
||||||
// The watch's Connect/Disconnect are explicit user choices, like the phone's own buttons.
|
// The watch's Connect/Disconnect are explicit user choices, like the phone's own buttons.
|
||||||
@@ -416,6 +423,7 @@ export class IosPreviewController {
|
|||||||
const phone = readPhoneBatteryState()
|
const phone = readPhoneBatteryState()
|
||||||
this.logBluetooth(`Phone battery ${phone.battery ?? "unknown"}% charging=${phone.charging}`)
|
this.logBluetooth(`Phone battery ${phone.battery ?? "unknown"}% charging=${phone.charging}`)
|
||||||
this.offSettings = onAnySettingChanged(() => {
|
this.offSettings = onAnySettingChanged(() => {
|
||||||
|
this.syncContinuousCapture()
|
||||||
this.syncLockSetting()
|
this.syncLockSetting()
|
||||||
this.pushBrightness()
|
this.pushBrightness()
|
||||||
this.relayout()
|
this.relayout()
|
||||||
@@ -801,7 +809,7 @@ export class IosPreviewController {
|
|||||||
const display = this.display
|
const display = this.display
|
||||||
if (!display) return
|
if (!display) return
|
||||||
await display.configureSurface(id, { ...appViewportRect(heightMode, appId), zOrder: 0, transparency: 'opaque' })
|
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),
|
setSurfaceVisible: (id, visible) => this.setWindowSurfaceVisible(id, visible),
|
||||||
removeSurface: id => this.removeWindowSurface(id),
|
removeSurface: id => this.removeWindowSurface(id),
|
||||||
@@ -880,7 +888,7 @@ export class IosPreviewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.communicator) await this.closeCommunicator()
|
if (this.communicator) await this.closeCommunicator()
|
||||||
const communicator = new FaceclawCommunicatorBridge(identifiers)
|
const communicator = new FaceclawCommunicatorBridge({ ...identifiers, glassesType: glassesTypeSetting.get() })
|
||||||
this.teardownPreviewDisplay()
|
this.teardownPreviewDisplay()
|
||||||
this.communicator = communicator
|
this.communicator = communicator
|
||||||
this.wearDetectionRequested = false
|
this.wearDetectionRequested = false
|
||||||
@@ -984,6 +992,8 @@ export class IosPreviewController {
|
|||||||
// (or re-pairs / installs the custom firmware, which lift the suppression).
|
// (or re-pairs / installs the custom firmware, which lift the suppression).
|
||||||
if (isHaltedSessionPhase(state.phase)) suppressAutoReconnect()
|
if (isHaltedSessionPhase(state.phase)) suppressAutoReconnect()
|
||||||
const phase: SessionPhase = state.phase === 'charging' ? 'connected' : isHaltedSessionPhase(state.phase) ? 'error' : state.phase
|
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.
|
// Wear state is a per-transport snapshot: ask again on every new session.
|
||||||
if (phase !== 'connected') this.wearDetectionRequested = false
|
if (phase !== 'connected') this.wearDetectionRequested = false
|
||||||
this.update(phase, state.status)
|
this.update(phase, state.status)
|
||||||
@@ -1027,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.`)
|
if (this.state.capabilities) notifications.stop(`Update glasses to Faceclaw firmware ${ANCS_FIRMWARE_VERSION} or newer for iPhone notifications.`)
|
||||||
return
|
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
|
if (notifications.state !== 'disconnected') return
|
||||||
notifications.start((Date.now() ^ Math.floor(Math.random() * 0xffffffff)) >>> 0, communicator.rightWriteLimit())
|
notifications.start((Date.now() ^ Math.floor(Math.random() * 0xffffffff)) >>> 0, communicator.rightWriteLimit())
|
||||||
}
|
}
|
||||||
@@ -1198,14 +1213,13 @@ export class IosPreviewController {
|
|||||||
/**
|
/**
|
||||||
* The transcription provider setting and the keys the cloud ones need. A
|
* The transcription provider setting and the keys the cloud ones need. A
|
||||||
* window that needs its own provider and language (Translate) sets them for
|
* window that needs its own provider and language (Translate) sets them for
|
||||||
* every capture while it is open; otherwise only Whisper server is told a
|
* every capture while it is open; otherwise use the shared language preference.
|
||||||
* language (its own setting).
|
|
||||||
*/
|
*/
|
||||||
private voiceProvider(): VoiceProviderSelection {
|
private voiceProvider(): VoiceProviderSelection {
|
||||||
const choice = [...this.continuousClients.values()].find(options => options.transcription)?.transcription
|
const choice = [...this.continuousClients.values()].find(options => options.transcription)?.transcription
|
||||||
const provider = choice?.provider ?? voiceProviderSetting.get()
|
const provider = choice?.provider ?? voiceProviderSetting.get()
|
||||||
return { provider, language: choice ? choice.language : provider === 'whisper-server' ? whisperServerLanguageSetting.get() : '',
|
return { provider, language: choice ? choice.language : getVoiceTranscriptionLanguage(provider),
|
||||||
elevenLabsApiKey: elevenLabsApiKeySetting.get(), openAiApiKey: openAiApiKeySetting.get(), sonioxApiKey: sonioxApiKeySetting.get(),
|
elevenLabsApiKey: elevenLabsApiKeySetting.get(), openAiApiKey: openAiApiKeySetting.get(), openAiTranscriptionModel: openAiTranscriptionModelSetting.get(), sonioxApiKey: sonioxApiKeySetting.get(),
|
||||||
whisperServerUrl: whisperServerUrlSetting.get(), whisperServerModel: whisperServerModelSetting.get(),
|
whisperServerUrl: whisperServerUrlSetting.get(), whisperServerModel: whisperServerModelSetting.get(),
|
||||||
whisperServerApiKey: whisperServerApiKeySetting.get() }
|
whisperServerApiKey: whisperServerApiKeySetting.get() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 { getDefaultMediumFont } from "../graphics/ui-fonts";
|
||||||
import { wrapText } from "../graphics/textwrap";
|
import { wrapText } from "../graphics/textwrap";
|
||||||
|
|
||||||
export const LOCK_SCREEN_SURFACE_ID = "lock-screen";
|
export const LOCK_SCREEN_SURFACE_ID = "lock-screen";
|
||||||
const LOCK_SCREEN_MESSAGE = "Glasses locked; unlock the phone to unlock the glasses.";
|
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 {
|
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 font = getDefaultMediumFont();
|
||||||
const boxWidth = 480;
|
const boxWidth = 480;
|
||||||
const boxHeight = 150;
|
const boxHeight = 150;
|
||||||
const boxX = Math.round((G2_LENS_WIDTH - boxWidth) / 2);
|
const boxX = Math.round((width - boxWidth) / 2);
|
||||||
const boxY = Math.round((G2_LENS_HEIGHT - boxHeight) / 2);
|
const boxY = Math.round((height - boxHeight) / 2);
|
||||||
image.drawRoundedRect(boxX, boxY, boxWidth, boxHeight, 150, 12);
|
image.drawRoundedRect(boxX, boxY, boxWidth, boxHeight, 150, 12);
|
||||||
const lines = wrapText(font, LOCK_SCREEN_MESSAGE, boxWidth - 64);
|
const lines = wrapText(font, LOCK_SCREEN_MESSAGE, boxWidth - 64);
|
||||||
const textHeight = lines.length * font.lineHeight;
|
const textHeight = lines.length * font.lineHeight;
|
||||||
const firstY = boxY + Math.round((boxHeight - textHeight) / 2);
|
const firstY = boxY + Math.round((boxHeight - textHeight) / 2);
|
||||||
lines.forEach((line, index) => {
|
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);
|
image.drawText(font, x, firstY + index * font.lineHeight, line, 230);
|
||||||
});
|
});
|
||||||
return image;
|
return image;
|
||||||
|
|||||||
+104
-10
@@ -16,12 +16,11 @@ import {
|
|||||||
RING_CALIBRATION,
|
RING_CALIBRATION,
|
||||||
sortedByProximity,
|
sortedByProximity,
|
||||||
zoneGlyph,
|
zoneGlyph,
|
||||||
zoneLabel,
|
|
||||||
type ProximityEstimate,
|
type ProximityEstimate,
|
||||||
type ProximityZone,
|
type ProximityZone,
|
||||||
} from "./ble-proximity";
|
} from "./ble-proximity";
|
||||||
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type RawAdvertisement } from "./even-advertisement";
|
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type G1Firmware, type RawAdvertisement } from "./even-advertisement";
|
||||||
import { glassesImagePath, R1_IMAGE_PATH } from "./glasses-artwork";
|
import { GENERIC_G2_IMAGE_PATH, glassesImagePath, R1_IMAGE_PATH } from "./glasses-artwork";
|
||||||
import {
|
import {
|
||||||
colorwayDisplayName,
|
colorwayDisplayName,
|
||||||
colorwaySwatchHex,
|
colorwaySwatchHex,
|
||||||
@@ -48,6 +47,8 @@ export type GlassesPairCandidate = {
|
|||||||
rssi: number | null;
|
rssi: number | null;
|
||||||
proximity: ProximityEstimate | null;
|
proximity: ProximityEstimate | null;
|
||||||
lastSeenMs: number;
|
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
|
* 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.
|
* serials — the mixed-pair situation the serial check exists to name.
|
||||||
@@ -56,6 +57,15 @@ export type GlassesPairCandidate = {
|
|||||||
mismatchWarning: string | null;
|
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 = {
|
export type RingCandidate = {
|
||||||
id: string;
|
id: string;
|
||||||
advertisement: EvenAdvertisement;
|
advertisement: EvenAdvertisement;
|
||||||
@@ -176,9 +186,10 @@ export class DiscoveryAggregator {
|
|||||||
pairs(): GlassesPairCandidate[] {
|
pairs(): GlassesPairCandidate[] {
|
||||||
const groups = new Map<string, { left: (EvenAdvertisement & { smoothedRssi: number | null }) | null; right: (EvenAdvertisement & { smoothedRssi: number | null }) | null }>();
|
const groups = new Map<string, { left: (EvenAdvertisement & { smoothedRssi: number | null }) | null; right: (EvenAdvertisement & { smoothedRssi: number | null }) | null }>();
|
||||||
for (const record of this.byAddress.values()) {
|
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 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 group = groups.get(key) ?? { left: null, right: null };
|
||||||
const slot = record.role === "left" ? "left" : "right";
|
const slot = record.role === "left" ? "left" : "right";
|
||||||
const incumbent = group[slot];
|
const incumbent = group[slot];
|
||||||
@@ -199,7 +210,9 @@ export class DiscoveryAggregator {
|
|||||||
pairs.push({
|
pairs.push({
|
||||||
id: serialKey(serial) ?? `arm:${any.address}`,
|
id: serialKey(serial) ?? `arm:${any.address}`,
|
||||||
serial,
|
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,
|
left: left ? stripSmoothing(left) : null,
|
||||||
right: right ? stripSmoothing(right) : null,
|
right: right ? stripSmoothing(right) : null,
|
||||||
completeness: left && right ? "complete" : left ? "left-only" : "right-only",
|
completeness: left && right ? "complete" : left ? "left-only" : "right-only",
|
||||||
@@ -225,6 +238,22 @@ export class DiscoveryAggregator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Every R1 ring seen, closest first. */
|
/** 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[] {
|
rings(): RingCandidate[] {
|
||||||
const rings: RingCandidate[] = [];
|
const rings: RingCandidate[] = [];
|
||||||
for (const record of this.byAddress.values()) {
|
for (const record of this.byAddress.values()) {
|
||||||
@@ -281,7 +310,7 @@ export function isPreviouslyPaired(name: string | null | undefined, pairedSerial
|
|||||||
|
|
||||||
export type PairingRowPresentation = {
|
export type PairingRowPresentation = {
|
||||||
id: string;
|
id: string;
|
||||||
kind: "glasses" | "ring";
|
kind: "glasses" | "ring" | "rayneo-io";
|
||||||
/** "Even G2 B" / "Even R1" / fallback product name. */
|
/** "Even G2 B" / "Even R1" / fallback product name. */
|
||||||
modelTitle: string;
|
modelTitle: string;
|
||||||
/** The serial (glasses) or local name (ring). */
|
/** The serial (glasses) or local name (ring). */
|
||||||
@@ -299,7 +328,6 @@ export type PairingRowPresentation = {
|
|||||||
isPreviouslyPaired: boolean;
|
isPreviouslyPaired: boolean;
|
||||||
/** "Yours" / "Closest" / "". */
|
/** "Yours" / "Closest" / "". */
|
||||||
badge: string;
|
badge: string;
|
||||||
proximitySummary: string;
|
|
||||||
proximityGlyph: string;
|
proximityGlyph: string;
|
||||||
zone: ProximityZone | null;
|
zone: ProximityZone | null;
|
||||||
/** "Left + right arms found", "Only the left arm has been seen", …; "" when there is nothing worth a line (an unbonded ring). */
|
/** "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,
|
isNearest: boolean,
|
||||||
isPaired: boolean,
|
isPaired: boolean,
|
||||||
warnings: readonly string[],
|
warnings: readonly string[],
|
||||||
): Pick<PairingRowPresentation, "isNearest" | "isPreviouslyPaired" | "badge" | "proximitySummary" | "proximityGlyph" | "zone" | "warning"> {
|
): Pick<PairingRowPresentation, "isNearest" | "isPreviouslyPaired" | "badge" | "proximityGlyph" | "zone" | "warning"> {
|
||||||
return {
|
return {
|
||||||
isNearest,
|
isNearest,
|
||||||
isPreviouslyPaired: isPaired,
|
isPreviouslyPaired: isPaired,
|
||||||
badge: isPaired ? "Yours" : isNearest ? "Closest" : "",
|
badge: isPaired ? "Yours" : isNearest ? "Closest" : "",
|
||||||
proximitySummary: proximity ? zoneLabel(proximity.zone) : "Signal unknown",
|
|
||||||
proximityGlyph: proximity ? zoneGlyph(proximity.zone) : "○○○○",
|
proximityGlyph: proximity ? zoneGlyph(proximity.zone) : "○○○○",
|
||||||
zone: proximity?.zone ?? null,
|
zone: proximity?.zone ?? null,
|
||||||
warning: warnings.join(" "),
|
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}.`;
|
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 {
|
export function glassesRow(pair: GlassesPairCandidate, context: RowContext = {}): PairingRowPresentation {
|
||||||
|
if (pair.g1Firmware) return g1Row(pair, context);
|
||||||
const identity = pair.identity;
|
const identity = pair.identity;
|
||||||
const imagePath = glassesImagePath(identity);
|
const imagePath = glassesImagePath(identity);
|
||||||
const isPreviouslyPairedRow = isPreviouslyPaired(pair.serial, context.pairedSerial);
|
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. */
|
/** Convenience: a colourway's display text, for rows that show the swatch alone. */
|
||||||
export function colorwayLabel(colorway: GlassesColorway | null): string {
|
export function colorwayLabel(colorway: GlassesColorway | null): string {
|
||||||
return colorway ? colorwayDisplayName(colorway) : "";
|
return colorway ? colorwayDisplayName(colorway) : "";
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
|
|
||||||
import { previewScalingSetting } from "../ui/dashboard-settings";
|
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";
|
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;
|
if (locked || previewScalingSetting.get() === "raw") return null;
|
||||||
const window = shell.foregroundWindow();
|
const window = shell.foregroundWindow();
|
||||||
const crop = phonePreviewRect(glanceRect ?? usedScreenRect(window?.heightMode ?? "min", window?.appId));
|
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;
|
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 } {
|
export function mirrorToPanelFraction(crop: ScreenRect | null, nx: number, ny: number): { nx: number; ny: number } {
|
||||||
if (!crop) return { nx, ny };
|
if (!crop) return { nx, ny };
|
||||||
return {
|
return {
|
||||||
nx: (crop.x + nx * crop.width) / G2_LENS_WIDTH,
|
nx: (crop.x + nx * crop.width) / screenWidth(),
|
||||||
ny: (crop.y + ny * crop.height) / G2_LENS_HEIGHT,
|
ny: (crop.y + ny * crop.height) / screenHeight(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,7 @@ import { type AppDefinition } from "../apps/app-definition";
|
|||||||
import { getInstalledEvenHubApps, installedEvenHubAppId } from "../apps/evenhub/installed-apps";
|
import { getInstalledEvenHubApps, installedEvenHubAppId } from "../apps/evenhub/installed-apps";
|
||||||
import { WEAR_PATHS, wearBridge, type WearMessage } from "../native/wear-bridge";
|
import { WEAR_PATHS, wearBridge, type WearMessage } from "../native/wear-bridge";
|
||||||
import {
|
import {
|
||||||
|
glassesModelName,
|
||||||
onAnySettingChanged,
|
onAnySettingChanged,
|
||||||
watchCanUnlockSetting,
|
watchCanUnlockSetting,
|
||||||
watchCrownClockwiseNextSetting,
|
watchCrownClockwiseNextSetting,
|
||||||
@@ -115,8 +116,8 @@ const WATCH_BATTERY_MAX_AGE_MS = 4 * 60 * 60_000;
|
|||||||
|
|
||||||
/** What the dashboard controller lends the watch remote. */
|
/** What the dashboard controller lends the watch remote. */
|
||||||
export type WearRemoteHost = {
|
export type WearRemoteHost = {
|
||||||
/** The launcher-grid apps; installed EvenHub packages are added dynamically. */
|
/** The launcher-grid apps for the paired glasses; installed EvenHub packages are added dynamically. */
|
||||||
apps: readonly AppDefinition[];
|
apps: () => readonly AppDefinition[];
|
||||||
injectInput: (kind: WearRemoteInputKind) => Promise<void>;
|
injectInput: (kind: WearRemoteInputKind) => Promise<void>;
|
||||||
launchApp: (appId: string) => Promise<void>;
|
launchApp: (appId: string) => Promise<void>;
|
||||||
connect: () => Promise<void>;
|
connect: () => Promise<void>;
|
||||||
@@ -294,6 +295,7 @@ export class WearRemote {
|
|||||||
worn: state.glassesWorn,
|
worn: state.glassesWorn,
|
||||||
listening: voiceActivity.isActive(),
|
listening: voiceActivity.isActive(),
|
||||||
battery: state.lastHeadsetBattery,
|
battery: state.lastHeadsetBattery,
|
||||||
|
glassesModel: glassesModelName(),
|
||||||
charging: state.phase === "charging" || battery.headsetCharging === true,
|
charging: state.phase === "charging" || battery.headsetCharging === true,
|
||||||
caseBattery: battery.case,
|
caseBattery: battery.case,
|
||||||
caseCharging: battery.caseCharging,
|
caseCharging: battery.caseCharging,
|
||||||
@@ -320,7 +322,7 @@ export class WearRemote {
|
|||||||
|
|
||||||
/** Launchable apps, matching the launcher grid and the apps.launch tool. */
|
/** Launchable apps, matching the launcher grid and the apps.launch tool. */
|
||||||
private listApps(): Array<{ appId: string; title: string }> {
|
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()) {
|
for (const installed of getInstalledEvenHubApps()) {
|
||||||
apps.push({ appId: installedEvenHubAppId(installed.packageId), title: installed.name });
|
apps.push({ appId: installedEvenHubAppId(installed.packageId), title: installed.name });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
* - Text SIZING / KERNING / WRAPPING: @evenrealities/pretext, whose advance
|
* - Text SIZING / KERNING / WRAPPING: @evenrealities/pretext, whose advance
|
||||||
* tables the bitmaps were validated against. Using pretext for measurement
|
* tables the bitmaps were validated against. Using pretext for measurement
|
||||||
* means our line breaks match exactly where EvenHub apps (which measure
|
* 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
|
* 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
|
* 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 { getTextWidth } from "@evenrealities/pretext";
|
||||||
import { EVENHUB_RUNTIME_FONT_FILENAME, isEvenHubFontAsset } from "../g2/firmware-fonts";
|
import { EVENHUB_RUNTIME_FONT_FILENAME, isEvenHubFontAsset } from "../g2/firmware-fonts";
|
||||||
import { lvglMetrics, lvglGlyph } from "../native/lvgl-font";
|
import { lvglMetrics, lvglGlyph } from "../native/lvgl-font";
|
||||||
|
import { wrapLvglText } from "./lvgl-wrap";
|
||||||
import { GrayImage, grayToNibble, type FwTextFont, type PlacedFwText, type PlacedFwTextGlyph } from "./image";
|
import { GrayImage, grayToNibble, type FwTextFont, type PlacedFwText, type PlacedFwTextGlyph } from "./image";
|
||||||
import { TtfFont } from "./ttf-font";
|
import { TtfFont } from "./ttf-font";
|
||||||
import { decodeBase64 } from "../util/base64";
|
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
|
* Wrap text to a pixel width, returning the actual line strings: pretext's
|
||||||
* pretext's measureTextWrap (LVGL lv_text_get_next_line semantics) so the
|
* breaks, but keeping leading spaces after a '\n' (see lvgl-wrap.ts).
|
||||||
* breaks land exactly where the measurement library reports them.
|
|
||||||
*/
|
*/
|
||||||
wrap(text: string, maxWidth: number): string[] {
|
wrap(text: string, maxWidth: number): string[] {
|
||||||
if (!text) return [""];
|
return wrapLvglText(text, maxWidth, kernedAdvance);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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
@@ -4,8 +4,14 @@ import type { MenuHighlightAnimation } from "../ui/menu-highlight-motion";
|
|||||||
import { Glyph } from "./bdffont";
|
import { Glyph } from "./bdffont";
|
||||||
import { wrapText } from "./textwrap";
|
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_WIDTH = 640;
|
||||||
export const G2_LENS_HEIGHT = 480;
|
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;
|
const DEFAULT_CORNER_RADIUS = 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,9 +162,15 @@ export class GrayImage {
|
|||||||
private memoizedSourceHash: number | null = null;
|
private memoizedSourceHash: number | null = null;
|
||||||
|
|
||||||
constructor(width: number, height: number, fill = 0) {
|
constructor(width: number, height: number, fill = 0) {
|
||||||
this.width = width;
|
// A fractional width would put most rows' `y * width + x` between pixels,
|
||||||
this.height = height;
|
// silently losing them. TTF text measures fractionally, so this is easy to
|
||||||
this.pixels = new Uint8Array(width * height);
|
// 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) {
|
if (fill !== 0) {
|
||||||
this.clear(fill);
|
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):
|
* A copy of this image with its brightness scaled by `factor` (0..1):
|
||||||
* raster and glyph / firmware-text draws alike, keeping the draws deferred
|
* 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). */
|
/** Where rasterizeGlyph writes: an image, or a clipped buffer (paintReplayDraws). */
|
||||||
type PixelSink = { setPixel(x: number, y: number, value: number): void };
|
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). */
|
/** Bake one glyph into an image's pixel buffer (y is the top of the line). */
|
||||||
function rasterizeGlyph(
|
function rasterizeGlyph(
|
||||||
target: PixelSink,
|
target: PixelSink,
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import type { UiFont } from "./image";
|
|||||||
import { TtfFont } from "./ttf-font";
|
import { TtfFont } from "./ttf-font";
|
||||||
import { ensurePreinstalledFonts, getInstalledFont, installedFontPath } from "./installed-fonts";
|
import { ensurePreinstalledFonts, getInstalledFont, installedFontPath } from "./installed-fonts";
|
||||||
import { getStringSetting, onSettingsStoreChanged, setStringSetting } from "../native/settings-store";
|
import { getStringSetting, onSettingsStoreChanged, setStringSetting } from "../native/settings-store";
|
||||||
|
import { GLASSES_TYPE_KEY, isRayNeoIoConfigured } from "./screen-size";
|
||||||
|
|
||||||
export type BitmapFace = "terminus" | "terminusv";
|
export type BitmapFace = "terminus" | "terminusv";
|
||||||
|
|
||||||
@@ -72,8 +73,18 @@ export function parseFontSelection(raw: string): UiFontSelection | null {
|
|||||||
return 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 {
|
export function getUiFontSelection(): UiFontSelection {
|
||||||
const parsed = parseFontSelection(getStringSetting(UI_FONT_SELECTION_KEY, ""));
|
const parsed = parseFontSelection(getStringSetting(UI_FONT_SELECTION_KEY, ""));
|
||||||
@@ -84,7 +95,7 @@ export function getUiFontSelection(): UiFontSelection {
|
|||||||
if (legacy === "terminus" || legacy === "terminusv") {
|
if (legacy === "terminus" || legacy === "terminusv") {
|
||||||
return { kind: "bitmap", face: legacy };
|
return { kind: "bitmap", face: legacy };
|
||||||
}
|
}
|
||||||
return DEFAULT_UI_FONT;
|
return defaultUiFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setUiFontSelection(selection: UiFontSelection): void {
|
export function setUiFontSelection(selection: UiFontSelection): void {
|
||||||
@@ -113,7 +124,8 @@ export function fontSelectionLabel(selection: UiFontSelection): string {
|
|||||||
|
|
||||||
type UiFontRole = "small" | "medium" | "large";
|
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
|
* The three role fonts for one selection source, resolved lazily and cached
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { healthStore } from "./health-store-files";
|
||||||
|
import { isFixtureData } from "./health-seed";
|
||||||
|
import { healthExportEnabledSetting, healthExportUrlSetting, healthExportKeySetting } from "../ui/dashboard-settings";
|
||||||
|
import { getStringSetting, setStringSetting } from "../native/settings-store";
|
||||||
|
import { fetchTextWithUserAgent } from "../util/http";
|
||||||
|
|
||||||
|
let running = false;
|
||||||
|
let started = false;
|
||||||
|
let status = "Not synchronized";
|
||||||
|
export function healthExportStatus(): string { return status; }
|
||||||
|
|
||||||
|
/** One bounded batch, with durable acknowledgement and no overlapping requests. */
|
||||||
|
export async function syncHealthExport(): Promise<void> {
|
||||||
|
if (running) return;
|
||||||
|
running = true;
|
||||||
|
try {
|
||||||
|
if (!healthExportEnabledSetting.get()) { status = "Export disabled"; return; }
|
||||||
|
if (isFixtureData()) { status = "Sample data is never exported"; return; }
|
||||||
|
const url = healthExportUrlSetting.get();
|
||||||
|
const key = healthExportKeySetting.get();
|
||||||
|
if (!url || healthExportUrlSetting.validationError() || !key) {
|
||||||
|
status = "Configure an HTTPS endpoint and API key";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const generation = getStringSetting("health.export.generation", "0");
|
||||||
|
let held: { url?: string; generation?: string; offsets?: Record<string, number> } = {};
|
||||||
|
try { held = JSON.parse(getStringSetting("health.export.cursor", "{}")) ?? {}; } catch { /* First sync. */ }
|
||||||
|
const offsets = held.url === url && held.generation === generation ? held.offsets ?? {} : {};
|
||||||
|
let limit = 200;
|
||||||
|
let batch = healthStore().exportBatch(offsets, limit);
|
||||||
|
let body = JSON.stringify({ version: 1, samples: batch.samples, sleep: batch.sleep });
|
||||||
|
// Normalized records contain only ASCII keys, numbers and metric names.
|
||||||
|
// Large sleep histories must fit the server body limit as well as its record limit.
|
||||||
|
while (body.length > 240_000 && limit > 1) {
|
||||||
|
limit = Math.max(1, Math.floor(limit / 2));
|
||||||
|
batch = healthStore().exportBatch(offsets, limit);
|
||||||
|
body = JSON.stringify({ version: 1, samples: batch.samples, sleep: batch.sleep });
|
||||||
|
}
|
||||||
|
if (body.length > 240_000) { status = "A health record exceeds the export size limit"; return; }
|
||||||
|
if (!batch.scanned) { status = "Up to date"; return; }
|
||||||
|
if (batch.samples.length || batch.sleep.length) {
|
||||||
|
status = "Sending health data";
|
||||||
|
const response = await fetchTextWithUserAgent(url, {
|
||||||
|
method: "POST", headers: { "Authorization": `Bearer ${key}`, "Content-Type": "application/json" },
|
||||||
|
body,
|
||||||
|
timeoutMs: 30_000, dontFollowRedirects: true,
|
||||||
|
});
|
||||||
|
if (response.status !== 200) {
|
||||||
|
status = response.status === 401 || response.status === 403
|
||||||
|
? "API key refused; check configuration" : `Server refused batch (HTTP ${response.status}); will retry`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ack = await response.json<{ accepted?: boolean }>();
|
||||||
|
if (ack.accepted !== true) { status = "Invalid server acknowledgement; will retry"; return; }
|
||||||
|
}
|
||||||
|
// An edit during the request must not acknowledge data on a different destination.
|
||||||
|
if (url !== healthExportUrlSetting.get() || generation !== getStringSetting("health.export.generation", "0")) return;
|
||||||
|
setStringSetting("health.export.cursor", JSON.stringify({ url, generation, offsets: batch.cursor }));
|
||||||
|
status = "Batch synchronized; remaining history follows automatically";
|
||||||
|
} catch {
|
||||||
|
// Errors may include request headers or data: never log or display them.
|
||||||
|
status = "Synchronization failed; will retry automatically";
|
||||||
|
} finally { running = false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Android app process only; no extra BLE pulls, wake locks, or background service. */
|
||||||
|
export function startHealthExport(): void {
|
||||||
|
if (started) return;
|
||||||
|
started = true;
|
||||||
|
setTimeout(() => { void syncHealthExport(); }, 10_000);
|
||||||
|
setInterval(() => { void syncHealthExport(); }, 60_000);
|
||||||
|
}
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
HOUR_MS,
|
HOUR_MS,
|
||||||
|
HEART_RATE_MEASUREMENT_SPAN_MS,
|
||||||
TEN_MINUTES_MS,
|
TEN_MINUTES_MS,
|
||||||
type HealthSample,
|
type HealthSample,
|
||||||
type SleepSession,
|
type SleepSession,
|
||||||
@@ -65,6 +66,8 @@ export type WireHourlyRecord = {
|
|||||||
* zero bytes instead.
|
* zero bytes instead.
|
||||||
*/
|
*/
|
||||||
anchorMs: number | null;
|
anchorMs: number | null;
|
||||||
|
/** Latest reading, only from live pages; raw journal replay does not guess its clock. */
|
||||||
|
latest?: { timestampSeconds: number; value: number; receivedAtMs: number; clockOffsetMs: number };
|
||||||
groups: readonly { hourIndex: number; avg: number; max: number; min: number }[];
|
groups: readonly { hourIndex: number; avg: number; max: number; min: number }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,6 +149,22 @@ export function convertRecords(records: readonly WireRecord[]): ConversionResult
|
|||||||
* guesses. Dropping loses a page; guessing corrupts the history silently.
|
* guesses. Dropping loses a page; guessing corrupts the history silently.
|
||||||
*/
|
*/
|
||||||
function convertHourly(record: WireHourlyRecord, result: ConversionResult): void {
|
function convertHourly(record: WireHourlyRecord, result: ConversionResult): void {
|
||||||
|
if (record.metric === "heartRate" && record.latest) {
|
||||||
|
const { timestampSeconds, value, receivedAtMs, clockOffsetMs } = record.latest;
|
||||||
|
const startMs = timestampSeconds * 1000 - clockOffsetMs;
|
||||||
|
// Invert the existing handshake clock shift, never replace measurement time
|
||||||
|
// with reception time or snap it onto an invented ten-minute bucket.
|
||||||
|
// Older pages can mix clock domains: only accept a recent live reading.
|
||||||
|
if (Number.isSafeInteger(timestampSeconds) && Number.isSafeInteger(receivedAtMs)
|
||||||
|
&& Number.isFinite(clockOffsetMs) && Number.isInteger(value) && value > 0 && value <= 300
|
||||||
|
&& startMs >= 946684800000 && startMs <= receivedAtMs + 120_000
|
||||||
|
&& receivedAtMs - startMs <= 20 * 60_000) {
|
||||||
|
result.samples.push({ metric: "heartRate", startMs, spanMs: HEART_RATE_MEASUREMENT_SPAN_MS,
|
||||||
|
min: value, max: value, avg: value, total: value });
|
||||||
|
} else {
|
||||||
|
result.skipped.push({ what: "latest heart rate", why: "invalid, stale or unresolved measurement timestamp/value" });
|
||||||
|
}
|
||||||
|
}
|
||||||
if (record.anchorMs === null) {
|
if (record.anchorMs === null) {
|
||||||
result.skipped.push({
|
result.skipped.push({
|
||||||
what: `${record.metric} page, ${record.groups.length} groups`,
|
what: `${record.metric} page, ${record.groups.length} groups`,
|
||||||
|
|||||||
+17
-14
@@ -240,7 +240,7 @@ function accumulateStepBuckets(
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toWire(record: any): WireRecord | null {
|
function toWire(record: any, includeLatest: boolean): WireRecord | null {
|
||||||
const cmdHi = Number(record.cmdHi);
|
const cmdHi = Number(record.cmdHi);
|
||||||
|
|
||||||
const metric = HOURLY_METRIC[cmdHi];
|
const metric = HOURLY_METRIC[cmdHi];
|
||||||
@@ -256,7 +256,12 @@ function toWire(record: any): WireRecord | null {
|
|||||||
min: Number(group.min),
|
min: Number(group.min),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { kind: "hourly", metric, anchorMs: anchorToMs(Number(record.anchorUnixSeconds), true), groups };
|
const receivedAtMs = Number(record.receivedAtMs);
|
||||||
|
const latest = includeLatest && metric === "heartRate" && Number(record.tagRaw) > 0 ? {
|
||||||
|
timestampSeconds: Number(record.tagRaw), value: Number(record.current), receivedAtMs,
|
||||||
|
clockOffsetMs: ringClockOffsetMs(receivedAtMs),
|
||||||
|
} : undefined;
|
||||||
|
return { kind: "hourly", metric, anchorMs: anchorToMs(Number(record.anchorUnixSeconds), true), groups, latest };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmdHi === CMD_STEPS) {
|
if (cmdHi === CMD_STEPS) {
|
||||||
@@ -391,12 +396,12 @@ type StoreResult = Omit<LiveSyncResult, "seen">;
|
|||||||
* fails, so the caller keeps whatever it would otherwise mark as consumed.
|
* fails, so the caller keeps whatever it would otherwise mark as consumed.
|
||||||
* Shared by the live batch and the journal replay.
|
* Shared by the live batch and the journal replay.
|
||||||
*/
|
*/
|
||||||
function storeRecords(records: JavaRecordList): StoreResult {
|
function storeRecords(records: JavaRecordList, includeLatest = true): StoreResult {
|
||||||
const wire: WireRecord[] = [];
|
const wire: WireRecord[] = [];
|
||||||
const size = records.size();
|
const size = records.size();
|
||||||
for (let i = 0; i < size; i++) {
|
for (let i = 0; i < size; i++) {
|
||||||
try {
|
try {
|
||||||
const converted = toWire(records.get(i));
|
const converted = toWire(records.get(i), includeLatest);
|
||||||
if (converted) wire.push(converted);
|
if (converted) wire.push(converted);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("health live: skipped an undecodable record", error);
|
console.warn("health live: skipped an undecodable record", error);
|
||||||
@@ -480,7 +485,7 @@ function replayFrameJournalOnce(): void {
|
|||||||
const records: JavaRecordList = ringProtocol.decodeFrameJournal(File.fromPath(journalPath).readTextSync(), after);
|
const records: JavaRecordList = ringProtocol.decodeFrameJournal(File.fromPath(journalPath).readTextSync(), after);
|
||||||
const size = records.size();
|
const size = records.size();
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
const result = storeRecords(records);
|
const result = storeRecords(records, false);
|
||||||
let through = after;
|
let through = after;
|
||||||
for (let i = 0; i < size; i++) through = Math.max(through, Number(records.get(i).receivedAtMs));
|
for (let i = 0; i < size; i++) through = Math.max(through, Number(records.get(i).receivedAtMs));
|
||||||
const next: ReplayCursor = { version: JOURNAL_DECODER_VERSION, throughReceivedAtMs: through };
|
const next: ReplayCursor = { version: JOURNAL_DECODER_VERSION, throughReceivedAtMs: through };
|
||||||
@@ -543,7 +548,7 @@ export function syncLiveRecords(): LiveSyncResult {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the ring for a fresh pull now, rather than waiting out the automatic
|
* Ask the ring for a fresh pull now, rather than waiting out the automatic
|
||||||
* 30-minute cycle. Returns immediately; the pull itself takes ~15s on the
|
* ten-minute cycle. Returns immediately; the pull itself takes ~15s on the
|
||||||
* communicator's worker thread and lands through the next `syncLiveRecords()`.
|
* communicator's worker thread and lands through the next `syncLiveRecords()`.
|
||||||
*
|
*
|
||||||
* Throttled communicator-side to one a minute — see
|
* Throttled communicator-side to one a minute — see
|
||||||
@@ -584,19 +589,17 @@ export function startLiveHealthSync(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull the ring on a wall-clock-aligned cadence: :01 and :31, every hour.
|
* Pull the ring every ten minutes, one minute after each bucket boundary.
|
||||||
*
|
*
|
||||||
* Chris, 2026-09-12: *"I think we should be polling the ring on the 30 minute
|
* This collects the latest heart-rate observation at roughly the cadence
|
||||||
* cycle (that was my intent, not a floor honestly)."* The 30-minute value in
|
* the stock app documents, as well as the existing historical buckets.
|
||||||
* `RING_HEALTH_MIN_PULL_INTERVAL_MS` was always meant as a collection rhythm
|
* It does not force the sensor to take a new measurement.
|
||||||
* and got built as a throttle, so a connected, stable ring pulled never —
|
|
||||||
* nothing in the system drives a pull on a timer at all.
|
|
||||||
*
|
*
|
||||||
* Two reasons this is aligned to the wall clock rather than a plain interval:
|
* Two reasons this is aligned to the wall clock rather than a plain interval:
|
||||||
*
|
*
|
||||||
* 1. **The ring's own step buckets close on 10-minute boundaries.** Pulling on
|
* 1. **The ring's own step buckets close on 10-minute boundaries.** Pulling on
|
||||||
* the boundary collects a just-closed bucket instead of a half-formed one.
|
* the boundary collects a just-closed bucket instead of a half-formed one.
|
||||||
* 2. **An elapsed timer drifts.** A pull at :07 sets the next at :37, then :07,
|
* 2. **An elapsed timer drifts.** A pull at :07 sets the next at :17, then :27,
|
||||||
* wandering away from the boundary it is supposed to track. Re-arming
|
* wandering away from the boundary it is supposed to track. Re-arming
|
||||||
* against the clock each time cannot drift.
|
* against the clock each time cannot drift.
|
||||||
*
|
*
|
||||||
@@ -606,7 +609,7 @@ export function startLiveHealthSync(): void {
|
|||||||
* This only *requests* a pull. The communicator still applies its own anti-spam
|
* This only *requests* a pull. The communicator still applies its own anti-spam
|
||||||
* floor, so an extra call here can never hammer the ring.
|
* floor, so an extra call here can never hammer the ring.
|
||||||
*/
|
*/
|
||||||
const ALIGNED_PULL_MINUTES = [1, 31];
|
const ALIGNED_PULL_MINUTES = [1, 11, 21, 31, 41, 51];
|
||||||
let alignedPullTimer: ReturnType<typeof setTimeout> | null = null;
|
let alignedPullTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
function msUntilNextAlignedPull(now: Date): number {
|
function msUntilNextAlignedPull(now: Date): number {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
type HealthSample,
|
type HealthSample,
|
||||||
|
isHeartRateMeasurement,
|
||||||
type Rollup,
|
type Rollup,
|
||||||
type SampleMetric,
|
type SampleMetric,
|
||||||
type SleepSession,
|
type SleepSession,
|
||||||
@@ -228,12 +229,51 @@ export class HealthStore {
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Reading
|
// Reading
|
||||||
|
|
||||||
/** Every stored sample overlapping [startMs, endMs). Exact - reads shards. */
|
/** Append-journal cursor, committed by the exporter only after server acknowledgement.
|
||||||
samplesInRange(startMs: number, endMs: number): HealthSample[] {
|
* Revisions appended to an old month are exported too; a time watermark would lose them.
|
||||||
|
*/
|
||||||
|
exportBatch(cursor: Record<string, number>, limit = 200): {
|
||||||
|
cursor: Record<string, number>; samples: HealthSample[]; sleep: SleepSession[]; scanned: number;
|
||||||
|
} {
|
||||||
|
const next = { ...cursor };
|
||||||
|
const samples: HealthSample[] = [];
|
||||||
|
const sleep: SleepSession[] = [];
|
||||||
|
let scanned = 0;
|
||||||
|
for (const name of this.backend.list().filter(candidate => /^samples-\d{4}-\d{2}\.jsonl$/.test(candidate) || candidate === SLEEP_FILE).sort()) {
|
||||||
|
const text = this.backend.read(name);
|
||||||
|
if (text === null) throw new Error("Health export could not read history");
|
||||||
|
let offset = next[name] ?? 0;
|
||||||
|
if (!Number.isSafeInteger(offset) || offset < 0 || offset > text.length) offset = 0;
|
||||||
|
while (scanned < limit) {
|
||||||
|
const end = text.indexOf("\n", offset);
|
||||||
|
if (end < 0) break; // Never consume a partially written final record.
|
||||||
|
const line = text.slice(offset, end);
|
||||||
|
offset = end + 1;
|
||||||
|
scanned++;
|
||||||
|
if (name === SLEEP_FILE) {
|
||||||
|
try {
|
||||||
|
const session = JSON.parse(line) as SleepSession;
|
||||||
|
if (session?.timeResolved === true) sleep.push(session);
|
||||||
|
} catch { /* Ignore incomplete/corrupt journal lines as the local reader does. */ }
|
||||||
|
} else {
|
||||||
|
const sample = fromLine(line);
|
||||||
|
if (sample) samples.push(sample);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next[name] = offset;
|
||||||
|
if (scanned >= limit) break;
|
||||||
|
}
|
||||||
|
return { cursor: next, samples, sleep, scanned };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bucket samples in [startMs, endMs). Point observations are opt-in so
|
||||||
|
* existing charts and daily averages never combine two overlapping series. */
|
||||||
|
samplesInRange(startMs: number, endMs: number, includeMeasurements = false): HealthSample[] {
|
||||||
const out: HealthSample[] = [];
|
const out: HealthSample[] = [];
|
||||||
for (const name of this.shardNamesInRange(startMs, endMs)) {
|
for (const name of this.shardNamesInRange(startMs, endMs)) {
|
||||||
for (const sample of this.loadShard(name).values()) {
|
for (const sample of this.loadShard(name).values()) {
|
||||||
if (sample.startMs >= startMs && sample.startMs < endMs) out.push(sample);
|
if (sample.startMs >= startMs && sample.startMs < endMs
|
||||||
|
&& (includeMeasurements || !isHeartRateMeasurement(sample))) out.push(sample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.sort((a, b) => a.startMs - b.startMs);
|
out.sort((a, b) => a.startMs - b.startMs);
|
||||||
@@ -297,6 +337,7 @@ export class HealthStore {
|
|||||||
for (const name of this.backend.list()) {
|
for (const name of this.backend.list()) {
|
||||||
if (!name.startsWith(SAMPLE_PREFIX) || !name.endsWith(SAMPLE_SUFFIX)) continue;
|
if (!name.startsWith(SAMPLE_PREFIX) || !name.endsWith(SAMPLE_SUFFIX)) continue;
|
||||||
for (const sample of this.loadShard(name).values()) {
|
for (const sample of this.loadShard(name).values()) {
|
||||||
|
if (isHeartRateMeasurement(sample)) continue;
|
||||||
const key = dayKey(sample.startMs);
|
const key = dayKey(sample.startMs);
|
||||||
let byMetric = perDay.get(key);
|
let byMetric = perDay.get(key);
|
||||||
if (!byMetric) {
|
if (!byMetric) {
|
||||||
@@ -323,7 +364,9 @@ export class HealthStore {
|
|||||||
private updateRollupsFor(samples: readonly HealthSample[]): void {
|
private updateRollupsFor(samples: readonly HealthSample[]): void {
|
||||||
const file = this.loadRollups();
|
const file = this.loadRollups();
|
||||||
const touched = new Set<string>();
|
const touched = new Set<string>();
|
||||||
for (const sample of samples) touched.add(dayKey(sample.startMs));
|
for (const sample of samples) {
|
||||||
|
if (!isHeartRateMeasurement(sample)) touched.add(dayKey(sample.startMs));
|
||||||
|
}
|
||||||
for (const key of touched) {
|
for (const key of touched) {
|
||||||
const parts = key.split("-").map(Number);
|
const parts = key.split("-").map(Number);
|
||||||
const dayStart = new Date(parts[0]!, parts[1]! - 1, parts[2]!).getTime();
|
const dayStart = new Date(parts[0]!, parts[1]! - 1, parts[2]!).getTime();
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ export function isCumulative(metric: SampleMetric): boolean {
|
|||||||
|
|
||||||
export const HOUR_MS = 3_600_000;
|
export const HOUR_MS = 3_600_000;
|
||||||
export const TEN_MINUTES_MS = 600_000;
|
export const TEN_MINUTES_MS = 600_000;
|
||||||
|
/** Point observation, not a ten-minute average. Distinct from hourly buckets. */
|
||||||
|
export const HEART_RATE_MEASUREMENT_SPAN_MS = 1;
|
||||||
|
|
||||||
|
export function isHeartRateMeasurement(sample: HealthSample): boolean {
|
||||||
|
return sample.metric === "heartRate" && sample.spanMs === HEART_RATE_MEASUREMENT_SPAN_MS;
|
||||||
|
}
|
||||||
export const DAY_MS = 86_400_000;
|
export const DAY_MS = 86_400_000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+32
-2
@@ -9,7 +9,7 @@ declare const java: any;
|
|||||||
* than bundled in the APK; FaceclawVoiceController reads the files from the
|
* than bundled in the APK; FaceclawVoiceController reads the files from the
|
||||||
* directory each model's `dirName` names.
|
* directory each model's `dirName` names.
|
||||||
*
|
*
|
||||||
* Two models, same shape:
|
* Downloadable models, same shape:
|
||||||
* - "moonshine": the original on-device option (three files). The model is
|
* - "moonshine": the original on-device option (three files). The model is
|
||||||
* no longer bundled in the APK; it is fetched into the same filesDir
|
* no longer bundled in the APK; it is fetched into the same filesDir
|
||||||
* location that earlier releases copied the bundled files to, so
|
* location that earlier releases copied the bundled files to, so
|
||||||
@@ -29,12 +29,17 @@ declare const java: any;
|
|||||||
* used for Moonshine below. Every hash here was computed locally from a
|
* used for Moonshine below. Every hash here was computed locally from a
|
||||||
* freshly downloaded copy of the file, not copied from a doc page.
|
* freshly downloaded copy of the file, not copied from a doc page.
|
||||||
*
|
*
|
||||||
|
* - "whisper-base": multilingual base, int8-quantized. Used for non-English
|
||||||
|
* speech and auto-detection; English-only downloads remain untouched.
|
||||||
|
* SHA-256/size values come from the maintainer's LFS metadata, with the
|
||||||
|
* vocabulary hash computed locally. URLs pin the source revision.
|
||||||
|
*
|
||||||
* Mirrors the on-phone assistant model flow in llama.ts, except each model
|
* Mirrors the on-phone assistant model flow in llama.ts, except each model
|
||||||
* here is multiple files rather than one; they download sequentially through
|
* here is multiple files rather than one; they download sequentially through
|
||||||
* FaceclawModelDownloader (resume + pinned sha256 per file).
|
* FaceclawModelDownloader (resume + pinned sha256 per file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type AsrModelId = "moonshine" | "whisper-base-en";
|
export type AsrModelId = "moonshine" | "whisper-base-en" | "whisper-base";
|
||||||
|
|
||||||
type AsrModelFile = {
|
type AsrModelFile = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -105,6 +110,30 @@ export const ASR_MODELS: Record<AsrModelId, AsrModelDef> = {
|
|||||||
],
|
],
|
||||||
totalBytes: 160626066,
|
totalBytes: 160626066,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"whisper-base": {
|
||||||
|
label: "Whisper (multilingual, base)",
|
||||||
|
dirName: "sherpa-onnx-whisper-base-int8",
|
||||||
|
baseUrl: "https://huggingface.co/csukuangfj/sherpa-onnx-whisper-base/resolve/bb53ee204431c90d314c1cc08d28d23e5b7927cc/",
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
name: "base-encoder.int8.onnx",
|
||||||
|
sha256: "0b8fb1304b6109976038efff5ace81720e00386f3ff6b54ee8c75291ca0a1e11",
|
||||||
|
sizeBytes: 29120534,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "base-decoder.int8.onnx",
|
||||||
|
sha256: "9759d217388a01b3a4c7c15533201067b48ae819c4daafc8624e64b9409dc02d",
|
||||||
|
sizeBytes: 130672026,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "base-tokens.txt",
|
||||||
|
sha256: "b34b360dbb493e781e479794586d661700670d65564001f23024971d1f2fa126",
|
||||||
|
sizeBytes: 816730,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
totalBytes: 160609290,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AsrModelState = {
|
export type AsrModelState = {
|
||||||
@@ -129,6 +158,7 @@ function freshRuntime(): ModelRuntime {
|
|||||||
const runtimes: Record<AsrModelId, ModelRuntime> = {
|
const runtimes: Record<AsrModelId, ModelRuntime> = {
|
||||||
moonshine: freshRuntime(),
|
moonshine: freshRuntime(),
|
||||||
"whisper-base-en": freshRuntime(),
|
"whisper-base-en": freshRuntime(),
|
||||||
|
"whisper-base": freshRuntime(),
|
||||||
};
|
};
|
||||||
|
|
||||||
function modelDirPath(id: AsrModelId): string {
|
function modelDirPath(id: AsrModelId): string {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { getStringSetting, setStringSetting } from "./settings-store";
|
||||||
|
|
||||||
|
export const CALENDAR_SELECTION_KEY = "calendar.selectedIds";
|
||||||
|
/** null means all calendars (including future ones); [] explicitly means none. */
|
||||||
|
export function readCalendarSelection(): string[] | null {
|
||||||
|
try {
|
||||||
|
const value = JSON.parse(getStringSetting(CALENDAR_SELECTION_KEY, "null"));
|
||||||
|
if (value === null) return null;
|
||||||
|
if (!Array.isArray(value) || !value.every(id => typeof id === "string" && /^\d+$/.test(id))) return null;
|
||||||
|
return Array.from(new Set<string>(value));
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setCalendarSelection(ids: readonly string[] | null): void {
|
||||||
|
if (ids !== null && !ids.every(id => /^\d+$/.test(id))) throw new Error("Invalid calendar ID");
|
||||||
|
setStringSetting(CALENDAR_SELECTION_KEY, JSON.stringify(ids === null ? null : Array.from(new Set(ids))));
|
||||||
|
}
|
||||||
Loaded 100 of 314 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user