janela 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -26
- package/bin/janela.mjs +382 -46
- package/package.json +3 -3
- package/runtime/janela.ts +289 -122
- package/shim/wvshim.cc +726 -67
- package/templates/index.html +31 -0
- package/templates/main.ts +62 -19
- package/templates/react/deps.json +4 -0
- package/templates/react/files/index.html +11 -0
- package/templates/react/files/janela.conf.json +10 -0
- package/templates/react/files/src/App.css +3 -0
- package/templates/react/files/src/App.jsx +38 -0
- package/templates/react/files/src/main.jsx +9 -0
- package/templates/react/files/src-host/main.ts +42 -0
- package/templates/react/files/vite.config.js +6 -0
- package/templates/solid/deps.json +4 -0
- package/templates/solid/files/index.html +11 -0
- package/templates/solid/files/janela.conf.json +10 -0
- package/templates/solid/files/src/App.css +3 -0
- package/templates/solid/files/src/App.jsx +35 -0
- package/templates/solid/files/src/main.jsx +4 -0
- package/templates/solid/files/src-host/main.ts +42 -0
- package/templates/solid/files/vite.config.js +6 -0
- package/templates/svelte/deps.json +7 -0
- package/templates/svelte/files/index.html +11 -0
- package/templates/svelte/files/janela.conf.json +10 -0
- package/templates/svelte/files/src/App.svelte +33 -0
- package/templates/svelte/files/src/main.js +4 -0
- package/templates/svelte/files/src-host/main.ts +42 -0
- package/templates/svelte/files/svelte.config.js +3 -0
- package/templates/svelte/files/vite.config.js +6 -0
- package/templates/vue/deps.json +4 -0
- package/templates/vue/files/index.html +11 -0
- package/templates/vue/files/janela.conf.json +10 -0
- package/templates/vue/files/src/App.vue +39 -0
- package/templates/vue/files/src/main.js +4 -0
- package/templates/vue/files/src-host/main.ts +42 -0
- package/templates/vue/files/vite.config.js +6 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src-host/main.ts — your app's backend, compiled to native code by scriptc.
|
|
2
|
+
//
|
|
3
|
+
// Register commands here; the page calls them with `await janela.invoke(name, args)`.
|
|
4
|
+
// Handlers take the arguments as a value and return a value — the runtime owns
|
|
5
|
+
// JSON at the boundary, so there is no parsing or stringifying to do here.
|
|
6
|
+
//
|
|
7
|
+
// Gotcha inherited from scriptc: never use a bare FFI-backed call as a
|
|
8
|
+
// complete variable initializer — wrap it in any expression (`+ 0`). Plain
|
|
9
|
+
// TypeScript like everything in this file is unaffected.
|
|
10
|
+
|
|
11
|
+
import type { JanelaApp } from "./janela";
|
|
12
|
+
|
|
13
|
+
export function setup(app: JanelaApp): void {
|
|
14
|
+
app.command("add", (args) => {
|
|
15
|
+
const a = args as { a: number; b: number };
|
|
16
|
+
const sum = a.a + a.b;
|
|
17
|
+
// Backend→frontend event: the page listens with janela.listen("added", …).
|
|
18
|
+
app.emit("added", sum);
|
|
19
|
+
return sum;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app.command("greet", (args) => {
|
|
23
|
+
const a = args as { name: string };
|
|
24
|
+
return "Hello, " + a.name + " — from the native TS binary";
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.command("log", (args) => {
|
|
28
|
+
console.log("[host] page says:", args as string);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// An async command: answers later, without freezing the window.
|
|
32
|
+
app.commandAsync("wait", (args, resolve) => {
|
|
33
|
+
const a = args as { ms: number };
|
|
34
|
+
app.sleep(a.ms, () => {
|
|
35
|
+
resolve("waited " + a.ms + "ms without blocking the UI");
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
app.command("quit", () => {
|
|
40
|
+
app.quit();
|
|
41
|
+
});
|
|
42
|
+
}
|