forked from Blendman974/faceclaw
Phone UI: Settings are a page instead of a tab, watch vs ring style input is a setting rather than a tab, EvenHub webview is a button with the main buttons rather than in the top bar
This commit is contained in:
1 parent
a02b849200
commit
cd61fefb21
35 files changed
+848
-429
No files matched your search
@@ -212,15 +212,12 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
|
||||
'./phone-gestures': { PhoneGestureRecognizer: class { cancel() {} } },
|
||||
'./ble-bandwidth-meter': require('../.test-build/app/phone-ui/ble-bandwidth-meter.js'),
|
||||
'../native/ble-traffic': { sampleBleTraffic: () => totals },
|
||||
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayLayoutSetting: { displayValue: () => 'Tall' }, showBleBandwidthSetting: { get: () => enabled }, glassesModelName: () => 'G2',
|
||||
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => 'watch' }, showBleBandwidthSetting: { get: () => enabled },
|
||||
onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } },
|
||||
'../g2/device-addresses': { loadDeviceAddresses: () => ({}) },
|
||||
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
|
||||
'./onboarding-state': { isPreviewOnlyMode: () => false },
|
||||
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
|
||||
'../g2/glasses-display-state': require('../.test-build/app/g2/glasses-display-state.js'),
|
||||
'../ui/shell/shell': { shell: { onBatteryLevelsChanged: () => () => {}, getBatteryLevels: () => ({
|
||||
headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }) } },
|
||||
};
|
||||
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] });
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
const NO_LEVELS = { headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null };
|
||||
|
||||
function fixture() {
|
||||
let brightness = '40', mode = 'small', style = 'watch', picked, levels = { ...NO_LEVELS };
|
||||
const changes = [], writes = [], back = [];
|
||||
const settingListeners = new Set(), batteryListeners = new Set();
|
||||
const subscribe = listeners => fn => { listeners.add(fn); return () => listeners.delete(fn); };
|
||||
class Observable {
|
||||
notifyPropertyChange(name, value) { changes.push([name, value]); }
|
||||
}
|
||||
const settings = {
|
||||
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
|
||||
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
|
||||
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
|
||||
phoneInputStyleSetting: { get: () => style, set: value => { style = value; } },
|
||||
glassesModelName: () => 'G2',
|
||||
onAnySettingChanged: subscribe(settingListeners),
|
||||
};
|
||||
// glasses-display-state and glasses-presence are pure, so the real ones load.
|
||||
const load = loader({}, {
|
||||
'@nativescript/core': { Observable, Dialogs: { action: async () => picked }, Frame: { topmost: () => ({ goBack: () => back.push(true) }) } },
|
||||
'../ui/dashboard-settings': settings,
|
||||
'../ui/shell/shell': { shell: { getBatteryLevels: () => levels, onBatteryLevelsChanged: subscribe(batteryListeners) } },
|
||||
});
|
||||
const { SettingsViewModel } = load('app/phone-ui/settings-view-model.ts');
|
||||
const presence = load('app/g2/glasses-presence.ts');
|
||||
return { model: new SettingsViewModel(), changes, writes, back, presence, settingListeners, batteryListeners,
|
||||
brightness: () => brightness, mode: () => mode, style: () => style, pick: value => { picked = value; },
|
||||
setLevels: next => { levels = { ...NO_LEVELS, ...next }; for (const fn of batteryListeners) fn(); },
|
||||
changeElsewhere: fn => { fn({ setBrightness: value => { brightness = value; }, setStyle: value => { style = value; } });
|
||||
for (const listener of settingListeners) listener(); } };
|
||||
}
|
||||
|
||||
test('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(), '2');
|
||||
h.model.onBrightnessChange({ value: NaN });
|
||||
assert.equal(h.brightness(), '2');
|
||||
});
|
||||
|
||||
test('display-mode picker preserves cancellation and applies the selected mode', async () => {
|
||||
const h = fixture();
|
||||
h.pick('Cancel'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
// Unavailable modes (Full Screen beside a side strip) are not offered.
|
||||
h.pick('Huge'); 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 ▾');
|
||||
});
|
||||
|
||||
test('Phone input style picks the pad, marks the chosen button and explains it', () => {
|
||||
const h = fixture();
|
||||
assert.match(h.model.watchStyleClass, /segment-button-selected/);
|
||||
assert.doesNotMatch(h.model.ringStyleClass, /selected/);
|
||||
const watchHint = h.model.phoneInputStyleHint;
|
||||
h.model.onWatchStyleTap();
|
||||
assert.deepEqual(h.changes, [], 'picking the current style changes nothing');
|
||||
h.model.onRingStyleTap();
|
||||
assert.equal(h.style(), 'ring');
|
||||
assert.match(h.model.ringStyleClass, /segment-button-selected/);
|
||||
assert.doesNotMatch(h.model.watchStyleClass, /selected/);
|
||||
assert.notEqual(h.model.phoneInputStyleHint, watchHint);
|
||||
// Updated at once, without waiting for the store's own (next-tick) notification.
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['watchStyleClass', 'ringStyleClass', 'phoneInputStyleHint']);
|
||||
});
|
||||
|
||||
test('the page follows changes made on the glasses only while it is on screen', () => {
|
||||
const h = fixture();
|
||||
assert.equal(h.settingListeners.size, 0, 'nothing is subscribed before the page loads');
|
||||
h.model.attach(); h.model.attach();
|
||||
assert.equal(h.settingListeners.size, 1); assert.equal(h.batteryListeners.size, 1);
|
||||
h.changes.length = 0;
|
||||
h.changeElsewhere(remote => { remote.setBrightness('auto'); remote.setStyle('ring'); });
|
||||
const changed = Object.fromEntries(h.changes);
|
||||
assert.equal(changed.brightnessAuto, true);
|
||||
assert.equal(changed.brightnessSliderEnabled, false);
|
||||
assert.match(changed.ringStyleClass, /segment-button-selected/);
|
||||
assert.ok('displayModeLabel' in changed);
|
||||
h.model.detach();
|
||||
assert.equal(h.settingListeners.size, 0); assert.equal(h.batteryListeners.size, 0);
|
||||
// Coming back (an app resume, or returning to the page) catches up.
|
||||
h.changeElsewhere(remote => remote.setBrightness('60'));
|
||||
h.changes.length = 0; h.model.attach();
|
||||
assert.equal(Object.fromEntries(h.changes).brightnessPercent, 60);
|
||||
h.model.detach();
|
||||
});
|
||||
|
||||
test('the battery row hides until a level is known and marks charging only over a live link', () => {
|
||||
const h = fixture();
|
||||
h.model.attach();
|
||||
assert.equal(h.model.batteryLineVisibility, 'collapse');
|
||||
h.setLevels({ headset: 90, headsetCharging: true, ring: 72 });
|
||||
assert.equal(h.model.batteryLine, 'G2 90% · R1 72%');
|
||||
assert.equal(h.model.batteryLineVisibility, 'visible');
|
||||
h.changes.length = 0;
|
||||
h.presence.updateGlassesPresence({ connected: true });
|
||||
assert.equal(h.model.batteryLine, 'G2 90% ⚡ · R1 72%');
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['batteryLine', 'batteryLineVisibility']);
|
||||
h.model.detach();
|
||||
h.presence.updateGlassesPresence({ connected: false });
|
||||
assert.equal(h.model.batteryLine, 'G2 90% ⚡ · R1 72%', 'a detached page is not updated');
|
||||
h.model.attach();
|
||||
assert.equal(h.model.batteryLine, 'G2 90% · R1 72%');
|
||||
h.model.detach();
|
||||
});
|
||||
|
||||
test('the back arrow pops the settings page', () => {
|
||||
const h = fixture();
|
||||
h.model.onBackTap();
|
||||
assert.deepEqual(h.back, [true]);
|
||||
});
|
||||
|
||||
test('the settings page binds every row the view model serves and is registered for iOS', () => {
|
||||
const fs = require('node:fs'), path = require('node:path');
|
||||
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||
const xml = read('app/phone-ui/settings-page.xml');
|
||||
for (const binding of ['displayModeLabel', 'onDisplayModeTap', 'brightnessAuto', 'onBrightnessAutoChange', 'brightnessPercent',
|
||||
'onBrightnessChange', 'brightnessSliderEnabled', 'watchStyleClass', 'ringStyleClass', 'onWatchStyleTap', 'onRingStyleTap',
|
||||
'phoneInputStyleHint', 'batteryLine', 'batteryLineVisibility', 'onBackTap']) {
|
||||
assert.ok(xml.includes(`{{ ${binding} }}`), `settings-page.xml binds ${binding}`);
|
||||
}
|
||||
// iOS skips webpack's automatic page discovery, and loads app.ios.css instead of app.css.
|
||||
const register = read('app/phone-ui/onboarding-register.ios.ts');
|
||||
assert.match(register, /registerModule\('phone-ui\/settings-page', /);
|
||||
assert.match(register, /registerModule\('phone-ui\/settings-page\.xml', /);
|
||||
for (const css of ['app/app.css', 'app/app.ios.css']) assert.match(read(css), /@import '\.\/phone-ui\/settings-page\.css';/);
|
||||
});
|
||||
|
||||
test('Phone input style is a stored setting, Watch by default, also offered in the glasses Settings app', () => {
|
||||
const fs = require('node:fs'), path = require('node:path'), vm = require('node:vm'), ts = require('typescript');
|
||||
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||
// The real setting object, over an in-memory settings store.
|
||||
const store = new Map(), sandbox = { exports: {}, global: { isIOS: false }, setTimeout: fn => fn(),
|
||||
require: id => id.includes('settings-store') ? { onSettingsStoreChanged() {},
|
||||
getStringSetting: (key, fallback) => store.get(key) ?? fallback, setStringSetting: (key, value) => store.set(key, value),
|
||||
getBooleanSetting: (key, fallback) => store.get(key) ?? fallback, setBooleanSetting: (key, value) => store.set(key, value) }
|
||||
: { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] } };
|
||||
vm.runInNewContext(ts.transpileModule(read('app/ui/dashboard-settings.ts'),
|
||||
{ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }).outputText, sandbox);
|
||||
const setting = sandbox.exports.phoneInputStyleSetting;
|
||||
assert.equal(setting.label, 'Phone input style');
|
||||
assert.equal(setting.get(), 'watch');
|
||||
assert.deepEqual([...setting.values].map(value => setting.displayValue(value)), ['Watch', 'Ring']);
|
||||
setting.set('ring');
|
||||
assert.equal(store.get('phone.inputStyle'), 'ring');
|
||||
assert.equal(setting.get(), 'ring');
|
||||
store.set('phone.inputStyle', 'settings');
|
||||
assert.equal(setting.get(), 'watch', 'an unknown stored value reads as the default');
|
||||
|
||||
// The on-glasses Settings app lists it with the other phone-screen settings.
|
||||
const menus = read('app/ui/dashboard/settings-menus.ts');
|
||||
const section = menus.slice(menus.indexOf('label: "Phone display"'), menus.indexOf('label: "Watch"'));
|
||||
assert.match(section, /enumSettingMenuItem\(phoneInputStyleSetting\)/);
|
||||
});
|
||||
@@ -3,62 +3,78 @@ const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
function fixture() {
|
||||
let brightness = '40', mode = 'small', picked;
|
||||
const changes = [], writes = [];
|
||||
let style = 'watch';
|
||||
const changes = [], navigations = [];
|
||||
class Observable {
|
||||
notifyPropertyChange(name, value) { changes.push([name, value]); }
|
||||
}
|
||||
const settings = {
|
||||
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
|
||||
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
|
||||
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
|
||||
};
|
||||
const { RemoteControlsViewModel } = loader({}, {
|
||||
'@nativescript/core': { Observable, Dialogs: { action: async () => picked } },
|
||||
'../ui/dashboard-settings': settings,
|
||||
'@nativescript/core': { Observable, Frame: { topmost: () => ({ navigate: entry => navigations.push(entry) }) } },
|
||||
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => style } },
|
||||
})('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; } };
|
||||
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, navigations,
|
||||
setStyle: value => { style = value; } };
|
||||
}
|
||||
|
||||
test('shared controls preserve the selected tab across page visits and update all tab bindings', () => {
|
||||
test('the touchpad follows the Phone input style setting and only notifies when it changes', () => {
|
||||
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');
|
||||
assert.equal(h.model.watchPadVisibility, 'visible');
|
||||
assert.equal(h.model.ringPadVisibility, 'collapse');
|
||||
// Some other setting changed: nothing to redraw, no gesture to cancel.
|
||||
h.model.refreshInputStyle();
|
||||
assert.deepEqual(h.changes, []);
|
||||
h.setStyle('ring'); h.model.refreshInputStyle();
|
||||
assert.equal(h.model.watchPadVisibility, 'collapse');
|
||||
assert.equal(h.model.ringPadVisibility, 'visible');
|
||||
assert.deepEqual(h.changes, [['watchPadVisibility', 'collapse'], ['ringPadVisibility', 'visible']]);
|
||||
// A page built later starts on the stored style.
|
||||
assert.equal(h.create().ringPadVisibility, '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(), '2');
|
||||
h.model.onBrightnessChange({ value: NaN });
|
||||
assert.equal(h.brightness(), '2');
|
||||
test('the EvenHub phone-UI button shows only with an icon and opens that app through the host', () => {
|
||||
const h = fixture(), opened = [], icon = { id: 'icon' };
|
||||
h.model.showEvenHubPhoneUi = windowId => opened.push(windowId);
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon: null };
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
assert.deepEqual(opened, [], 'a hidden button opens nothing');
|
||||
|
||||
h.changes.length = 0;
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'visible');
|
||||
assert.equal(h.model.evenHubPhoneUiIcon, icon);
|
||||
assert.equal(h.model.evenHubPhoneUiLabel, 'Open Chess on phone');
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['evenHubPhoneUiIcon', 'evenHubPhoneUiVisibility', 'evenHubPhoneUiLabel']);
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
assert.deepEqual(opened, ['w1']);
|
||||
|
||||
// The host pushes a fresh object on every snapshot; an equal one is not a change.
|
||||
h.changes.length = 0;
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
|
||||
assert.deepEqual(h.changes, []);
|
||||
h.model.evenHubPhoneUi = null;
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
assert.equal(h.model.evenHubPhoneUiLabel, '');
|
||||
});
|
||||
|
||||
test('shared display-mode picker preserves cancellation and applies the selected mode', async () => {
|
||||
test('the gear button opens the settings page', () => {
|
||||
const h = fixture();
|
||||
h.pick('Cancel'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
// Unavailable modes (Full Screen beside a side strip) are not offered.
|
||||
h.pick('Huge'); 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 ▾');
|
||||
h.model.onSettingsTap();
|
||||
// The entry is built in the module's own realm, so compare its field.
|
||||
assert.deepEqual(h.navigations.map(entry => entry.moduleName), ['phone-ui/settings-page']);
|
||||
});
|
||||
|
||||
test('the control bar keeps the EvenHub button leftmost and the pads bound to the input style', () => {
|
||||
const xml = require('node:fs').readFileSync(require('node:path').join(__dirname, '../app/phone-ui/remote-controls.xml'), 'utf8');
|
||||
const bar = xml.slice(xml.indexOf('class="control-bar"'), xml.indexOf('onControlsContentLayoutChanged'));
|
||||
const order = ['onEvenHubPhoneUiTap', 'onSyntheticMicTap', 'onKeyboardTap', 'onSettingsTap'].map(name => bar.indexOf(name));
|
||||
assert.ok(order.every(index => index >= 0), 'all four buttons are in the bar');
|
||||
assert.deepEqual(order, [...order].sort((a, b) => a - b));
|
||||
// A leading star column takes the slack, so the app button's coming and going moves no other button.
|
||||
assert.match(xml, /columns="\*,auto,auto,auto,auto"[^>]*class="control-bar"/);
|
||||
assert.match(xml, /visibility="\{\{ watchPadVisibility \}\}"/);
|
||||
assert.match(xml, /visibility="\{\{ ringPadVisibility \}\}"/);
|
||||
assert.doesNotMatch(xml, /TabVisibility|TabClass|TabTap/);
|
||||
});
|
||||
Reference in new issue
Block a user