M0: WIT package, MoonBit components, JS host, docs, CI (#1)
CI / test (push) Successful in 19s

This commit was merged in pull request #1.
This commit is contained in:
nandi committed 2026-11-24 23:51:26 +00:00
1 parent e5548fc067
commit 880ecd4102
141 files changed
+9681 -1

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
// Host-side implementations of the capability interfaces components may import.
// This is where a native host would talk to the OS; here it is in-memory so the
// desktop is deterministic and testable.
/** @param {{now?: () => Date, apps: any[], tokens: any}} opts */
export function createPlatform({ now = () => new Date(), apps, tokens }) {
const p = {
tokens,
apps,
launches: [],
now,
launchable: new Set(apps.map((a) => a.id)),
};
/** Capability name -> WIT interface implementation (jco import shape). */
p.interfaces = {
theme: () => ({ getTokens: () => p.tokens }),
clock: () => ({
now() {
const d = p.now();
return {
year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate(),
hour: d.getHours(), minute: d.getMinutes(), second: d.getSeconds(), weekday: d.getDay(),
};
},
}),
'app-catalog': () => ({ listApps: () => p.apps }),
'app-launch': () => ({
launch(id) {
if (!p.launchable.has(id)) return { tag: 'err', val: `unknown application: ${id}` };
p.launches.push(id);
console.log(`[host] launch ${id}`);
return { tag: 'ok', val: undefined };
},
}),
};
return p;
}
export const CAPABILITIES = ['theme', 'clock', 'app-catalog', 'app-launch'];