Experiment to rebuild Diffuse using web applets.
1<script>
2 import type { Actions } from "@scripts/processor/search/worker";
3 import type { Track } from "@applets/core/types";
4 import { register } from "@scripts/applet/common";
5 import { endpoint } from "@scripts/common";
6
7 ////////////////////////////////////////////
8 // SETUP
9 ////////////////////////////////////////////
10 const worker = endpoint<Actions>(
11 new SharedWorker(new URL("../../../scripts/processor/search/worker", import.meta.url), {
12 type: "module",
13 }).port,
14 );
15
16 // Register applet
17 const context = register();
18
19 ////////////////////////////////////////////
20 // ACTIONS
21 ////////////////////////////////////////////
22 context.setActionHandler("search", search);
23 context.setActionHandler("supply", supply);
24
25 async function search(term: string): Promise<Track[]> {
26 return worker.call.search(term);
27 }
28
29 async function supply(tracks: Track[]) {
30 return worker.call.supply(tracks);
31 }
32</script>