Make iOS app main screen match the Android UI

This commit is contained in:
James Babcock committed 2026-09-19 21:54:18 -07:00
1 parent 9f53847bb7
commit 6c3144cc31
30 files changed
+1013 -439

No files matched your search

@@ -0,0 +1,13 @@
{
"images": [
{
"idiom": "universal",
"filename": "ic_tab_keyboard@3x.png",
"scale": "3x"
}
],
"info": {
"author": "xcode",
"version": 1
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

@@ -0,0 +1,13 @@
{
"images": [
{
"idiom": "universal",
"filename": "ic_tab_mic@3x.png",
"scale": "3x"
}
],
"info": {
"author": "xcode",
"version": 1
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

+3 -1
View File
@@ -20,8 +20,10 @@
<true/> <true/>
<key>NSBluetoothAlwaysUsageDescription</key> <key>NSBluetoothAlwaysUsageDescription</key>
<string>Faceclaw uses Bluetooth to connect to your glasses and ring, display your apps, and receive gestures.</string> <string>Faceclaw uses Bluetooth to connect to your glasses and ring, display your apps, and receive gestures.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Faceclaw uses your phone microphone for voice input when your glasses are disconnected.</string>
<key>NSSpeechRecognitionUsageDescription</key> <key>NSSpeechRecognitionUsageDescription</key>
<string>Faceclaw turns audio from your glasses microphone into text for the app you choose. Dictation uses on-device recognition.</string> <string>Faceclaw turns audio from your glasses or phone microphone into text for the app you choose. Dictation uses on-device recognition.</string>
<key>NSCameraUsageDescription</key> <key>NSCameraUsageDescription</key>
<string>Faceclaw uses the camera to scan QR codes for app URLs you open in Developer.</string> <string>Faceclaw uses the camera to scan QR codes for app URLs you open in Developer.</string>
<key>NSCalendarsUsageDescription</key> <key>NSCalendarsUsageDescription</key>
+4 -1
View File
@@ -1,11 +1,14 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
/** On-device speech recognition fed ONLY by decoded G2 BLE microphone packets. */ /** On-device speech recognition fed by G2 BLE audio or the default phone microphone. */
@interface FaceclawSpeech : NSObject @interface FaceclawSpeech : NSObject
@property(nonatomic, copy) void (^eventHandler)(NSString *json); @property(nonatomic, copy) void (^eventHandler)(NSString *json);
+ (NSInteger)authorizationStatus; + (NSInteger)authorizationStatus;
+ (NSInteger)microphoneAuthorizationStatus;
+ (void)requestMicrophoneAuthorization:(void (^)(NSInteger status))completion;
+ (void)requestAuthorization:(void (^)(NSInteger status))completion; + (void)requestAuthorization:(void (^)(NSInteger status))completion;
/** Returns an actionable error, or an empty string when capture starts. */ /** Returns an actionable error, or an empty string when capture starts. */
- (NSString *)startWithEndpointing:(BOOL)endpointing; - (NSString *)startWithEndpointing:(BOOL)endpointing;
- (NSString *)startPhoneWithEndpointing:(BOOL)endpointing;
- (void)acceptPacket:(NSData *)packet; - (void)acceptPacket:(NSData *)packet;
- (void)finish; - (void)finish;
- (void)cancel; - (void)cancel;
+101 -4
View File
@@ -14,7 +14,11 @@
@property(nonatomic, strong) dispatch_queue_t audioQueue; @property(nonatomic, strong) dispatch_queue_t audioQueue;
@property(atomic) NSUInteger generation; @property(atomic) NSUInteger generation;
@property(nonatomic) NSUInteger pendingPackets; @property(nonatomic) NSUInteger pendingPackets;
@property(nonatomic) BOOL accepting; @property(atomic) BOOL accepting;
@property(nonatomic, strong) AVAudioEngine *phoneEngine;
@property(nonatomic) BOOL phoneTapInstalled;
@property(nonatomic) BOOL phoneSessionActive;
@property(nonatomic, strong) id interruptionObserver;
@property(nonatomic, copy) NSString *bestText; @property(nonatomic, copy) NSString *bestText;
@property(nonatomic, strong) FaceclawSpeechTranscript *transcript; @property(nonatomic, strong) FaceclawSpeechTranscript *transcript;
@property(nonatomic, strong) FaceclawKitVoiceEndpointDetector *endpointDetector; @property(nonatomic, strong) FaceclawKitVoiceEndpointDetector *endpointDetector;
@@ -24,6 +28,12 @@
if ((self = [super init])) _audioQueue = dispatch_queue_create("com.faceclaw.glasses-speech", DISPATCH_QUEUE_SERIAL); if ((self = [super init])) _audioQueue = dispatch_queue_create("com.faceclaw.glasses-speech", DISPATCH_QUEUE_SERIAL);
return self; return self;
} }
+ (NSInteger)microphoneAuthorizationStatus { return [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; }
+ (void)requestMicrophoneAuthorization:(void (^)(NSInteger))completion {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
dispatch_async(dispatch_get_main_queue(), ^{ completion(granted ? 3 : 2); });
}];
}
+ (NSInteger)authorizationStatus { return SFSpeechRecognizer.authorizationStatus; } + (NSInteger)authorizationStatus { return SFSpeechRecognizer.authorizationStatus; }
+ (void)requestAuthorization:(void (^)(NSInteger))completion { + (void)requestAuthorization:(void (^)(NSInteger))completion {
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) { [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
@@ -36,7 +46,15 @@
if (json) self.eventHandler([[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]); if (json) self.eventHandler([[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]);
} }
- (NSString *)startWithEndpointing:(BOOL)endpointing { - (NSString *)startWithEndpointing:(BOOL)endpointing {
return [self startWithEndpointing:endpointing phone:NO];
}
- (NSString *)startPhoneWithEndpointing:(BOOL)endpointing {
return [self startWithEndpointing:endpointing phone:YES];
}
- (NSString *)startWithEndpointing:(BOOL)endpointing phone:(BOOL)phone {
[self cancel]; [self cancel];
if (phone && [FaceclawSpeech microphoneAuthorizationStatus] != AVAuthorizationStatusAuthorized)
return @"Allow Microphone access for Faceclaw in iPhone Settings.";
if (SFSpeechRecognizer.authorizationStatus != SFSpeechRecognizerAuthorizationStatusAuthorized) if (SFSpeechRecognizer.authorizationStatus != SFSpeechRecognizerAuthorizationStatusAuthorized)
return @"Allow Speech Recognition for Faceclaw in iPhone Settings."; return @"Allow Speech Recognition for Faceclaw in iPhone Settings.";
NSString *language = NSLocale.preferredLanguages.firstObject ?: @"en-US"; NSString *language = NSLocale.preferredLanguages.firstObject ?: @"en-US";
@@ -44,8 +62,10 @@
if (!self.recognizer.supportsOnDeviceRecognition) if (!self.recognizer.supportsOnDeviceRecognition)
return [NSString stringWithFormat:@"On-device speech is unavailable for %@. Enable Dictation for that language in iPhone Settings → General → Keyboard, then retry.", language]; return [NSString stringWithFormat:@"On-device speech is unavailable for %@. Enable Dictation for that language in iPhone Settings → General → Keyboard, then retry.", language];
if (!self.recognizer.available) return @"Speech recognition is temporarily unavailable. Try again shortly."; if (!self.recognizer.available) return @"Speech recognition is temporarily unavailable. Try again shortly.";
self.decoder = [FaceclawLc3Decoder new]; if (!phone) {
if (!self.decoder) return @"Could not initialize the glasses audio decoder."; self.decoder = [FaceclawLc3Decoder new];
if (!self.decoder) return @"Could not initialize the glasses audio decoder.";
}
self.recognizer.queue = NSOperationQueue.mainQueue; self.recognizer.queue = NSOperationQueue.mainQueue;
self.request = [SFSpeechAudioBufferRecognitionRequest new]; self.request = [SFSpeechAudioBufferRecognitionRequest new];
self.request.requiresOnDeviceRecognition = YES; self.request.requiresOnDeviceRecognition = YES;
@@ -77,7 +97,11 @@
} }
}); });
}]; }];
[self emit:@{@"kind":@"status", @"message":[NSString stringWithFormat:@"Listening on glasses (%@, on-device)…", language]}]; if (phone) {
NSString *error = [self startPhoneAudio];
if (error.length) { [self cancel]; return error; }
}
[self emit:@{@"kind":@"status", @"message":[NSString stringWithFormat:@"Listening on %@ (%@, on-device)…", phone ? @"phone" : @"glasses", language]}];
// Bound a dictation to the recognizer's supported short-session workflow. // Bound a dictation to the recognizer's supported short-session workflow.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 55 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 55 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
FaceclawSpeech *owner = weakSelf; FaceclawSpeech *owner = weakSelf;
@@ -85,6 +109,77 @@
}); });
return @""; return @"";
} }
- (NSString *)startPhoneAudio {
AVAudioSession *session = AVAudioSession.sharedInstance;
NSError *error = nil;
// Leave preferredInput unset so iOS selects its current default route,
// including a headset microphone when one is attached.
if (![session setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeMeasurement
options:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionAllowBluetoothHFP error:&error])
return [NSString stringWithFormat:@"Could not configure phone microphone: %@", error.localizedDescription];
if (![session setActive:YES error:&error])
return [NSString stringWithFormat:@"Could not activate phone microphone: %@", error.localizedDescription];
self.phoneSessionActive = YES;
self.phoneEngine = [AVAudioEngine new];
AVAudioInputNode *input = self.phoneEngine.inputNode;
AVAudioFormat *format = [input outputFormatForBus:0];
if (format.sampleRate <= 0 || !format.channelCount) return @"No phone microphone is available. Check your audio input and try again.";
NSUInteger generation = self.generation;
SFSpeechAudioBufferRecognitionRequest *request = self.request;
FaceclawKitVoiceEndpointDetector *detector = self.endpointDetector;
__weak FaceclawSpeech *weakSelf = self;
[input installTapOnBus:0 bufferSize:1024 format:format block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {
FaceclawSpeech *owner = weakSelf;
if (!owner || owner.generation != generation || !owner.accepting || !buffer.frameLength) return;
// The tap owns buffer only for this callback. Copy before handing it
// to the serial recognition queue, which finish drains before endAudio.
AVAudioPCMBuffer *copy = [[AVAudioPCMBuffer alloc] initWithPCMFormat:buffer.format frameCapacity:buffer.frameLength];
copy.frameLength = buffer.frameLength;
const AudioBufferList *source = buffer.audioBufferList;
AudioBufferList *destination = copy.mutableAudioBufferList;
for (UInt32 i = 0; i < source->mNumberBuffers; i++)
memcpy(destination->mBuffers[i].mData, source->mBuffers[i].mData, source->mBuffers[i].mDataByteSize);
dispatch_async(owner.audioQueue, ^{ @autoreleasepool {
if (owner.generation != generation) return;
[request appendAudioPCMBuffer:copy];
double sum = 0;
if (copy.floatChannelData) {
const float *samples = copy.floatChannelData[0];
NSUInteger stride = copy.format.interleaved ? copy.format.channelCount : 1;
for (NSUInteger i = 0; i < copy.frameLength; i++) sum += samples[i * stride] * samples[i * stride];
}
double rms = sqrt(sum / copy.frameLength);
// The endpoint detector uses a 16 kHz sample clock; device input
// commonly arrives at 48 kHz. Recognition accepts its native rate.
int32_t samples = (int32_t)llround(copy.frameLength * 16000.0 / copy.format.sampleRate);
BOOL ended = [detector acceptLevelRms:rms * 32768.0 sampleCount:samples];
if (ended) dispatch_async(dispatch_get_main_queue(), ^{
if (owner.generation == generation && owner.accepting) [owner finish];
});
}});
}];
self.phoneTapInstalled = YES;
[self.phoneEngine prepare];
if (![self.phoneEngine startAndReturnError:&error])
return [NSString stringWithFormat:@"Could not start phone microphone: %@", error.localizedDescription];
self.interruptionObserver = [NSNotificationCenter.defaultCenter addObserverForName:AVAudioSessionInterruptionNotification
object:session queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *notification) {
FaceclawSpeech *owner = weakSelf;
if (owner.generation == generation && [notification.userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue] == AVAudioSessionInterruptionTypeBegan)
[owner complete:@"Phone microphone interrupted. Start voice input again to continue."];
}];
return @"";
}
- (void)stopPhoneAudio {
if (self.interruptionObserver) [NSNotificationCenter.defaultCenter removeObserver:self.interruptionObserver];
self.interruptionObserver = nil;
[self.phoneEngine stop];
if (self.phoneTapInstalled) [self.phoneEngine.inputNode removeTapOnBus:0];
self.phoneTapInstalled = NO;
self.phoneEngine = nil;
if (self.phoneSessionActive) [AVAudioSession.sharedInstance setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
self.phoneSessionActive = NO;
}
- (void)acceptPacket:(NSData *)packet { - (void)acceptPacket:(NSData *)packet {
if (!self.accepting) return; if (!self.accepting) return;
if (self.pendingPackets >= 40) { [self complete:@"Audio processing fell behind. Please try again."]; return; } if (self.pendingPackets >= 40) { [self complete:@"Audio processing fell behind. Please try again."]; return; }
@@ -125,6 +220,7 @@
- (void)finish { - (void)finish {
if (!self.accepting) return; if (!self.accepting) return;
self.accepting = NO; self.accepting = NO;
[self stopPhoneAudio];
NSUInteger generation = self.generation; NSUInteger generation = self.generation;
SFSpeechAudioBufferRecognitionRequest *request = self.request; SFSpeechAudioBufferRecognitionRequest *request = self.request;
[self emit:@{@"kind":@"finishing"}]; [self emit:@{@"kind":@"finishing"}];
@@ -146,6 +242,7 @@
- (void)cancel { - (void)cancel {
self.generation++; self.generation++;
self.accepting = NO; self.pendingPackets = 0; self.accepting = NO; self.pendingPackets = 0;
[self stopPhoneAudio];
[self.task cancel]; self.task = nil; self.request = nil; self.decoder = nil; self.recognizer = nil; [self.task cancel]; self.task = nil; self.request = nil; self.decoder = nil; self.recognizer = nil;
self.bestText = @""; self.transcript = nil; self.endpointDetector = nil; self.bestText = @""; self.transcript = nil; self.endpointDetector = nil;
} }
+1
View File
@@ -3,6 +3,7 @@
## 0.7.3 - Future ## 0.7.3 - Future
* Add iOS calendar integration * Add iOS calendar integration
* iOS main screen matches the Android version's styling
## 0.7.2 - 2026-09-19 ## 0.7.2 - 2026-09-19
+2 -134
View File
@@ -1,5 +1,6 @@
@import '@nativescript/theme/css/core.css'; @import '@nativescript/theme/css/core.css';
@import '@nativescript/theme/css/default.css'; @import '@nativescript/theme/css/default.css';
@import './phone-ui/remote-controls.css';
Page { Page {
background-color: #ffffff; background-color: #ffffff;
@@ -171,139 +172,6 @@ Button.-primary {
margin-bottom: 12; margin-bottom: 12;
} }
/* The phone's controller for the glasses (phone-ui/remote-controls.xml). */
.remote-controls {
margin: 0 8 0 8;
}
/* The Settings / Watch / Ring tab bar above the controls. */
.controls-tab-bar {
margin-bottom: 8;
}
.tab-button {
font-size: 14;
padding: 8 0;
margin: 0 2;
border-radius: 6;
background-color: #e2e2e2;
color: #333333;
}
.tab-button-selected {
background-color: #424242;
color: #ffffff;
}
/* The wakeword and keyboard buttons at the tab bar's right edge: icon-only,
* narrower than the tabs, and never in the selected state (they aren't tabs).
* Each is a button-styled GridLayout (Buttons can't hold images), so it
* borrows the .tab-button look and adds the elevation MaterialButtons get for
* free. */
.tab-icon-button {
width: 56;
/* The real MaterialButtons render 48dp tall inside a 60dp layout box (6dp
* insets top and bottom); the margins and explicit height reproduce that.
* The height also bounds the tile's measure, without which its star row
* would collapse to content and pin the icon to the top. */
height: 48;
margin: 6 2;
android-elevation: 2;
}
.tab-icon {
height: 20;
tint-color: #333333;
}
/* Landscape uses the full page height and a shared left edge for tabs/pad. */
.landscape-layout .remote-controls {
margin: 0;
}
.landscape-layout .controls-tab-bar {
margin-bottom: 2;
}
.landscape-layout .tab-button {
margin-left: 1;
margin-right: 1;
min-width: 0;
}
.landscape-layout .tab-button[col="0"] {
margin-left: 0;
}
.landscape-layout .tab-icon-button {
width: 48;
}
.landscape-layout .tab-icon-button[col="4"] {
margin-right: 0;
}
.ns-dark .tab-icon {
tint-color: #cccccc;
}
.ns-dark .tab-button {
background-color: #333333;
color: #cccccc;
}
.ns-dark .tab-button-selected {
background-color: #e2e2e2;
color: #222222;
}
/* Settings tab rows. */
.settings-row {
margin-bottom: 8;
}
.settings-row-label {
font-size: 14;
margin-right: 10;
}
.mode-button {
font-size: 13;
padding: 6 10;
margin-right: 6;
}
.brightness-icon {
font-size: 16;
margin: 0 4 0 4;
color: #444444;
}
.auto-toggle Label {
font-size: 13;
margin-right: 2;
}
.touchpad {
height: 230;
background-color: #1f1f1f;
border-radius: 14;
border-width: 1;
border-color: #3a3a3a;
color: #f0f0f0;
margin-top: 2;
}
.pad-focus {
font-size: 20;
color: #ffffff;
}
.pad-legend {
font-size: 11;
color: #8a8a8a;
margin-bottom: 8;
}
.action-row {
margin-top: 6;
}
.action-button {
margin: 2;
font-size: 14;
}
/* Ring tab: the same touchpad, but portrait like the ring's own pad. */
.ring-touchpad {
width: 150;
height: 250;
}
/* Cosmetic marks mirroring the six rectangles on the physical ring's touch
strip; barely lighter than the pad so they read as texture, not buttons. */
.ring-pad-marking {
width: 18;
height: 5;
border-radius: 2;
background-color: #2a2a2a;
horizontal-align: center;
vertical-align: center;
}
/* /*
* Pairing scan list (phone-ui/pairing-page). Rows are Repeater items: product * Pairing scan list (phone-ui/pairing-page). Rows are Repeater items: product
* art (or a colourway swatch) on the left, decoded SKU + proximity + serial in * art (or a colourway swatch) on the left, decoded SKU + proximity + serial in
+45
View File
@@ -1,4 +1,5 @@
@import '@nativescript/theme/css/core.css'; @import '@nativescript/theme/css/core.css';
@import './phone-ui/remote-controls.css';
.pairing-instructions { .pairing-instructions {
color: #555555; color: #555555;
@@ -159,3 +160,47 @@ Button {
margin-right: 4; margin-right: 4;
font-size: 15; font-size: 15;
} }
Page.main-page {
background-color: #ffffff;
color: #222222;
}
.main-page .main-header {
background-color: #424242;
color: #ffffff;
padding: 0 0 0 16;
height: 56;
}
.main-page .action-bar-title { font-size: 18; font-weight: bold; color: #ffffff; }
.main-page .action-bar-status { font-size: 14; color: #ffffff; margin-right: 12; }
.main-page .overflow-button {
background-color: transparent;
color: #ffffff;
font-size: 24;
width: 44;
height: 48;
margin: 0;
padding: 0;
}
/* Match Android's button layout boxes, including the inset around each tile. */
.main-page Button.tab-button { height: 48; margin-top: 6; margin-bottom: 6; }
.main-page .mode-button { background-color: #e2e2e2; color: #333333; border-radius: 6; }
.main-page .ble-bandwidth-indicator { color: #777777; font-size: 12; padding: 2 8; }
.main-page .system-name-modal {
background-color: #eeeeee;
color: #222222;
padding: 16;
}
.main-page .system-name-modal TextView {
margin: 0;
padding: 4;
background-color: #ffffff;
color: #222222;
placeholder-color: #666666;
}
.main-landscape .system-name-modal { padding: 6 12; }
.main-landscape .system-name-modal .h2 { visibility: collapse; }
.main-landscape .system-name-modal Button { padding: 6 8; margin-top: 0; margin-bottom: 0; }
+8
View File
@@ -0,0 +1,8 @@
import { bytes, concat, integer } from './ble-protocol'
/** Same G2SettingPackage as Kotlin BleProtocol.buildSetBrightness. */
export function setBrightness(magic: number, level: number | null): Uint8Array {
const fields = level === null ? integer(1, 1)
: concat(integer(1, 0), integer(2, Math.max(0, Math.min(100, Math.round(level)))))
return concat(integer(1, 1), integer(2, magic), bytes(3, bytes(1, fields)))
}
+5
View File
@@ -1,3 +1,4 @@
import { setBrightness } from './brightness-protocol'
import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client' import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client'
import { type CompassEvent } from '../native/compass-types' import { type CompassEvent } from '../native/compass-types'
import * as protocol from './ble-protocol' import * as protocol from './ble-protocol'
@@ -423,6 +424,10 @@ export class GlassesSession {
this.check(generation) this.check(generation)
await this.send('left', protocol.SID.settings, 0x20, queryWearState()) await this.send('left', protocol.SID.settings, 0x20, queryWearState())
} }
async setBrightness(level: number | null): Promise<void> {
if (this.state.phase !== 'connected') return
await this.request('right', protocol.SID.settings, magic => setBrightness(magic, level), 'Brightness')
}
setFrame(gray: Uint8Array): void { setFrame(gray: Uint8Array): void {
if (this.state.phase !== 'connected') return if (this.state.phase !== 'connected') return
this.latest = protocol.packGray4(gray, 640, 480); this.schedule(0) this.latest = protocol.packGray4(gray, 640, 480); this.schedule(0)
+42 -22
View File
@@ -1,3 +1,4 @@
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 } from '../native/notification-icons.ios' import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup } from '../native/notification-icons.ios'
import { shouldShowNotificationOnGlasses } from '../native/notification-sources' import { shouldShowNotificationOnGlasses } from '../native/notification-sources'
@@ -42,7 +43,7 @@ import { TextViewerLayer } from '../apps/files/text-viewer'
import { shell, rawInputEventToInputEvent, type ShellWindow } from '../ui/shell/shell' import { shell, rawInputEventToInputEvent, type ShellWindow } from '../ui/shell/shell'
import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible } from '../ui/shell/geometry' import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible } from '../ui/shell/geometry'
import { DISPLAY_MODE_VALUES, displayModeLabel, displayModeSetting, onAnySettingChanged, import { DISPLAY_MODE_VALUES, displayModeLabel, displayModeSetting, onAnySettingChanged,
previewColorSetting, lockScreenEnabledSetting } from '../ui/dashboard-settings' previewColorSetting, lockScreenEnabledSetting, brightnessSetting, brightnessSettingToLevel } from '../ui/dashboard-settings'
import type { PhoneGesture } from '../phone-ui/phone-gestures' import type { PhoneGesture } from '../phone-ui/phone-gestures'
import { isWelcomeSoundPending, setWelcomeSoundPending } from '../phone-ui/onboarding-state' import { isWelcomeSoundPending, setWelcomeSoundPending } from '../phone-ui/onboarding-state'
import { findSoundEffect, playSoundEffect } from '../ui/sound-effects' import { findSoundEffect, playSoundEffect } from '../ui/sound-effects'
@@ -83,13 +84,13 @@ export class IosPreviewController {
private renderTimer: ReturnType<typeof setTimeout> | null = null private renderTimer: ReturnType<typeof setTimeout> | null = null
private clockTimer: ReturnType<typeof setInterval> | null = null private clockTimer: ReturnType<typeof setInterval> | null = null
private offSettings: (() => void) | null = null private offSettings: (() => void) | null = null
private lastBrightness: string | null = null
private active = false private active = false
private runtimeRunning = false private runtimeRunning = false
private clockMinute = -1 private clockMinute = -1
private shellDirty = true private shellDirty = true
private inputQueue: Promise<void> = Promise.resolve() private inputQueue: Promise<void> = Promise.resolve()
private lastLayout = '' private lastLayout = ''
private prompting = false
private readonly appHosts = new Map<string, WorkerAppHost>() private readonly appHosts = new Map<string, WorkerAppHost>()
private readonly inProcessApps = new Map<string, InProcessWindow>() private readonly inProcessApps = new Map<string, InProcessWindow>()
private readonly batteryObservers: any[] = [] private readonly batteryObservers: any[] = []
@@ -124,7 +125,8 @@ export class IosPreviewController {
constructor(private readonly onFrame: (image: ImageSource, focus: string) => void, constructor(private readonly onFrame: (image: ImageSource, focus: string) => void,
private readonly onError: (message: string) => void, private readonly onError: (message: string) => void,
private readonly onConnectionState: (state: SessionState) => void = () => {}) { private readonly onConnectionState: (state: SessionState) => void = () => {},
private readonly onKeyboardInputChanged: (session: KeyboardInputSession | null) => void = () => {}) {
this.compositor.configureSurface('shell', { x: 0, y: 0, width: 640, height: 480, zOrder: 1, transparency: 'color-key' }) this.compositor.configureSurface('shell', { x: 0, y: 0, width: 640, height: 480, zOrder: 1, transparency: 'color-key' })
this.compositor.configureSurface(LOCK_SCREEN_SURFACE_ID, { this.compositor.configureSurface(LOCK_SCREEN_SURFACE_ID, {
x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT, zOrder: 1000, transparency: 'opaque', x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT, zOrder: 1000, transparency: 'opaque',
@@ -133,6 +135,13 @@ export class IosPreviewController {
shell.configure({ shell.configure({
actions: this.actions, actions: this.actions,
voiceInputEnabled: true, voiceInputEnabled: true,
onKeyboardInputChanged: session => this.onKeyboardInputChanged(session ? {
targets: session.targets,
setText: text => { if (this.active && !this.glassesLocked) session.setText(text) },
send: () => { if (this.active && !this.glassesLocked) session.send() },
sendTo: id => { if (this.active && !this.glassesLocked) session.sendTo(id) },
discard: () => session.discard(),
} : null),
prepareVoiceCapture: () => this.prepareVoiceCapture(), prepareVoiceCapture: () => this.prepareVoiceCapture(),
getScreenTimeoutMs: () => null, getScreenTimeoutMs: () => null,
requestShellRender: () => this.requestShellRender(), requestShellRender: () => this.requestShellRender(),
@@ -184,6 +193,7 @@ export class IosPreviewController {
pause(): void { pause(): void {
if (!this.active) return if (!this.active) return
this.active = false this.active = false
iosVoiceInput.stopPhoneCapture()
// The phone preview is hidden; the glasses still own their screen and input. // The phone preview is hidden; the glasses still own their screen and input.
this.syncRuntime() this.syncRuntime()
this.logBluetooth(`Phone background; glasses ${this.session?.state.phase ?? 'disconnected'}`) this.logBluetooth(`Phone background; glasses ${this.session?.state.phase ?? 'disconnected'}`)
@@ -230,12 +240,24 @@ export class IosPreviewController {
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.syncLockSetting() this.syncLockSetting()
this.pushBrightness()
this.relayout() this.relayout()
shell.foregroundWindow()?.requestRender() shell.foregroundWindow()?.requestRender()
this.requestShellRender() this.requestShellRender()
}) })
this.clockTimer = setInterval(() => this.refreshClock(), 60_000) this.clockTimer = setInterval(() => this.refreshClock(), 60_000)
} }
private pushBrightness(): void {
const session = this.session
if (session?.state.phase !== 'connected') { this.lastBrightness = null; return }
const value = brightnessSetting.get()
if (value === this.lastBrightness) return
this.lastBrightness = value
void session.setBrightness(brightnessSettingToLevel(value)).catch(error => {
this.lastBrightness = null
this.logBluetooth(`Brightness: ${String(error)}`)
})
}
private syncLockSetting(): void { private syncLockSetting(): void {
const enabled = lockScreenEnabledSetting.get() const enabled = lockScreenEnabledSetting.get()
if (enabled === this.lockEnabled) return if (enabled === this.lockEnabled) return
@@ -500,6 +522,7 @@ export class IosPreviewController {
if (!this.session) { if (!this.session) {
this.session = new GlassesSession(iosBluetooth(), state => { this.session = new GlassesSession(iosBluetooth(), state => {
if (state.phase !== "connected") resetRingInputFilter() if (state.phase !== "connected") resetRingInputFilter()
this.pushBrightness()
this.maybePlayWelcomeSound(state) this.maybePlayWelcomeSound(state)
if (state.phase !== 'connected' && state.phase !== 'connecting') this.glassesWorn = null if (state.phase !== 'connected' && state.phase !== 'connecting') this.glassesWorn = null
if (state.phase !== 'connected') iosVoiceInput.handleSessionEnded() if (state.phase !== 'connected') iosVoiceInput.handleSessionEnded()
@@ -540,17 +563,22 @@ export class IosPreviewController {
startVoiceInput(): void { if (!this.glassesLocked) shell.startVoiceInput() } startVoiceInput(): void { if (!this.glassesLocked) shell.startVoiceInput() }
private async prepareVoiceCapture(): Promise<boolean> { private async prepareVoiceCapture(): Promise<boolean> {
if (this.glassesLocked) return false if (this.glassesLocked) return false
if (this.session?.state.phase !== 'connected') { const usePhoneMic = this.session?.state.phase !== 'connected'
if (this.active) this.onError('Connect the glasses to use their microphone.') if (usePhoneMic && !this.active) return false
return false const ready = await iosVoiceInput.prepare(this.active, usePhoneMic)
}
const ready = await iosVoiceInput.prepare(this.active)
if (!ready && this.active) this.onError(iosVoiceInput.statusText) if (!ready && this.active) this.onError(iosVoiceInput.statusText)
return ready && !this.glassesLocked && this.session?.state.phase === 'connected' return ready && !this.glassesLocked && (this.session?.state.phase === 'connected' || this.active)
} }
private async startVoiceCapture(endpointing = false): Promise<void> { private async startVoiceCapture(endpointing = false): Promise<void> {
if (this.glassesLocked || !this.session || this.session.state.phase !== 'connected') return if (this.glassesLocked) return
await iosVoiceInput.startGlassesCapture(this.session, message => this.logBluetooth(message), endpointing) const log = (message: string) => this.logBluetooth(message)
if (this.session?.state.phase === 'connected') {
await iosVoiceInput.startGlassesCapture(this.session, log, endpointing)
} else if (this.active) {
// Recheck microphone permission if the glasses disconnected after prepare.
if (!await iosVoiceInput.prepare(this.active, true) || !this.active || this.glassesLocked) return
await iosVoiceInput.startPhoneCapture(log, endpointing)
}
} }
private logBluetooth(message: string): void { private logBluetooth(message: string): void {
const line = `${new Date().toISOString()} [${this.active ? 'foreground' : 'background'}${UIApplication.sharedApplication.protectedDataAvailable ? '' : ',protected-data-unavailable'}] ${message}` const line = `${new Date().toISOString()} [${this.active ? 'foreground' : 'background'}${UIApplication.sharedApplication.protectedDataAvailable ? '' : ',protected-data-unavailable'}] ${message}`
@@ -568,17 +596,9 @@ export class IosPreviewController {
try { File.fromPath(path.join(knownFolders.documents().path, 'bluetooth.log')).writeTextSync(this.logLines.join('\n')) } try { File.fromPath(path.join(knownFolders.documents().path, 'bluetooth.log')).writeTextSync(this.logLines.join('\n')) }
catch (error) { console.warn(`Bluetooth log: ${error}`) } catch (error) { console.warn(`Bluetooth log: ${error}`) }
} }
async typeIntoApp(): Promise<void> { typeIntoApp(): void {
if (this.glassesLocked) return if (this.glassesLocked || !this.active) return
if (!this.active) { this.logBluetooth('Text input requires opening Faceclaw on the phone'); return } shell.startKeyboardInput()
if (this.prompting || !shell.foregroundWindow()?.receiveTextInput) return
this.prompting = true
try {
const result = await Dialogs.prompt({ title: 'Type into ' + shell.foregroundWindow()?.title,
message: 'Enter text to send to this app.', okButtonText: 'Send', cancelButtonText: 'Cancel' })
if (result.result && !this.glassesLocked) shell.sendTextToForegroundWindow(result.text)
} catch (error) { this.fail(error) }
finally { this.prompting = false }
} }
private async editSetting(setting: { editorTitle: string; inputKind?: string; get(): string; set(value: string): void }): Promise<boolean> { private async editSetting(setting: { editorTitle: string; inputKind?: string; get(): string; set(value: string): void }): Promise<boolean> {
if (!this.active) { this.logBluetooth('Editing text settings requires opening Faceclaw on the phone'); return false } if (!this.active) { this.logBluetooth('Editing text settings requires opening Faceclaw on the phone'); return false }
+28 -5
View File
@@ -6,7 +6,7 @@ export type IosMicrophoneSession = {
} }
/** iOS implementation of the shared voice dialog's event bridge. Audio comes /** iOS implementation of the shared voice dialog's event bridge. Audio comes
* exclusively from the connected glasses, never from the phone microphone. * from the glasses when connected, or the default phone input in preview mode.
*/ */
export class IosVoiceControlBridge { export class IosVoiceControlBridge {
private native: any = null private native: any = null
@@ -16,6 +16,7 @@ export class IosVoiceControlBridge {
private status = 'Voice input ready.' private status = 'Voice input ready.'
private generation = 0 private generation = 0
private session: IosMicrophoneSession | null = null private session: IosMicrophoneSession | null = null
private source: 'glasses' | 'phone' | null = null
private capturing = false private capturing = false
private finalizing = false private finalizing = false
private completion: Promise<void> = Promise.resolve() private completion: Promise<void> = Promise.resolve()
@@ -40,20 +41,28 @@ export class IosVoiceControlBridge {
} }
return this.native return this.native
} }
async prepare(foreground: boolean): Promise<boolean> { async prepare(foreground: boolean, usePhoneMic = false): Promise<boolean> {
let status = FaceclawSpeech.authorizationStatus() let status = FaceclawSpeech.authorizationStatus()
if (status === 0) { if (status === 0) {
if (!foreground) { this.setStatus('Open Faceclaw on the phone once to allow Speech Recognition.'); return false } if (!foreground) { this.setStatus('Open Faceclaw on the phone once to allow Speech Recognition.'); return false }
status = await new Promise<number>(resolve => FaceclawSpeech.requestAuthorization(resolve)) status = await new Promise<number>(resolve => FaceclawSpeech.requestAuthorization(resolve))
} }
if (status !== 3) { this.setStatus('Allow Speech Recognition for Faceclaw in iPhone Settings.'); return false } if (status !== 3) { this.setStatus('Allow Speech Recognition for Faceclaw in iPhone Settings.'); return false }
if (usePhoneMic) {
let microphoneStatus = FaceclawSpeech.microphoneAuthorizationStatus()
if (microphoneStatus === 0) {
if (!foreground) { this.setStatus('Open Faceclaw on the phone to allow microphone access.'); return false }
microphoneStatus = await new Promise<number>(resolve => FaceclawSpeech.requestMicrophoneAuthorization(resolve))
}
if (microphoneStatus !== 3) { this.setStatus('Allow Microphone access for Faceclaw in iPhone Settings.'); return false }
}
return true return true
} }
get statusText(): string { return this.status } get statusText(): string { return this.status }
async startGlassesCapture(session: IosMicrophoneSession, log: (message: string) => void, endpointing = false): Promise<void> { async startGlassesCapture(session: IosMicrophoneSession, log: (message: string) => void, endpointing = false): Promise<void> {
this.stop() this.stop()
const generation = ++this.generation const generation = ++this.generation
this.log = log; this.session = session; this.packets = 0; this.capturing = true this.log = log; this.source = 'glasses'; this.session = session; this.packets = 0; this.capturing = true
this.completion = new Promise(resolve => { this.resolveCompletion = resolve }) this.completion = new Promise(resolve => { this.resolveCompletion = resolve })
const error = String(this.ensureNative().startWithEndpointing(endpointing) ?? '') const error = String(this.ensureNative().startWithEndpointing(endpointing) ?? '')
if (error) { this.stop(); this.setStatus(error); this.emitEnd(); return } if (error) { this.stop(); this.setStatus(error); this.emitEnd(); return }
@@ -77,6 +86,18 @@ export class IosVoiceControlBridge {
this.stop(); this.setStatus(error instanceof Error ? error.message : String(error)); this.emitEnd() this.stop(); this.setStatus(error instanceof Error ? error.message : String(error)); this.emitEnd()
} }
} }
async startPhoneCapture(log: (message: string) => void, endpointing = false): Promise<void> {
this.stop()
this.log = log; this.source = 'phone'; this.capturing = true
this.completion = new Promise(resolve => { this.resolveCompletion = resolve })
const error = String(this.ensureNative().startPhoneWithEndpointing(endpointing) ?? '')
if (error) { this.stop(); this.setStatus(error); this.emitEnd(); return }
log('Voice: phone default microphone enabled; using on-device recognition')
}
stopPhoneCapture(): void {
if (this.source !== 'phone') return
this.stop(); this.setStatus('Phone voice input stopped.'); this.emitEnd()
}
stopPushToTalk(): Promise<void> { stopPushToTalk(): Promise<void> {
const completion = this.completion const completion = this.completion
if (!this.capturing) return completion if (!this.capturing) return completion
@@ -88,11 +109,12 @@ export class IosVoiceControlBridge {
stop(): void { stop(): void {
++this.generation ++this.generation
this.capturing = this.finalizing = false this.capturing = this.finalizing = false
this.source = null
this.clearAudioTimer(); this.releaseMicrophone(); this.native?.cancel() this.clearAudioTimer(); this.releaseMicrophone(); this.native?.cancel()
this.finishCompletion() this.finishCompletion()
} }
handleSessionEnded(message = 'Glasses disconnected. Start voice input again after reconnecting.'): void { handleSessionEnded(message = 'Glasses disconnected. Start voice input again after reconnecting.'): void {
if (!this.capturing && !this.finalizing) return if (this.source !== 'glasses' || !this.capturing && !this.finalizing) return
this.stop(); this.setStatus(message); this.emitEnd() this.stop(); this.setStatus(message); this.emitEnd()
} }
private clearAudioTimer(): void { if (this.audioTimer !== null) clearTimeout(this.audioTimer); this.audioTimer = null } private clearAudioTimer(): void { if (this.audioTimer !== null) clearTimeout(this.audioTimer); this.audioTimer = null }
@@ -112,10 +134,11 @@ export class IosVoiceControlBridge {
} else if (event.kind === 'status') this.setStatus(event.message ?? '') } else if (event.kind === 'status') this.setStatus(event.message ?? '')
else if (event.kind === 'audio') { else if (event.kind === 'audio') {
this.log(`Voice audio: ${event.seconds?.toFixed(1)}s, packets=${event.packets}, RMS=${event.rms?.toFixed(4)}, missing=${event.missing}, errors=${event.errors}`) this.log(`Voice audio: ${event.seconds?.toFixed(1)}s, packets=${event.packets}, RMS=${event.rms?.toFixed(4)}, missing=${event.missing}, errors=${event.errors}`)
if (this.capturing) this.setStatus(`Listening on glasses… ${event.seconds?.toFixed(0)}s`) if (this.capturing) this.setStatus(`Listening on ${this.source === 'phone' ? 'phone' : 'glasses'}… ${event.seconds?.toFixed(0)}s`)
} else if (event.kind === 'finishing') { } else if (event.kind === 'finishing') {
this.stopPushToTalk(); this.emitEnd() this.stopPushToTalk(); this.emitEnd()
} else if (event.kind === 'ended') { } else if (event.kind === 'ended') {
this.source = null
this.capturing = this.finalizing = false this.capturing = this.finalizing = false
this.clearAudioTimer(); this.releaseMicrophone() this.clearAudioTimer(); this.releaseMicrophone()
this.finishCompletion() this.finishCompletion()
+33
View File
@@ -0,0 +1,33 @@
# Main-screen UI
Android and iOS share `remote-controls.xml`, `remote-controls.css`, and
`RemoteControlsViewModel`: tab order and selection, screen-size choices,
brightness/Auto settings, watch labels, ring markings, and microphone/keyboard
buttons. Import the stylesheet at the top of each platform's application CSS
(before any rules), so the NativeScript CSS pipeline includes it.
Android's `MainViewModel` extends that shared model and connects it to
`dashboardController`. iOS loads the same XML with `Builder.load` and connects
it to `IosPreviewController`. Keep platform-specific transport, page lifecycle,
and navigation in those adapters. Android uses NativeScript gesture events;
iOS feeds raw touches to `PhoneGestureRecognizer`, so the discrete pad gesture
bindings in the XML are Android-only to avoid delivering each gesture twice.
The iOS shell uses the same portrait preview-above-controls layout and 345-DIP
landscape controls column. It respects safe areas, uses the same overflow menu
labels/order, and retains device diagnostics under the connection status.
Conversations and Record screen are disabled on iOS because their storage and
recording services are currently Android-only. Take screenshot opens the iOS
share sheet. Text settings still use native dialogs. Keyboard input uses the
shared `keyboard-input-panel.xml` multiline editor and shell keyboard session,
with separate Agent and App destinations when available. iOS keeps the editor
above the software keyboard in both orientations.
Voice input uses the glasses microphone when connected and the phone's default
audio input in preview mode. The phone path requires both Speech Recognition
and Microphone permissions and stops when Faceclaw leaves the foreground;
connected-glasses capture retains its existing background behavior.
The iOS microphone and keyboard image assets are 3x rasterizations of the
Android vector drawables with the same names; regenerate them from those
vectors if the icon designs change.
+18
View File
@@ -0,0 +1,18 @@
<GridLayout rows="auto,*,auto" maxHeight="280" xmlns="http://schemas.nativescript.org/tns.xsd"
class="system-name-modal"
visibility="{{ keyboardInputVisibility }}"
horizontalAlignment="stretch"
verticalAlignment="bottom">
<Label row="0" text="Keyboard input" class="h2" />
<TextView row="1"
id="keyboardInputField"
text="{{ keyboardInputText }}"
hint="Type a message"
textChange="{{ onKeyboardInputTextChange }}" />
<!-- Wraps onto a second line when the labels don't fit side by side. -->
<FlexboxLayout row="2" flexWrap="wrap" class="m-t-8">
<Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" />
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" />
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" />
</FlexboxLayout>
</GridLayout>
+41
View File
@@ -0,0 +1,41 @@
import { Observable } from '@nativescript/core'
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
/** Phone editor for the shell's keyboard session, using the shared XML panel. */
export class KeyboardInputViewModel extends Observable {
private session: KeyboardInputSession | null = null
private text = ''
setSession(session: KeyboardInputSession | null): void {
if (session === this.session) return
this.session = session
this.text = ''
for (const property of ['keyboardInputText', 'keyboardInputVisibility', 'keyboardInputPrimaryTargetLabel',
'keyboardInputPrimaryTargetVisibility', 'keyboardInputSecondaryTargetLabel', 'keyboardInputSecondaryTargetVisibility']) {
this.notifyPropertyChange(property, this.get(property))
}
}
get keyboardInputVisibility(): 'visible' | 'collapse' { return this.session ? 'visible' : 'collapse' }
get keyboardInputText(): string { return this.text }
set keyboardInputText(text: string) { this.text = text; this.session?.setText(text) }
private targetLabel(index: number): string {
const target = this.session?.targets[index]
return target?.id === 'assistant' ? 'Send to Agent' : target?.id === 'app' ? 'Type into App' : target?.label ?? ''
}
get keyboardInputPrimaryTargetLabel(): string { return this.targetLabel(0) }
get keyboardInputSecondaryTargetLabel(): string { return this.targetLabel(1) }
get keyboardInputPrimaryTargetVisibility(): 'visible' | 'collapse' { return this.session?.targets[0] ? 'visible' : 'collapse' }
get keyboardInputSecondaryTargetVisibility(): 'visible' | 'collapse' { return this.session?.targets[1] ? 'visible' : 'collapse' }
onKeyboardInputTextChange(args: { value?: string; object?: { text?: string } }): void {
this.keyboardInputText = args.object?.text ?? args.value ?? ''
}
onKeyboardInputPrimarySendTap(): void { this.send(0) }
onKeyboardInputSecondarySendTap(): void { this.send(1) }
private send(index: number): void {
const target = this.session?.targets[index]
if (!target) return
this.session.setText(this.text)
this.session.sendTo(target.id)
}
onKeyboardInputDiscardTap(): void { this.session?.discard() }
}
+144 -103
View File
@@ -1,75 +1,122 @@
import { Application, Button, Color, Dialogs, Frame, GridLayout, Image, Label, Page, StackLayout, type TouchGestureEventData } from '@nativescript/core' import { KeyboardInputViewModel } from './keyboard-input-view-model'
import { Application, Builder, Button, Color, Dialogs, Frame, GridLayout, Image, Label, Page, TextView, type PropertyChangeData, type TouchGestureEventData, type View } from '@nativescript/core'
import { isPreviewOnlyMode } from './onboarding-state' import { isPreviewOnlyMode } from './onboarding-state'
import { isAutoReconnectSuppressed, resumeAutoReconnect, suppressAutoReconnect } from '../g2/reconnect-policy' import { isAutoReconnectSuppressed, resumeAutoReconnect, suppressAutoReconnect } from '../g2/reconnect-policy'
import { launcherEntries } from '../apps/launcher' import { RemoteControlsViewModel } from './remote-controls-view-model'
import { ALL_APPS } from '../apps/all-apps'
import { IosPreviewController } from '../g2/ios-preview-controller' import { IosPreviewController } from '../g2/ios-preview-controller'
import { PhoneGestureRecognizer } from './phone-gestures' import { PhoneGestureRecognizer } from './phone-gestures'
import { BleBandwidthMeter } from './ble-bandwidth-meter' import { BleBandwidthMeter } from './ble-bandwidth-meter'
import { sampleBleTraffic } from '../native/ble-traffic' import { sampleBleTraffic } from '../native/ble-traffic'
import { onAnySettingChanged, previewColorSetting, showBleBandwidthSetting } from '../ui/dashboard-settings' import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
import { loadDeviceAddresses } from '../g2/device-addresses' import { loadDeviceAddresses } from '../g2/device-addresses'
import { deviceAddressError } from '../g2/ios-peripheral-identity' import { deviceAddressError } from '../g2/ios-peripheral-identity'
export function createMainPage(): Page { export function createMainPage(): Page {
const page = new Page() const page = new Page()
page.actionBarHidden = true page.actionBarHidden = true
page.className = 'main-page'
page.iosOverflowSafeAreaEnabled = false
const root = new GridLayout() const root = new GridLayout()
root.rows = 'auto,*,auto' root.rows = 'auto,*'
page.content = root page.content = root
const header = new GridLayout() const header = new GridLayout()
header.columns = '*,auto'; header.padding = '12 20' header.columns = '*,auto,auto'; header.className = 'main-header'
const title = new Label() const title = new Label()
title.text = 'Faceclaw'; title.fontSize = 25; title.fontWeight = 'bold' title.text = 'Faceclaw'; title.className = 'action-bar-title'
const heading = new StackLayout(); heading.addChild(title); header.addChild(heading) header.addChild(title)
const state = new Label() const state = new Label()
state.text = 'Preview only'; state.fontSize = 12; heading.addChild(state) state.text = 'Preview'; state.className = 'action-bar-status'
const devices = new Button() state.verticalAlignment = 'middle'
devices.text = 'Devices'; devices.accessibilityLabel = 'Configure devices'; devices.fontSize = 14; devices.padding = '10 12' state.on('tap', () => { void openDevices() })
devices.on('tap', () => { void openDevices() }) GridLayout.setColumn(state, 1); header.addChild(state)
GridLayout.setColumn(devices, 1); header.addChild(devices); root.addChild(header) const overflow = new Button()
overflow.text = '⋮'; overflow.accessibilityLabel = 'More options'; overflow.className = 'overflow-button'
overflow.on('tap', () => openMenu())
GridLayout.setColumn(overflow, 2); header.addChild(overflow); root.addChild(header)
const body = new GridLayout() const body = new GridLayout()
GridLayout.setRow(body, 1); root.addChild(body) GridLayout.setRow(body, 1); root.addChild(body)
const mirror = new Image() const mirror = new Image()
mirror.stretch = 'fill'; mirror.backgroundColor = new Color('black') mirror.stretch = 'fill'; mirror.backgroundColor = new Color('black')
mirror.accessibilityIdentifier = 'glasses-preview' mirror.accessibilityIdentifier = 'glasses-preview'
mirror.accessibilityLabel = 'Interactive glasses screen preview' mirror.accessibilityLabel = 'Interactive glasses screen preview'
mirror.verticalAlignment = 'middle'; body.addChild(mirror) mirror.horizontalAlignment = 'left'; mirror.verticalAlignment = 'middle'; body.addChild(mirror)
// Load exactly the same XML and binding model as Android. Only input dispatch
// and the surrounding platform navigation/runtime remain iOS-specific.
const model = new RemoteControlsViewModel()
const controls = new GridLayout() const controls = new GridLayout()
controls.rows = 'auto,*,auto'; controls.padding = 16; body.addChild(controls) const remote = Builder.load('~/phone-ui/remote-controls')
const tabs = new GridLayout() remote.bindingContext = model
tabs.columns = '*,*,*'; controls.addChild(tabs) controls.addChild(remote); body.addChild(controls)
const pad = new GridLayout() const keyboardModel = new KeyboardInputViewModel()
pad.borderRadius = 18; pad.backgroundColor = new Color('#202522') const keyboardPanel = Builder.load('~/phone-ui/keyboard-input-panel')
pad.verticalAlignment = 'middle'; pad.horizontalAlignment = 'center' keyboardPanel.bindingContext = keyboardModel
pad.accessibilityIdentifier = 'gesture-pad' GridLayout.setRow(keyboardPanel, 1); root.addChild(keyboardPanel)
GridLayout.setRow(pad, 1); controls.addChild(pad) let focusTimer: ReturnType<typeof setTimeout> | null = null
const focus = new Label() const keyboardField = () => keyboardPanel.getViewById<TextView>('keyboardInputField')
focus.color = new Color('#ffffff'); focus.fontSize = 22; focus.textWrap = true
focus.textAlignment = 'center'; focus.margin = 18; focus.verticalAlignment = 'middle'
focus.isUserInteractionEnabled = false; pad.addChild(focus)
const legend = new Label()
legend.color = new Color('#b8c1bb'); legend.fontSize = 12; legend.textAlignment = 'center'
legend.textWrap = true; legend.margin = 12; legend.verticalAlignment = 'bottom'
legend.isUserInteractionEnabled = false; pad.addChild(legend)
const settings = new StackLayout()
settings.verticalAlignment = 'middle'
GridLayout.setRow(settings, 1); controls.addChild(settings)
const errorLabel = new Label()
errorLabel.textWrap = true; errorLabel.color = new Color('#a02d2d'); errorLabel.visibility = 'collapse'
settings.addChild(errorLabel)
let selectedTab: 'watch' | 'ring' | 'settings' = 'watch'
const controller = new IosPreviewController((image, label) => { const controller = new IosPreviewController((image, label) => {
mirror.imageSource = image; focus.text = selectedTab === 'ring' ? 'Ring' : label mirror.imageSource = image; model.set('padFocusLine', label)
}, message => { }, message => {
errorLabel.text = message; errorLabel.visibility = 'visible'; selectTab('settings') void Dialogs.alert({ title: 'Faceclaw', message, okButtonText: 'OK' })
}, connection => { }, connection => {
state.text = connection.phase === 'connected' ? `Connected${connection.battery !== null ? ` · ${connection.battery}%` : ''}${connection.ring ? ' · R1' : ''}` state.text = ({ connected: 'Connected', disconnected: 'Preview', connecting: 'Connecting',
: ({ disconnected: 'Preview only', connecting: 'Connecting…', retrying: 'Reconnecting…', disconnecting: 'Disconnecting…', error: 'Connection failed · Devices for details' })[connection.phase] || connection.phase retrying: 'Reconnecting', disconnecting: 'Disconnecting', error: 'Failed' })[connection.phase]
}, session => {
keyboardModel.setSession(session)
controls.visibility = session ? 'collapse' : 'visible'
if (focusTimer !== null) clearTimeout(focusTimer)
focusTimer = null
if (session) {
focusTimer = setTimeout(() => { focusTimer = null; keyboardField()?.focus() }, 0)
} else keyboardField()?.dismissSoftInput()
}) })
async function navigateDevicePage(moduleName: string, context?: object): Promise<void> {
suppressAutoReconnect()
await controller.disconnect()
Frame.topmost()?.navigate({ moduleName, context })
}
function openMenu(): void {
const connected = ['connected', 'connecting', 'retrying'].includes(controller.connectionState?.phase ?? '')
const configured = !deviceAddressError(loadDeviceAddresses())
const menu = UIAlertController.alertControllerWithTitleMessagePreferredStyle(null, null, UIAlertControllerStyle.ActionSheet)
const add = (label: string, action: (() => void) | null) => {
const item = UIAlertAction.actionWithTitleStyleHandler(label, UIAlertActionStyle.Default, () => {
// Finish dismissal before presenting a share sheet or another page.
menu.dismissViewControllerAnimatedCompletion(true, () => action?.())
})
item.enabled = action !== null
menu.addAction(item)
}
if (configured) add(connected ? 'Disconnect' : 'Connect', () => {
if (connected) { suppressAutoReconnect(); void controller.disconnect() }
else { resumeAutoReconnect(); void controller.connect() }
})
add('Pair glasses', () => { void navigateDevicePage('phone-ui/onboarding-unpair-page') })
add('Permissions', () => Frame.topmost()?.navigate({ moduleName: 'phone-ui/permissions-page' }))
// Keep Android's menu order/text. These services still require Android;
// disabled items make the platform limitation visible without dead actions.
add('Conversations', null)
add('Take screenshot', mirror.imageSource ? () => {
const share = UIActivityViewController.alloc().initWithActivityItemsApplicationActivities([mirror.imageSource.ios], null)
if (share.popoverPresentationController) {
share.popoverPresentationController.sourceView = overflow.ios
share.popoverPresentationController.sourceRect = overflow.ios.bounds
}
page.ios.presentViewControllerAnimatedCompletion(share, true, null)
} : null)
add('Record screen', null)
if (configured) add('Uninstall custom firmware', () => {
void navigateDevicePage('phone-ui/onboarding-flash-page', { mode: 'uninstall', fromOnboarding: false })
})
menu.addAction(UIAlertAction.actionWithTitleStyleHandler('Cancel', UIAlertActionStyle.Cancel, null))
if (menu.popoverPresentationController) {
menu.popoverPresentationController.sourceView = overflow.ios
menu.popoverPresentationController.sourceRect = overflow.ios.bounds
}
page.ios.presentViewControllerAnimatedCompletion(menu, true, null)
}
async function openDevices(): Promise<void> { async function openDevices(): Promise<void> {
const connected = ['connected', 'connecting', 'retrying'].includes(controller.connectionState?.phase ?? '') const connected = ['connected', 'connecting', 'retrying'].includes(controller.connectionState?.phase ?? '')
const choice = await Dialogs.action({ title: 'Devices', message: controller.connectionState?.status ?? 'Preview only', cancelButtonText: 'Cancel', const choice = await Dialogs.action({ title: 'Connection status', message: controller.connectionState?.status ?? 'Preview only', cancelButtonText: 'Cancel',
actions: ['Pair glasses', 'Configure devices', connected ? 'Disconnect' : 'Connect', 'Check firmware', 'Install custom firmware', 'Uninstall custom firmware', 'Connection details'] }) actions: ['Pair glasses', 'Configure devices', connected ? 'Disconnect' : 'Connect', 'Check firmware', 'Install custom firmware', 'Uninstall custom firmware', 'Connection details'] })
if (['Pair glasses', 'Configure devices', 'Check firmware', 'Install custom firmware', 'Uninstall custom firmware'].includes(choice)) { if (['Pair glasses', 'Configure devices', 'Check firmware', 'Install custom firmware', 'Uninstall custom firmware'].includes(choice)) {
suppressAutoReconnect() suppressAutoReconnect()
@@ -87,8 +134,10 @@ export function createMainPage(): Page {
else if (choice === 'Disconnect') { suppressAutoReconnect(); await controller.disconnect() } else if (choice === 'Disconnect') { suppressAutoReconnect(); await controller.disconnect() }
else if (choice === 'Connection details') await Dialogs.alert({ title: 'Connection details', message: controller.connectionDetails, okButtonText: 'OK' }) else if (choice === 'Connection details') await Dialogs.alert({ title: 'Connection details', message: controller.connectionDetails, okButtonText: 'OK' })
} }
const padInput = new PhoneGestureRecognizer(gesture => controller.gesture(gesture, selectedTab === 'ring' ? 'ring' : 'watch')) const watchInput = new PhoneGestureRecognizer(gesture => controller.gesture(gesture, 'watch'))
const ringInput = new PhoneGestureRecognizer(gesture => controller.gesture(gesture, 'ring'))
const mirrorInput = new PhoneGestureRecognizer((gesture, x, y) => { const mirrorInput = new PhoneGestureRecognizer((gesture, x, y) => {
if (!mirrorTouchSetting.get()) return
const size = mirror.getActualSize() const size = mirror.getActualSize()
if (size.width > 0 && size.height > 0) controller.gesture(gesture, 'mirror', x / size.width, y / size.height) if (size.width > 0 && size.height > 0) controller.gesture(gesture, 'mirror', x / size.width, y / size.height)
}) })
@@ -96,56 +145,33 @@ export function createMainPage(): Page {
if (!['down', 'move', 'up', 'cancel'].includes(event.action)) return if (!['down', 'move', 'up', 'cancel'].includes(event.action)) return
recognizer.touch({ action: event.action as 'down' | 'move' | 'up' | 'cancel', x: event.getX(), y: event.getY(), pointers: event.getPointerCount() }) recognizer.touch({ action: event.action as 'down' | 'move' | 'up' | 'cancel', x: event.getX(), y: event.getY(), pointers: event.getPointerCount() })
} }
pad.on('touch', touch(padInput)); mirror.on('touch', touch(mirrorInput)) model.set('onPadTouch', touch(watchInput))
function button(text: string, action: () => void): Button { model.set('onRingPadTouch', touch(ringInput))
const view = new Button() model.set('onSyntheticMicTap', () => controller.startVoiceInput())
view.text = text; view.fontSize = 15; view.margin = 3; view.on('tap', action) model.set('onKeyboardTap', () => { void controller.typeIntoApp() })
return view mirror.on('touch', touch(mirrorInput))
} const cancelGestures = () => { watchInput.cancel(); ringInput.cancel(); mirrorInput.cancel() }
const tabButtons: Button[] = [] model.on('propertyChange', (args: PropertyChangeData) => {
function selectTab(tab: typeof selectedTab): void { if (args.propertyName === 'watchTabVisibility') cancelGestures()
padInput.cancel(); selectedTab = tab })
pad.visibility = tab === 'settings' ? 'collapse' : 'visible' let controlsLayoutTimer: ReturnType<typeof setTimeout> | null = null
settings.visibility = tab === 'settings' ? 'visible' : 'collapse' model.set('onControlsContentLayoutChanged', (args: { object: View }) => {
for (let i = 0; i < tabButtons.length; i++) tabButtons[i].opacity = ['settings', 'watch', 'ring'][i] === tab ? 1 : 0.5 if (controlsLayoutTimer !== null) clearTimeout(controlsLayoutTimer)
focus.text = tab === 'ring' ? 'Ring' : 'Watch controls' // Defer binding updates out of UIKit's layout pass.
legend.text = tab === 'ring' ? 'Swipe up/down · Tap to select\nDouble-tap: back · Hold: menu' : 'Swipe to navigate · Tap to select\nDouble-tap / two fingers: back · Hold: menu' controlsLayoutTimer = setTimeout(() => {
layout() controlsLayoutTimer = null
} const { width, height } = args.object.getActualSize()
for (const [index, tab] of (['settings', 'watch', 'ring'] as const).entries()) { model.set('watchFaceWidth', Math.min(345, Math.max(0, width)))
const view = button(tab[0].toUpperCase() + tab.slice(1), () => selectTab(tab)) model.set('watchFaceHeight', Math.min(230, Math.max(0, height - 2)))
GridLayout.setColumn(view, index); tabs.addChild(view); tabButtons.push(view) model.set('ringTouchpadHeight', Math.min(250, Math.max(0, height - 2)))
} }, 0)
const sizeButton = button(controller.displayModeLabel, () => controller.cycleDisplayMode())
settings.addChild(button('Open app', () => { void (async () => {
const apps = launcherEntries(ALL_APPS).sort((a, b) => a.label.localeCompare(b.label))
const title = await Dialogs.action({ title: 'Open app', cancelButtonText: 'Cancel', actions: apps.map(app => app.label) })
const app = apps.find(app => app.label === title)
if (app) { await controller.launchApp(app.appId); selectTab('watch') }
})() }))
settings.addChild(sizeButton)
settings.addChild(button('Toggle green / grayscale', () => previewColorSetting.set(previewColorSetting.get() === 'green' ? 'white' : 'green')))
const help = new Label()
help.text = 'Tap preview icons to open apps.\nHold: system menu\nTap then hold: app menu'
help.fontSize = 13; help.textWrap = true; help.margin = 6; settings.addChild(help)
const footer = new GridLayout()
footer.columns = '*,*,*,*'; GridLayout.setRow(footer, 2); controls.addChild(footer)
const back = button('Back', () => controller.gesture('double-tap', 'watch'))
const menu = button('Menu', () => {
controller.gesture('long-press', 'watch'); controller.gesture('long-press-release', 'watch')
}) })
const keyboard = button('Keyboard', () => { void controller.typeIntoApp() })
const voice = button('Voice', () => controller.startVoiceInput())
for (const [index, view] of [back, menu, voice, keyboard].entries()) {
view.padding = '16 8'; view.fontSize = 14
GridLayout.setColumn(view, index); footer.addChild(view)
}
const bandwidth = new Label() const bandwidth = new Label()
bandwidth.accessibilityIdentifier = 'ble-bandwidth-indicator' bandwidth.accessibilityIdentifier = 'ble-bandwidth-indicator'
bandwidth.fontSize = 10; bandwidth.textWrap = true; bandwidth.padding = '2 8 4' bandwidth.className = 'ble-bandwidth-indicator'; bandwidth.isUserInteractionEnabled = false
bandwidth.color = new Color('#68756c'); bandwidth.isUserInteractionEnabled = false bandwidth.horizontalAlignment = 'center'; bandwidth.verticalAlignment = 'bottom'
bandwidth.visibility = 'collapse' bandwidth.visibility = 'collapse'
GridLayout.setRow(bandwidth, 2); root.addChild(bandwidth) GridLayout.setRow(bandwidth, 1); root.addChild(bandwidth)
const bandwidthMeter = new BleBandwidthMeter() const bandwidthMeter = new BleBandwidthMeter()
let bandwidthTimer: ReturnType<typeof setInterval> | null = null let bandwidthTimer: ReturnType<typeof setInterval> | null = null
let foreground = false let foreground = false
@@ -164,25 +190,24 @@ export function createMainPage(): Page {
} }
let lastLayout = '' let lastLayout = ''
function layout(): void { function layout(): void {
const size = root.getActualSize() const size = body.getActualSize()
if (size.width <= 0 || size.height <= 0) return if (size.width <= 0 || size.height <= 0) return
const metricsHeight = bandwidth.visibility === 'visible' ? bandwidth.getActualSize().height : 0 const landscape = root.getActualSize().width > root.getActualSize().height
const availableHeight = size.height - metricsHeight const key = `${size.width}:${size.height}:${landscape}`
const key = `${size.width}:${availableHeight}:${selectedTab}`
if (key === lastLayout) return if (key === lastLayout) return
lastLayout = key; padInput.cancel(); mirrorInput.cancel() lastLayout = key; cancelGestures()
const landscape = size.width > size.height body.className = landscape ? 'landscape-layout' : ''
body.rows = landscape ? '*' : 'auto,*'; body.columns = landscape ? '*,320' : '*' root.className = landscape ? 'main-landscape' : ''
body.rows = landscape ? '*' : 'auto,*'; body.columns = landscape ? '*,345' : '*'
controls.padding = landscape ? 0 : 20
GridLayout.setRow(controls, landscape ? 0 : 1); GridLayout.setColumn(controls, landscape ? 1 : 0) GridLayout.setRow(controls, landscape ? 0 : 1); GridLayout.setColumn(controls, landscape ? 1 : 0)
const width = landscape ? Math.min(size.width - 320, (availableHeight - 64) * 4 / 3) : size.width const width = landscape ? Math.max(0, Math.min(size.width - 345, size.height * 4 / 3)) : size.width
mirror.width = width; mirror.height = width * 3 / 4 mirror.width = width; mirror.height = width * 3 / 4
pad.width = selectedTab === 'ring' ? 150 : Math.min(360, (landscape ? 320 : size.width) - 32)
pad.height = Math.max(120, Math.min(250, availableHeight - (landscape ? 180 : width * 3 / 4 + 200)))
} }
// iOS emits layoutChanged inside its layout pass. Defer mutations so // iOS emits layoutChanged inside its layout pass. Defer mutations so
// NativeScript does not clear our new layout request at the end of that pass. // NativeScript does not clear our new layout request at the end of that pass.
let layoutTimer: ReturnType<typeof setTimeout> | null = null let layoutTimer: ReturnType<typeof setTimeout> | null = null
root.on('layoutChanged', () => { body.on('layoutChanged', () => {
if (layoutTimer !== null) return if (layoutTimer !== null) return
layoutTimer = setTimeout(() => { layoutTimer = null; layout() }, 0) layoutTimer = setTimeout(() => { layoutTimer = null; layout() }, 0)
}) })
@@ -190,17 +215,33 @@ export function createMainPage(): Page {
foreground = false; stopBandwidth() foreground = false; stopBandwidth()
if (layoutTimer !== null) clearTimeout(layoutTimer) if (layoutTimer !== null) clearTimeout(layoutTimer)
layoutTimer = null layoutTimer = null
padInput.cancel(); mirrorInput.cancel(); controller.pause() if (controlsLayoutTimer !== null) clearTimeout(controlsLayoutTimer)
controlsLayoutTimer = null
if (focusTimer !== null) clearTimeout(focusTimer)
focusTimer = null
keyboardField()?.dismissSoftInput()
cancelGestures(); controller.pause()
} }
const resume = () => { foreground = true; controller.resume(); syncBandwidth() } const resume = () => { foreground = true; controller.resume(); syncBandwidth() }
let keyboardObserver: any = null
let offSettings: (() => void) | null = null let offSettings: (() => void) | null = null
page.on('loaded', () => { page.on('loaded', () => {
if (!keyboardObserver) keyboardObserver = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(
UIKeyboardWillChangeFrameNotification, null, NSOperationQueue.mainQueue, notification => {
const frame = notification.userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue
const view = page.ios.view
const local = view.convertRectFromView(frame, null)
root.paddingBottom = Math.max(0, view.bounds.size.height - local.origin.y - view.safeAreaInsets.bottom)
})
Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume) Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume)
offSettings?.(); offSettings = onAnySettingChanged(() => { sizeButton.text = controller.displayModeLabel; syncBandwidth() }) offSettings?.(); offSettings = onAnySettingChanged(() => { model.refreshDisplayControls(); syncBandwidth() })
selectTab(selectedTab); resume() model.refreshDisplayControls(); resume()
if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect() if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect()
}) })
page.on('unloaded', () => { page.on('unloaded', () => {
if (keyboardObserver) NSNotificationCenter.defaultCenter.removeObserver(keyboardObserver)
keyboardObserver = null
root.paddingBottom = 0
pause(); offSettings?.(); offSettings = null pause(); offSettings?.(); offSettings = null
Application.off(Application.suspendEvent, pause); Application.off(Application.resumeEvent, resume) Application.off(Application.suspendEvent, pause); Application.off(Application.resumeEvent, resume)
}) })
+1 -19
View File
@@ -155,24 +155,6 @@
(ui/shell/keyboard-input.ts). Same placement and collapsing rules (ui/shell/keyboard-input.ts). Same placement and collapsing rules
as the setting editor above. Enter inserts a newline; the send as the setting editor above. Enter inserts a newline; the send
buttons pick a destination directly. --> buttons pick a destination directly. -->
<StackLayout <rc:keyboard-input-panel />
class="system-name-modal"
visibility="{{ keyboardInputVisibility }}"
horizontalAlignment="stretch"
verticalAlignment="bottom">
<Label text="Keyboard input" class="h2" />
<TextView
id="keyboardInputField"
text="{{ keyboardInputText }}"
hint="Type a message"
textChange="{{ onKeyboardInputTextChange }}"
height="120" />
<!-- Wraps onto a second line when the labels don't fit side by side. -->
<FlexboxLayout flexWrap="wrap" class="m-t-8">
<Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" />
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" />
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" />
</FlexboxLayout>
</StackLayout>
</GridLayout> </GridLayout>
</Page> </Page>
+2 -132
View File
@@ -1,10 +1,10 @@
import { RemoteControlsViewModel } from './remote-controls-view-model';
import { BleBandwidthMeter } from "./ble-bandwidth-meter"; import { BleBandwidthMeter } from "./ble-bandwidth-meter";
import { import {
Application, Application,
Dialogs, Dialogs,
Frame, Frame,
ImageSource, ImageSource,
Observable,
Screen, Screen,
SwipeDirection, SwipeDirection,
type GestureEventData, type GestureEventData,
@@ -14,15 +14,9 @@ import {
} from "@nativescript/core"; } from "@nativescript/core";
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller"; import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
import { import {
brightnessSetting,
DISPLAY_MODE_VALUES,
displayModeLabel,
displayModeSetting,
mirrorTouchSetting, mirrorTouchSetting,
onAnySettingChanged, onAnySettingChanged,
showBleBandwidthSetting, showBleBandwidthSetting,
type BrightnessSetting,
type DisplayModeSetting,
} from "../ui/dashboard-settings"; } from "../ui/dashboard-settings";
import { sampleBleTraffic } from "../native/ble-traffic"; import { sampleBleTraffic } from "../native/ble-traffic";
import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses"; import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
@@ -35,13 +29,7 @@ const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
type LayoutOrientation = "portrait" | "landscape"; type LayoutOrientation = "portrait" | "landscape";
type ControlsTab = "settings" | "watch" | "ring"; export class MainViewModel extends RemoteControlsViewModel {
// Survives navigation round-trips (a fresh view model is built per visit) but
// not process restarts.
let lastControlsTab: ControlsTab = "watch";
export class MainViewModel extends Observable {
private _status = "Disconnected."; private _status = "Disconnected.";
private _displayPreview: ImageSource | null = null; private _displayPreview: ImageSource | null = null;
private _displayPreviewMessage = ""; private _displayPreviewMessage = "";
@@ -1193,128 +1181,10 @@ export class MainViewModel extends Observable {
// watch face), Ring (simulated R1 inputs). The whole area collapses while a // watch face), Ring (simulated R1 inputs). The whole area collapses while a
// text setting is being edited so the editor gets the space instead. // text setting is being edited so the editor gets the space instead.
private _controlsTab: ControlsTab = lastControlsTab;
get controlsVisibility(): "visible" | "collapse" { get controlsVisibility(): "visible" | "collapse" {
return this.isTextSettingEditorActive || this._keyboardInputActive ? "collapse" : "visible"; return this.isTextSettingEditorActive || this._keyboardInputActive ? "collapse" : "visible";
} }
get settingsTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "settings" ? "visible" : "collapse";
}
get watchTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "watch" ? "visible" : "collapse";
}
get ringTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "ring" ? "visible" : "collapse";
}
get settingsTabClass(): string {
return this._controlsTab === "settings" ? "tab-button tab-button-selected" : "tab-button";
}
get watchTabClass(): string {
return this._controlsTab === "watch" ? "tab-button tab-button-selected" : "tab-button";
}
get ringTabClass(): string {
return this._controlsTab === "ring" ? "tab-button tab-button-selected" : "tab-button";
}
onSettingsTabTap(): void {
this.setControlsTab("settings");
}
onWatchTabTap(): void {
this.setControlsTab("watch");
}
onRingTabTap(): void {
this.setControlsTab("ring");
}
private setControlsTab(tab: ControlsTab): void {
if (this._controlsTab === tab) return;
this._controlsTab = tab;
// Remembered across navigations (module-level) so the page comes back on
// the tab it left on; deliberately not persisted to disk.
lastControlsTab = tab;
this.notifyPropertyChange("settingsTabVisibility", this.settingsTabVisibility);
this.notifyPropertyChange("watchTabVisibility", this.watchTabVisibility);
this.notifyPropertyChange("ringTabVisibility", this.ringTabVisibility);
this.notifyPropertyChange("settingsTabClass", this.settingsTabClass);
this.notifyPropertyChange("watchTabClass", this.watchTabClass);
this.notifyPropertyChange("ringTabClass", this.ringTabClass);
}
// ---- display mode and brightness, on the Settings tab ----
get displayModeLabel(): string {
return displayModeLabel(displayModeSetting.get()) + " ▾";
}
async onDisplayModeTap(): Promise<void> {
const current = displayModeSetting.get();
const options = DISPLAY_MODE_VALUES.map((value) => displayModeLabel(value) + (value === current ? " ✓" : ""));
const picked = await Dialogs.action({ title: "Display mode", cancelButtonText: "Cancel", actions: options });
const index = options.indexOf(picked);
if (index < 0) return;
const value = DISPLAY_MODE_VALUES[index] as DisplayModeSetting;
if (value !== current) displayModeSetting.set(value);
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
}
get brightnessAuto(): boolean {
return brightnessSetting.get() === "auto";
}
get brightnessSliderEnabled(): boolean {
return !this.brightnessAuto;
}
/** The slider's position; while Auto, the last manual level (or 50). */
get brightnessPercent(): number {
const value = brightnessSetting.get();
if (value === "auto") return this.lastManualBrightness;
const numeric = parseInt(value, 10);
return Number.isFinite(numeric) ? numeric : 50;
}
private lastManualBrightness = 50;
onBrightnessChange(args: { value?: number; object?: { value?: number } }): void {
if (this.brightnessAuto) return;
const raw = typeof args.value === "number" ? args.value : Number(args.object?.value ?? NaN);
if (!Number.isFinite(raw)) return;
// The setting only has every tenth level; snap to the nearest.
const level = Math.min(100, Math.max(0, Math.round(raw / 10) * 10));
this.lastManualBrightness = level;
const value = String(level) as BrightnessSetting;
if (brightnessSetting.get() !== value) brightnessSetting.set(value);
}
onBrightnessAutoChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
const on = typeof args.value === "boolean" ? args.value : Boolean(args.object?.checked);
if (on) {
if (brightnessSetting.get() !== "auto") {
this.lastManualBrightness = this.brightnessPercent;
brightnessSetting.set("auto");
}
} else if (brightnessSetting.get() === "auto") {
brightnessSetting.set(String(this.lastManualBrightness) as BrightnessSetting);
}
this.refreshDisplayControls();
}
private refreshDisplayControls(): void {
this.notifyPropertyChange("brightnessAuto", this.brightnessAuto);
this.notifyPropertyChange("brightnessSliderEnabled", this.brightnessSliderEnabled);
this.notifyPropertyChange("brightnessPercent", this.brightnessPercent);
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
}
// ---- BLE bandwidth indicator (Settings > Developer > Show BLE bandwidth usage) ---- // ---- BLE bandwidth indicator (Settings > Developer > Show BLE bandwidth usage) ----
// //
// A running total of outbound BLE messages/bytes, overlaid at the bottom of // A running total of outbound BLE messages/bytes, overlaid at the bottom of
+2
View File
@@ -17,3 +17,5 @@ global.registerModule('phone-ui/onboarding-flash-page.xml', () => require('./onb
global.registerModule('phone-ui/document-page', () => require('./document-page')); global.registerModule('phone-ui/document-page', () => require('./document-page'));
global.registerModule('phone-ui/document-page.xml', () => require('./document-page.xml')); global.registerModule('phone-ui/document-page.xml', () => require('./document-page.xml'));
global.registerModule('phone-ui/main-page', () => require('./main-page.ios')); global.registerModule('phone-ui/main-page', () => require('./main-page.ios'));
global.registerModule('phone-ui/remote-controls.xml', () => require('./remote-controls.xml'));
global.registerModule('phone-ui/keyboard-input-panel.xml', () => require('./keyboard-input-panel.xml'));
+131
View File
@@ -0,0 +1,131 @@
import { Dialogs, Observable } from '@nativescript/core';
import {
brightnessSetting, DISPLAY_MODE_VALUES, displayModeLabel, displayModeSetting,
type BrightnessSetting, type DisplayModeSetting,
} from '../ui/dashboard-settings';
type ControlsTab = 'settings' | 'watch' | 'ring';
// Remember the tab across navigation on both platforms, without persisting it.
let lastControlsTab: ControlsTab = 'watch';
/** Shared state and actions for remote-controls.xml; transport stays in the host. */
export class RemoteControlsViewModel extends Observable {
private _controlsTab: ControlsTab = lastControlsTab;
get settingsTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "settings" ? "visible" : "collapse";
}
get watchTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "watch" ? "visible" : "collapse";
}
get ringTabVisibility(): "visible" | "collapse" {
return this._controlsTab === "ring" ? "visible" : "collapse";
}
get settingsTabClass(): string {
return this._controlsTab === "settings" ? "tab-button tab-button-selected" : "tab-button";
}
get watchTabClass(): string {
return this._controlsTab === "watch" ? "tab-button tab-button-selected" : "tab-button";
}
get ringTabClass(): string {
return this._controlsTab === "ring" ? "tab-button tab-button-selected" : "tab-button";
}
onSettingsTabTap(): void {
this.setControlsTab("settings");
}
onWatchTabTap(): void {
this.setControlsTab("watch");
}
onRingTabTap(): void {
this.setControlsTab("ring");
}
protected setControlsTab(tab: ControlsTab): void {
if (this._controlsTab === tab) return;
this._controlsTab = tab;
// Remembered across navigations (module-level) so the page comes back on
// the tab it left on; deliberately not persisted to disk.
lastControlsTab = tab;
this.notifyPropertyChange("settingsTabVisibility", this.settingsTabVisibility);
this.notifyPropertyChange("watchTabVisibility", this.watchTabVisibility);
this.notifyPropertyChange("ringTabVisibility", this.ringTabVisibility);
this.notifyPropertyChange("settingsTabClass", this.settingsTabClass);
this.notifyPropertyChange("watchTabClass", this.watchTabClass);
this.notifyPropertyChange("ringTabClass", this.ringTabClass);
}
// ---- display mode and brightness, on the Settings tab ----
get displayModeLabel(): string {
return displayModeLabel(displayModeSetting.get()) + " ▾";
}
async onDisplayModeTap(): Promise<void> {
const current = displayModeSetting.get();
const options = DISPLAY_MODE_VALUES.map((value) => displayModeLabel(value) + (value === current ? " ✓" : ""));
const picked = await Dialogs.action({ title: "Display mode", cancelButtonText: "Cancel", actions: options });
const index = options.indexOf(picked);
if (index < 0) return;
const value = DISPLAY_MODE_VALUES[index] as DisplayModeSetting;
if (value !== current) displayModeSetting.set(value);
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
}
get brightnessAuto(): boolean {
return brightnessSetting.get() === "auto";
}
get brightnessSliderEnabled(): boolean {
return !this.brightnessAuto;
}
/** The slider's position; while Auto, the last manual level (or 50). */
get brightnessPercent(): number {
const value = brightnessSetting.get();
if (value === "auto") return this.lastManualBrightness;
const numeric = parseInt(value, 10);
return Number.isFinite(numeric) ? numeric : 50;
}
private lastManualBrightness = 50;
onBrightnessChange(args: { value?: number; object?: { value?: number } }): void {
if (this.brightnessAuto) return;
const raw = typeof args.value === "number" ? args.value : Number(args.object?.value ?? NaN);
if (!Number.isFinite(raw)) return;
// The setting only has every tenth level; snap to the nearest.
const level = Math.min(100, Math.max(0, Math.round(raw / 10) * 10));
this.lastManualBrightness = level;
const value = String(level) as BrightnessSetting;
if (brightnessSetting.get() !== value) brightnessSetting.set(value);
}
onBrightnessAutoChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
const on = typeof args.value === "boolean" ? args.value : Boolean(args.object?.checked);
if (on) {
if (brightnessSetting.get() !== "auto") {
this.lastManualBrightness = this.brightnessPercent;
brightnessSetting.set("auto");
}
} else if (brightnessSetting.get() === "auto") {
brightnessSetting.set(String(this.lastManualBrightness) as BrightnessSetting);
}
this.refreshDisplayControls();
}
public refreshDisplayControls(): void {
this.notifyPropertyChange("brightnessAuto", this.brightnessAuto);
this.notifyPropertyChange("brightnessSliderEnabled", this.brightnessSliderEnabled);
this.notifyPropertyChange("brightnessPercent", this.brightnessPercent);
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
}
}
+133
View File
@@ -0,0 +1,133 @@
/* The phone's controller for the glasses (phone-ui/remote-controls.xml). */
.remote-controls {
margin: 0 8 0 8;
}
/* The Settings / Watch / Ring tab bar above the controls. */
.controls-tab-bar {
margin-bottom: 8;
}
.tab-button {
font-size: 14;
padding: 8 0;
margin: 0 2;
border-radius: 6;
background-color: #e2e2e2;
color: #333333;
}
.tab-button-selected {
background-color: #424242;
color: #ffffff;
}
/* The wakeword and keyboard buttons at the tab bar's right edge: icon-only,
* narrower than the tabs, and never in the selected state (they aren't tabs).
* Each is a button-styled GridLayout (Buttons can't hold images), so it
* borrows the .tab-button look and adds the elevation MaterialButtons get for
* free. */
.tab-icon-button {
width: 56;
/* The real MaterialButtons render 48dp tall inside a 60dp layout box (6dp
* insets top and bottom); the margins and explicit height reproduce that.
* The height also bounds the tile's measure, without which its star row
* would collapse to content and pin the icon to the top. */
height: 48;
margin: 6 2;
android-elevation: 2;
}
.tab-icon {
height: 20;
tint-color: #333333;
}
/* Landscape uses the full page height and a shared left edge for tabs/pad. */
.landscape-layout .remote-controls {
margin: 0;
}
.landscape-layout .controls-tab-bar {
margin-bottom: 2;
}
.landscape-layout .tab-button {
margin-left: 1;
margin-right: 1;
min-width: 0;
}
.landscape-layout .tab-button[col="0"] {
margin-left: 0;
}
.landscape-layout .tab-icon-button {
width: 48;
}
.landscape-layout .tab-icon-button[col="4"] {
margin-right: 0;
}
.ns-dark .tab-icon {
tint-color: #cccccc;
}
.ns-dark .tab-button {
background-color: #333333;
color: #cccccc;
}
.ns-dark .tab-button-selected {
background-color: #e2e2e2;
color: #222222;
}
/* Settings tab rows. */
.settings-row {
margin-bottom: 8;
}
.settings-row-label {
font-size: 14;
margin-right: 10;
}
.mode-button {
font-size: 13;
padding: 6 10;
margin-right: 6;
}
.brightness-icon {
font-size: 16;
margin: 0 4 0 4;
color: #444444;
}
.auto-toggle Label {
font-size: 13;
margin-right: 2;
}
.touchpad {
height: 230;
background-color: #1f1f1f;
border-radius: 14;
border-width: 1;
border-color: #3a3a3a;
color: #f0f0f0;
margin-top: 2;
}
.pad-focus {
font-size: 20;
color: #ffffff;
}
.pad-legend {
font-size: 11;
color: #8a8a8a;
margin-bottom: 8;
}
.action-row {
margin-top: 6;
}
.action-button {
margin: 2;
font-size: 14;
}
/* Ring tab: the same touchpad, but portrait like the ring's own pad. */
.ring-touchpad {
width: 150;
height: 250;
}
/* Cosmetic marks mirroring the six rectangles on the physical ring's touch
strip; barely lighter than the pad so they read as texture, not buttons. */
.ring-pad-marking {
width: 18;
height: 5;
border-radius: 2;
background-color: #2a2a2a;
horizontal-align: center;
vertical-align: center;
}
+8 -8
View File
@@ -15,7 +15,7 @@
height (the Watch face centers in it); the three sections share the star height (the Watch face centers in it); the three sections share the star
cell, only one visible at a time. cell, only one visible at a time.
--> -->
<GridLayout xmlns="http://schemas.nativescript.org/tns.xsd" rows="auto,*" class="remote-controls"> <GridLayout xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:android="http://schemas.nativescript.org/tns.xsd" rows="auto,*" class="remote-controls">
<!-- rows="auto" everywhere below: a rows-less GridLayout's implicit row <!-- rows="auto" everywhere below: a rows-less GridLayout's implicit row
acts as star, and this component sits in a bounded (star-row) parent, acts as star, and this component sits in a bounded (star-row) parent,
where that would balloon the first grid to fill all remaining height. --> where that would balloon the first grid to fill all remaining height. -->
@@ -26,10 +26,10 @@
<!-- A Button can't hold an image, so these are button-styled tiles. The <!-- A Button can't hold an image, so these are button-styled tiles. The
explicit star row makes the cell fill the tile's height so the icon's explicit star row makes the cell fill the tile's height so the icon's
center alignment has room to work in. --> center alignment has room to work in. -->
<GridLayout col="3" rows="*" tap="{{ onSyntheticMicTap }}" class="tab-button tab-icon-button"> <GridLayout col="3" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Voice input" tap="{{ onSyntheticMicTap }}" class="tab-button tab-icon-button">
<Image src="res://ic_tab_mic" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" /> <Image src="res://ic_tab_mic" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" />
</GridLayout> </GridLayout>
<GridLayout col="4" rows="*" tap="{{ onKeyboardTap }}" class="tab-button tab-icon-button"> <GridLayout col="4" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Keyboard input" tap="{{ onKeyboardTap }}" class="tab-button tab-icon-button">
<Image src="res://ic_tab_keyboard" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" /> <Image src="res://ic_tab_keyboard" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" />
</GridLayout> </GridLayout>
</GridLayout> </GridLayout>
@@ -53,9 +53,9 @@
<!-- Watch tab: centered in the leftover height, capped at the 1.5:1 face <!-- Watch tab: centered in the leftover height, capped at the 1.5:1 face
aspect (watchFaceWidth = min(available, 1.5 x face height). --> aspect (watchFaceWidth = min(available, 1.5 x face height). -->
<GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" horizontalAlignment="center" verticalAlignment="center" class="touchpad" tap="{{ onPadTap }}" doubleTap="{{ onPadDoubleTap }}" longPress="{{ onPadLongPress }}" swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}"> <GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
<Label text="{{ padFocusLine }}" class="pad-focus" horizontalAlignment="center" verticalAlignment="center" /> <Label isUserInteractionEnabled="false" text="{{ padFocusLine }}" class="pad-focus" horizontalAlignment="center" verticalAlignment="center" />
<Label text="▲▼ swipe ● select ●● back ‒ menu" class="pad-legend" horizontalAlignment="center" verticalAlignment="bottom" /> <Label isUserInteractionEnabled="false" text="▲▼ swipe ● select ●● back ‒ menu" class="pad-legend" horizontalAlignment="center" verticalAlignment="bottom" />
</GridLayout> </GridLayout>
<!-- Ring tab: a touchpad on the ring's own scheme. Vertical swipes only <!-- Ring tab: a touchpad on the ring's own scheme. Vertical swipes only
@@ -66,8 +66,8 @@
<GridLayout visibility="{{ ringTabVisibility }}" height="{{ ringTouchpadHeight }}" class="touchpad ring-touchpad" <GridLayout visibility="{{ ringTabVisibility }}" height="{{ ringTouchpadHeight }}" class="touchpad ring-touchpad"
rows="*,auto,*,auto,*,auto,*,auto,*,auto,*,auto,*" rows="*,auto,*,auto,*,auto,*,auto,*,auto,*,auto,*"
horizontalAlignment="center" verticalAlignment="center" horizontalAlignment="center" verticalAlignment="center"
tap="{{ onRingPadTap }}" doubleTap="{{ onRingPadDoubleTap }}" android:tap="{{ onRingPadTap }}" android:doubleTap="{{ onRingPadDoubleTap }}"
longPress="{{ onRingPadLongPress }}" swipe="{{ onRingPadSwipe }}" android:longPress="{{ onRingPadLongPress }}" android:swipe="{{ onRingPadSwipe }}"
touch="{{ onRingPadTouch }}"> touch="{{ onRingPadTouch }}">
<Label row="1" class="ring-pad-marking" isUserInteractionEnabled="false" /> <Label row="1" class="ring-pad-marking" isUserInteractionEnabled="false" />
<Label row="3" class="ring-pad-marking" isUserInteractionEnabled="false" /> <Label row="3" class="ring-pad-marking" isUserInteractionEnabled="false" />
+44 -4
View File
@@ -185,11 +185,12 @@ test('background glasses input still composites frames; phone resume preserves t
constructor(_transport, onState, onInput) { session = this; this.onState = onState; this.onInput = onInput; } constructor(_transport, onState, onInput) { session = this; this.onState = onState; this.onInput = onInput; }
async start() { starts++; this.state = { phase: 'connected' }; this.onState(this.state); } async start() { starts++; this.state = { phase: 'connected' }; this.onState(this.state); }
async stop() { stops++; this.state = { phase: 'disconnected' }; this.onState(this.state); } async stop() { stops++; this.state = { phase: 'disconnected' }; this.onState(this.state); }
async setBrightness() {}
setFrame(pixels) { if (this.state.phase === 'connected') frames.push(pixels); } setFrame(pixels) { if (this.state.phase === 'connected') frames.push(pixels); }
playBuzzerSequence(payload) { sounds.push([...payload]); } playBuzzerSequence(payload) { sounds.push([...payload]); }
wake() {} wake() {}
} }
const settings = { lockScreenEnabledSetting: { get: () => true }, onAnySettingChanged: () => () => {}, previewColorSetting: { get: () => 'white' } }; const settings = { brightnessSetting: { get: () => 'auto' }, brightnessSettingToLevel: () => null, lockScreenEnabledSetting: { get: () => true }, onAnySettingChanged: () => () => {}, previewColorSetting: { get: () => 'white' } };
const modules = { const modules = {
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}), "../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
'../assistant/system-tools': { registerSystemTools() {} }, '../assistant/system-tools': { registerSystemTools() {} },
@@ -201,7 +202,7 @@ test('background glasses input still composites frames; phone resume preserves t
'../native/notification-sources': { shouldShowNotificationOnGlasses: () => true }, '../native/notification-sources': { shouldShowNotificationOnGlasses: () => true },
'../native/compass.ios': { bindCompassSession() {}, receiveCompassEvent() {} }, '../native/compass.ios': { bindCompassSession() {}, receiveCompassEvent() {} },
'@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) }, knownFolders: { documents: () => ({ path: '/tmp' }) }, path }, '@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) }, knownFolders: { documents: () => ({ path: '/tmp' }) }, path },
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {} } }, '../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {} } },
'../native/ios-bluetooth': { iosBluetooth: () => ({}) }, './glasses-session': { GlassesSession: Session }, '../native/ios-bluetooth': { iosBluetooth: () => ({}) }, './glasses-session': { GlassesSession: Session },
'../native/nightscout-bridge': { nightscoutBridge: { async start() { pollStarts++; }, async stop() { pollStops++; } } }, '../native/nightscout-bridge': { nightscoutBridge: { async start() { pollStarts++; }, async stop() { pollStops++; } } },
'./glance-host': { GlanceHost: class { dismiss() {} isVisible() { return false; } } }, './glance-host': { GlanceHost: class { dismiss() {} isVisible() { return false; } } },
@@ -266,12 +267,15 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
constructor() { views.push(this); } constructor() { views.push(this); }
on(event, fn) { this.events.set(event, fn); } on(event, fn) { this.events.set(event, fn); }
addChild(view) { this.children.push(view); } addChild(view) { this.children.push(view); }
set(key, value) { this[key] = value; }
notifyPropertyChange() {}
getActualSize() { return { width: 0, height: 0 }; } getActualSize() { return { width: 0, height: 0 }; }
getViewById() { return null; }
static setRow() {} static setColumn() {} static setRow() {} static setColumn() {}
} }
const core = { Application: { suspendEvent: 'suspend', resumeEvent: 'resume', const core = { Application: { suspendEvent: 'suspend', resumeEvent: 'resume',
on: (key, fn) => appEvents.set(key, fn), off: key => appEvents.delete(key) }, on: (key, fn) => appEvents.set(key, fn), off: key => appEvents.delete(key) },
Button: View, Color: class {}, Dialogs: {}, GridLayout: View, Image: View, Label: View, Page: View, StackLayout: View }; Builder: { load: () => new View() }, Observable: View, Button: View, Color: class {}, Dialogs: {}, GridLayout: View, Image: View, Label: View, Page: View, StackLayout: View };
const modules = { const modules = {
"../ui/input-monitor": load("app/ui/input-monitor.ts", {}), "../ui/input-monitor": load("app/ui/input-monitor.ts", {}),
'../assistant/system-tools': { registerSystemTools() {} }, '../assistant/system-tools': { registerSystemTools() {} },
@@ -289,15 +293,19 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
'./phone-gestures': { PhoneGestureRecognizer: class { cancel() {} } }, './phone-gestures': { PhoneGestureRecognizer: class { cancel() {} } },
'./ble-bandwidth-meter': require('../.test-build/app/phone-ui/ble-bandwidth-meter.js'), './ble-bandwidth-meter': require('../.test-build/app/phone-ui/ble-bandwidth-meter.js'),
'../native/ble-traffic': { sampleBleTraffic: () => totals }, '../native/ble-traffic': { sampleBleTraffic: () => totals },
'../ui/dashboard-settings': { showBleBandwidthSetting: { get: () => enabled }, '../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayModeSetting: { get: () => 'full' }, displayModeLabel: () => 'Full', showBleBandwidthSetting: { get: () => enabled },
onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } }, onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } },
'../g2/device-addresses': { loadDeviceAddresses: () => ({}) }, '../g2/device-addresses': { loadDeviceAddresses: () => ({}) },
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' }, '../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
'./onboarding-state': { isPreviewOnlyMode: () => false }, './onboarding-state': { isPreviewOnlyMode: () => false },
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false }, '../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
}; };
modules['./keyboard-input-view-model'] = load('app/phone-ui/keyboard-input-view-model.ts', { require: id => modules[id] });
modules['./remote-controls-view-model'] = load('app/phone-ui/remote-controls-view-model.ts', { require: id => modules[id] });
const { createMainPage } = load('app/phone-ui/main-page.ios.ts', { const { createMainPage } = load('app/phone-ui/main-page.ios.ts', {
require: id => modules[id] ?? {}, Date: { now: () => atMs }, require: id => modules[id] ?? {}, Date: { now: () => atMs },
NSNotificationCenter: { defaultCenter: { addObserverForNameObjectQueueUsingBlock: () => ({}), removeObserver() {} } },
UIKeyboardWillChangeFrameNotification: 'keyboard', NSOperationQueue: { mainQueue: {} },
setInterval: fn => { const id = ++nextId; intervals.set(id, fn); return id; }, clearInterval: id => intervals.delete(id), setInterval: fn => { const id = ++nextId; intervals.set(id, fn); return id; }, clearInterval: id => intervals.delete(id),
setTimeout: () => 1, clearTimeout() {}, setTimeout: () => 1, clearTimeout() {},
}); });
@@ -397,3 +405,35 @@ test('iOS welcome sound waits for a new acknowledged frame and is consumed once'
host.maybePlayWelcomeSound({ phase: 'connected', frames: 2 }); host.maybePlayWelcomeSound({ phase: 'connected', frames: 2 });
assert.equal(played.length, count); assert.equal(played.length, count);
}); });
test('iOS preview voice uses the phone microphone, while connected capture stays on glasses', async () => {
const calls = [];
const bridge = { prepare: async (foreground, phone) => { calls.push(['prepare', foreground, phone]); return true; },
startPhoneCapture: async (_log, endpointing) => calls.push(['phone', endpointing]),
startGlassesCapture: async (_session, _log, endpointing) => calls.push(['glasses', endpointing]) };
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : {},
});
const host = Object.create(IosPreviewController.prototype);
host.active = true; host.glassesLocked = false;
assert.equal(await host.prepareVoiceCapture(), true);
await host.startVoiceCapture(true);
assert.deepEqual(calls, [['prepare', true, true], ['prepare', true, true], ['phone', true]]);
calls.length = 0; host.session = { state: { phase: 'connected' } };
assert.equal(await host.prepareVoiceCapture(), true); await host.startVoiceCapture(false);
assert.deepEqual(calls, [['prepare', true, false], ['glasses', false]]);
calls.length = 0; host.active = false; host.session = null;
assert.equal(await host.prepareVoiceCapture(), false); await host.startVoiceCapture();
assert.deepEqual(calls, []);
});
test('iOS keyboard action opens the shared destination session and remains blocked while locked', () => {
let opened = 0;
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', {
require: id => id === '../ui/shell/shell' ? { shell: { startKeyboardInput: () => opened++ } } : {},
});
const host = Object.create(IosPreviewController.prototype);
host.active = true; host.glassesLocked = false; host.typeIntoApp(); assert.equal(opened, 1);
host.glassesLocked = true; host.typeIntoApp(); assert.equal(opened, 1);
host.glassesLocked = false; host.active = false; host.typeIntoApp(); assert.equal(opened, 1);
});
+17
View File
@@ -667,3 +667,20 @@ test('ANCS app-name lookup uses the right-link write limit, including after reau
assert.equal(h.session.notifications.read()[0].appName,'Pushover Notifications'); assert.equal(h.session.notifications.read()[0].appName,'Pushover Notifications');
} }
}); });
test('brightness sends the Android settings payload to the right temple, including explicit zero and Auto', async () => {
const transport = new FakeTransport(), session = new GlassesSession(transport, () => {}, () => {});
await session.setBrightness(50);
assert.equal(transport.sent.length, 0, 'preview mode must not send Bluetooth commands');
const requests = [];
session.state.phase = 'connected';
session.request = async (role, sid, build) => { requests.push({ role, sid, payload: hex(build(105)) }); };
await session.setBrightness(0);
await session.setBrightness(80);
await session.setBrightness(null);
assert.deepEqual(requests, [
{ role: 'right', sid: 9, payload: '080110691a060a0408001000' },
{ role: 'right', sid: 9, payload: '080110691a060a0408001050' },
{ role: 'right', sid: 9, payload: '080110691a040a020801' },
]);
});
+23 -3
View File
@@ -60,6 +60,7 @@ function fixture() {
async enableWearDetectionAndRequestState() {} async enableWearDetectionAndRequestState() {}
async start() { this.state = { phase: 'connected' }; this.onState(this.state); } async start() { this.state = { phase: 'connected' }; this.onState(this.state); }
async stop() { this.state = { phase: 'disconnected' }; this.onState(this.state); } async stop() { this.state = { phase: 'disconnected' }; this.onState(this.state); }
async setBrightness() {}
setFrame(pixels) { if (this.state.phase === 'connected') sent.push(pixels); } setFrame(pixels) { if (this.state.phase === 'connected') sent.push(pixels); }
wake() {} wake() {}
} }
@@ -84,7 +85,7 @@ function fixture() {
'@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) }, '@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) },
knownFolders: { documents: () => ({ path: '/tmp' }) }, path }, knownFolders: { documents: () => ({ path: '/tmp' }) }, path },
'../native/ios-bluetooth': { iosBluetooth: () => ({}) }, '../native/ios-bluetooth': { iosBluetooth: () => ({}) },
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {} } }, '../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {} } },
'./glasses-session': { GlassesSession: Session }, './glasses-session': { GlassesSession: Session },
'../native/nightscout-bridge': { nightscoutBridge: { async start() {}, async stop() {} } }, '../native/nightscout-bridge': { nightscoutBridge: { async start() {}, async stop() {} } },
'./glance-host': { GlanceHost }, './events': events, './glance-host': { GlanceHost }, './events': events,
@@ -97,7 +98,7 @@ function fixture() {
'../phone-ui/onboarding-state': { isWelcomeSoundPending: () => false }, '../phone-ui/onboarding-state': { isWelcomeSoundPending: () => false },
'../ui/sound-effects': {}, '../ui/sound-effects': {},
'../ui/shell/worker-window': {}, '../ui/shell/in-process-window': {}, '../ui/shell/worker-window': {}, '../ui/shell/in-process-window': {},
'../ui/dashboard-settings': { lockScreenEnabledSetting: { get: () => settings.lock }, onAnySettingChanged: fn => { settingsChanged = fn; return () => {}; }, previewColorSetting: { get: () => 'white' } }, '../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, brightnessSettingToLevel: () => null, lockScreenEnabledSetting: { get: () => settings.lock }, onAnySettingChanged: fn => { settingsChanged = fn; return () => {}; }, previewColorSetting: { get: () => 'white' } },
'../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) }, '../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) },
'../apps/ios-availability': { iosAppUnavailableReason: () => null }, '../apps/ios-availability': { iosAppUnavailableReason: () => null },
'../graphics/surface-compositor': { SurfaceCompositor }, '../graphics/plane': planes, '../graphics/image': images, '../graphics/surface-compositor': { SurfaceCompositor }, '../graphics/plane': planes, '../graphics/image': images,
@@ -138,7 +139,7 @@ function fixture() {
await render(); await render();
} }
async function phone(type, origin = 'ring') { controller.gesture(type, origin); await render(); } async function phone(type, origin = 'ring') { controller.gesture(type, origin); await render(); }
return { controller, shell, settings, phoneState, observers, wear: wearing => session.onWear(wearing), settingsChanged: () => settingsChanged(), sent, previews, received, boardStats, hardware, phone, advance, render }; return { controller, shell, keyboardChanged: session => shellOptions.onKeyboardInputChanged(session), settings, phoneState, observers, wear: wearing => session.onWear(wearing), settingsChanged: () => settingsChanged(), sent, previews, received, boardStats, hardware, phone, advance, render };
} }
const assertBlank = pixels => assert.ok(pixels.every(p => p === 0)); const assertBlank = pixels => assert.ok(pixels.every(p => p === 0));
const assertBoard = pixels => { const assertBoard = pixels => {
@@ -299,3 +300,22 @@ test('iOS deduplicates original ring ticks before apps, lock toggles and Glanceb
f.controller.session.onState({ phase:'connected' }); f.controller.session.onState({ phase:'connected' });
await f.hardware(3,2,2051); assert.equal(f.shell.isScreenOn(),false); await f.hardware(3,2,2051); assert.equal(f.shell.isScreenOn(),false);
}); });
test('keyboard sessions cannot deliver text after the glasses lock or phone leaves the foreground', () => {
const f = fixture();
let editor;
f.controller.onKeyboardInputChanged = session => { editor = session; };
const calls = [];
f.keyboardChanged({ targets: [{ id: 'app', label: 'Type into App' }],
setText: text => calls.push(['text', text]), send: () => calls.push(['send']),
sendTo: id => calls.push(['target', id]), discard: () => calls.push(['discard']) });
editor.setText('hello'); editor.sendTo('app');
assert.deepEqual(calls, [['text', 'hello'], ['target', 'app']]);
f.controller.glassesLocked = true;
editor.setText('locked'); editor.send(); editor.sendTo('app');
assert.equal(calls.length, 2);
f.controller.glassesLocked = false; f.controller.pause();
editor.setText('background'); editor.sendTo('app');
assert.equal(calls.length, 2);
editor.discard(); assert.deepEqual(calls.at(-1), ['discard']);
});
+58 -3
View File
@@ -4,11 +4,13 @@ const fs = require('node:fs');
const vm = require('node:vm'); const vm = require('node:vm');
const ts = require('typescript'); const ts = require('typescript');
function harness() { function harness() {
const native = { startWithEndpointing(endpointing) { this.endpointing = endpointing; return ''; }, cancel() { this.cancels++; }, cancels: 0, finish() { this.finished = true; }, acceptPacket: p => audio.push(p) }; const native = { startWithEndpointing(endpointing) { this.endpointing = endpointing; return ''; }, startPhoneWithEndpointing(endpointing) { this.endpointing = endpointing; this.phone = true; return this.error ?? ''; }, cancel() { this.cancels++; }, cancels: 0, finish() { this.finished = true; }, acceptPacket: p => audio.push(p) };
const audio = [], timers = new Map(), commands = [], text = []; const audio = [], timers = new Map(), commands = [], text = [];
let authorization = 3, permissionRequests = 0, release; let authorization = 3, microphoneAuthorization = 3, microphoneRequests = 0, permissionRequests = 0, release;
const sandbox = { exports: {}, FaceclawSpeech: { new: () => native, authorizationStatus: () => authorization, const sandbox = { exports: {}, FaceclawSpeech: { new: () => native, authorizationStatus: () => authorization,
requestAuthorization: done => { permissionRequests++; done(3); } }, requestAuthorization: done => { permissionRequests++; done(3); },
microphoneAuthorizationStatus: () => microphoneAuthorization,
requestMicrophoneAuthorization: done => { microphoneRequests++; done(3); } },
setTimeout: fn => { timers.set(fn, fn); return fn; }, clearTimeout: fn => timers.delete(fn), setTimeout: fn => { timers.set(fn, fn); return fn; }, clearTimeout: fn => timers.delete(fn),
NSData: { dataWithBytesLength: (b, n) => Buffer.from(b, 0, n) }, interop: { handleof: b => b } }; NSData: { dataWithBytesLength: (b, n) => Buffer.from(b, 0, n) }, interop: { handleof: b => b } };
vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/native/voice-control.ios.ts', 'utf8'), { vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/native/voice-control.ios.ts', 'utf8'), {
@@ -21,6 +23,7 @@ function harness() {
return Promise.resolve(); return Promise.resolve();
} }; } };
return { bridge, native, session, audio, commands, text, timers, release: () => release(), return { bridge, native, session, audio, commands, text, timers, release: () => release(),
microphoneAuthorization: value => { microphoneAuthorization = value; }, microphoneRequests: () => microphoneRequests,
authorization: value => { authorization = value; }, permissionRequests: () => permissionRequests, authorization: value => { authorization = value; }, permissionRequests: () => permissionRequests,
event: event => native.eventHandler(JSON.stringify(event)) }; event: event => native.eventHandler(JSON.stringify(event)) };
} }
@@ -81,3 +84,55 @@ test('hands-free endpointing releases the microphone and waits for the final tra
assert.equal(h.native.endpointing, false); assert.equal(h.native.endpointing, false);
const cancelled = h.bridge.stopPushToTalk(); h.bridge.stop(); await cancelled; const cancelled = h.bridge.stopPushToTalk(); h.bridge.stop(); await cancelled;
}); });
test('phone microphone permission is requested only for foreground preview capture', async () => {
const h = harness(); h.microphoneAuthorization(0);
assert.equal(await h.bridge.prepare(true), true);
assert.equal(h.microphoneRequests(), 0, 'glasses input does not need phone microphone permission');
assert.equal(await h.bridge.prepare(false, true), false);
assert.equal(h.microphoneRequests(), 0);
assert.equal(await h.bridge.prepare(true, true), true);
assert.equal(h.microphoneRequests(), 1);
h.microphoneAuthorization(2);
assert.equal(await h.bridge.prepare(true, true), false);
assert.match(h.bridge.statusText, /Microphone.*Settings/);
});
test('phone capture forwards endpointing and drains final text without touching Bluetooth', async () => {
const h = harness();
await h.bridge.startPhoneCapture(() => {}, true);
assert.equal(h.native.phone, true); assert.equal(h.native.endpointing, true);
h.bridge.handleSessionEnded();
h.event({ kind: 'transcript', text: 'First line\nSecond line', final: false });
assert.equal(h.text.length, 1, 'BLE state changes must not stop phone capture');
h.event({ kind: 'finishing' });
let finished = false;
const completion = h.bridge.stopPushToTalk().then(() => { finished = true; });
await Promise.resolve(); assert.equal(finished, false);
h.bridge.handleSessionEnded();
h.event({ kind: 'transcript', text: 'First line\nSecond line.', final: true });
h.event({ kind: 'ended' }); await completion;
assert.equal(h.text.at(-1).text, 'First line\nSecond line.');
assert.deepEqual(h.commands, []);
});
test('background cleanup stops phone capture but preserves glasses capture', async () => {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
await h.bridge.startPhoneCapture(() => {});
h.bridge.stopPhoneCapture();
assert.equal(ends, 1);
h.event({ kind: 'transcript', text: 'stale', final: true }); assert.equal(h.text.length, 0);
const start = h.bridge.startGlassesCapture(h.session, () => {}); h.release(); await start;
h.bridge.stopPhoneCapture();
h.event({ kind: 'transcript', text: 'on glasses', final: false });
assert.equal(h.text.at(-1).text, 'on glasses');
h.bridge.stop();
});
test('phone microphone startup errors end capture with an actionable status', async () => {
const h = harness(); let ends = 0; h.bridge.onSpeechEnd(() => ends++);
h.native.error = 'No phone microphone is available.';
await h.bridge.startPhoneCapture(() => {});
assert.equal(ends, 1); assert.match(h.bridge.statusText, /No phone microphone/);
await h.bridge.stopPushToTalk();
});
+32
View File
@@ -0,0 +1,32 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function fixture() {
class Observable { get(key) { return this[key]; } notifyPropertyChange() {} }
const { KeyboardInputViewModel } = loader({}, { '@nativescript/core': { Observable } })('app/phone-ui/keyboard-input-view-model.ts');
const model = new KeyboardInputViewModel(), sent = [], text = [];
const session = { targets: [{ id: 'assistant', label: 'Send to Assistant' }, { id: 'app', label: 'Type Into App' }],
setText: value => text.push(value), sendTo: id => sent.push(id), discard: () => model.setSession(null) };
model.setSession(session);
return { model, session, sent, text };
}
test('multiline keyboard editor routes Agent and App buttons to distinct shell destinations', () => {
const h = fixture();
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'Send to Agent');
assert.equal(h.model.keyboardInputSecondaryTargetLabel, 'Type into App');
h.model.onKeyboardInputTextChange({ object: { text: 'First line\nSecond line' } });
h.model.onKeyboardInputPrimarySendTap();
h.model.onKeyboardInputSecondarySendTap();
assert.deepEqual(h.sent, ['assistant', 'app']);
assert.equal(h.text.at(-1), 'First line\nSecond line');
});
test('discard and shell-side closure reset the editor; unsupported destinations stay hidden', () => {
const h = fixture();
h.model.keyboardInputText = 'draft'; h.model.onKeyboardInputDiscardTap();
assert.equal(h.model.keyboardInputText, '');
assert.equal(h.model.keyboardInputVisibility, 'collapse');
h.model.setSession({ ...h.session, targets: [{ id: 'assistant', label: 'Send' }] });
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'Send to Agent');
assert.equal(h.model.keyboardInputSecondaryTargetVisibility, 'collapse');
h.model.onKeyboardInputSecondarySendTap(); assert.deepEqual(h.sent, []);
});
+61
View File
@@ -0,0 +1,61 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
function fixture() {
let brightness = '40', mode = 'small', picked;
const changes = [], writes = [];
class Observable {
notifyPropertyChange(name, value) { changes.push([name, value]); }
}
const settings = {
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
displayModeSetting: { get: () => mode, set: value => { mode = value; } },
DISPLAY_MODE_VALUES: ['small', 'large'], displayModeLabel: value => value === 'small' ? 'Small' : 'Large',
};
const { RemoteControlsViewModel } = loader({}, {
'@nativescript/core': { Observable, Dialogs: { action: async () => picked } },
'../ui/dashboard-settings': settings,
})('app/phone-ui/remote-controls-view-model.ts');
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, writes,
brightness: () => brightness, mode: () => mode, pick: value => { picked = value; } };
}
test('shared controls preserve the selected tab across page visits and update all tab bindings', () => {
const h = fixture();
assert.equal(h.model.watchTabVisibility, 'visible');
h.model.onRingTabTap();
assert.equal(h.model.watchTabVisibility, 'collapse');
assert.equal(h.model.ringTabVisibility, 'visible');
assert.match(h.model.ringTabClass, /tab-button-selected/);
assert.equal(h.changes.length, 6);
assert.equal(h.create().ringTabVisibility, 'visible');
h.model.onSettingsTabTap();
assert.equal(h.model.settingsTabVisibility, 'visible');
});
test('shared brightness controls snap manual levels and restore the manual value after Auto', () => {
const h = fixture();
h.model.onBrightnessChange({ value: 76 });
assert.equal(h.brightness(), '80');
h.model.onBrightnessAutoChange({ value: true });
assert.equal(h.brightness(), 'auto');
assert.equal(h.model.brightnessSliderEnabled, false);
h.model.onBrightnessChange({ value: 10 });
assert.equal(h.brightness(), 'auto');
h.model.onBrightnessAutoChange({ value: false });
assert.equal(h.brightness(), '80');
h.model.onBrightnessChange({ value: -10 });
assert.equal(h.brightness(), '0');
h.model.onBrightnessChange({ value: NaN });
assert.equal(h.brightness(), '0');
});
test('shared screen-size picker preserves cancellation and applies the selected mode', async () => {
const h = fixture();
h.pick('Cancel'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'small');
h.pick('Large'); await h.model.onDisplayModeTap();
assert.equal(h.mode(), 'large');
assert.equal(h.model.displayModeLabel, 'Large ▾');
});