mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
iOS porting: Config pull and push scripts; Terminal works; voice input with Siri works
This commit is contained in:
1 parent
b07ae0b479
commit
319d3dc44b
21 files changed
+339
-9
No files matched your search
@@ -39,6 +39,7 @@ old
|
||||
|
||||
# pull_config.sh output: the phone's live settings, including API keys
|
||||
faceclaw_settings.xml
|
||||
faceclaw_settings.ios.json
|
||||
|
||||
# Developer configs
|
||||
build_paths.sh
|
||||
|
||||
@@ -26,6 +26,18 @@
|
||||
<array>
|
||||
<string>bluetooth-central</string>
|
||||
</array>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
<!-- iOS 17+ needs an explicit exception for the configured g2mirror IP.
|
||||
This permits its ws:// endpoint; TLS certificate validation stays on. -->
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>100.68.94.67</key>
|
||||
<dict><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>NSLocalNetworkUsageDescription</key>
|
||||
<string>Faceclaw connects to the terminal servers you configure on your local network.</string>
|
||||
<key>UILaunchScreen</key>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
/** Developer config transfer through the app container, before workers start. */
|
||||
@interface FaceclawConfigPort : NSObject
|
||||
+ (void)processPendingRequest;
|
||||
+ (void)processDirectory:(NSString *)directory defaults:(NSUserDefaults *)defaults domain:(NSString *)domain;
|
||||
@end
|
||||
@@ -0,0 +1,59 @@
|
||||
#import "FaceclawConfigPort.h"
|
||||
@implementation FaceclawConfigPort
|
||||
+ (void)processPendingRequest {
|
||||
NSString *library = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).firstObject;
|
||||
[self processDirectory:[library stringByAppendingPathComponent:@"FaceclawConfigPort"]
|
||||
defaults:NSUserDefaults.standardUserDefaults domain:NSBundle.mainBundle.bundleIdentifier];
|
||||
}
|
||||
+ (BOOL)validSettings:(id)settings {
|
||||
if (![settings isKindOfClass:NSDictionary.class] || [settings count] > 4096) return NO;
|
||||
for (id key in settings) {
|
||||
id value = settings[key];
|
||||
if (![key isKindOfClass:NSString.class] || ![key length] || [key length] > 512 ||
|
||||
!([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class])) return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
+ (void)processDirectory:(NSString *)directory defaults:(NSUserDefaults *)defaults domain:(NSString *)domain {
|
||||
NSString *requestPath = [directory stringByAppendingPathComponent:@"request.json"];
|
||||
NSData *data = [NSData dataWithContentsOfFile:requestPath];
|
||||
if (!data) return;
|
||||
NSFileManager *fm = NSFileManager.defaultManager;
|
||||
// Consume once. A failed import must never be replayed at a later launch.
|
||||
[fm removeItemAtPath:requestPath error:nil];
|
||||
id request = data.length <= 2 * 1024 * 1024 ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
||||
BOOL valid = [request isKindOfClass:NSDictionary.class];
|
||||
NSString *identifier = valid && [request[@"id"] isKindOfClass:NSString.class] ? request[@"id"] : @"";
|
||||
NSMutableDictionary *reply = [@{@"id":identifier, @"ok":@NO, @"message":@"Invalid config request"} mutableCopy];
|
||||
[defaults synchronize];
|
||||
NSDictionary *before = [defaults persistentDomainForName:domain] ?: @{};
|
||||
if (valid && [request[@"operation"] isEqual:@"pull"]) {
|
||||
NSMutableDictionary *settings = [NSMutableDictionary new];
|
||||
for (NSString *key in before) {
|
||||
id value = before[key];
|
||||
if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class]) settings[key] = value;
|
||||
}
|
||||
[settings removeObjectForKey:@"ios.settings.changeToken"];
|
||||
reply[@"config"] = @{@"schema":@1, @"settings":settings}; reply[@"ok"] = @YES;
|
||||
reply[@"message"] = @"Config exported";
|
||||
} else if (valid && [request[@"operation"] isEqual:@"push"] && [self validSettings:request[@"settings"]]) {
|
||||
NSError *error = nil;
|
||||
NSData *backup = [NSPropertyListSerialization dataWithPropertyList:before format:NSPropertyListBinaryFormat_v1_0 options:0 error:&error];
|
||||
if (backup && [backup writeToFile:[directory stringByAppendingPathComponent:@"previous.plist"] options:NSDataWritingAtomic error:&error]) {
|
||||
NSMutableDictionary *next = [before mutableCopy];
|
||||
[next addEntriesFromDictionary:request[@"settings"]];
|
||||
next[@"ios.settings.changeToken"] = NSUUID.UUID.UUIDString;
|
||||
[defaults setPersistentDomain:next forName:domain];
|
||||
if ([defaults synchronize]) {
|
||||
reply[@"ok"] = @YES; reply[@"message"] = @"Config imported";
|
||||
reply[@"count"] = @([request[@"settings"] count]);
|
||||
} else {
|
||||
[defaults setPersistentDomain:before forName:domain]; [defaults synchronize];
|
||||
reply[@"message"] = @"Could not persist config; restored previous settings";
|
||||
}
|
||||
} else reply[@"message"] = @"Could not back up existing settings; import skipped";
|
||||
}
|
||||
NSData *response = [NSJSONSerialization dataWithJSONObject:reply options:NSJSONWritingPrettyPrinted error:nil];
|
||||
[response writeToFile:[directory stringByAppendingPathComponent:@"response.json"] options:NSDataWritingAtomic error:nil];
|
||||
}
|
||||
@end
|
||||
@@ -1,5 +1,6 @@
|
||||
#import "FaceclawSpeech.h"
|
||||
#import "FaceclawLc3Decoder.h"
|
||||
#import "FaceclawSpeechTranscript.h"
|
||||
#import <Speech/Speech.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <math.h>
|
||||
@@ -14,6 +15,7 @@
|
||||
@property(nonatomic) NSUInteger pendingPackets;
|
||||
@property(nonatomic) BOOL accepting;
|
||||
@property(nonatomic, copy) NSString *bestText;
|
||||
@property(nonatomic, strong) FaceclawSpeechTranscript *transcript;
|
||||
@end
|
||||
@implementation FaceclawSpeech
|
||||
- (instancetype)init {
|
||||
@@ -49,6 +51,7 @@
|
||||
self.request.taskHint = SFSpeechRecognitionTaskHintDictation;
|
||||
if (@available(iOS 16.0, *)) self.request.addsPunctuation = YES;
|
||||
self.bestText = @""; self.accepting = YES;
|
||||
self.transcript = [FaceclawSpeechTranscript new];
|
||||
NSUInteger generation = self.generation;
|
||||
__weak FaceclawSpeech *weakSelf = self;
|
||||
self.task = [self.recognizer recognitionTaskWithRequest:self.request resultHandler:^(SFSpeechRecognitionResult *result, NSError *error) {
|
||||
@@ -56,7 +59,13 @@
|
||||
FaceclawSpeech *owner = weakSelf;
|
||||
if (!owner || owner.generation != generation) return;
|
||||
if (result) {
|
||||
owner.bestText = result.bestTranscription.formattedString ?: @"";
|
||||
SFSpeechRecognitionMetadata *metadata = result.speechRecognitionMetadata;
|
||||
SFTranscriptionSegment *first = result.bestTranscription.segments.firstObject;
|
||||
SFTranscriptionSegment *last = result.bestTranscription.segments.lastObject;
|
||||
NSTimeInterval start = metadata ? metadata.speechStartTimestamp : first.timestamp;
|
||||
NSTimeInterval duration = metadata ? metadata.speechDuration : last.timestamp + last.duration - start;
|
||||
owner.bestText = [owner.transcript updateText:result.bestTranscription.formattedString ?: @""
|
||||
start:start duration:duration settled:metadata != nil || result.final final:result.final];
|
||||
if (!result.final) [owner emit:@{@"kind":@"transcript", @"text":owner.bestText, @"final":@NO}];
|
||||
}
|
||||
if (result.final || error) {
|
||||
@@ -131,6 +140,6 @@
|
||||
self.generation++;
|
||||
self.accepting = NO; self.pendingPackets = 0;
|
||||
[self.task cancel]; self.task = nil; self.request = nil; self.decoder = nil; self.recognizer = nil;
|
||||
self.bestText = @"";
|
||||
self.bestText = @""; self.transcript = nil;
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
/** Accumulates on-device utterances while allowing revisions within each one. */
|
||||
@interface FaceclawSpeechTranscript : NSObject
|
||||
@property(nonatomic, readonly) NSString *text;
|
||||
- (NSString *)updateText:(NSString *)text start:(NSTimeInterval)start duration:(NSTimeInterval)duration settled:(BOOL)settled final:(BOOL)final;
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
#import "FaceclawSpeechTranscript.h"
|
||||
#import <math.h>
|
||||
@interface FaceclawSpeechTranscript ()
|
||||
@property(nonatomic, strong) NSMutableArray<NSDictionary *> *utterances;
|
||||
@end
|
||||
@implementation FaceclawSpeechTranscript
|
||||
- (instancetype)init {
|
||||
if ((self = [super init])) _utterances = [NSMutableArray new];
|
||||
return self;
|
||||
}
|
||||
- (NSString *)text {
|
||||
NSMutableArray *parts = [NSMutableArray new];
|
||||
for (NSDictionary *utterance in self.utterances) [parts addObject:utterance[@"text"]];
|
||||
return [parts componentsJoinedByString:@" "];
|
||||
}
|
||||
- (NSString *)updateText:(NSString *)text start:(NSTimeInterval)start duration:(NSTimeInterval)duration settled:(BOOL)settled final:(BOOL)final {
|
||||
text = [text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
||||
// Apple's final callback can be empty after a pause. Keep the best result.
|
||||
if (!text.length || (final && [text isEqual:self.text])) return self.text;
|
||||
BOOL timed = isfinite(start) && start >= 0 && isfinite(duration) && duration > 0;
|
||||
NSUInteger index = self.utterances.count;
|
||||
if (timed) {
|
||||
// Audio timestamps identify revisions, repeated callbacks and cumulative
|
||||
// results. Replace the covered suffix, preserving earlier utterances.
|
||||
for (NSUInteger i = 0; i < self.utterances.count; i++) {
|
||||
NSDictionary *item = self.utterances[i];
|
||||
if (![item[@"settled"] boolValue] || start < [item[@"end"] doubleValue] - 0.01) { index = i; break; }
|
||||
}
|
||||
} else if (index && (final || ![self.utterances.lastObject[@"settled"] boolValue])) {
|
||||
index--; // An ordinary partial corrects the active utterance.
|
||||
}
|
||||
// Untimed partials following a metadata-bearing result begin a new
|
||||
// utterance even when the words are identical ("yes" ... "yes").
|
||||
if (index < self.utterances.count) [self.utterances removeObjectsInRange:NSMakeRange(index, self.utterances.count - index)];
|
||||
[self.utterances addObject:@{@"text":text, @"end":@(timed ? start + duration : 0), @"settled":@(settled)}];
|
||||
return self.text;
|
||||
}
|
||||
@end
|
||||
@@ -5,5 +5,6 @@ module FaceclawGraphics {
|
||||
header "FaceclawSocket.h"
|
||||
header "FaceclawLc3Decoder.h"
|
||||
header "FaceclawSpeech.h"
|
||||
header "FaceclawConfigPort.h"
|
||||
export *
|
||||
}
|
||||
@@ -29,7 +29,9 @@ walk you through pairing with the glasses and installing custom firmware.
|
||||
|
||||
## Compiling
|
||||
|
||||
For the initial NativeScript iOS port, see [iOS development](notes/ios-development.md).
|
||||
For the NativeScript iOS port, see [iOS development](notes/ios-development.md).
|
||||
Use `scripts/pull_config_ios.sh` and `scripts/push_config_ios.sh` to transfer iPhone
|
||||
settings; see [iOS config transfer](scripts/ios-config.md) for options and Android XML support.
|
||||
The instructions below build the Android app.
|
||||
|
||||
If you want to customize faceclaw, the best way to do it is to download the
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { wrapText, type WrapFont } from '../../graphics/textwrap';
|
||||
|
||||
/** Keep short status on the title row; give long errors their full width. */
|
||||
export function layoutHubHeader(font: WrapFont, title: string, status: string, width: number, step: number) {
|
||||
const inlineX = 18 + font.measureText(title) + 16;
|
||||
const inline = !/[\r\n]/.test(status) && font.measureText(status) <= Math.max(0, width - inlineX - 12);
|
||||
const lines = inline ? [status] : wrapText(font, status, Math.max(1, width - 30));
|
||||
const x = inline ? inlineX : 18;
|
||||
const y = inline ? 10 : 10 + step;
|
||||
return { x, y, lines, listTop: inline ? 16 + step : 16 + step * (1 + lines.length) };
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
|
||||
import { layoutHubHeader } from "./hub-header";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { TERMINAL_ICON_GLYPHS } from "../../graphics/icons";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
@@ -1497,13 +1498,13 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
const font = chromeFont();
|
||||
const step = lineStep(font);
|
||||
// No border box: the shell chrome (top bar + sidebar) already frames the app.
|
||||
// Title and status share the top line.
|
||||
// Long statuses get a wrapped block and move the list below it.
|
||||
const title = window.mode === "connections" ? "Terminal - Connections" : "Terminal";
|
||||
image.drawText(font, 18, 10, title, 220);
|
||||
const statusX = 18 + font.measureText(title) + 16;
|
||||
image.drawText(font, statusX, 10, truncateText(font, hubStatusLine(window), Math.max(0, window.viewportWidth - statusX - 12)), 170);
|
||||
const header = layoutHubHeader(font, title, hubStatusLine(window), window.viewportWidth, step);
|
||||
header.lines.forEach((line, index) => image.drawText(font, header.x, header.y + index * step, line, 170));
|
||||
|
||||
let listTop = 16 + step;
|
||||
let listTop = header.listTop;
|
||||
if (window.mode === "sessions" && controls.size === 0) {
|
||||
image.drawText(font, 24, listTop, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(font, 24, listTop + step, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Application } from '@nativescript/core'
|
||||
import { createMainPage } from './phone-ui/main-page.ios'
|
||||
declare const FaceclawConfigPort: any
|
||||
|
||||
// Apply transferred preferences before settings getters or app workers load.
|
||||
FaceclawConfigPort.processPendingRequest()
|
||||
const { createMainPage } = require('./phone-ui/main-page.ios') as typeof import('./phone-ui/main-page.ios')
|
||||
|
||||
Application.run({ create: createMainPage })
|
||||
@@ -326,7 +326,9 @@ export class G2MirrorClient {
|
||||
*/
|
||||
submitInput(text: string): void {
|
||||
if (this.phase !== "attached") return;
|
||||
const textByteLength = new java.lang.String(text).getBytes("UTF-8").length;
|
||||
const textByteLength = global.isIOS
|
||||
? NSString.stringWithString(text).lengthOfBytesUsingEncoding(NSUTF8StringEncoding)
|
||||
: new java.lang.String(text).getBytes("UTF-8").length;
|
||||
this.send({
|
||||
type: "input",
|
||||
data: encodeBase64Utf8(`${text}\r`),
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const { mkdtempSync, rmSync } = require('node:fs');
|
||||
const { tmpdir } = require('node:os');
|
||||
const { join, resolve } = require('node:path');
|
||||
const root = resolve(__dirname, '..'), dir = mkdtempSync(join(tmpdir(), 'faceclaw-config-'));
|
||||
try {
|
||||
execFileSync('xcrun', ['clang', '-fobjc-arc', '-framework', 'Foundation', '-I', 'App_Resources/iOS/src',
|
||||
'tests/native/ios-config-test.m', 'App_Resources/iOS/src/FaceclawConfigPort.m', '-o', join(dir, 'config-test')], { cwd: root, stdio: 'inherit' });
|
||||
execFileSync(join(dir, 'config-test'), [dir], { stdio: 'inherit' });
|
||||
} finally { rmSync(dir, { recursive: true, force: true }); }
|
||||
@@ -0,0 +1,21 @@
|
||||
const test = require('node:test');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
test('iOS config codec preserves Android XML and JSON types and rejects malformed imports', () => {
|
||||
execFileSync('python3', ['-c', `
|
||||
import importlib.util, pathlib, tempfile
|
||||
spec = importlib.util.spec_from_file_location('config', 'scripts/ios_config.py')
|
||||
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
|
||||
values = {'terminal.connections': '[{"url":"g2mirror://test@host"}]', 'flag': True, 'empty': '', 'number': 42, 'ratio': 0.25, 'unicode': 'π & < 🔋\\nnext'}
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p = pathlib.Path(d) / 'settings'
|
||||
for xml in [False, True]:
|
||||
m.atomic_write(p, m.encode_config(values, xml))
|
||||
assert m.read_config(p) == values
|
||||
assert p.stat().st_mode & 0o777 == 0o600
|
||||
for invalid in [b'{}', b'<map><set name="x"/></map>', b'<map><boolean name="x" value="maybe"/></map>', b'<map><string name="x">a</string><string name="x">b</string></map>', b'{"schema":1,"settings":{"x":null}}', b'{"schema":1,"settings":{"x":NaN}}', b'<map><string name="x">oops']:
|
||||
p.write_bytes(invalid)
|
||||
try: m.read_config(p)
|
||||
except (ValueError, m.ET.ParseError): pass
|
||||
else: raise AssertionError('accepted invalid config')
|
||||
`], { stdio: 'inherit' });
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const { mkdtempSync, rmSync } = require('node:fs');
|
||||
const { tmpdir } = require('node:os');
|
||||
const { join } = require('node:path');
|
||||
const dir = mkdtempSync(join(tmpdir(), 'faceclaw-transcript-'));
|
||||
try {
|
||||
execFileSync('xcrun', ['clang', '-fobjc-arc', '-framework', 'Foundation', '-I', 'App_Resources/iOS/src',
|
||||
'tests/native/ios-speech-transcript-test.m', 'App_Resources/iOS/src/FaceclawSpeechTranscript.m', '-o', join(dir, 'test')], { stdio: 'inherit' });
|
||||
execFileSync(join(dir, 'test'), [], { stdio: 'inherit' });
|
||||
} finally { rmSync(dir, { recursive: true, force: true }); }
|
||||
@@ -0,0 +1,43 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
function load(file, context) {
|
||||
const sandbox = { exports: {}, ...context };
|
||||
vm.runInNewContext(ts.transpileModule(fs.readFileSync(file, 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }).outputText, sandbox);
|
||||
return sandbox.exports;
|
||||
}
|
||||
test('iOS Type Into App submits UTF-8 terminal text and delays Enter at the byte boundary without Java', () => {
|
||||
const sent = [];
|
||||
const { G2MirrorClient } = load('app/native/g2mirror-client.ts', {
|
||||
require: () => ({}), global: { isIOS: true }, NSUTF8StringEncoding: 4,
|
||||
NSString: { stringWithString: text => ({
|
||||
lengthOfBytesUsingEncoding: () => Buffer.byteLength(text, 'utf8'),
|
||||
dataUsingEncoding: () => ({ base64EncodedStringWithOptions: () => Buffer.from(text).toString('base64') }),
|
||||
}) },
|
||||
});
|
||||
const client = new G2MirrorClient({});
|
||||
client.ws = { sendText: json => sent.push(JSON.parse(json)) };
|
||||
client.handleMessage(JSON.stringify({ type: 'connect', command: 'test' }));
|
||||
const { VoiceInputLayer } = load('app/ui/shell/voice-input.ts', {
|
||||
require: id => id.includes('voice-control') ? { voiceControlBridge: { stop() {} } }
|
||||
: id.includes('dashboard-settings') ? { anthropicApiKeySetting: { get: () => '' } } : {},
|
||||
global: { isIOS: true },
|
||||
});
|
||||
for (const text of ['hello terminal', 'café π 🔋', 'line one\n第二行', '']) {
|
||||
let closed = false;
|
||||
const layer = new VoiceInputLayer({ actions: { requestRender() {} }, onClosed() {},
|
||||
dismiss() { closed = true; layer.onRemoved(); }, sendTargets: [{ id: 'app', label: 'Type Into App', onSend: value => client.submitInput(value) }] });
|
||||
layer.onTranscript({ text, isFinal: true });
|
||||
const count = sent.length;
|
||||
layer.menuRows()[0].onSelect();
|
||||
assert.equal(closed, true);
|
||||
if (!text) { assert.equal(sent.length, count); continue; }
|
||||
const message = sent.at(-1);
|
||||
assert.equal(message.type, 'input');
|
||||
assert.equal(Buffer.from(message.data, 'base64').toString('utf8'), text + '\r');
|
||||
assert.deepEqual(message.delays, [{ at: Buffer.byteLength(text), ms: 150 }]);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "FaceclawConfigPort.h"
|
||||
#include <assert.h>
|
||||
static NSDictionary *send(NSString *dir, NSUserDefaults *defaults, NSString *domain, NSDictionary *request) {
|
||||
NSData *json = [NSJSONSerialization dataWithJSONObject:request options:0 error:nil];
|
||||
assert([json writeToFile:[dir stringByAppendingPathComponent:@"request.json"] atomically:YES]);
|
||||
[FaceclawConfigPort processDirectory:dir defaults:defaults domain:domain];
|
||||
assert(![NSFileManager.defaultManager fileExistsAtPath:[dir stringByAppendingPathComponent:@"request.json"]]);
|
||||
return [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[dir stringByAppendingPathComponent:@"response.json"]] options:0 error:nil];
|
||||
}
|
||||
int main(int argc, const char **argv) { @autoreleasepool {
|
||||
NSString *dir = [NSString stringWithUTF8String:argv[1]];
|
||||
NSString *domain = [@"com.faceclaw.config-test." stringByAppendingString:NSUUID.UUID.UUIDString];
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:domain];
|
||||
[defaults setPersistentDomain:@{@"keep":@"original", @"enabled":@NO} forName:domain];
|
||||
NSDictionary *input = @{@"terminal.connections":@"[{\"url\":\"g2mirror://test@host\"}]", @"enabled":@YES, @"empty":@"", @"number":@42, @"unicode":@"π & < \n 🔋"};
|
||||
NSDictionary *reply = send(dir, defaults, domain, @{@"id":@"1", @"operation":@"push", @"settings":input});
|
||||
assert([reply[@"ok"] boolValue] && [reply[@"count"] intValue] == 5);
|
||||
assert([[defaults persistentDomainForName:domain][@"keep"] isEqual:@"original"]);
|
||||
NSDictionary *backup = [NSDictionary dictionaryWithContentsOfFile:[dir stringByAppendingPathComponent:@"previous.plist"]];
|
||||
assert([backup[@"keep"] isEqual:@"original"] && ![backup[@"enabled"] boolValue]);
|
||||
reply = send(dir, defaults, domain, @{@"id":@"2", @"operation":@"pull"});
|
||||
assert([reply[@"id"] isEqual:@"2"] && [reply[@"ok"] boolValue]);
|
||||
NSDictionary *output = reply[@"config"][@"settings"];
|
||||
for (NSString *key in input) assert([output[key] isEqual:input[key]]);
|
||||
assert(!output[@"ios.settings.changeToken"]);
|
||||
NSDictionary *before = [defaults persistentDomainForName:domain];
|
||||
reply = send(dir, defaults, domain, @{@"id":@"3", @"operation":@"push", @"settings":@{@"keep":@"changed", @"invalid":@[]}});
|
||||
assert(![reply[@"ok"] boolValue]);
|
||||
assert([[defaults persistentDomainForName:domain] isEqual:before]);
|
||||
reply = send(dir, defaults, domain, @{@"id":@"4", @"operation":@"bad"});
|
||||
assert(![reply[@"ok"] boolValue]);
|
||||
[defaults removePersistentDomainForName:domain]; [defaults synchronize];
|
||||
puts("PASS: native config merges typed values, backs up, exports, consumes requests once and rejects invalid imports atomically");
|
||||
} return 0; }
|
||||
@@ -0,0 +1,28 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "FaceclawSpeechTranscript.h"
|
||||
#include <assert.h>
|
||||
static void check(NSString *actual, NSString *expected) { assert([actual isEqual:expected]); }
|
||||
int main(void) { @autoreleasepool {
|
||||
FaceclawSpeechTranscript *t = [FaceclawSpeechTranscript new];
|
||||
check([t updateText:@"How" start:0 duration:0 settled:NO final:NO], @"How");
|
||||
check([t updateText:@"How are you" start:0 duration:0 settled:NO final:NO], @"How are you");
|
||||
check([t updateText:@"How are you?" start:0.5 duration:1.2 settled:YES final:NO], @"How are you?");
|
||||
check([t updateText:@"How are you?" start:0.5 duration:1.2 settled:YES final:NO], @"How are you?");
|
||||
check([t updateText:@"Fine" start:0 duration:0 settled:NO final:NO], @"How are you? Fine");
|
||||
check([t updateText:@"Fine thanks" start:0 duration:0 settled:NO final:NO], @"How are you? Fine thanks");
|
||||
check([t updateText:@"Fine, thanks." start:3 duration:1 settled:YES final:NO], @"How are you? Fine, thanks.");
|
||||
check([t updateText:@"" start:0 duration:0 settled:YES final:NO], @"How are you? Fine, thanks.");
|
||||
check([t updateText:@"Fine, thanks." start:0 duration:0 settled:YES final:YES], @"How are you? Fine, thanks.");
|
||||
// Identical utterances are real repetition, not duplicate callbacks.
|
||||
check([t updateText:@"Fine, thanks." start:0 duration:0 settled:NO final:NO], @"How are you? Fine, thanks. Fine, thanks.");
|
||||
check([t updateText:@"Fine, thanks." start:5 duration:1 settled:YES final:NO], @"How are you? Fine, thanks. Fine, thanks.");
|
||||
// Some OS/model combinations return cumulative text; retain it once.
|
||||
check([t updateText:@"How are you? Fine, thanks. Fine, thanks." start:0.5 duration:5.5 settled:YES final:NO], @"How are you? Fine, thanks. Fine, thanks.");
|
||||
t = [FaceclawSpeechTranscript new];
|
||||
check([t updateText:@"I scream" start:0.5 duration:1 settled:NO final:NO], @"I scream");
|
||||
check([t updateText:@"Ice cream" start:0.5 duration:1.1 settled:NO final:NO], @"Ice cream");
|
||||
check([t updateText:@"Ice cream is good." start:0.5 duration:2 settled:YES final:NO], @"Ice cream is good.");
|
||||
check([t updateText:@"Next sentence" start:4 duration:1 settled:NO final:NO], @"Ice cream is good. Next sentence");
|
||||
check([t updateText:@"Next sentence." start:4 duration:1 settled:YES final:NO], @"Ice cream is good. Next sentence.");
|
||||
puts("PASS: utterance accumulation, live revisions, repeated words, duplicate/cumulative results and empty final callbacks");
|
||||
} return 0; }
|
||||
@@ -0,0 +1,30 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { layoutHubHeader } = require('../.test-build/app/apps/terminal/hub-header.js');
|
||||
const font = size => ({ measureText: text => [...text].length * size, getGlyph: () => ({ dwidthX: size }) });
|
||||
test('terminal short status stays inline; exact-fit status does not move the list', () => {
|
||||
const f = font(7), title = 'Terminal', status = 'Connected.';
|
||||
const width = 18 + f.measureText(title) + 16 + f.measureText(status) + 12;
|
||||
const header = layoutHubHeader(f, title, status, width, 18);
|
||||
assert.equal(header.y, 10); assert.equal(header.listTop, 34); assert.deepEqual(header.lines, [status]);
|
||||
assert.equal(layoutHubHeader(f, title, status, width - 1, 18).y, 28);
|
||||
});
|
||||
test('terminal long error wraps in full-width block and moves menu below all lines at each font size', () => {
|
||||
const status = 'Connection failed. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.';
|
||||
for (const size of [5, 7, 12, 20]) for (const width of [320, 576, 640]) {
|
||||
const f = font(size), step = size * 2;
|
||||
const header = layoutHubHeader(f, 'Terminal - Connections', status, width, step);
|
||||
assert.equal(header.x, 18); assert.equal(header.y, 10 + step);
|
||||
assert.equal(header.lines.join(' '), status);
|
||||
assert.ok(header.lines.every(line => f.measureText(line) <= width - 30));
|
||||
assert.ok(header.listTop >= header.y + header.lines.length * step);
|
||||
assert.equal(header.listTop, 16 + step * (1 + header.lines.length));
|
||||
}
|
||||
});
|
||||
test('terminal explicit newlines and long unbroken messages remain complete', () => {
|
||||
const h = layoutHubHeader(font(7), 'Terminal', 'First\nSecond', 640, 18);
|
||||
assert.equal(h.x, 18); assert.deepEqual(h.lines, ['First', 'Second']);
|
||||
const word = 'x'.repeat(200);
|
||||
const wrapped = layoutHubHeader(font(7), 'Terminal', word, 320, 18);
|
||||
assert.equal(wrapped.lines.join(''), word);
|
||||
});
|
||||
@@ -12,6 +12,7 @@
|
||||
},
|
||||
"include": [
|
||||
"../app/g2/ble-protocol.ts",
|
||||
"../app/apps/terminal/hub-header.ts",
|
||||
"../app/g2/ios-peripheral-identity.ts",
|
||||
"../app/g2/glasses-session.ts",
|
||||
"../app/graphics/surface-compositor.ts",
|
||||
|
||||
Reference in new issue
Block a user