janela 0.14.1 → 0.14.2

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.
Files changed (32) hide show
  1. package/README.md +10 -2
  2. package/api/index.d.ts +11 -1
  3. package/bin/janela.mjs +18 -2
  4. package/package.json +1 -1
  5. package/templates/index.html +224 -53
  6. package/templates/janela.conf.json +2 -2
  7. package/templates/react/files/index.html +1 -0
  8. package/templates/react/files/janela.conf.json +2 -2
  9. package/templates/react/files/src/App.tsx +154 -37
  10. package/templates/react/files/src/main.tsx +1 -0
  11. package/templates/react/files/src/styles.css +137 -0
  12. package/templates/react/files/src-host/main.ts +82 -0
  13. package/templates/solid/files/index.html +1 -0
  14. package/templates/solid/files/janela.conf.json +2 -2
  15. package/templates/solid/files/src/App.tsx +145 -35
  16. package/templates/solid/files/src/main.tsx +1 -0
  17. package/templates/solid/files/src/styles.css +137 -0
  18. package/templates/solid/files/src-host/main.ts +82 -0
  19. package/templates/svelte/files/index.html +1 -0
  20. package/templates/svelte/files/janela.conf.json +2 -2
  21. package/templates/svelte/files/src/App.svelte +116 -27
  22. package/templates/svelte/files/src/main.ts +1 -0
  23. package/templates/svelte/files/src/styles.css +137 -0
  24. package/templates/svelte/files/src-host/main.ts +82 -0
  25. package/templates/vue/files/index.html +1 -0
  26. package/templates/vue/files/janela.conf.json +2 -2
  27. package/templates/vue/files/src/App.vue +99 -20
  28. package/templates/vue/files/src/main.ts +1 -0
  29. package/templates/vue/files/src/styles.css +137 -0
  30. package/templates/vue/files/src-host/main.ts +82 -0
  31. package/templates/react/files/src/App.css +0 -3
  32. package/templates/solid/files/src/App.css +0 -3
@@ -1,55 +1,172 @@
1
- import { useEffect, useState } from "react";
1
+ import { useEffect, useRef, useState } from "react";
2
2
  import { createClient } from "janela/api";
3
- // Type-only import of the host contract: erased at compile time, so no host
4
- // code is bundled into the page.
5
- import type { App as Contract } from "../src-host/main";
6
- import "./App.css";
3
+ // A type-only import of the host's contract. It is erased at compile time, so
4
+ // no host code is bundled into the page — this is purely a type edge.
5
+ import type { App as HostApp } from "../src-host/main";
7
6
 
8
- const client = createClient<Contract>();
7
+ const client = createClient<HostApp>();
9
8
 
10
9
  export default function App() {
11
- const [greeting, setGreeting] = useState("…");
10
+ const [greeting, setGreeting] = useState("booting…");
12
11
  const [a, setA] = useState(2);
13
12
  const [b, setB] = useState(40);
14
- const [sum, setSum] = useState<number | null>(null);
13
+ const [sum, setSum] = useState("—");
14
+ const [waited, setWaited] = useState("—");
15
+ const [waiting, setWaiting] = useState(false);
15
16
  const [events, setEvents] = useState<string[]>([]);
17
+ const [path, setPath] = useState("janela.conf.json");
18
+ const [title, setTitle] = useState("__NAME__ — renamed");
19
+ const [fileOut, setFileOut] = useState("—");
20
+
21
+ // StrictMode mounts effects twice in development; the guard keeps the
22
+ // greeting from being fetched (and the listener registered) twice.
23
+ const started = useRef(false);
16
24
 
17
25
  useEffect(() => {
18
- // The event name is checked against the contract, `value` is inferred,
19
- // and `on` returns a disposer.
26
+ // The event name is checked against the contract and `value` is inferred.
27
+ // `on` returns a disposer.
20
28
  const off = client.on("added", (value) =>
21
- setEvents((prev) => [`host emitted: ${value}`, ...prev]),
29
+ setEvents((prev) => [`host emitted 'added': ${value}`, ...prev]),
22
30
  );
23
- client.invoke("greet", { name: "__NAME__" }).then(setGreeting);
31
+ if (!started.current) {
32
+ started.current = true;
33
+ client.invoke("greet", { name: "__NAME__" }).then(setGreeting);
34
+ client.invoke("log", "page loaded");
35
+ }
24
36
  return off;
25
37
  }, []);
26
38
 
27
- const add = async () =>
28
- setSum(await client.invoke("add", { a, b }));
39
+ async function add() {
40
+ setSum(`add(${a}, ${b}) → ${await client.invoke("add", { a, b })}`);
41
+ }
42
+
43
+ async function wait() {
44
+ setWaiting(true);
45
+ setWaited("waiting… try add, it still answers");
46
+ setWaited(await client.invoke("wait", { ms: 2000 }));
47
+ setWaiting(false);
48
+ }
49
+
50
+ async function read() {
51
+ const r = await client.invoke("readFile", { path });
52
+ setFileOut(r.ok ? `${path} — ${r.length} chars\n\n${r.text.slice(0, 400)}` : `error: ${r.error}`);
53
+ }
54
+
55
+ // The native open dialog. The window keeps serving other commands while the
56
+ // user is deciding.
57
+ async function pick() {
58
+ const r = await client.invoke("openFile");
59
+ if (!r.ok) setFileOut(`error: ${r.error}`);
60
+ else if (r.cancelled) setFileOut("cancelled");
61
+ else setFileOut(`${r.path} — ${r.length} chars\n\n${r.text.slice(0, 400)}`);
62
+ }
29
63
 
30
64
  return (
31
- <>
32
- <h1>{greeting}</h1>
33
- <p>
34
- <input
35
- type="number"
36
- value={a}
37
- onChange={(e) => setA(Number(e.target.value))}
38
- />{" "}
39
- +
40
- <input
41
- type="number"
42
- value={b}
43
- onChange={(e) => setB(Number(e.target.value))}
44
- />
45
- <button onClick={add}>add</button>
46
- {sum !== null && <span> = {sum}</span>}
47
- </p>
48
- <ul>
49
- {events.map((e, i) => (
50
- <li key={i}>{e}</li>
51
- ))}
52
- </ul>
53
- </>
65
+ <main>
66
+ <header>
67
+ <div className="mark" aria-hidden="true">
68
+ <div className="bar">
69
+ <i />
70
+ <i />
71
+ <i />
72
+ </div>
73
+ <div className="pane" />
74
+ </div>
75
+ <h1>__NAME__</h1>
76
+ <p className="sub">TypeScript, compiled to a native binary. No Rust, no Node, no Electron.</p>
77
+ </header>
78
+
79
+ <p className="greeting">{greeting}</p>
80
+
81
+ <div className="grid">
82
+ <section className="card">
83
+ <h2>Typed commands</h2>
84
+ <p className="why">
85
+ The name, the arguments and the result are all checked at compile time — no codegen,
86
+ because both sides are TypeScript.
87
+ </p>
88
+ <div className="row">
89
+ <input
90
+ type="number"
91
+ value={a}
92
+ aria-label="first number"
93
+ onChange={(e) => setA(Number(e.target.value))}
94
+ />
95
+ <span aria-hidden="true">+</span>
96
+ <input
97
+ type="number"
98
+ value={b}
99
+ aria-label="second number"
100
+ onChange={(e) => setB(Number(e.target.value))}
101
+ />
102
+ <button className="primary" onClick={add}>
103
+ add
104
+ </button>
105
+ </div>
106
+ <p className={sum === "—" ? "result" : "result filled"}>{sum}</p>
107
+ <h3>Events from the host</h3>
108
+ <ul className="events">
109
+ {events.map((e, i) => (
110
+ <li key={i}>{e}</li>
111
+ ))}
112
+ </ul>
113
+ </section>
114
+
115
+ <section className="card">
116
+ <h2>Async without blocking</h2>
117
+ <p className="why">
118
+ The window keeps answering while this is pending: the dot keeps moving and{" "}
119
+ <strong>add</strong> still works.
120
+ </p>
121
+ <div className="row">
122
+ <button disabled={waiting} onClick={wait}>
123
+ wait 2s
124
+ </button>
125
+ {waiting && (
126
+ <span>
127
+ <span className="pulse" />
128
+ </span>
129
+ )}
130
+ </div>
131
+ <p className={waited === "—" ? "result" : "result filled"}>{waited}</p>
132
+ </section>
133
+
134
+ <section className="card wide">
135
+ <h2>Files and the window</h2>
136
+ <p className="why">
137
+ Reads run on a worker thread, so a large file never freezes the window. The dialog is
138
+ the real native one.
139
+ </p>
140
+ <div className="row">
141
+ <input
142
+ className="grow"
143
+ type="text"
144
+ value={path}
145
+ aria-label="file to read"
146
+ onChange={(e) => setPath(e.target.value)}
147
+ />
148
+ <button onClick={read}>read</button>
149
+ <button onClick={pick}>pick a file…</button>
150
+ <input
151
+ className="grow"
152
+ type="text"
153
+ value={title}
154
+ aria-label="window title"
155
+ onChange={(e) => setTitle(e.target.value)}
156
+ />
157
+ <button onClick={() => client.invoke("setTitle", { title })}>set title</button>
158
+ </div>
159
+ <pre className={fileOut === "—" ? "result" : "result filled"}>{fileOut}</pre>
160
+ </section>
161
+ </div>
162
+
163
+ <footer>
164
+ <span>
165
+ Edit <code>src/App.tsx</code> for the page and <code>src-host/main.ts</code> for the
166
+ commands.
167
+ </span>
168
+ <button onClick={() => client.invoke("quit")}>Quit</button>
169
+ </footer>
170
+ </main>
54
171
  );
55
172
  }
@@ -1,3 +1,4 @@
1
+ import "./styles.css";
1
2
  import { StrictMode } from "react";
2
3
  import { createRoot } from "react-dom/client";
3
4
  import App from "./App.tsx";
@@ -0,0 +1,137 @@
1
+ /* The janela starter's look. Shared by every template so a project scaffolded
2
+ with --template vue looks the same as one scaffolded without a framework.
3
+ All of it is yours to replace.
4
+
5
+ The window mark in App is drawn in CSS rather than shipped as an image: a
6
+ janela frontend is embedded in the binary, so every asset has to be inlined
7
+ anyway, and a window needs no artwork. */
8
+
9
+ :root {
10
+ color-scheme: light dark;
11
+ --bg: #f6f6f7;
12
+ --card: #ffffff;
13
+ --text: #18181b;
14
+ --muted: #71717a;
15
+ --line: #e4e4e7;
16
+ --accent: #2563eb;
17
+ --accent-soft: #eff4ff;
18
+ --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px -12px rgb(0 0 0 / 0.12);
19
+ }
20
+ @media (prefers-color-scheme: dark) {
21
+ :root {
22
+ --bg: #17171a;
23
+ --card: #202024;
24
+ --text: #fafafa;
25
+ --muted: #a1a1aa;
26
+ --line: #2e2e34;
27
+ --accent: #60a5fa;
28
+ --accent-soft: #1d2433;
29
+ --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -12px rgb(0 0 0 / 0.5);
30
+ }
31
+ }
32
+
33
+ * { box-sizing: border-box; }
34
+ body {
35
+ margin: 0;
36
+ min-height: 100vh;
37
+ display: flex;
38
+ justify-content: center;
39
+ background: var(--bg);
40
+ color: var(--text);
41
+ font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
42
+ -webkit-font-smoothing: antialiased;
43
+ }
44
+ main { width: 100%; max-width: 760px; padding: 26px 22px 32px; }
45
+
46
+ /* --- header ------------------------------------------------------- */
47
+ header { text-align: center; margin-bottom: 20px; }
48
+ .mark {
49
+ width: 56px; height: 44px; margin: 0 auto 14px;
50
+ border: 2px solid var(--text); border-radius: 8px;
51
+ display: flex; flex-direction: column; overflow: hidden;
52
+ }
53
+ .mark .bar {
54
+ height: 13px; flex: none;
55
+ border-bottom: 2px solid var(--text);
56
+ display: flex; align-items: center; gap: 3px; padding: 0 4px;
57
+ }
58
+ .mark .bar i { width: 3px; height: 3px; border-radius: 50%; background: var(--text); }
59
+ .mark .pane { flex: 1; background: linear-gradient(135deg, var(--accent), transparent 70%); opacity: 0.85; }
60
+ h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; font-weight: 650; }
61
+ .sub { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; }
62
+
63
+ /* The one line that proves the whole stack: this string was produced by
64
+ TypeScript compiled to machine code, and handed to the page. */
65
+ .greeting {
66
+ margin: 0 0 20px;
67
+ padding: 11px 16px;
68
+ border: 1px solid var(--line);
69
+ border-radius: 10px;
70
+ background: var(--accent-soft);
71
+ font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
72
+ text-align: center;
73
+ overflow-wrap: anywhere;
74
+ }
75
+
76
+ /* --- cards -------------------------------------------------------- */
77
+ /* auto-fit rather than a fixed column count: the same page is the iOS and
78
+ Android frontend, where it must read as a single column. */
79
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 13px; }
80
+ .card {
81
+ background: var(--card);
82
+ border: 1px solid var(--line);
83
+ border-radius: 12px;
84
+ padding: 15px 17px;
85
+ box-shadow: var(--shadow);
86
+ }
87
+ .card h2 {
88
+ margin: 0 0 2px;
89
+ font-size: 13px; font-weight: 600;
90
+ letter-spacing: 0.04em; text-transform: uppercase;
91
+ color: var(--muted);
92
+ }
93
+ .card.wide { grid-column: 1 / -1; }
94
+ .card p.why { margin: 0 0 11px; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
95
+ .card h3 {
96
+ margin: 16px 0 6px; font-size: 11px; font-weight: 600;
97
+ letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
98
+ }
99
+ .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
100
+
101
+ input, button {
102
+ font: inherit;
103
+ border-radius: 8px;
104
+ border: 1px solid var(--line);
105
+ padding: 8px 12px;
106
+ background: var(--card);
107
+ color: var(--text);
108
+ transition: border-color 0.15s, background 0.15s;
109
+ }
110
+ input { min-width: 0; }
111
+ input[type="number"] { width: 5.5em; text-align: center; }
112
+ input.grow { flex: 1 1 12em; }
113
+ input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
114
+ button { cursor: pointer; font-weight: 500; }
115
+ button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
116
+ button:disabled { opacity: 0.5; cursor: default; }
117
+ button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
118
+ button.primary:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
119
+
120
+ .result { margin: 12px 0 0; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
121
+ .result.filled { color: var(--text); }
122
+ pre.result { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 11em; overflow: auto; margin-top: 12px; }
123
+
124
+ /* A dot that keeps moving while a 2s command is pending. If it stalls,
125
+ the host has blocked the UI thread — which is the bug this proves is
126
+ absent. */
127
+ .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
128
+ @keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.15); } }
129
+ @media (prefers-reduced-motion: reduce) { .pulse { animation: none; opacity: 1; } }
130
+
131
+ ul.events { list-style: none; margin: 0; padding: 0; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
132
+ ul.events li { padding: 3px 0; border-bottom: 1px dashed var(--line); }
133
+ ul.events li:last-child { border-bottom: 0; }
134
+ ul.events:empty::after { content: "nothing yet — press add"; color: var(--muted); font-family: inherit; }
135
+
136
+ footer { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
137
+ footer code { background: var(--card); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 12px; }
@@ -17,9 +17,29 @@ export type AppCommands = {
17
17
  greet: (args: { name: string }) => string;
18
18
  log: (args: string) => void;
19
19
  wait: (args: { ms: number }) => string;
20
+ readFile: (args: { path: string }) => ReadResult;
21
+ openFile: () => PickResult;
22
+ setTitle: (args: { title: string }) => void;
20
23
  quit: () => void;
21
24
  };
22
25
 
26
+ /**
27
+ * Results are declared as TOTAL records rather than unions of shapes: every
28
+ * field is always present, and `error` is null on success. A discriminated
29
+ * union would read better in isolation, but the page would then have to narrow
30
+ * before touching `text` — and the point of this template is to show the type
31
+ * edge working, not to teach narrowing.
32
+ */
33
+ export type ReadResult = { ok: boolean; error: string | null; length: number; text: string };
34
+ export type PickResult = {
35
+ ok: boolean;
36
+ error: string | null;
37
+ cancelled: boolean;
38
+ path: string;
39
+ length: number;
40
+ text: string;
41
+ };
42
+
23
43
  /** Every event this app emits, and what each one carries. */
24
44
  export type AppEvents = {
25
45
  added: number;
@@ -54,6 +74,68 @@ export function setup(app: App): void {
54
74
  });
55
75
  });
56
76
 
77
+ // File I/O without freezing the window: the read happens on a worker thread
78
+ // in the shim. Use this instead of node:fs readFileSync, which blocks the
79
+ // host loop — and with it the whole UI — until the syscall returns.
80
+ app.commandAsync("readFile", (args, resolve) => {
81
+ app.readFileAsync(args.path, (err, text) => {
82
+ // Annotated, not inferred: a bare `null` in a returned literal infers as
83
+ // `null | undefined`, which does not lift into the declared
84
+ // `string | null` (scriptc SC2002).
85
+ const answer: ReadResult =
86
+ err !== null
87
+ ? { ok: false, error: err, length: 0, text: "" }
88
+ : { ok: true, error: null, length: text.length, text: text };
89
+ resolve(answer);
90
+ });
91
+ });
92
+
93
+ // The native "open" dialog, paired with the reader above — picking a file is
94
+ // what makes readFileAsync useful. commandAsync is the right shape here: the
95
+ // page's promise stays parked while the user takes as long as they like, and
96
+ // the window carries on serving other calls meanwhile.
97
+ app.commandAsync("openFile", (_args, resolve) => {
98
+ app.openFileDialog(
99
+ { title: "Pick a file", filters: [{ name: "Text", extensions: ["txt", "md"] }] },
100
+ (paths, err) => {
101
+ if (err !== undefined) {
102
+ const failed: PickResult = {
103
+ ok: false, error: err, cancelled: false, path: "", length: 0, text: "",
104
+ };
105
+ resolve(failed);
106
+ return;
107
+ }
108
+ if (paths === null) {
109
+ const cancelled: PickResult = {
110
+ ok: true, error: null, cancelled: true, path: "", length: 0, text: "",
111
+ };
112
+ resolve(cancelled);
113
+ return;
114
+ }
115
+ app.readFileAsync(paths[0], (rerr, text) => {
116
+ const answer: PickResult =
117
+ rerr !== null
118
+ ? { ok: false, error: rerr, cancelled: false, path: paths[0], length: 0, text: "" }
119
+ : {
120
+ ok: true,
121
+ error: null,
122
+ cancelled: false,
123
+ path: paths[0],
124
+ length: text.length,
125
+ text: text,
126
+ };
127
+ resolve(answer);
128
+ });
129
+ },
130
+ );
131
+ });
132
+
133
+ // The window is yours to change at runtime, not just at startup.
134
+ app.command("setTitle", (args) => {
135
+ app.setTitle(args.title);
136
+ return null;
137
+ });
138
+
57
139
  app.command("quit", (_args) => {
58
140
  app.quit();
59
141
  return null;
@@ -2,6 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
5
6
  <title>__NAME__</title>
6
7
  </head>
7
8
  <body>
@@ -4,8 +4,8 @@
4
4
  "version": "0.1.0",
5
5
  "window": {
6
6
  "title": "__NAME__",
7
- "width": 640,
8
- "height": 420
7
+ "width": 820,
8
+ "height": 700
9
9
  },
10
10
  "ios": {
11
11
  "identifier": "dev.janela.__NAME__",
@@ -1,55 +1,165 @@
1
- import { createSignal, onMount, For, Show } from "solid-js";
1
+ import { createSignal, onCleanup, onMount, For, Show } from "solid-js";
2
2
  import { createClient } from "janela/api";
3
3
  // Type-only import of the host contract: erased at compile time, so no host
4
4
  // code is bundled into the page.
5
5
  import type { App as Contract } from "../src-host/main";
6
- import "./App.css";
7
6
 
8
7
  const client = createClient<Contract>();
9
8
 
10
9
  export default function App() {
11
- const [greeting, setGreeting] = createSignal("…");
10
+ const [greeting, setGreeting] = createSignal("booting…");
12
11
  const [a, setA] = createSignal(2);
13
12
  const [b, setB] = createSignal(40);
14
- const [sum, setSum] = createSignal<number | null>(null);
13
+ const [sum, setSum] = createSignal("—");
14
+ const [waited, setWaited] = createSignal("—");
15
+ const [waiting, setWaiting] = createSignal(false);
15
16
  const [events, setEvents] = createSignal<string[]>([]);
17
+ const [path, setPath] = createSignal("janela.conf.json");
18
+ const [title, setTitle] = createSignal("__NAME__ — renamed");
19
+ const [fileOut, setFileOut] = createSignal("—");
16
20
 
17
21
  // Backend→frontend events. The payload arrives as a value, and the generic
18
- // says which value.
19
- client.on("added", (value) =>
20
- setEvents((prev) => [`host emitted: ${value}`, ...prev]),
22
+ // says which value. `on` returns a disposer.
23
+ onCleanup(
24
+ client.on("added", (value) => setEvents((prev) => [`host emitted 'added': ${value}`, ...prev])),
21
25
  );
22
26
 
23
- onMount(async () =>
24
- setGreeting(await client.invoke("greet", { name: "__NAME__" })),
25
- );
27
+ onMount(async () => {
28
+ setGreeting(await client.invoke("greet", { name: "__NAME__" }));
29
+ await client.invoke("log", "page loaded");
30
+ });
31
+
32
+ async function add() {
33
+ const [x, y] = [a(), b()];
34
+ setSum(`add(${x}, ${y}) → ${await client.invoke("add", { a: x, b: y })}`);
35
+ }
36
+
37
+ async function wait() {
38
+ setWaiting(true);
39
+ setWaited("waiting… try add, it still answers");
40
+ setWaited(await client.invoke("wait", { ms: 2000 }));
41
+ setWaiting(false);
42
+ }
26
43
 
27
- const add = async () =>
28
- setSum(await client.invoke("add", { a: a(), b: b() }));
44
+ async function read() {
45
+ const p = path();
46
+ const r = await client.invoke("readFile", { path: p });
47
+ setFileOut(r.ok ? `${p} — ${r.length} chars\n\n${r.text.slice(0, 400)}` : `error: ${r.error}`);
48
+ }
49
+
50
+ // The native open dialog. The window keeps serving other commands while the
51
+ // user is deciding.
52
+ async function pick() {
53
+ const r = await client.invoke("openFile");
54
+ if (!r.ok) setFileOut(`error: ${r.error}`);
55
+ else if (r.cancelled) setFileOut("cancelled");
56
+ else setFileOut(`${r.path} — ${r.length} chars\n\n${r.text.slice(0, 400)}`);
57
+ }
29
58
 
30
59
  return (
31
- <>
32
- <h1>{greeting()}</h1>
33
- <p>
34
- <input
35
- type="number"
36
- value={a()}
37
- onInput={(e) => setA(Number(e.currentTarget.value))}
38
- />{" "}
39
- +
40
- <input
41
- type="number"
42
- value={b()}
43
- onInput={(e) => setB(Number(e.currentTarget.value))}
44
- />
45
- <button onClick={add}>add</button>
46
- <Show when={sum() !== null}>
47
- <span> = {sum()}</span>
48
- </Show>
49
- </p>
50
- <ul>
51
- <For each={events()}>{(e) => <li>{e}</li>}</For>
52
- </ul>
53
- </>
60
+ <main>
61
+ <header>
62
+ <div class="mark" aria-hidden="true">
63
+ <div class="bar">
64
+ <i />
65
+ <i />
66
+ <i />
67
+ </div>
68
+ <div class="pane" />
69
+ </div>
70
+ <h1>__NAME__</h1>
71
+ <p class="sub">TypeScript, compiled to a native binary. No Rust, no Node, no Electron.</p>
72
+ </header>
73
+
74
+ <p class="greeting">{greeting()}</p>
75
+
76
+ <div class="grid">
77
+ <section class="card">
78
+ <h2>Typed commands</h2>
79
+ <p class="why">
80
+ The name, the arguments and the result are all checked at compile time — no codegen,
81
+ because both sides are TypeScript.
82
+ </p>
83
+ <div class="row">
84
+ <input
85
+ type="number"
86
+ value={a()}
87
+ aria-label="first number"
88
+ onInput={(e) => setA(Number(e.currentTarget.value))}
89
+ />
90
+ <span aria-hidden="true">+</span>
91
+ <input
92
+ type="number"
93
+ value={b()}
94
+ aria-label="second number"
95
+ onInput={(e) => setB(Number(e.currentTarget.value))}
96
+ />
97
+ <button class="primary" onClick={add}>
98
+ add
99
+ </button>
100
+ </div>
101
+ <p class={sum() === "—" ? "result" : "result filled"}>{sum()}</p>
102
+ <h3>Events from the host</h3>
103
+ <ul class="events">
104
+ <For each={events()}>{(e) => <li>{e}</li>}</For>
105
+ </ul>
106
+ </section>
107
+
108
+ <section class="card">
109
+ <h2>Async without blocking</h2>
110
+ <p class="why">
111
+ The window keeps answering while this is pending: the dot keeps moving and{" "}
112
+ <strong>add</strong> still works.
113
+ </p>
114
+ <div class="row">
115
+ <button disabled={waiting()} onClick={wait}>
116
+ wait 2s
117
+ </button>
118
+ <Show when={waiting()}>
119
+ <span>
120
+ <span class="pulse" />
121
+ </span>
122
+ </Show>
123
+ </div>
124
+ <p class={waited() === "—" ? "result" : "result filled"}>{waited()}</p>
125
+ </section>
126
+
127
+ <section class="card wide">
128
+ <h2>Files and the window</h2>
129
+ <p class="why">
130
+ Reads run on a worker thread, so a large file never freezes the window. The dialog is
131
+ the real native one.
132
+ </p>
133
+ <div class="row">
134
+ <input
135
+ class="grow"
136
+ type="text"
137
+ value={path()}
138
+ aria-label="file to read"
139
+ onInput={(e) => setPath(e.currentTarget.value)}
140
+ />
141
+ <button onClick={read}>read</button>
142
+ <button onClick={pick}>pick a file…</button>
143
+ <input
144
+ class="grow"
145
+ type="text"
146
+ value={title()}
147
+ aria-label="window title"
148
+ onInput={(e) => setTitle(e.currentTarget.value)}
149
+ />
150
+ <button onClick={() => client.invoke("setTitle", { title: title() })}>set title</button>
151
+ </div>
152
+ <pre class={fileOut() === "—" ? "result" : "result filled"}>{fileOut()}</pre>
153
+ </section>
154
+ </div>
155
+
156
+ <footer>
157
+ <span>
158
+ Edit <code>src/App.tsx</code> for the page and <code>src-host/main.ts</code> for the
159
+ commands.
160
+ </span>
161
+ <button onClick={() => client.invoke("quit")}>Quit</button>
162
+ </footer>
163
+ </main>
54
164
  );
55
165
  }
@@ -1,3 +1,4 @@
1
+ import "./styles.css";
1
2
  import { render } from "solid-js/web";
2
3
  import App from "./App.tsx";
3
4