forked from Blendman974/faceclaw
Merge branch 'main' of https://github.com/jimrandomh/faceclaw
This commit is contained in:
commit
bc57557f04
32 files changed
+652
-151
No files matched your search
@@ -366,7 +366,7 @@ test('iOS preview voice uses the phone microphone, while connected capture stays
|
||||
test('iOS continuous capture is shared by windows and restarts after a disconnect, a lock or backgrounding', async () => {
|
||||
const calls = [], claims = [], providers = [];
|
||||
// Models the bridge's continuous state: listening on a source, or draining after a stop.
|
||||
const bridge = { source: null, draining: false, recording: '',
|
||||
const bridge = { source: null, draining: false, recording: '', rawSession: undefined,
|
||||
supportsContinuous: voice => voice.provider !== 'onboard',
|
||||
get continuousSource() { return this.source; },
|
||||
get continuousActive() { return !!this.source || this.draining; },
|
||||
@@ -378,7 +378,8 @@ test('iOS continuous capture is shared by windows and restarts after a disconnec
|
||||
stopContinuousCapture: async () => { calls.push(['stop']); bridge.drain(); },
|
||||
handleSessionEnded() { if (bridge.source === 'glasses') bridge.drain(); },
|
||||
stopPhoneCapture() { if (bridge.source === 'phone') bridge.drain(); },
|
||||
recordTo: name => { bridge.recording = name; } };
|
||||
recordTo: name => { bridge.recording = name; },
|
||||
setRawSession: session => { bridge.rawSession = session; } };
|
||||
const settings = { ...voiceSettings, voiceProviderSetting: { get: () => 'whisper-server' },
|
||||
whisperServerUrlSetting: { get: () => 'http://whisper.local:8000' }, whisperServerLanguageSetting: { get: () => 'en' },
|
||||
saveTranscribeAudioSetting: { get: () => true } };
|
||||
@@ -427,11 +428,13 @@ test('iOS continuous capture is shared by windows and restarts after a disconnec
|
||||
session('connected'); await settle();
|
||||
assert.deepEqual(calls, [['glasses', true]]);
|
||||
|
||||
// Locking drains; unlocking resumes.
|
||||
// Locking drains; unlocking resumes. EvenHub apps' raw mic tap follows the lock too.
|
||||
calls.length = 0; host.setGlassesLocked(true); drained(); await settle();
|
||||
assert.deepEqual(calls, []);
|
||||
assert.equal(bridge.rawSession, null, 'locking unbinds the raw mic session');
|
||||
host.setGlassesLocked(false); await settle();
|
||||
assert.deepEqual(calls, [['glasses', true]]);
|
||||
assert.equal(bridge.rawSession, host.communicator, 'unlocking rebinds it to the connected session');
|
||||
|
||||
// A failed capture is not retried in a loop, only on the next session.
|
||||
calls.length = 0; bridge.source = null; drained(); await settle();
|
||||
|
||||
@@ -140,7 +140,7 @@ function fixture() {
|
||||
"../native/compass.ios": { bindCompassSession() {}, receiveCompassEvent() {} },
|
||||
'@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) },
|
||||
knownFolders: { documents: () => ({ path: '/tmp' }) }, path },
|
||||
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {}, onSpeechEnd: () => () => {} } },
|
||||
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {}, setRawSession() {}, onSpeechEnd: () => () => {} } },
|
||||
'../native/cloud-stt-provider': { transcriptionKey: voice => voice.provider },
|
||||
'../ui/shell/voice-activity': { voiceActivity: { setActive() {}, isActive: () => false, subscribe: () => () => {} } },
|
||||
'../native/faceclaw-communicator.ios': { FaceclawCommunicatorBridge, resolveIosPeripherals: async addresses => addresses },
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
function fixture() {
|
||||
function fixture({ choose } = {}) {
|
||||
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 dialogs = [];
|
||||
const Dialogs = { action: async options => { dialogs.push(options); return choose ? choose(options.actions) : options.cancelButtonText; } };
|
||||
const { KeyboardInputViewModel } = loader({ setTimeout: callback => callback() },
|
||||
{ '@nativescript/core': { Observable, Dialogs } })('app/phone-ui/keyboard-input-view-model.ts');
|
||||
const model = new KeyboardInputViewModel(), sent = [], text = [], visibilities = [];
|
||||
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) };
|
||||
setText: value => text.push(value), sendTo: id => sent.push(id), discard: () => model.setSession(null),
|
||||
visibility: 'both', setVisibility(value) { visibilities.push(value); this.visibility = value; },
|
||||
history: [] };
|
||||
model.setSession(session);
|
||||
return { model, session, sent, text };
|
||||
const field = { text: '', focused: 0, selection: null, focus() { this.focused++; }, setSelection(start) { this.selection = start; } };
|
||||
const button = { page: { getViewById: id => id === 'keyboardInputField' ? field : undefined } };
|
||||
return { model, session, sent, text, visibilities, dialogs, field, button };
|
||||
}
|
||||
test('multiline keyboard editor routes Agent and App buttons to distinct shell destinations', () => {
|
||||
test('multiline keyboard editor routes Assistant 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');
|
||||
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'To Assistant');
|
||||
assert.equal(h.model.keyboardInputSecondaryTargetLabel, 'To App');
|
||||
h.model.onKeyboardInputTextChange({ object: { text: 'First line\nSecond line' } });
|
||||
h.model.onKeyboardInputPrimarySendTap();
|
||||
h.model.onKeyboardInputSecondarySendTap();
|
||||
@@ -26,7 +33,96 @@ test('discard and shell-side closure reset the editor; unsupported destinations
|
||||
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.keyboardInputPrimaryTargetLabel, 'Send');
|
||||
assert.equal(h.model.keyboardInputSecondaryTargetVisibility, 'collapse');
|
||||
h.model.onKeyboardInputSecondarySendTap(); assert.deepEqual(h.sent, []);
|
||||
});
|
||||
test('visibility button cycles both, phone only, glasses only; glasses-only hides the field but keeps it', () => {
|
||||
const h = fixture();
|
||||
const state = () => [h.model.keyboardInputPhoneIconOpacity, h.model.keyboardInputGlassesIconOpacity,
|
||||
h.model.keyboardInputFieldClass, h.model.keyboardInputGlassesOnlyVisibility];
|
||||
assert.deepEqual(state(), [1, 1, '', 'collapse']);
|
||||
h.model.onKeyboardInputVisibilityTap();
|
||||
assert.deepEqual(state(), [1, 0.3, '', 'collapse']);
|
||||
h.model.onKeyboardInputVisibilityTap();
|
||||
assert.deepEqual(state(), [0.3, 1, 'keyboard-input-field-hidden', 'visible']);
|
||||
h.model.onKeyboardInputGlassesOnlyHintTap({ object: h.button });
|
||||
assert.equal(h.field.focused, 1);
|
||||
h.model.onKeyboardInputVisibilityTap();
|
||||
assert.deepEqual(h.visibilities, ['phone', 'glasses', 'both']);
|
||||
assert.equal(h.model.keyboardInputVisibilityDescription, 'Shown on phone and glasses');
|
||||
});
|
||||
test('history button lists recent inputs on one line each and puts the pick in the field', async () => {
|
||||
const long = 'x'.repeat(100);
|
||||
const h = fixture({ choose: actions => actions[1] });
|
||||
assert.equal(h.model.keyboardInputHistoryOpacity, 0.3);
|
||||
await h.model.onKeyboardInputHistoryTap({ object: h.button });
|
||||
assert.equal(h.dialogs.length, 0);
|
||||
h.session.history = ['first line\n second', long];
|
||||
h.model.setSession(null); h.model.setSession(h.session);
|
||||
assert.equal(h.model.keyboardInputHistoryOpacity, 1);
|
||||
await h.model.onKeyboardInputHistoryTap({ object: h.button });
|
||||
assert.deepEqual([...h.dialogs[0].actions], ['first line second', `${'x'.repeat(79)}…`]);
|
||||
assert.equal(h.model.keyboardInputText, long);
|
||||
assert.equal(h.text.at(-1), long);
|
||||
assert.equal(h.field.text, long);
|
||||
assert.equal(h.field.selection, 100);
|
||||
});
|
||||
|
||||
function layerFixture(visibility = 'both', history = []) {
|
||||
const menu = { items: [], setItems(items) { this.items = items; }, get selectedItem() { return this.items[0]; } };
|
||||
const { KeyboardInputLayer } = loader({}, {
|
||||
'./input-dialog': { createInputDialogMenu: () => menu, paintInputDialog() {} },
|
||||
})('app/ui/shell/keyboard-input.ts');
|
||||
const stack = new Set(), events = [];
|
||||
const layer = new KeyboardInputLayer({
|
||||
actions: { requestRender() {} },
|
||||
onClosed: () => events.push('closed'),
|
||||
dismiss: () => { if (stack.delete(layer)) layer.onRemoved(); },
|
||||
setShownOnGlasses: shown => { if (shown) stack.add(layer); else if (stack.delete(layer)) layer.onRemoved(); },
|
||||
visibility, onVisibilityChanged: value => events.push(`visibility:${value}`), history,
|
||||
sendTargets: [{ id: 'app', label: 'Type Into App', onSend: text => events.push(`sent:${text}`) }],
|
||||
});
|
||||
if (layer.shownOnGlasses) stack.add(layer);
|
||||
// The shell's sleep path: the stack is cleared and each layer told.
|
||||
const clearStack = () => { for (const removed of [...stack]) { stack.delete(removed); removed.onRemoved(); } };
|
||||
return { layer, stack, events, history, clearStack };
|
||||
}
|
||||
test('phone-only takes the dialog off the glasses without ending the session', () => {
|
||||
const f = layerFixture();
|
||||
f.layer.setVisibility('phone');
|
||||
assert.equal(f.stack.size, 0);
|
||||
assert.deepEqual(f.events, ['visibility:phone']);
|
||||
f.clearStack();
|
||||
f.layer.setText('typed while hidden'); f.layer.sendTo('app');
|
||||
assert.deepEqual(f.events, ['visibility:phone', 'closed', 'sent:typed while hidden']);
|
||||
f.layer.setVisibility('both');
|
||||
assert.equal(f.stack.size, 0);
|
||||
});
|
||||
test('shown again on the glasses, the dialog closes with the stack as before', () => {
|
||||
const f = layerFixture('phone');
|
||||
assert.equal(f.stack.size, 0);
|
||||
f.layer.setVisibility('glasses');
|
||||
assert.equal(f.stack.size, 1);
|
||||
f.layer.setVisibility('both');
|
||||
assert.deepEqual(f.events, ['visibility:glasses', 'visibility:both']);
|
||||
f.clearStack();
|
||||
assert.deepEqual(f.events.at(-1), 'closed');
|
||||
const discarded = layerFixture('phone');
|
||||
discarded.layer.discard();
|
||||
assert.deepEqual(discarded.events, ['closed']);
|
||||
});
|
||||
test('sent messages go into the shared history newest first, without duplicates or blanks', () => {
|
||||
const history = [];
|
||||
for (const text of ['one', ' ', 'two', 'one ']) {
|
||||
const f = layerFixture('both', history);
|
||||
f.layer.setText(text); f.layer.sendTo('app');
|
||||
}
|
||||
assert.deepEqual(history, ['one', 'two']);
|
||||
for (let i = 0; i < 25; i++) {
|
||||
const f = layerFixture('phone', history);
|
||||
f.layer.setText(`message ${i}`); f.layer.sendTo('app');
|
||||
}
|
||||
assert.equal(history.length, 20);
|
||||
assert.equal(history[0], 'message 24');
|
||||
});
|
||||
@@ -64,6 +64,22 @@ test('context menu surface and selected row both use +4 without changing the app
|
||||
assert.deepEqual(closed.image.pixels,base.pixels);
|
||||
assert.deepEqual(wire.presentationRecords(prepareFrameDraws(closed.draws)),[]);
|
||||
});
|
||||
test('a submenu that replaces its parent menu skips the parent plane and dims the content once',()=>{
|
||||
const base=new graphics.GrayImage(100,90,200);
|
||||
const stack=new LayerStack({paint:()=>base},noopLayerActions,{width:100,height:90});
|
||||
const layout={x:10,y:8,width:80,minHeight:70,maxHeight:70,dimUnderneath:0.5};
|
||||
class SubmenuLayer extends MenuLayer { replacesLayerBelow(below) { return below instanceof MenuLayer; } }
|
||||
const parent=new MenuLayer('PARENT',[{label:'SUB',onSelect(){}}],layout);
|
||||
stack.push(parent);
|
||||
stack.push(new SubmenuLayer('CHILD',[{label:'ITEM',onSelect(){}}],layout));
|
||||
stack.push(new SubmenuLayer('GRANDCHILD',[{label:'ITEM',onSelect(){}}],layout));
|
||||
const painted=stack.paint();
|
||||
assert.equal(painted.length,2);
|
||||
assert.equal(painted[0].image.pixels[0],100);
|
||||
assert.equal(stack.baseDim(),0.5);
|
||||
stack.pop();stack.pop();
|
||||
assert.equal(stack.paint().length,2);
|
||||
});
|
||||
test('text page paints at the stack size, not the lens size',()=>{
|
||||
// An app window's stack is its viewport; a lens-sized plane is rejected by
|
||||
// the compositor as larger than the window surface.
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { wrapText } = require('../.test-build/app/graphics/textwrap.js');
|
||||
|
||||
// Monospace: every character is one unit wide, so widths count characters.
|
||||
const mono = {
|
||||
measureText: (text) => [...text].length,
|
||||
getGlyph: () => ({ dwidthX: 1 }),
|
||||
};
|
||||
|
||||
test('breakLongWords keeps words that fit on a line whole', () => {
|
||||
const text = 'Spotify plays on whichever of your devices is open';
|
||||
const expected = ['Spotify plays on', 'whichever of your', 'devices is open'];
|
||||
assert.deepEqual(wrapText(mono, text, 18), expected);
|
||||
assert.deepEqual(wrapText(mono, text, 18, { breakLongWords: true }), expected);
|
||||
});
|
||||
|
||||
test('breakLongWords splits a word wider than a line, starting it on the current line', () => {
|
||||
assert.deepEqual(
|
||||
wrapText(mono, 'see abcdefghijklmnop end', 8, { breakLongWords: true }),
|
||||
['see abcd', 'efghijkl', 'mnop end'],
|
||||
);
|
||||
});
|
||||
|
||||
test('a word wider than a line is split when nothing else fits', () => {
|
||||
assert.deepEqual(wrapText(mono, 'abcdefghij', 4), ['abcd', 'efgh', 'ij']);
|
||||
assert.deepEqual(wrapText(mono, 'abcdefghij', 4, { breakLongWords: true }), ['abcd', 'efgh', 'ij']);
|
||||
});
|
||||
|
||||
test('wrapping still breaks after slashes and hyphens', () => {
|
||||
assert.deepEqual(
|
||||
wrapText(mono, 'URI: http://127.0.0.1:43823/spotify-callback', 20, { breakLongWords: true }),
|
||||
['URI: http://', '127.0.0.1:43823/', 'spotify-callback'],
|
||||
);
|
||||
});
|
||||
@@ -20,6 +20,7 @@
|
||||
"../app/apps/terminal/hub-header.ts",
|
||||
"../app/g2/ios-peripheral-identity.ts",
|
||||
"../app/graphics/image.ts",
|
||||
"../app/graphics/textwrap.ts",
|
||||
"../app/graphics/battery.ts",
|
||||
"../app/graphics/plane.ts",
|
||||
"../app/graphics/shell-scene.ts",
|
||||
|
||||
Reference in new issue
Block a user