Files
VandClaude Opus 5.5 af774d76fe
CI / test (push) Failing after 16s
Rename the project to Chandra
moon-plasma / moonplasma / MoonPlasma / Moon Plasma become chandra / Chandra
everywhere: the WIT package (chandra:desktop, chandra:host, chandra:wm), the
MoonBit module (chandra/desktop) and generated bindings, the Rust host,
identifiers (ChandraCompositor), the session script (chandra-session) and
desktop entry (chandra.desktop), config and data paths
($XDG_CONFIG_HOME/chandra, share/chandra/modules), env vars (CHANDRA_*),
UI strings, docs and tests. The test fixture components are rebuilt against
the renamed WIT.

Saved panel.edn and state.edn are still read from the old
$XDG_CONFIG_HOME/moon-plasma until the first save writes the new copy.

The remote repository keeps its experiments/moon-plasma name for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hi3L9oVBoRd373Qr4n
2026-11-25 17:12:57 +00:00

88 lines
3.3 KiB
JavaScript

import { Desktop } from '../src/desktop.mjs';
import { createPlatform } from '../src/platform.mjs';
import { tokensFromJson } from '../src/theme.mjs';
import { webLoader } from '../src/loader-web.mjs';
import { WasiGfxSurface, WasiGfxFrameBufferContext } from '../src/wasi-gfx.mjs';
import { paint } from './canvas.mjs';
const base = new URL('../../', import.meta.url).href.replace(/\/$/, '');
const q = new URLSearchParams(location.search);
const getJson = async (p) => {
const r = await fetch(`${base}/${p}`);
if (!r.ok) throw new Error(`GET ${p}: HTTP ${r.status}`);
return r.json();
};
async function drainStream(stream, handler) {
const reader = stream.getReader();
while (true) {
const { value, done } = await reader.read();
if (done) break;
handler(value);
}
}
const status = document.getElementById('status');
try {
const config = await getJson(`config/${q.get('config') ?? 'desktop.json'}`);
const apps = await getJson('config/apps.json');
const tokens = tokensFromJson(await getJson(`config/themes/${q.get('theme') ?? config.theme}.json`));
const fixed = q.get('time') ? new Date(q.get('time')) : null;
const platform = createPlatform({ apps, tokens, now: fixed ? () => fixed : undefined });
const desktop = await new Desktop({ config, loader: webLoader(base), platform }).start();
// Present the desktop GUI through a wasi-gfx Surface + FrameBuffer Context.
const canvas = document.getElementById('screen');
const gfxSurface = new WasiGfxSurface(
{ width: desktop.screen.w, height: desktop.screen.h },
{ canvas },
);
const gfxContext = new WasiGfxFrameBufferContext(gfxSurface);
const offscreen = document.createElement('canvas');
offscreen.width = desktop.screen.w;
offscreen.height = desktop.screen.h;
const offCtx = offscreen.getContext('2d');
const redraw = () => {
paint(offCtx, desktop.frame().ops, desktop.screen);
const img = offCtx.getImageData(0, 0, desktop.screen.w, desktop.screen.h);
const buf = gfxContext.getCurrentBuffer();
buf.setWithCopy(new Uint8Array(img.data.buffer, img.data.byteOffset, img.data.byteLength));
gfxContext.present();
};
// Route input events from wasi-gfx Surface streams into Desktop.
drainStream(gfxSurface.onPointerMove(), (e) => {
if (desktop.pointer('move', Math.round(e.x), Math.round(e.y))) redraw();
});
drainStream(gfxSurface.onPointerDown(), (e) => {
if (desktop.pointer('down', Math.round(e.x), Math.round(e.y))) redraw();
});
drainStream(gfxSurface.onPointerUp(), (e) => {
if (desktop.pointer('up', Math.round(e.x), Math.round(e.y))) redraw();
});
drainStream(gfxSurface.onKeyDown(), (e) => {
const k = e.text && (e.text.length === 1 || ['Backspace', 'Enter', 'Escape'].includes(e.text)) ? e.text : null;
if (k && desktop.key(k)) redraw();
});
redraw();
if (!fixed) setInterval(redraw, 1000);
status.textContent = `${desktop.widgets.map((w) => `${w.id}=${w.componentName}`).join(' ')} | theme: ${platform.tokens.name} | wasi-gfx`;
// Handle for automation / the browser console.
window.chandra = {
desktop,
platform,
gfxSurface,
gfxContext,
redraw,
swap: async (id, c) => { await desktop.swap(id, c); redraw(); },
ready: true,
};
} catch (e) {
status.textContent = `ERROR: ${e.message}`;
status.style.color = '#f66';
window.chandraError = String(e.stack ?? e);
throw e;
}