Clean up unused code

Mostly remnants of iOS porting, where some things were temporarily in
typescript but became shared kotlin
This commit is contained in:
James Babcock committed 2026-09-30 13:54:50 -07:00
1 parent 2c088378bd
commit 7d8f03ffe5
18 files changed
+66 -644

No files matched your search

-23
View File
@@ -1,10 +1,8 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs'), vm = require('node:vm');
const { createHash } = require('node:crypto');
const { zstdCompressSync } = require('node:zlib');
const { loader } = require('./helpers/load-typescript.cjs');
const { LvglFont } = require('../.test-build/app/graphics/lvgl-font.js');
function pack(files) {
const key = Buffer.from('EVEN REALITIES');
@@ -17,27 +15,6 @@ function pack(files) {
})]);
}
test('iOS LVGL reader loads the bundled font including CJK and game symbols', () => {
const bytes = new Uint8Array(fs.readFileSync('app/fonts/source-han-sans/SourceHanSansSC-Light-20.lvgl.bin'));
const font = new LvglFont(bytes);
// Metrics and full glyph SHA-256 vectors from production Java LvglFontFile.
assert.deepEqual([...font.metrics], [25, 19]);
const vectors = [
[0x25a6, 'b08ecb603fd059b0a00ba3088f18b79185c421e73049797cd3cb0828e1e5cd04'],
[0x25c6, 'c176d5dcdb5f7e3a7220455528efde3760672c40cee39b422fc3f5ad20df66dd'],
[0x4e2d, '9bde2c8f1ffcf7afc598f4d0350c9ff262484816aa0c9b46d31f0c3c09613003'],
[0xff21, '0074f96299a75b86912282416e47e0823790e091352aec852eff49b89b2e719d'],
];
for (const [cp, hash] of vectors) {
const glyph = font.glyph(cp);
const w = glyph[0] | glyph[1] << 8, h = glyph[2] | glyph[3] << 8;
assert.ok(w > 0 && h > 0); assert.equal(glyph.length, 8 + (Math.floor(w / 2) + 1) * h);
assert.equal(createHash('sha256').update(glyph).digest('hex'), hash);
}
assert.equal(font.glyph(0x10ffff).length, 0);
assert.throws(() => new LvglFont(bytes.subarray(0, 80)), /bounds|Truncated/);
});
test('EHPK entrypoints and extraction paths cannot escape their package directory', () => {
const load = loader({}, { fzstd: require('fzstd') });
const api = load('app/apps/evenhub/ehpk.ts');
+43 -21
View File
@@ -5,7 +5,6 @@ const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const images = require('../.test-build/app/graphics/image.js');
const { SurfaceCompositor } = require('../.test-build/app/graphics/surface-compositor.js');
const events = require('../.test-build/app/g2/events.js');
function load(file, modules, globals = {}) {
@@ -20,6 +19,7 @@ function load(file, modules, globals = {}) {
}
const planes = load('app/graphics/plane.ts', { './image': images });
const timings = load('app/native/frame-timings.ts', {});
const LAUNCHER_GRAY = 75;
function fixture() {
const observers = new Map(), phoneState = { protectedDataAvailable: true };
@@ -38,7 +38,7 @@ function fixture() {
'../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false },
'./glance-state': require('../.test-build/app/g2/glance-state.js'),
}, clock);
const launcherPixels = new Uint8Array(640 * 480).fill(75), fullRect = { x: 0, y: 0, width: 640, height: 480 };
const launcherPixels = new Uint8Array(640 * 480).fill(LAUNCHER_GRAY), fullRect = { x: 0, y: 0, width: 640, height: 480 };
const window = { windowId: 'launcher', surfaceId: 'launcher', appId: 'launcher', title: 'Apps',
// The launcher repaints into whichever display target the controller has after a switch.
requestRender() { void controller?.displayReady.then(() => controller.display?.submitSurfaceFrame('launcher', launcherPixels, fullRect, 'launcher')); }, setScreenOn() {} };
@@ -55,21 +55,43 @@ function fixture() {
if (input.type === 'display-wake' || !screenOn && input.type === 'double-click') shell.wake();
},
};
// Both display targets compose with the real (TypeScript reference) compositor so
// the pixel assertions below exercise real layering, blanking and lock surfaces.
// Both display targets share a minimal compositor (z-ordered opaque and
// color-keyed surfaces, visibility, blanking) so the pixel assertions below
// exercise layering, blanking and lock surfaces.
class Display {
compositor = new SurfaceCompositor(640, 480);
surfaces = new Map(); blanked = false; depths = [];
async configureCompositorScreen() {}
async configureSurface(id, options) { this.compositor.configureSurface(id, options); }
async removeSurface(id) { this.compositor.removeSurface(id); this.changed(); }
async setSurfaceVisible(id, visible) { this.compositor.setSurfaceVisible(id, visible); this.changed(); }
depths = [];
async setSurfaceDepth(id, depth) { this.depths.push([id, depth]); this.compositor.setSurfaceDepth(id, depth); }
async setUnderlayDim(below, factor) { this.compositor.setUnderlayDim(below, factor); this.changed(); }
async setScreenBlanked(blanked) { this.compositor.setScreenBlanked(blanked); this.changed(); }
async submitSurfaceFrame(id, pixels, rect, _fingerprint, _paintMs, _frameId, draws = null) { this.compositor.submitSurfaceFrame(id, pixels, rect, draws); this.changed(); }
async submitShellScene(bytes) { this.compositor.setShellScene(bytes); this.changed(); }
getCompositePreview() { return this.compositor.composite(); }
async configureSurface(id, options) {
const previous = this.surfaces.get(id);
const pixels = previous?.width === options.width && previous.height === options.height
? previous.pixels : new Uint8Array(options.width * options.height);
this.surfaces.set(id, { ...options, pixels, visible: previous?.visible ?? true });
}
async removeSurface(id) { this.surfaces.delete(id); this.changed(); }
async setSurfaceVisible(id, visible) { const surface = this.surfaces.get(id); if (surface) surface.visible = visible; this.changed(); }
async setSurfaceDepth(id, depth) { this.depths.push([id, depth]); }
async setUnderlayDim() { this.changed(); }
async setScreenBlanked(blanked) { this.blanked = blanked; this.changed(); }
async submitSurfaceFrame(id, pixels, rect) {
const surface = this.surfaces.get(id);
if (!surface) throw new Error(`Unknown surface: ${id}`);
for (let y = 0; y < rect.height; y++) {
surface.pixels.set(pixels.subarray(y * rect.width, (y + 1) * rect.width), (rect.y + y) * surface.width + rect.x);
}
this.changed();
}
async submitShellScene() { this.changed(); }
getCompositePreview() {
const output = new Uint8Array(640 * 480);
if (this.blanked) return output;
for (const s of [...this.surfaces.values()].filter(s => s.visible).sort((a, b) => a.zOrder - b.zOrder)) {
for (let y = 0; y < s.height; y++) for (let x = 0; x < s.width; x++) {
const value = s.pixels[y * s.width + x];
if (s.transparency !== 'color-key' || value) output[(s.y + y) * 640 + s.x + x] = value;
}
}
return output;
}
changed() {}
}
class PreviewDisplayTarget extends Display {
@@ -93,7 +115,7 @@ function fixture() {
async start() { this.emitState('connected', 'Connected.'); }
async disconnect() { this.emitState('disconnected', 'Disconnected.'); }
waitForFrameFinished() { return Promise.resolve('sent'); }
changed() { if (this.phase === 'connected') sent.push(this.compositor.composite()); }
changed() { if (this.phase === 'connected') sent.push(this.getCompositePreview()); }
}
const provider = {
isEnabled: () => settings.enabled, showOnTap: () => settings.tap,
@@ -221,17 +243,17 @@ test('double-tap and other shell wakes replace Glanceboard without waking it aga
const f = fixture(); await f.connect(); f.shell.sleep();
await f.hardware(9); await f.hardware(3);
assert.equal(f.shell.isScreenOn(), true); assert.equal(f.controller.glance.isVisible(), false);
assert.equal(f.sent.at(-1)[0], 80); assert.equal(f.boardStats.stops, 1);
assert.equal(f.sent.at(-1)[0], LAUNCHER_GRAY); assert.equal(f.boardStats.stops, 1);
f.shell.sleep(); await f.hardware(0); f.shell.wake(); await f.render();
assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], 80);
await f.advance(5000); await f.render(); assert.equal(f.sent.at(-1)[0], 80);
assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], LAUNCHER_GRAY);
await f.advance(5000); await f.render(); assert.equal(f.sent.at(-1)[0], LAUNCHER_GRAY);
});
test('head tilt uses Glanceboard when enabled and otherwise wakes the regular UI', async () => {
const f = fixture(); await f.connect(); f.shell.sleep();
await f.hardware(12, 1); assertBoard(f.sent.at(-1)); assert.equal(f.shell.isScreenOn(), false);
await f.hardware(3); f.shell.sleep(); f.settings.tilt = false;
await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], 80);
await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], LAUNCHER_GRAY);
});
test('disabled triggers and scrolls do not show the board; awake taps still reach the shell', async () => {
@@ -276,7 +298,7 @@ test('iOS lock hides apps and Glanceboard, blocks input, and stays locked when p
await f.hardware(12, 1); assert.ok(f.sent.at(-1).every(p => p === 123));
f.observers.get('unlock')(); await f.render();
assert.equal(f.controller.glassesLocked, false);
assert.equal(f.sent.at(-1)[0], 80);
assert.equal(f.sent.at(-1)[0], LAUNCHER_GRAY);
await f.hardware(0); assert.equal(f.received.length, 1);
});
+8 -30
View File
@@ -7,7 +7,6 @@ const graphics=require('../.test-build/app/graphics/image.js');
const planes=require('../.test-build/app/graphics/plane.js');
const wire=require('../.test-build/app/graphics/presentation-wire.js');
const {encodeShellScene}=require('../.test-build/app/graphics/shell-scene.js');
const {SurfaceCompositor}=require('../.test-build/app/graphics/surface-compositor.js');
function load(file,modules) {
const context={exports:{},require:name=>{assert.ok(name in modules, name);return modules[name];}};
vm.runInNewContext(ts.transpileModule(fs.readFileSync(file,'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2020}}).outputText,context);
@@ -37,27 +36,17 @@ test('menu retains the selected text and rounded highlight on the menu plane',as
assert.ok(row.source.pixels.some(v=>v===255));assert.ok(!image.withDrawsBaked(false).pixels.some(v=>v===255));
const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0}]);
const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.equal(records.length,1);
const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'});
c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws));
const screen=flat.image.pixels.slice(),preview=c.composite();
assert.ok(preview.some(v=>v===240));assert.deepEqual(flat.image.pixels,screen);
await m.layer.handleInput({type:'scroll-down'},m.context);
const next=m.paint().draws.find(d=>d.presentation);assert.ok(next.y>row.y);assert.equal(next.presentation.depth,0);
});
test('shell menu selection survives serialization and is not baked into its surface',()=>{
test('shell menu selection survives serialization',()=>{
const image=menu().paint(),bytes=encodeShellScene([{image,x:0,y:0,shellKey:7}]);
assert.equal(new DataView(bytes.buffer).getUint16(14,true),1);
const c=new SurfaceCompositor(80,80);c.setShellScene(bytes);assert.ok(c.composite().some(v=>v===240));
});
test('later opaque planes occlude a replayed selection without erasing its visible part',()=>{
test('later opaque planes add an occlusion to a replayed selection',()=>{
const image=menu().paint(),row=image.draws.find(d=>d.presentation),cover=new graphics.GrayImage(10,8,1);
const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0},{image:cover,x:row.x+10,y:row.y+2}]);
const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].displayList.calls.some(c => c.op === 2 && c.resource === 65535));
const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'});
c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws));
const preview=c.composite();
for(let y=row.y+2;y<row.y+10;y++) for(let x=row.x+10;x<row.x+20;x++) assert.equal(preview[y*80+x],0);
assert.ok(preview.some(v=>v===240));
});
const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{
@@ -71,24 +60,15 @@ test('context menu surface and selected row both use +4 without changing the app
assert.deepEqual(frame.image.pixels,base.pixels);
const records=wire.presentationRecords(prepareFrameDraws(frame.draws));
assert.deepEqual(records.map(r=>r.depth),[4,4]);assert.equal(records[0].mode,'masked-image');
const c=new SurfaceCompositor(100,90);c.configureSurface('app',{x:0,y:0,width:100,height:90,zOrder:0,transparency:'opaque'});
c.submitSurfaceFrame('app',frame.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(frame.draws));
const preview=c.composite();
assert.equal(preview[45*100+10],96); // old left edge has no baked menu
assert.equal(preview[45*100+13],0); // shifted opaque black interior
assert.equal(preview[8*100+12],96); // transparent rounded corner
assert.ok(preview.some(v=>v===240));
stack.pop();const closed=planes.flattenPlanesWithDraws(stack.paint());
c.submitSurfaceFrame('app',closed.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(closed.draws));
assert.deepEqual(c.composite(),base.pixels);
assert.deepEqual(closed.image.pixels,base.pixels);
assert.deepEqual(wire.presentationRecords(prepareFrameDraws(closed.draws)),[]);
});
test('system menu bridge shifts its surface and selected row together by +4',()=>{
const image=menu().paint(),bytes=encodeShellScene([{image,x:8,y:0,shellKey:7,depth:4}]);
const view=new DataView(bytes.buffer),w=view.getUint16(8,true),h=view.getUint16(10,true);
assert.equal(view.getInt16(16,true),4);
assert.equal(wire.readPresentation(bytes,18+w*h).selection.depth,4);
const c=new SurfaceCompositor(100,80);c.setShellScene(bytes);const preview=c.composite();
assert.equal(preview[40*100+8],0);assert.equal(preview[40*100+10],80);
});
test('unselected sidebar icons retain -2 depth through shell cropping, including attention badges',()=>{
const shellScene=require('../.test-build/app/graphics/shell-scene.js');
@@ -106,10 +86,10 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
chrome.drawSidebar(image,state);
assert.deepEqual(Array.from(image.draws.filter(d=>d.presentation),d=>d.presentation.depth),[-2,-2]);
const crop=shellScene.shellCrop(image,0,0,64,280,1),bytes=encodeShellScene([crop]);
const c=new SurfaceCompositor(640,480);c.setShellScene(bytes);const preview=c.composite();
assert.equal(preview[34*640+30],240); // selected icon stays at its original x
assert.equal(preview[74*640+29],240); // unselected icon moves left by one
assert.equal(preview[74*640+33],0); // no baked copy at the original right edge
const view=new DataView(bytes.buffer),w=view.getUint16(8,true),h=view.getUint16(10,true);
assert.equal(view.getUint16(14,true),2);
const first=wire.readPresentation(bytes,18+w*h),second=wire.readPresentation(bytes,first.end);
assert.deepEqual([first.selection.depth,second.selection.depth],[-2,-2]);
state.selectedIndex=1;const next=new graphics.GrayImage(640,480);chrome.drawSidebar(next,state);
assert.equal(next.draws.filter(d=>d.presentation).length,2);
});
@@ -128,6 +108,4 @@ test('shell modal carries its inner menu highlight animation instead of baking i
const image=paint(),row=image.draws.find(d=>d.presentation);
assert.ok(row.y>before.y);assert.ok(row.presentation.displayList.timeline,'the slide stays a timed display list');
assert.ok(!image.withDrawsBaked(false).pixels.some(v=>v===255),'selected text is not baked into the modal surface');
const c=new SurfaceCompositor(200,200);c.setShellScene(encodeShellScene([{image,x:0,y:0,shellKey:9}]));
assert.ok(c.composite().some(v=>v===240));
});
-49
View File
@@ -1,49 +0,0 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { SurfaceCompositor } = require('../.test-build/app/graphics/surface-compositor.js');
const rect = (x, y, width, height) => ({ x, y, width, height });
function surface(c, id, box, values, zOrder = 0, transparency = 'opaque') {
c.configureSurface(id, { ...box, zOrder, transparency });
c.submitSurfaceFrame(id, Uint8Array.from(values), rect(0, 0, box.width, box.height));
}
test('shell color key preserves underlying text while opaque black covers it', () => {
const c = new SurfaceCompositor(3, 2);
surface(c, 'app', rect(0, 0, 3, 2), [200, 200, 200, 200, 200, 200]);
surface(c, 'shell', rect(0, 0, 3, 2), [0, 1, 255, 0, 0, 0], 1, 'color-key');
c.setUnderlayDim(1, 0.5);
assert.deepEqual([...c.composite()], [100, 1, 255, 100, 100, 100]);
c.setSurfaceVisible('shell', false);
assert.deepEqual([...c.composite()], [100, 100, 100, 100, 100, 100]);
surface(c, 'opaque', rect(1, 0, 1, 2), [0, 0], 2);
assert.deepEqual([...c.composite()], [100, 0, 100, 100, 0, 100]);
});
test('partial frames clip in surface coordinates, then surfaces clip to the screen', () => {
const c = new SurfaceCompositor(3, 2);
surface(c, 'app', rect(-1, 0, 3, 2), [1, 2, 3, 4, 5, 6]);
const source = Uint8Array.from([99, 10, 20, 99, 30, 40, 99]);
c.submitSurfaceFrame('app', source.subarray(1, 5), rect(1, 1, 2, 2));
source.fill(0);
assert.deepEqual([...c.composite()], [2, 3, 0, 10, 20, 0]);
c.submitSurfaceFrame('app', Uint8Array.from([50, 60, 70, 80]), rect(-1, -1, 2, 2));
// The clipped update changed the offscreen column, leaving visible pixels intact.
assert.deepEqual([...c.composite()], [2, 3, 0, 10, 20, 0]);
});
test('moving a surface retains its frame; resizing clears it; blanking is reversible', () => {
const c = new SurfaceCompositor(3, 1);
surface(c, 'app', rect(0, 0, 2, 1), [7, 9]);
c.configureSurface('app', { ...rect(1, 0, 2, 1), zOrder: 0, transparency: 'opaque' });
assert.deepEqual([...c.composite()], [0, 7, 9]);
c.setScreenBlanked(true); assert.deepEqual([...c.composite()], [0, 0, 0]);
c.setScreenBlanked(false); assert.deepEqual([...c.composite()], [0, 7, 9]);
c.configureSurface('app', { ...rect(0, 0, 3, 1), zOrder: 0, transparency: 'opaque' });
assert.deepEqual([...c.composite()], [0, 0, 0]);
});
test('layer order is independent of creation order; removal reveals lower surfaces', () => {
const c = new SurfaceCompositor(1, 1);
surface(c, 'top', rect(0, 0, 1, 1), [20], 10);
surface(c, 'bottom', rect(0, 0, 1, 1), [80], -1);
assert.equal(c.composite()[0], 20);
c.removeSurface('top'); assert.equal(c.composite()[0], 80);
assert.throws(() => c.submitSurfaceFrame('missing', new Uint8Array(1), rect(0, 0, 1, 1)));
assert.throws(() => c.submitSurfaceFrame('bottom', new Uint8Array(2), rect(0, 0, 1, 1)));
});
-2
View File
@@ -16,11 +16,9 @@
"../app/remote/protocol.ts",
"../app/remote/listeners.ts",
"../app/g2/ancs-client.ts",
"../app/graphics/lvgl-font.ts",
"../app/phone-ui/ble-bandwidth-meter.ts",
"../app/apps/terminal/hub-header.ts",
"../app/g2/ios-peripheral-identity.ts",
"../app/graphics/surface-compositor.ts",
"../app/graphics/image.ts",
"../app/graphics/plane.ts",
"../app/graphics/shell-scene.ts",