~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
63 lines · 3.1 KB Raw History
// The landing's picture (crates/hud-server/hero/), made again: the `hero`
// state (states.mjs: chadtmiller.com's own canvas, nothing of anyone
// else's) drawn by look.mjs on a desktop in each of HUD's themes (themes/),
// light and dark first; then workspace-light.webp and workspace-dark.webp,
// the two still ones, and workspace-themes.webp, every theme in turn, an
// animated WebP that loops. Needs cwebp, img2webp and sips (macOS), and
// target/debug/hud built with the web as it is (`just hero` does both).
//
//   node harness/look/hero.mjs    `just hero`

import { execFileSync, spawnSync } from 'node:child_process';
import { mkdirSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { states } from './states.mjs';

const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
const look = join(root, 'target/look');
const frames = join(root, 'target/hero');
const hero = join(root, 'crates/hud-server/hero');
/** How long each theme shows, in milliseconds. */
const HOLD = 2500;
/** The still pictures' width, crisp at twice the landing's width; the animated one's, lighter. */
const STILL = 2048;
const MOVING = 1600;

const themes = readdirSync(join(root, 'themes'))
	.filter((f) => f.endsWith('.json'))
	.map((f) => ({ file: join(root, 'themes', f), ...JSON.parse(readFileSync(join(root, 'themes', f), 'utf8')) }))
	.sort((a, b) => order(a) - order(b) || a.key.localeCompare(b.key));
/** Light, then dark, then the palettes. */
function order(theme) {
	return theme.key === 'light' ? 0 : theme.key === 'dark' ? 1 : 2;
}

const run = (tool, args) => execFileSync(tool, args, { cwd: root, stdio: ['ignore', 'ignore', 'inherit'] });
mkdirSync(frames, { recursive: true });

const drawn = [];
for (const theme of themes) {
	const name = `hero-${theme.key}`;
	const args = [...states.hero.filter((a) => a !== '--light' && a !== '--dark'), `--${theme.colorScheme}`, '--set', `getWorkspace.theme=@${theme.file}`];
	const made = spawnSync('node', [join(root, 'harness/look.mjs'), name, ...args], { cwd: root, encoding: 'utf8' });
	if (made.status !== 0) {
		console.error(`==> ${theme.key}: look failed\n${made.stderr.trim()}`);
		process.exit(1);
	}
	const png = join(look, `${name}-desktop-${theme.colorScheme}.png`);
	const frame = join(frames, `${theme.key}.png`);
	run('sips', ['--resampleWidth', String(MOVING), png, '--out', frame]);
	drawn.push({ theme, png, frame });
	console.log(`==> ${theme.key}`);
}

for (const scheme of ['light', 'dark']) {
	const { png } = drawn.find((d) => d.theme.key === scheme);
	run('cwebp', ['-quiet', '-q', '80', '-m', '6', '-resize', String(STILL), '0', png, '-o', join(hero, `workspace-${scheme}.webp`)]);
}
run('img2webp', ['-loop', '0', '-lossy', '-q', '72', '-m', '6', '-d', String(HOLD), ...drawn.map((d) => d.frame), '-o', join(hero, 'workspace-themes.webp')]);

for (const file of ['workspace-light.webp', 'workspace-dark.webp', 'workspace-themes.webp']) {
	console.log(`==> ${file}: ${Math.round(statSync(join(hero, file)).size / 1024)} KB`);
}