forked from Blendman974/faceclaw
Merge branch 'main' of https://github.com/jimrandomh/faceclaw
This commit is contained in:
commit
43738b181d
28 files changed
+1062
-95
No files matched your search
@@ -283,6 +283,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
||||
'../notifications': {}, '../dashboard-settings': settings, './ambient-cards': {},
|
||||
'./chrome-layer': { ShellChromeLayer: class {} }, './modal-layer': {}, './tool-debug-layer': {},
|
||||
'./brightness-picker-layer': {}, './notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts', {}),
|
||||
'./notification-popup-timeout': {},
|
||||
'../../native/notification-icons': {}, '../../native/notification-sources': {},
|
||||
'../../assistant/tool-registry': {}, './geometry': {
|
||||
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
|
||||
|
||||
@@ -73,6 +73,7 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
|
||||
openSettingsSubMenu() {},
|
||||
},
|
||||
'../font-picker': { uiFontPickerMenuItem: () => ({ label: 'Font' }) },
|
||||
'../notification-filter': { NotificationFilterLayer: class {} },
|
||||
'../openai-compatible-model-picker': {
|
||||
compatibleModelDiscoveryMenuItem: () => ({ label: 'Discover models' }),
|
||||
},
|
||||
|
||||
@@ -17,6 +17,8 @@ const setting = (initial = '') => {
|
||||
|
||||
class AuthError extends Error {}
|
||||
|
||||
const gestures = loader({}, {})('app/ui/gestures.ts');
|
||||
|
||||
/**
|
||||
* Load the store layer, by default with a signed-out account and no stored
|
||||
* credentials. `api` overrides evenHubApi methods; text the layer paints is
|
||||
@@ -34,7 +36,7 @@ const loadStoreLayer = ({ configured = false, api = {} } = {}) => {
|
||||
'../../graphics/image': { GrayImage: class { drawText(_f, _x, _y, text) { drawn.push(text); } fillRect() {} } },
|
||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] },
|
||||
'../../util/numeric-util': { clamp: (v, lo, hi) => Math.min(hi, Math.max(lo, v)) },
|
||||
'../../ui/gestures': { GESTURE_CLICK: 'click' },
|
||||
'../../ui/gestures': { ...gestures, GESTURE_CLICK: 'click' },
|
||||
'../../ui/menu': { drawSelectionHighlight() {} },
|
||||
'../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'),
|
||||
'../../ui/shell/shell': { shell: { yieldFocusToSidebar() {} } },
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
// EvenHub store navigation: watch swipes on the tab strip, the Updates tab's
|
||||
// Update All row, and page-at-a-time scrolling in the permission dialog.
|
||||
//
|
||||
// The real layers run with their dependencies mocked; what they paint is
|
||||
// collected as text, so these assert what the user would see.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
const gestures = loader({}, {})('app/ui/gestures.ts');
|
||||
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
|
||||
|
||||
/** Records drawn text; every other drawing call is a no-op. */
|
||||
const makeImageClass = (drawn) => class {
|
||||
drawText(_font, _x, _y, text) { drawn.push(text); }
|
||||
fillRect() {}
|
||||
fillRoundedRect() {}
|
||||
drawRoundedRect() {}
|
||||
};
|
||||
|
||||
/** Stand-in for ui/menu-core's Menu: draws every row in order, scrolls the selection by one. */
|
||||
class FakeMenu {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.items = options.items;
|
||||
this.selectedIndex = 0;
|
||||
this.scrollTop = 0;
|
||||
}
|
||||
setItems(items, selectedIndex) {
|
||||
this.items = items;
|
||||
if (selectedIndex !== undefined) this.selectedIndex = selectedIndex;
|
||||
this.selectedIndex = Math.max(0, Math.min(this.selectedIndex, items.length - 1));
|
||||
}
|
||||
get selectedItem() { return this.items[this.selectedIndex] ?? null; }
|
||||
handleInput(event) {
|
||||
if (event.type === 'scroll-down') this.selectedIndex = Math.min(this.items.length - 1, this.selectedIndex + 1);
|
||||
if (event.type === 'scroll-up') this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
||||
}
|
||||
paint(image, box) {
|
||||
this.items.forEach((item, index) => this.options.draw({ image, item, index, x: box.x, y: box.y, width: box.width }));
|
||||
}
|
||||
drawScrollbar() {}
|
||||
}
|
||||
|
||||
const storeApp = (packageId, name, version) => ({
|
||||
id: 1, packageId, name, version, creatorName: '', tagline: '', description: '', categories: [],
|
||||
installCount: 0, likeCount: 0, firstPublishedAt: '', iconPath: '', changelog: '', fileSize: 0,
|
||||
});
|
||||
|
||||
const emptyPage = { apps: [], total: 0, page: 1, pageSize: 20 };
|
||||
|
||||
/** A signed-in store layer; `updates` is what the update check reports. */
|
||||
const loadStore = ({ updates = [] } = {}) => {
|
||||
const drawn = [];
|
||||
const installs = [];
|
||||
const setting = { get: () => '', set() {} };
|
||||
const load = loader({}, {
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../../graphics/image': { GrayImage: makeImageClass(drawn) },
|
||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] },
|
||||
'../../ui/gestures': { ...gestures, GESTURE_CLICK: 'click' },
|
||||
'../../ui/menu': { drawSelectionHighlight() {} },
|
||||
'../../ui/menu-core': { Menu: FakeMenu },
|
||||
'../../ui/shell/shell': { shell: { yieldFocusToSidebar() {} } },
|
||||
'../../ui/metrics': { lineStep: () => 12 },
|
||||
'../../ui/dashboard-settings': {
|
||||
ConfigSettingString: class { constructor(options) { this.value = options.defaultValue ?? ''; }
|
||||
get() { return this.value; } set(next) { this.value = next; return next; } },
|
||||
},
|
||||
'./even-api': {
|
||||
evenHubApi: { listApps: async () => emptyPage, listNewApps: async () => emptyPage, searchApps: async () => emptyPage },
|
||||
EvenHubAuthenticationError: class extends Error {},
|
||||
isEvenHubStoreConfigured: () => true,
|
||||
},
|
||||
'./credentials': {
|
||||
evenHubLoginEmailSetting: setting, evenHubLoginPasswordSetting: setting, evenHubRememberMeSetting: setting,
|
||||
clearEvenHubLoginForm() {}, resetEvenHubLoginForm() {}, clearEvenHubSession() {}, clearTransientEvenHubSession() {},
|
||||
},
|
||||
'./installed-apps': { getInstalledEvenHubApps: () => updates.map((update) => update.installed), uninstallEvenHubPackage: () => true },
|
||||
'./store-detail-layer': { EvenHubStoreDetailLayer: class {} },
|
||||
'./store-install': {
|
||||
cleanError: (error) => String(error?.message ?? error),
|
||||
installStoreApp: async (_ctx, app) => { installs.push(app.packageId); return { packageId: app.packageId }; },
|
||||
},
|
||||
'./updates': {
|
||||
checkForEvenHubUpdates: async () => updates,
|
||||
describeUpdate: () => ({ updateAvailable: false, packageMissing: false }),
|
||||
},
|
||||
});
|
||||
const { EvenHubStoreLayer } = load('app/apps/evenhub/store-layer.ts');
|
||||
const layer = new EvenHubStoreLayer({ launchApp: async () => {}, appendLog: () => {} });
|
||||
return { layer, drawn, installs };
|
||||
};
|
||||
|
||||
const makeCtx = () => ({
|
||||
stack: {
|
||||
getBaseSize: () => ({ width: 576, height: 288 }),
|
||||
isFocused: () => true,
|
||||
clearToBase() {},
|
||||
push() {},
|
||||
pop() {},
|
||||
},
|
||||
actions: { requestRender() {}, endTextSettingEdit() {}, startTextSettingsEdit() {} },
|
||||
});
|
||||
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
/** Repaint and return the drawn text. */
|
||||
const repaint = (layer, drawn, ctx) => {
|
||||
drawn.length = 0;
|
||||
layer.paint(ctx);
|
||||
return [...drawn];
|
||||
};
|
||||
|
||||
const watch = (type) => ({ type, source: 'watch', timestampMs: 0 });
|
||||
|
||||
test('watch swipes left and right switch tabs while the tab strip is focused', async () => {
|
||||
const { layer, drawn } = loadStore();
|
||||
const ctx = makeCtx();
|
||||
layer.paint(ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Public apps by popularity'));
|
||||
|
||||
// In the list, a right swipe is "select" and must not change tabs.
|
||||
await layer.handleInput(watch('swipe-right'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Public apps by popularity'), 'still on Top');
|
||||
|
||||
// A left swipe in the list is "back", which focuses the tab strip.
|
||||
await layer.handleInput(watch('swipe-left'), ctx);
|
||||
await layer.handleInput(watch('swipe-right'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Recently published apps'), 'right moved to New');
|
||||
|
||||
await layer.handleInput(watch('swipe-left'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Public apps by popularity'), 'left moved back to Top');
|
||||
|
||||
// Up/down still switch tabs too.
|
||||
await layer.handleInput(watch('swipe-down'), ctx);
|
||||
await settle();
|
||||
assert.ok(repaint(layer, drawn, ctx).includes('Recently published apps'), 'down moved to New');
|
||||
});
|
||||
|
||||
/** Open the store and move to the Updates tab, with focus back in its list. */
|
||||
const openUpdatesTab = async (layer, ctx) => {
|
||||
layer.paint(ctx);
|
||||
await settle();
|
||||
await layer.handleInput({ type: 'double-click', source: 'ring' }, ctx);
|
||||
for (let i = 0; i < 3; i++) await layer.handleInput({ type: 'scroll-down' }, ctx);
|
||||
await settle();
|
||||
await layer.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
};
|
||||
|
||||
test('the Updates tab lists Update All first and it installs every update', async () => {
|
||||
const updates = [
|
||||
{ installed: { packageId: 'a', name: 'Alpha', version: '1' }, latest: storeApp('a', 'Alpha', '2'), packageMissing: false },
|
||||
{ installed: { packageId: 'b', name: 'Beta', version: '1' }, latest: storeApp('b', 'Beta', '3'), packageMissing: false },
|
||||
{ installed: { packageId: 'c', name: 'Gamma', version: '1' } },
|
||||
];
|
||||
const { layer, drawn, installs } = loadStore({ updates });
|
||||
const ctx = makeCtx();
|
||||
await openUpdatesTab(layer, ctx);
|
||||
|
||||
const painted = repaint(layer, drawn, ctx);
|
||||
assert.ok(painted.includes('Updates (3)'), `the tab count is apps, not rows: ${JSON.stringify(painted)}`);
|
||||
assert.ok(painted.includes('3 apps need attention'));
|
||||
const updateAll = painted.indexOf('Update All');
|
||||
assert.ok(updateAll >= 0, `painted: ${JSON.stringify(painted)}`);
|
||||
assert.ok(painted.includes('Install all 2 available updates'), 'the orphan is not counted');
|
||||
assert.ok(updateAll < painted.indexOf('Alpha') && updateAll < painted.indexOf('Gamma'), 'Update All is the first row');
|
||||
|
||||
// The list opens on Update All; clicking it installs both updatable apps.
|
||||
await layer.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
await settle();
|
||||
assert.deepEqual(installs, ['a', 'b']);
|
||||
const after = repaint(layer, drawn, ctx);
|
||||
assert.ok(!after.includes('Update All'), 'nothing left to update, so the row goes');
|
||||
assert.ok(after.includes('Gamma'), 'the missing package stays listed');
|
||||
assert.ok(after.includes('Updated 2 apps.'));
|
||||
});
|
||||
|
||||
test('the Updates tab has no Update All row when nothing can be installed', async () => {
|
||||
const updates = [{ installed: { packageId: 'c', name: 'Gamma', version: '1' } }];
|
||||
const { layer, drawn } = loadStore({ updates });
|
||||
const ctx = makeCtx();
|
||||
await openUpdatesTab(layer, ctx);
|
||||
const painted = repaint(layer, drawn, ctx);
|
||||
assert.ok(painted.includes('Gamma'));
|
||||
assert.ok(!painted.includes('Update All'));
|
||||
});
|
||||
|
||||
// ---- permission dialog ---------------------------------------------------
|
||||
|
||||
const loadDialog = (detailLines) => {
|
||||
const drawn = [];
|
||||
const load = loader({}, {
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../../graphics/image': { GrayImage: makeImageClass(drawn) },
|
||||
'../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => text.split('|') },
|
||||
'../../ui/gestures': gestures,
|
||||
'../../ui/layers': {},
|
||||
'../../ui/menu': { drawListScrollbar() {}, drawSelectionHighlight() {} },
|
||||
'./permissions': { permissionDetail: (permission) => permission.detail, permissionLabel: (name) => name },
|
||||
'./privacy-policy': { openPrivacyPolicyOnPhone() {} },
|
||||
'../../ui/metrics': { lineStep: () => 12, listRowHeight: () => 20 },
|
||||
});
|
||||
const { EvenHubPermissionDialogLayer } = load('app/apps/evenhub/permission-dialog.ts');
|
||||
const ImageClass = makeImageClass(drawn);
|
||||
const outcome = { confirmed: null };
|
||||
const dialog = new EvenHubPermissionDialogLayer(
|
||||
'Demo',
|
||||
[{ name: 'network', detail: detailLines.join('|') }],
|
||||
'',
|
||||
() => { outcome.confirmed = true; },
|
||||
() => { outcome.confirmed = false; },
|
||||
);
|
||||
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 136 }), isFocused: () => true, pop() {} } };
|
||||
const paint = () => {
|
||||
drawn.length = 0;
|
||||
dialog.paint(ctx, () => new ImageClass());
|
||||
return [...drawn];
|
||||
};
|
||||
return { dialog, ctx, paint, outcome };
|
||||
};
|
||||
|
||||
test('the permission dialog scrolls a page at a time with one line of overlap', () => {
|
||||
const lines = Array.from({ length: 30 }, (_, i) => `line ${i + 1}`);
|
||||
const { dialog, ctx, paint, outcome } = loadDialog(lines);
|
||||
|
||||
const pages = [paint()];
|
||||
while (!pages[pages.length - 1].includes('Allow')) {
|
||||
assert.ok(pages.length < 20, 'paging reaches the actions');
|
||||
dialog.handleInput({ type: 'scroll-down' }, ctx);
|
||||
pages.push(paint());
|
||||
}
|
||||
assert.ok(pages.length >= 3, `the list is long enough to need several pages (${pages.length})`);
|
||||
// Every page but the last (which stops at the bottom) starts on the line the previous one ended on.
|
||||
for (let page = 1; page < pages.length - 1; page++) {
|
||||
const previous = pages[page - 1];
|
||||
assert.equal(pages[page][0], previous[previous.length - 1], `page ${page + 1} overlaps page ${page} by one line`);
|
||||
assert.ok(pages[page].length > 2, 'a page moves by more than one line');
|
||||
}
|
||||
// Every line was on screen on some page.
|
||||
for (const line of lines) assert.ok(pages.some((page) => page.includes(line)), `${line} was shown`);
|
||||
|
||||
// Paging up from the bottom: the old first line becomes the new last one.
|
||||
const bottom = pages[pages.length - 1];
|
||||
dialog.handleInput({ type: 'scroll-up' }, ctx);
|
||||
const up = paint();
|
||||
assert.equal(up[up.length - 1], bottom[0], 'one line of overlap going up');
|
||||
assert.ok(up.length > 2);
|
||||
for (let i = 0; i < pages.length; i++) dialog.handleInput({ type: 'scroll-up' }, ctx);
|
||||
assert.deepEqual(paint(), pages[0], 'back at the top');
|
||||
|
||||
// A click before the bottom pages down rather than allowing; scrolling up returns.
|
||||
dialog.handleInput({ type: 'click', source: 'ring' }, ctx);
|
||||
assert.deepEqual(paint(), pages[1]);
|
||||
assert.equal(outcome.confirmed, null);
|
||||
dialog.handleInput({ type: 'scroll-up' }, ctx);
|
||||
assert.deepEqual(paint(), pages[0]);
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.test.*
|
||||
|
||||
class ColorGlyphArtTest {
|
||||
private val size = 16
|
||||
|
||||
private val clear = 0
|
||||
private val white = argb(255, 255, 255, 255)
|
||||
private val yellow = argb(255, 255, 204, 50)
|
||||
private val brown = argb(255, 90, 50, 20)
|
||||
private val darkGray = argb(255, 60, 60, 60)
|
||||
private val green = argb(255, 120, 170, 60)
|
||||
private val red = argb(255, 230, 60, 50)
|
||||
private val lightRed = argb(255, 250, 140, 130)
|
||||
|
||||
private fun argb(a: Int, r: Int, g: Int, b: Int): Int = (a shl 24) or (r shl 16) or (g shl 8) or b
|
||||
|
||||
private fun glyph(pixel: (x: Int, y: Int) -> Int): IntArray = IntArray(size * size) { pixel(it % size, it / size) }
|
||||
|
||||
private fun inDisc(x: Int, y: Int): Boolean {
|
||||
val dx = x + 0.5 - size / 2.0
|
||||
val dy = y + 0.5 - size / 2.0
|
||||
return dx * dx + dy * dy <= 7.0 * 7.0
|
||||
}
|
||||
|
||||
private fun at(shade: ByteArray, x: Int, y: Int): Int = shade[y * size + x].toInt() and 0xff
|
||||
|
||||
private fun lit(level: Double): Int = (255 * level.pow(NotificationIconArt.GAMMA)).roundToInt()
|
||||
|
||||
@Test fun whiteGlyphIsItsAlpha() {
|
||||
// An ordinary glyph drawn in white: antialiased edges, no color anywhere.
|
||||
val pixels = glyph { x, y -> if (x in 4..11) argb(if (x == 4 || x == 11) 90 else 255, 255, 255, 255) else clear }
|
||||
assertFalse(ColorGlyphArt.isColor(pixels))
|
||||
assertContentEquals(ByteArray(pixels.size) { ((pixels[it] ushr 24) and 0xff).toByte() }, ColorGlyphArt.coverage(pixels))
|
||||
}
|
||||
|
||||
@Test fun faintColorFringeIsNotColor() {
|
||||
// Unpremultiplying a nearly transparent pixel can land anywhere; only real ink counts.
|
||||
val pixels = glyph { x, _ -> if (x == 3) argb(8, 0, 0, 0) else if (x in 4..11) white else clear }
|
||||
assertFalse(ColorGlyphArt.isColor(pixels))
|
||||
}
|
||||
|
||||
@Test fun oneColorGlyphLightsFully() {
|
||||
// 🖤: dark by lightness, but its shape is what matters.
|
||||
val pixels = glyph { x, y -> if (inDisc(x, y)) darkGray else clear }
|
||||
assertTrue(ColorGlyphArt.isColor(pixels))
|
||||
val shade = ColorGlyphArt.coverage(pixels)
|
||||
assertEquals(255, at(shade, 8, 8))
|
||||
assertEquals(0, at(shade, 0, 0))
|
||||
}
|
||||
|
||||
@Test fun darkDetailOnALightBodyStaysVisibleButDim() {
|
||||
// 😀: a yellow disc with dark eyes and mouth; the body stays full, the features dim.
|
||||
val pixels = glyph { x, y ->
|
||||
when {
|
||||
!inDisc(x, y) -> clear
|
||||
(y in 5..6 && (x == 5 || x == 10)) || (y == 11 && x in 5..10) -> brown
|
||||
else -> yellow
|
||||
}
|
||||
}
|
||||
val shade = ColorGlyphArt.coverage(pixels)
|
||||
assertEquals(255, at(shade, 8, 8))
|
||||
assertEquals(lit(0.3), at(shade, 5, 5))
|
||||
assertTrue(at(shade, 5, 5) > 0)
|
||||
}
|
||||
|
||||
@Test fun lightDetailOnADarkerBodyDimsTheBody() {
|
||||
// ✅: a green tile with a large white check; the check lights fully above a dimmer tile.
|
||||
val pixels = glyph { x, y ->
|
||||
when {
|
||||
x !in 1..14 || y !in 1..14 -> clear
|
||||
(x in 4..7 && y in 9..11) || (x in 7..12 && y in 4..8) -> white
|
||||
else -> green
|
||||
}
|
||||
}
|
||||
val shade = ColorGlyphArt.coverage(pixels)
|
||||
assertEquals(255, at(shade, 9, 6))
|
||||
assertEquals(lit(0.6), at(shade, 2, 2))
|
||||
}
|
||||
|
||||
@Test fun smallHighlightLeavesTheBodyFull() {
|
||||
// ❤️: a red body with a small glint; the glint is not detail worth dimming the body for.
|
||||
val pixels = glyph { x, y ->
|
||||
when {
|
||||
!inDisc(x, y) -> clear
|
||||
x in 4..5 && y in 4..5 -> lightRed
|
||||
else -> red
|
||||
}
|
||||
}
|
||||
val shade = ColorGlyphArt.coverage(pixels)
|
||||
assertEquals(255, at(shade, 8, 8))
|
||||
assertEquals(255, at(shade, 4, 4))
|
||||
}
|
||||
|
||||
@Test fun edgeAlphaScalesTheShade() {
|
||||
val pixels = glyph { x, y -> if (x == 2) argb(128, 60, 60, 60) else if (x in 3..12 && y in 3..12) darkGray else clear }
|
||||
val shade = ColorGlyphArt.coverage(pixels)
|
||||
assertEquals(128, at(shade, 2, 8))
|
||||
assertEquals(0, at(shade, 1, 8))
|
||||
}
|
||||
|
||||
@Test fun emptyGlyphIsEmpty() {
|
||||
assertTrue(ColorGlyphArt.shade(IntArray(size * size)).all { it.toInt() == 0 })
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,41 @@ function store(settings = new Map()) {
|
||||
}
|
||||
const mail = { packageName: 'com.mail', appName: 'Mail' };
|
||||
|
||||
/** dashboard-settings.ts over the same in-memory store, with `prefs` as its notification-sources. */
|
||||
function dashboardSettings(settings, prefs) {
|
||||
return evaluate(source('app/ui/dashboard-settings.ts'), (id) => {
|
||||
if (id.includes('settings-store')) return {
|
||||
onSettingsStoreChanged() {}, getStringSetting: (key, fallback) => settings.get(key) ?? fallback,
|
||||
setStringSetting: (key, value) => settings.set(key, value),
|
||||
getBooleanSetting: (key, fallback) => settings.get(key) ?? fallback, setBooleanSetting: (key, value) => settings.set(key, value),
|
||||
};
|
||||
if (id.includes('notification-sources')) return prefs;
|
||||
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
|
||||
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
|
||||
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
|
||||
}, { global: { isIOS: false } });
|
||||
}
|
||||
|
||||
test('"Display new notifications" defaults to 15s; Off stops every popup, the filter still mutes single apps', () => {
|
||||
const settings = new Map();
|
||||
const prefs = store(settings);
|
||||
const api = dashboardSettings(settings, prefs);
|
||||
assert.equal(api.newNotificationDisplaySetting.get(), '15s');
|
||||
// Array.from: the module's arrays come from its own VM realm.
|
||||
const values = Array.from(api.newNotificationDisplaySetting.values);
|
||||
assert.deepEqual(values.map((value) => api.newNotificationDisplaySetting.displayValue(value)),
|
||||
['Off', 'Until dismissed', '5s', '15s', '1min']);
|
||||
assert.deepEqual(values.map(api.newNotificationDisplayTimeoutMs), [null, null, 5_000, 15_000, 60_000]);
|
||||
assert.equal(api.shouldPopUpNewNotification(mail.packageName), true);
|
||||
prefs.setNotificationSourceEnabled(mail, false);
|
||||
assert.equal(api.shouldPopUpNewNotification(mail.packageName), false);
|
||||
assert.equal(api.shouldPopUpNewNotification('com.other'), true);
|
||||
api.newNotificationDisplaySetting.set('off');
|
||||
assert.equal(api.shouldPopUpNewNotification('com.other'), false);
|
||||
api.newNotificationDisplaySetting.set('until-dismissed');
|
||||
assert.equal(api.shouldPopUpNewNotification('com.other'), true);
|
||||
});
|
||||
|
||||
test('sources default on and retain per-package choices and names across restart and rediscovery', () => {
|
||||
const settings = new Map();
|
||||
let prefs = store(settings);
|
||||
@@ -194,14 +229,16 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
||||
const members = ['handleAndroidNotificationPosted', 'handleAndroidNotificationRemoved', 'popUpAndroidNotification']
|
||||
.map((name) => controller.members.find((node) => node.name?.getText(file) === name).getText(file));
|
||||
const { NotificationPopupDelay, notificationPopupDelayMs } = require('../.test-build/app/ui/shell/notification-popup-delay.js');
|
||||
const prefs = store();
|
||||
const settings = new Map();
|
||||
const prefs = store(settings);
|
||||
const { newNotificationDisplaySetting, shouldPopUpNewNotification } = dashboardSettings(settings, prefs);
|
||||
let active = [{ ...mail, key: 'key' }];
|
||||
let wakes = 0, popups = 0, renders = 0;
|
||||
const removed = [];
|
||||
const { Harness } = evaluate(`export class Harness { ${members.join('\n')} }`, null, {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => active,
|
||||
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
|
||||
shouldPopUpNewNotification,
|
||||
notificationPopupDelayMs,
|
||||
shell: {
|
||||
isScreenOn: () => false,
|
||||
@@ -253,4 +290,16 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
||||
prefs.setNotificationSourceEnabled(mail, false);
|
||||
elapse();
|
||||
assert.equal(popups, 1);
|
||||
|
||||
// "Display new notifications: Off" holds back every app's popup, also once the delay is over.
|
||||
prefs.setNotificationSourceEnabled(mail, true);
|
||||
newNotificationDisplaySetting.set('off');
|
||||
instance.handleAndroidNotificationPosted('key');
|
||||
elapse();
|
||||
newNotificationDisplaySetting.set('15s');
|
||||
instance.handleAndroidNotificationPosted('key');
|
||||
newNotificationDisplaySetting.set('off');
|
||||
elapse();
|
||||
assert.equal(wakes, 1);
|
||||
assert.equal(popups, 1);
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const { NotificationPopupTimeout } = require("../.test-build/app/ui/shell/notification-popup-timeout.js");
|
||||
|
||||
/** A manual clock: schedule() queues timers that advance() fires when due. */
|
||||
function makeClock() {
|
||||
const clock = {
|
||||
nowMs: 0,
|
||||
timers: [],
|
||||
schedule(run, delayMs) {
|
||||
const timer = { dueAtMs: clock.nowMs + delayMs, run, cancelled: false };
|
||||
clock.timers.push(timer);
|
||||
return () => { timer.cancelled = true; };
|
||||
},
|
||||
advance(ms) {
|
||||
const until = clock.nowMs + ms;
|
||||
for (;;) {
|
||||
const due = clock.timers.filter((timer) => !timer.cancelled && timer.dueAtMs <= until)
|
||||
.sort((a, b) => a.dueAtMs - b.dueAtMs)[0];
|
||||
if (!due) break;
|
||||
clock.nowMs = due.dueAtMs;
|
||||
due.cancelled = true;
|
||||
due.run();
|
||||
}
|
||||
clock.nowMs = until;
|
||||
},
|
||||
};
|
||||
return clock;
|
||||
}
|
||||
|
||||
function makeTimeout(timeoutMs) {
|
||||
const clock = makeClock();
|
||||
let expiries = 0;
|
||||
const timeout = new NotificationPopupTimeout(timeoutMs, () => { expiries++; }, clock.schedule);
|
||||
return { clock, timeout, expiries: () => expiries };
|
||||
}
|
||||
|
||||
test("an untouched popup expires once its timeout passes", () => {
|
||||
const { clock, timeout, expiries } = makeTimeout(15_000);
|
||||
timeout.restart();
|
||||
clock.advance(14_999);
|
||||
assert.equal(expiries(), 0);
|
||||
clock.advance(1);
|
||||
assert.equal(expiries(), 1);
|
||||
assert.equal(timeout.isRunning(), false);
|
||||
clock.advance(60_000);
|
||||
assert.equal(expiries(), 1);
|
||||
});
|
||||
|
||||
test("each interaction starts the countdown over", () => {
|
||||
const { clock, timeout, expiries } = makeTimeout(5_000);
|
||||
timeout.restart();
|
||||
clock.advance(4_000);
|
||||
timeout.restart(); // e.g. scrolling the action menu
|
||||
clock.advance(4_000);
|
||||
assert.equal(expiries(), 0);
|
||||
clock.advance(1_000);
|
||||
assert.equal(expiries(), 1);
|
||||
});
|
||||
|
||||
test("a popup that goes away first never expires", () => {
|
||||
const { clock, timeout, expiries } = makeTimeout(5_000);
|
||||
timeout.restart();
|
||||
clock.advance(2_000);
|
||||
timeout.stop();
|
||||
clock.advance(10_000);
|
||||
assert.equal(expiries(), 0);
|
||||
});
|
||||
|
||||
test("until-dismissed (no timeout) never schedules anything", () => {
|
||||
const { clock, timeout, expiries } = makeTimeout(null);
|
||||
timeout.restart();
|
||||
assert.equal(timeout.isRunning(), false);
|
||||
assert.equal(clock.timers.length, 0);
|
||||
clock.advance(1_000_000);
|
||||
assert.equal(expiries(), 0);
|
||||
});
|
||||
|
||||
test("the expiry callback can restart the countdown (something was over the popup)", () => {
|
||||
const clock = makeClock();
|
||||
let expiries = 0;
|
||||
const timeout = new NotificationPopupTimeout(5_000, () => {
|
||||
expiries++;
|
||||
if (expiries === 1) timeout.restart();
|
||||
}, clock.schedule);
|
||||
timeout.restart();
|
||||
clock.advance(5_000);
|
||||
assert.equal(expiries, 1);
|
||||
assert.equal(timeout.isRunning(), true);
|
||||
clock.advance(5_000);
|
||||
assert.equal(expiries, 2);
|
||||
assert.equal(timeout.isRunning(), false);
|
||||
});
|
||||
@@ -39,6 +39,7 @@
|
||||
"../app/g2/glance-state.ts",
|
||||
"../app/ui/shell/notification-modal-queue.ts",
|
||||
"../app/ui/shell/notification-popup-delay.ts",
|
||||
"../app/ui/shell/notification-popup-timeout.ts",
|
||||
"../app/apps/glanceboard/layout.ts",
|
||||
"../app/apps/files/video-layout.ts",
|
||||
"../app/g2/pairing-candidates.ts",
|
||||
|
||||
Reference in new issue
Block a user