@decaf-ts/for-os 0.0.0-stage → 0.2.7

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 (77) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +380 -2
  3. package/lib/cjs/errors.cjs +73 -0
  4. package/lib/cjs/errors.cjs.map +1 -0
  5. package/lib/cjs/index.cjs +46 -0
  6. package/lib/cjs/index.cjs.map +1 -0
  7. package/lib/cjs/native/icons.cjs +123 -0
  8. package/lib/cjs/native/icons.cjs.map +1 -0
  9. package/lib/cjs/native/loader.cjs +123 -0
  10. package/lib/cjs/native/loader.cjs.map +1 -0
  11. package/lib/cjs/native/types.cjs +4 -0
  12. package/lib/cjs/native/types.cjs.map +1 -0
  13. package/lib/cjs/notifications/NotificationCenter.cjs +328 -0
  14. package/lib/cjs/notifications/NotificationCenter.cjs.map +1 -0
  15. package/lib/cjs/tray/TrayIcon.cjs +367 -0
  16. package/lib/cjs/tray/TrayIcon.cjs.map +1 -0
  17. package/lib/cjs/tray/assets.cjs +31 -0
  18. package/lib/cjs/tray/assets.cjs.map +1 -0
  19. package/lib/esm/errors.js +65 -0
  20. package/lib/esm/errors.js.map +1 -0
  21. package/lib/esm/index.js +28 -0
  22. package/lib/esm/index.js.map +1 -0
  23. package/lib/esm/native/icons.js +117 -0
  24. package/lib/esm/native/icons.js.map +1 -0
  25. package/lib/esm/native/loader.js +116 -0
  26. package/lib/esm/native/loader.js.map +1 -0
  27. package/lib/esm/native/types.js +8 -0
  28. package/lib/esm/native/types.js.map +1 -0
  29. package/lib/esm/notifications/NotificationCenter.js +322 -0
  30. package/lib/esm/notifications/NotificationCenter.js.map +1 -0
  31. package/lib/esm/tray/TrayIcon.js +362 -0
  32. package/lib/esm/tray/TrayIcon.js.map +1 -0
  33. package/lib/esm/tray/assets.js +26 -0
  34. package/lib/esm/tray/assets.js.map +1 -0
  35. package/lib/types/errors.d.cts +56 -0
  36. package/lib/types/errors.d.mts +56 -0
  37. package/lib/types/index.d.cts +27 -0
  38. package/lib/types/index.d.mts +27 -0
  39. package/lib/types/native/icons.d.cts +71 -0
  40. package/lib/types/native/icons.d.mts +71 -0
  41. package/lib/types/native/loader.d.cts +37 -0
  42. package/lib/types/native/loader.d.mts +37 -0
  43. package/lib/types/native/types.d.cts +104 -0
  44. package/lib/types/native/types.d.mts +104 -0
  45. package/lib/types/notifications/NotificationCenter.d.cts +163 -0
  46. package/lib/types/notifications/NotificationCenter.d.mts +163 -0
  47. package/lib/types/tray/TrayIcon.d.cts +174 -0
  48. package/lib/types/tray/TrayIcon.d.mts +174 -0
  49. package/lib/types/tray/assets.d.cts +25 -0
  50. package/lib/types/tray/assets.d.mts +25 -0
  51. package/native/tray-icon-node/Cargo.lock +1511 -0
  52. package/native/tray-icon-node/Cargo.toml +45 -0
  53. package/native/tray-icon-node/Cross.toml +10 -0
  54. package/native/tray-icon-node/LICENSE +21 -0
  55. package/native/tray-icon-node/UPSTREAM-README.md +281 -0
  56. package/native/tray-icon-node/UPSTREAM.md +213 -0
  57. package/native/tray-icon-node/build-manifest.json +16 -0
  58. package/native/tray-icon-node/build.rs +5 -0
  59. package/native/tray-icon-node/index.d.ts +368 -0
  60. package/native/tray-icon-node/index.js +609 -0
  61. package/native/tray-icon-node/package.json +55 -0
  62. package/native/tray-icon-node/rustfmt.toml +31 -0
  63. package/native/tray-icon-node/source-manifest.json +30 -0
  64. package/native/tray-icon-node/src/common.rs +101 -0
  65. package/native/tray-icon-node/src/icon.rs +255 -0
  66. package/native/tray-icon-node/src/lib.rs +449 -0
  67. package/native/tray-icon-node/src/menu.rs +849 -0
  68. package/native/tray-icon-node/src/tray.rs +251 -0
  69. package/native/tray-icon-node/tray-icon-node.linux-x64-gnu.node +0 -0
  70. package/package.json +131 -4
  71. package/scripts/for-os-build.mjs +60 -0
  72. package/scripts/for-os-init.mjs +327 -0
  73. package/scripts/for-os-install.mjs +47 -0
  74. package/scripts/for-os-integration.mjs +137 -0
  75. package/scripts/for-os-integrity.mjs +51 -0
  76. package/scripts/for-os-package.mjs +49 -0
  77. package/scripts/lib/native.mjs +591 -0
@@ -0,0 +1,327 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Initializes everything needed to build the native tray/notification addon.
4
+ *
5
+ * Checks the Node version, the pinned Rust toolchain (rustup), the platform
6
+ * native build dependencies, and the notification service, installs what is
7
+ * missing when it is allowed to, then builds and materializes the addon.
8
+ * Installation is explicit: use `--install` (the default) on a development
9
+ * machine and `--check` in CI to report readiness without mutating the host.
10
+ *
11
+ * Rust is pinned so local and CI builds stay reproducible instead of silently
12
+ * tracking whatever `stable` happens to be that day:
13
+ *
14
+ * - Toolchain {@link RUST_TOOLCHAIN} (`1.100.0`) is the current stable release
15
+ * (2026-11-12) and is the only version `--check`/`--install` consider ready.
16
+ * - Bootstrap uses rustup-init {@link RUSTUP_INIT_VERSION} (`1.29.3`), downloaded
17
+ * from the versioned archive and verified against a hard-coded SHA-256 before
18
+ * execution. The installer is never piped from the network into a shell.
19
+ * - The SHA-256 values come from the official rustup archive checksum files:
20
+ * `https://static.rust-lang.org/rustup/archive/1.29.3/<target>/rustup-init.sha256`
21
+ * (Unix) and `.../<target>/rustup-init.exe.sha256` (Windows).
22
+ * @module scripts/for-os-init
23
+ */
24
+ import { createHash } from "node:crypto";
25
+ import {
26
+ chmodSync,
27
+ existsSync,
28
+ mkdtempSync,
29
+ readFileSync,
30
+ rmSync,
31
+ } from "node:fs";
32
+ import { homedir, tmpdir } from "node:os";
33
+ import { join } from "node:path";
34
+ import { spawnSync } from "node:child_process";
35
+ import {
36
+ commandVersion,
37
+ installNative,
38
+ missingLinuxNativeModules,
39
+ run,
40
+ } from "./lib/native.mjs";
41
+
42
+ const process = globalThis.process;
43
+
44
+ /** Pinned stable Rust toolchain used for every native addon build. */
45
+ const RUST_TOOLCHAIN = "1.100.0";
46
+
47
+ /** Pinned rustup-init release used to bootstrap a fresh machine. */
48
+ const RUSTUP_INIT_VERSION = "1.29.3";
49
+
50
+ /** Base URL of the versioned rustup-init archive. */
51
+ const RUSTUP_INIT_ARCHIVE = `https://static.rust-lang.org/rustup/archive/${RUSTUP_INIT_VERSION}`;
52
+
53
+ /**
54
+ * rustup-init artifacts pinned per Node `platform-arch`, with the SHA-256 taken
55
+ * from the matching official `rustup-init*.sha256` file in the archive.
56
+ */
57
+ const RUSTUP_INIT_PINS = {
58
+ "linux-x64": {
59
+ triple: "x86_64-unknown-linux-gnu",
60
+ binary: "rustup-init",
61
+ sha256: "b1c8cb14e30889e7e2999e6b69e62d9e9b9ffc0f4df8180564d306d9680e6c55",
62
+ },
63
+ "linux-arm64": {
64
+ triple: "aarch64-unknown-linux-gnu",
65
+ binary: "rustup-init",
66
+ sha256: "9f608c142e0e38a78957d0661ba1dfaf0b6fb37184cfaa4b9a0aa57af6184282",
67
+ },
68
+ "darwin-x64": {
69
+ triple: "x86_64-apple-darwin",
70
+ binary: "rustup-init",
71
+ sha256: "bc107f1fb0228de7fa32413c89c1b305cea9cd256e94b01150cd054128145429",
72
+ },
73
+ "darwin-arm64": {
74
+ triple: "aarch64-apple-darwin",
75
+ binary: "rustup-init",
76
+ sha256: "63752a1919a3a4793173ec70f8f212621a7ce38ba6a246095984482f4de20f9f",
77
+ },
78
+ "win32-x64": {
79
+ triple: "x86_64-pc-windows-msvc",
80
+ binary: "rustup-init.exe",
81
+ sha256: "38027d51d69a5d05493627a0634dbea52d6cd793c8f072d2373d3f4163eec7db",
82
+ },
83
+ "win32-ia32": {
84
+ triple: "i686-pc-windows-msvc",
85
+ binary: "rustup-init.exe",
86
+ sha256: "fa448cc3839d6fbacb5ed1954c16f60c4d16e7e6476677a66fffb34dc91bd201",
87
+ },
88
+ };
89
+
90
+ const HELP = `Usage: node scripts/for-os-init.mjs [--check] [--skip-build]
91
+
92
+ Installs the Rust toolchain and native build dependencies required by
93
+ native/tray-icon-node, then builds and materializes the addon.
94
+
95
+ --check report readiness without installing anything
96
+ --skip-build install dependencies but do not build the addon
97
+ --help show this help
98
+
99
+ Linux packages (Ubuntu/Debian): build-essential pkg-config libgtk-3-dev
100
+ libayatana-appindicator3-dev libglib2.0-dev libxdo-dev libx11-dev libnotify-bin`;
101
+
102
+ const LINUX_PACKAGES = [
103
+ "build-essential",
104
+ "pkg-config",
105
+ "libgtk-3-dev",
106
+ "libayatana-appindicator3-dev",
107
+ "libglib2.0-dev",
108
+ "libxdo-dev",
109
+ "libx11-dev",
110
+ "libnotify-bin",
111
+ ];
112
+
113
+ function log(message) {
114
+ console.log(`for-os-init: ${message}`);
115
+ }
116
+
117
+ function ensurePath() {
118
+ const cargoBin = join(homedir(), ".cargo", "bin");
119
+ if (existsSync(cargoBin) && !process.env.PATH.split(":").includes(cargoBin)) {
120
+ process.env.PATH = `${cargoBin}:${process.env.PATH}`;
121
+ }
122
+ }
123
+
124
+ function nodeReady() {
125
+ const major = Number(process.versions.node.split(".")[0]);
126
+ if (major >= 20) return true;
127
+ log(`Node ${process.versions.node} is too old; @decaf-ts/for-os requires Node >= 20.`);
128
+ return false;
129
+ }
130
+
131
+ function installedRustVersion() {
132
+ const rustc = commandVersion("rustc");
133
+ if (!rustc) return undefined;
134
+ const match = rustc.match(/rustc\s+(\d+\.\d+\.\d+)/);
135
+ return match ? match[1] : undefined;
136
+ }
137
+
138
+ function rustReady() {
139
+ ensurePath();
140
+ const cargo = commandVersion("cargo");
141
+ const rustc = commandVersion("rustc");
142
+ if (!cargo || !rustc) {
143
+ log("Rust toolchain is missing.");
144
+ return false;
145
+ }
146
+ const version = installedRustVersion();
147
+ if (version !== RUST_TOOLCHAIN) {
148
+ log(
149
+ `Rust ${version || "unknown"} is installed, but for-os builds are pinned to ${RUST_TOOLCHAIN}.`
150
+ );
151
+ return false;
152
+ }
153
+ log(`Rust ready: ${cargo}; ${rustc}`);
154
+ return true;
155
+ }
156
+
157
+ function rustupInitPin() {
158
+ return RUSTUP_INIT_PINS[`${process.platform}-${process.arch}`];
159
+ }
160
+
161
+ function downloadRustupInit(pin, destination) {
162
+ const url = `${RUSTUP_INIT_ARCHIVE}/${pin.triple}/${pin.binary}`;
163
+ log(`Downloading rustup-init ${RUSTUP_INIT_VERSION} for ${pin.triple}...`);
164
+ const download = spawnSync(
165
+ "curl",
166
+ ["--proto", "=https", "--tlsv1.2", "-sSfL", "-o", destination, url],
167
+ { stdio: "inherit" }
168
+ );
169
+ return download.status === 0;
170
+ }
171
+
172
+ function verifyRustupInit(file, expected) {
173
+ const actual = createHash("sha256").update(readFileSync(file)).digest("hex");
174
+ if (actual !== expected) {
175
+ log(`rustup-init checksum mismatch: expected ${expected}, got ${actual}.`);
176
+ return false;
177
+ }
178
+ log(`rustup-init sha256 verified: ${expected}`);
179
+ return true;
180
+ }
181
+
182
+ function bootstrapRustup() {
183
+ const pin = rustupInitPin();
184
+ if (!pin) {
185
+ log(
186
+ `No pinned rustup-init is available for ${process.platform}-${process.arch}. ` +
187
+ "Install Rust manually from https://rustup.rs and retry."
188
+ );
189
+ return false;
190
+ }
191
+ const dir = mkdtempSync(join(tmpdir(), "for-os-rustup-"));
192
+ const installer = join(dir, pin.binary);
193
+ try {
194
+ if (!downloadRustupInit(pin, installer)) {
195
+ log("rustup-init download failed. Install Rust manually from https://rustup.rs and retry.");
196
+ return false;
197
+ }
198
+ if (!verifyRustupInit(installer, pin.sha256)) {
199
+ log("Refusing to run an unverified rustup-init; install Rust manually from https://rustup.rs.");
200
+ return false;
201
+ }
202
+ if (process.platform !== "win32") chmodSync(installer, 0o755);
203
+ const result = spawnSync(
204
+ installer,
205
+ ["-y", "--default-toolchain", RUST_TOOLCHAIN],
206
+ { stdio: "inherit" }
207
+ );
208
+ if (result.status !== 0) {
209
+ log("rustup-init failed. Install Rust manually from https://rustup.rs and retry.");
210
+ return false;
211
+ }
212
+ return true;
213
+ } finally {
214
+ rmSync(dir, { recursive: true, force: true });
215
+ }
216
+ }
217
+
218
+ function installRust() {
219
+ ensurePath();
220
+ if (rustReady()) return true;
221
+
222
+ const hadRustup = Boolean(commandVersion("rustup"));
223
+ if (!hadRustup) {
224
+ if (!bootstrapRustup()) return false;
225
+ ensurePath();
226
+ if (rustReady()) return true;
227
+ }
228
+
229
+ log(`Ensuring pinned Rust toolchain ${RUST_TOOLCHAIN}...`);
230
+ const toolchain = run("rustup", ["toolchain", "install", RUST_TOOLCHAIN]);
231
+ if (!toolchain.ok) return false;
232
+ const setDefault = run("rustup", ["default", RUST_TOOLCHAIN]);
233
+ return setDefault.ok && rustReady();
234
+ }
235
+
236
+ function linuxPackagesReady() {
237
+ const missing = missingLinuxNativeModules();
238
+ if (!missing.length) {
239
+ log("Linux tray development libraries ready.");
240
+ return true;
241
+ }
242
+ log(`Missing Linux development modules: ${missing.join(", ")}`);
243
+ return false;
244
+ }
245
+
246
+ function installLinuxPackages() {
247
+ if (process.platform !== "linux") return true;
248
+ if (linuxPackagesReady()) return true;
249
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
250
+ if (!isRoot && !run("sudo", ["-n", "true"], { capture: true }).ok) {
251
+ log(
252
+ "Native development libraries are missing and passwordless sudo is unavailable. " +
253
+ `Install them as root, then rerun: apt-get update && apt-get install -y ${LINUX_PACKAGES.join(" ")}`
254
+ );
255
+ return false;
256
+ }
257
+ log("Installing Linux native development libraries...");
258
+ const runner = isRoot ? "apt-get" : "sudo";
259
+ const updateArgs = isRoot ? ["update"] : ["apt-get", "update"];
260
+ const installArgs = isRoot
261
+ ? ["install", "-y", ...LINUX_PACKAGES]
262
+ : ["apt-get", "install", "-y", ...LINUX_PACKAGES];
263
+ const update = run(runner, updateArgs);
264
+ if (!update.ok) {
265
+ log("apt-get update failed.");
266
+ return false;
267
+ }
268
+ const install = spawnSync(runner, installArgs, { stdio: "inherit" });
269
+ if (install.status !== 0) {
270
+ log("Native package installation failed.");
271
+ return false;
272
+ }
273
+ return linuxPackagesReady();
274
+ }
275
+
276
+ function notifyServiceReady() {
277
+ if (process.platform !== "linux") {
278
+ log(`Notification service: using the native ${process.platform} backend.`);
279
+ return true;
280
+ }
281
+ const hasNotifySend = Boolean(commandVersion("notify-send", ["--version"]));
282
+ log(hasNotifySend ? "notify-send available." : "notify-send missing (install libnotify-bin).");
283
+ return hasNotifySend;
284
+ }
285
+
286
+ function main(argv) {
287
+ if (argv.includes("--help") || argv.includes("-h")) {
288
+ console.log(HELP);
289
+ return 0;
290
+ }
291
+ const unknown = argv.filter(
292
+ (argument) => !["--check", "--install", "--skip-build"].includes(argument)
293
+ );
294
+ if (unknown.length) {
295
+ console.error(`Unknown argument "${unknown[0]}".\n\n${HELP}`);
296
+ return 2;
297
+ }
298
+ const checkOnly = argv.includes("--check");
299
+ const skipBuild = argv.includes("--skip-build");
300
+
301
+ let ready = nodeReady();
302
+ ready = (checkOnly ? rustReady() : installRust()) && ready;
303
+ ready = (checkOnly ? linuxPackagesReady() : installLinuxPackages()) && ready;
304
+ ready = notifyServiceReady() && ready;
305
+
306
+ if (!ready) {
307
+ log(
308
+ checkOnly
309
+ ? "Host is not ready to build the native addon. Rerun without --check to install dependencies."
310
+ : "Dependencies are incomplete; see the messages above."
311
+ );
312
+ return 1;
313
+ }
314
+ if (checkOnly) {
315
+ log("Host is ready to build the native addon.");
316
+ return 0;
317
+ }
318
+ if (skipBuild) {
319
+ log("Dependencies installed; skipping the native build (--skip-build).");
320
+ return 0;
321
+ }
322
+ installNative({ required: true });
323
+ log("Native addon built and materialized. Tray and notification bridges are ready.");
324
+ return 0;
325
+ }
326
+
327
+ process.exitCode = main(process.argv.slice(2));
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Install-time materialization of the vendored `tray-icon-node` addon.
4
+ *
5
+ * Verifies `native/tray-icon-node` against `source-manifest.json`, builds the
6
+ * native addon when a toolchain is available, and writes a verified copy to
7
+ * `node_modules/tray-icon-node`. Without `--require-build` a missing toolchain
8
+ * degrades to a binary-less install; the TypeScript bridges then report
9
+ * unavailable at runtime instead of failing the package install.
10
+ * @module scripts/for-os-install
11
+ */
12
+ import { installNative, verifySourceTree } from "./lib/native.mjs";
13
+
14
+ const process = globalThis.process;
15
+
16
+ const HELP = `Usage: node scripts/for-os-install.mjs [--require-build]
17
+
18
+ Verifies native/tray-icon-node against source-manifest.json, builds the native
19
+ addon when possible, and materializes a verified copy at
20
+ node_modules/tray-icon-node.
21
+
22
+ --require-build fail instead of degrading when the native build cannot run
23
+ --help show this help`;
24
+
25
+ function main(argv) {
26
+ if (argv.includes("--help") || argv.includes("-h")) {
27
+ console.log(HELP);
28
+ return 0;
29
+ }
30
+ const unknown = argv.filter((argument) => argument !== "--require-build");
31
+ if (unknown.length) {
32
+ console.error(`Unknown argument "${unknown[0]}".\n\n${HELP}`);
33
+ return 2;
34
+ }
35
+ try {
36
+ verifySourceTree();
37
+ installNative({ required: argv.includes("--require-build") });
38
+ return 0;
39
+ } catch (failure) {
40
+ console.error(
41
+ `for-os-install: ${String(failure instanceof Error ? failure.message : failure)}`
42
+ );
43
+ return 1;
44
+ }
45
+ }
46
+
47
+ process.exitCode = main(process.argv.slice(2));
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Real native integration check for the built addon and TypeScript bridges.
4
+ *
5
+ * `--smoke` creates a tray, switches its icon at runtime, updates the tooltip,
6
+ * sends a timed notification, and closes the tray. The default interactive
7
+ * mode additionally waits for menu actions and notification buttons.
8
+ * @module scripts/for-os-integration
9
+ */
10
+ const process = globalThis.process;
11
+ const importModule = new Function("specifier", "return import(specifier);");
12
+
13
+ const smokeOnly = process.argv.includes("--smoke");
14
+ const buttonsOnly = process.argv.includes("--buttons");
15
+ const timeoutMs = Number(process.env.FOR_OS_TRAY_TEST_TIMEOUT_MS || 90_000);
16
+ const libPath = new URL("../lib/esm/index.js", import.meta.url).href;
17
+
18
+ const actions = [];
19
+ let tray;
20
+ let center;
21
+ let wake;
22
+
23
+ function waitForAction(expected) {
24
+ const deadline = Date.now() + timeoutMs;
25
+ return new Promise((resolve, reject) => {
26
+ const poll = () => {
27
+ const index = actions.indexOf(expected);
28
+ if (index >= 0) {
29
+ actions.splice(index, 1);
30
+ resolve();
31
+ return;
32
+ }
33
+ if (Date.now() >= deadline) {
34
+ reject(new Error(`Timed out waiting for tray action "${expected}".`));
35
+ return;
36
+ }
37
+ wake = setTimeout(poll, 100);
38
+ };
39
+ poll();
40
+ });
41
+ }
42
+
43
+ async function main() {
44
+ const { TrayIcon, NotificationCenter, TRAY_ICON_BASE64 } = await importModule(libPath);
45
+ tray = TrayIcon.create({
46
+ icon: { base64: TRAY_ICON_BASE64.idle },
47
+ tooltip: "for-os integration check",
48
+ menu: [
49
+ { id: "search", label: "Search now" },
50
+ { id: "accept", label: "Accept appointment" },
51
+ { id: "auto", label: "Auto toggle", checkable: true, checked: false },
52
+ { id: "quit", label: "Quit" },
53
+ ],
54
+ onEvent: (event) => console.log(`tray event: ${event.eventType}`),
55
+ });
56
+ for (const id of ["search", "accept", "quit"]) {
57
+ tray.on(id, (action) => actions.push(action));
58
+ }
59
+ center = new NotificationCenter();
60
+ center.registerAction("accept", (action) => actions.push(action));
61
+
62
+ // Runtime icon switching: idle -> active -> idle.
63
+ tray.setIcon({ base64: TRAY_ICON_BASE64.active });
64
+ tray.setTooltip("for-os integration check: active");
65
+ tray.setIcon({ base64: TRAY_ICON_BASE64.idle });
66
+ tray.updateMenuItem("accept", { enabled: true });
67
+ console.log("PASS: native tray created and its icon switched at runtime.");
68
+
69
+ // Checkable menu toggling against the real addon: false -> true -> false.
70
+ const autoInitial = tray.isMenuItemChecked("auto");
71
+ const autoFirst = tray.toggleMenuItem("auto");
72
+ const autoFirstRead = tray.isMenuItemChecked("auto");
73
+ const autoSecond = tray.toggleMenuItem("auto");
74
+ const autoSecondRead = tray.isMenuItemChecked("auto");
75
+ if (
76
+ autoInitial !== false ||
77
+ autoFirst !== true ||
78
+ autoFirstRead !== true ||
79
+ autoSecond !== false ||
80
+ autoSecondRead !== false
81
+ ) {
82
+ throw new Error(
83
+ "toggleMenuItem regression: expected checked state false -> true -> false, " +
84
+ `got initial=${autoInitial} toggle1=${autoFirst}/${autoFirstRead} toggle2=${autoSecond}/${autoSecondRead}.`
85
+ );
86
+ }
87
+ console.log("PASS: checkable menu item toggled false -> true -> false.");
88
+
89
+ if (smokeOnly) {
90
+ const notification = center.notify({
91
+ title: "for-os tray test",
92
+ body: "Rust delivered this timed notification through the operating system.",
93
+ timeoutMs: 3_000,
94
+ });
95
+ console.log(`PASS: timed notification dispatched (${notification.id}).`);
96
+ await new Promise((resolve) => setTimeout(resolve, 500));
97
+ console.log("PASS: native tray smoke check complete.");
98
+ return;
99
+ }
100
+
101
+ const notification = center.notify({
102
+ title: "for-os button mapping",
103
+ body: "Activate a button to prove the native action reaches a JavaScript callback.",
104
+ timeoutMs,
105
+ buttons: [
106
+ { id: "accept", label: "Accept appointment" },
107
+ { id: "see", label: "See appointment" },
108
+ ],
109
+ });
110
+ console.log(`Notification ${notification.id} sent. Activate "Accept appointment".`);
111
+ await waitForAction("accept");
112
+ console.log("PASS: native notification button reached its JavaScript callback.");
113
+ if (buttonsOnly) return;
114
+
115
+ for (const step of [
116
+ { id: "search", instruction: "choose “Search now”" },
117
+ { id: "accept", instruction: "choose “Accept appointment”" },
118
+ { id: "quit", instruction: "choose “Quit”" },
119
+ ]) {
120
+ console.log(`Step: open the tray menu and ${step.instruction}.`);
121
+ await waitForAction(step.id);
122
+ console.log(`PASS: tray menu action "${step.id}" reached JavaScript.`);
123
+ }
124
+ console.log("PASS: for-os tray, dynamic icons, notification timers, and JS buttons are integrated.");
125
+ }
126
+
127
+ try {
128
+ await main();
129
+ process.exitCode = 0;
130
+ } catch (error) {
131
+ console.error(error instanceof Error ? error.message : String(error));
132
+ process.exitCode = 1;
133
+ } finally {
134
+ if (wake) clearTimeout(wake);
135
+ center?.close();
136
+ tray?.close();
137
+ }
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Re-records `native/tray-icon-node/source-manifest.json`.
4
+ *
5
+ * Regenerating the pin is a security-relevant change: review the native source
6
+ * diff before committing the new manifest.
7
+ * @module scripts/for-os-integrity
8
+ */
9
+ import { writeSourceManifest } from "./lib/native.mjs";
10
+
11
+ const process = globalThis.process;
12
+
13
+ const HELP = `Usage: node scripts/for-os-integrity.mjs [--check]
14
+
15
+ Records the SHA-512 of every native source file and the canonical source-tree
16
+ digest in native/tray-icon-node/source-manifest.json.
17
+
18
+ --check verify the current tree against the manifest instead of rewriting it
19
+ --help show this help`;
20
+
21
+ async function main(argv) {
22
+ if (argv.includes("--help") || argv.includes("-h")) {
23
+ console.log(HELP);
24
+ return 0;
25
+ }
26
+ const unknown = argv.filter((argument) => argument !== "--check");
27
+ if (unknown.length) {
28
+ console.error(`Unknown argument "${unknown[0]}".\n\n${HELP}`);
29
+ return 2;
30
+ }
31
+ if (argv.includes("--check")) {
32
+ const { verifySourceTree } = await import("./lib/native.mjs");
33
+ verifySourceTree();
34
+ console.log("for-os-integrity: native source matches source-manifest.json.");
35
+ return 0;
36
+ }
37
+ const manifest = writeSourceManifest();
38
+ console.log(
39
+ `for-os-integrity: recorded ${Object.keys(manifest.files).length} files (source digest ${manifest.sourceDigest}).`
40
+ );
41
+ return 0;
42
+ }
43
+
44
+ try {
45
+ process.exitCode = await main(process.argv.slice(2));
46
+ } catch (failure) {
47
+ console.error(
48
+ `for-os-integrity: ${String(failure instanceof Error ? failure.message : failure)}`
49
+ );
50
+ process.exitCode = 1;
51
+ }
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ /** Verifies that an npm package contains every supported native binary. */
3
+ import { existsSync, writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import {
6
+ NATIVE_DIR,
7
+ NATIVE_PACKAGE,
8
+ NATIVE_VERSION,
9
+ TARGET_BINARIES,
10
+ sha512File,
11
+ verifySourceTree,
12
+ } from "./lib/native.mjs";
13
+
14
+ const process = globalThis.process;
15
+ const write = process.argv.includes("--write");
16
+ const allowed = new Set(["--write", "--help", "-h"]);
17
+ const unknown = process.argv.slice(2).find((arg) => !allowed.has(arg));
18
+
19
+ if (unknown) {
20
+ console.error(`Unknown argument "${unknown}". Usage: node scripts/for-os-package.mjs [--write]`);
21
+ process.exitCode = 2;
22
+ } else if (process.argv.includes("--help") || process.argv.includes("-h")) {
23
+ console.log("Usage: node scripts/for-os-package.mjs [--write]\nChecks that all release native binaries are present; --write records their SHA-512 digests.");
24
+ } else {
25
+ try {
26
+ const { observed } = verifySourceTree();
27
+ const binaries = Object.fromEntries(
28
+ Object.entries(TARGET_BINARIES).map(([target, filename]) => {
29
+ const path = join(NATIVE_DIR, filename);
30
+ if (!existsSync(path)) throw new Error(`Missing native binary for ${target}: ${filename}`);
31
+ return [filename, sha512File(path)];
32
+ })
33
+ );
34
+ if (write) {
35
+ const manifest = {
36
+ version: 2,
37
+ package: NATIVE_PACKAGE,
38
+ packageVersion: NATIVE_VERSION,
39
+ sourceDigest: observed.sourceDigest,
40
+ binaries,
41
+ };
42
+ writeFileSync(join(NATIVE_DIR, "build-manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);
43
+ }
44
+ console.log(`for-os: verified ${Object.keys(binaries).length} packaged native binaries.`);
45
+ } catch (error) {
46
+ console.error(`for-os-package: ${error instanceof Error ? error.message : String(error)}`);
47
+ process.exitCode = 1;
48
+ }
49
+ }