opentray 0.4.1 → 0.5.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 +67 -17
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +76 -246
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-Db-tztnj.mjs → client-B_zxQOo5.mjs} +11 -1
- package/dist/client-B_zxQOo5.mjs.map +1 -0
- package/dist/{client-C_zT7PEt.d.mts → client-h6gZdeOk.d.mts} +3 -2
- package/dist/client-h6gZdeOk.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{local-broker-mQmeVLF5.mjs → local-broker-CEIHPBcK.mjs} +15 -17
- package/dist/local-broker-CEIHPBcK.mjs.map +1 -0
- package/dist/node.d.mts +1 -1
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +1 -1
- package/package.json +10 -9
- package/assets/lynx-review/README.md +0 -14
- package/assets/lynx-review/main.lynx.bundle +0 -0
- package/dist/client-C_zT7PEt.d.mts.map +0 -1
- package/dist/client-Db-tztnj.mjs.map +0 -1
- package/dist/local-broker-mQmeVLF5.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -38,14 +38,11 @@ await space.createTray({
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
const defaultSpace = await resolveDefaultSpace();
|
|
41
|
-
await createTray(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
{ space: defaultSpace.space }
|
|
48
|
-
);
|
|
41
|
+
await createTray({
|
|
42
|
+
trayId: "secondary",
|
|
43
|
+
title: "Secondary",
|
|
44
|
+
icon: { type: "rgba", data: [0, 0, 0, 0], width: 1, height: 1 },
|
|
45
|
+
}, { space: defaultSpace.space });
|
|
49
46
|
```
|
|
50
47
|
|
|
51
48
|
`createTray()` resolves the broker default space when no explicit target is provided. If you already know the target, pass `space: defaultSpace.space` in the second argument instead of relying on default-space lookup.
|
|
@@ -56,15 +53,50 @@ Run the human-visible daemon tray example:
|
|
|
56
53
|
pnpm --filter opentray example:daemon-tray
|
|
57
54
|
```
|
|
58
55
|
|
|
56
|
+
Run the direct webview control demo:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pnpm --filter opentray example:webview-control
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
That demo opens a native WebView window immediately and puts the controls inside the page itself, so you can exercise frameless, transparent, keep-on-top, title, icon, screen, and navigation behavior without going through the tray menu first.
|
|
63
|
+
Treat `example:webview-control` as the API exercise surface. It is useful for probing capabilities and events, but it is not the canonical recipe for a tray-anchored glass shell.
|
|
64
|
+
|
|
65
|
+
Run the dedicated tray-panel demo:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
cargo build -p opentray-bin -p opentray-ext-webview
|
|
69
|
+
pnpm --filter opentray example:tray-panel
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This demo is the canonical custom TrayPanel case: one `primaryEvent` tray item, backend `tray.getBounds()`, page `navigator.opentray.tray.getBounds()`, screen-aware repositioning, and a frameless glass panel with `keepOnTop`.
|
|
73
|
+
It also follows the native-glass rule strictly: transparent native window background, no root HTML shell styling, and content padding only inside the page.
|
|
74
|
+
It now also pins `style.platform.macos.materialState: "active"` so the tray-launched material surface does not immediately fall back to the inactive grey AppKit appearance.
|
|
75
|
+
For a step-by-step walkthrough of the examples and expected behavior, read [examples/EXAMPLE.md](./examples/EXAMPLE.md).
|
|
76
|
+
|
|
77
|
+
## Release Channels And Maturity
|
|
78
|
+
|
|
79
|
+
OpenTray uses release channels and capability maturity together. Do not read a published platform package as proof that every visible runtime path is already stable.
|
|
80
|
+
|
|
81
|
+
- `latest`: the stable package line
|
|
82
|
+
- `alpha`: the prerelease/testing package line, installed as `npm i opentray@alpha`
|
|
83
|
+
|
|
84
|
+
Current WebView truth:
|
|
85
|
+
|
|
86
|
+
- macOS is the current `stable` human-visible acceptance path
|
|
87
|
+
- Windows and Linux are currently `alpha` for WebView runtime behavior, even though their platform packages are published
|
|
88
|
+
- some requests are `unsupported by design`, such as asking the macOS runtime to apply a Windows-only style family
|
|
89
|
+
- some results are `unavailable by context`, such as tray-bounds projection when the current session has no authoritative tray anchor
|
|
90
|
+
|
|
91
|
+
When run from the repo worktree, the example automatically discovers `target/debug` or `target/release` `libopentray_ext_webview` and wires it through `OPENTRAY_EXT_PATH` before starting the daemon. That keeps the example on the real `load-ext` path without requiring a manual staging step for routine source-level testing.
|
|
92
|
+
|
|
59
93
|
After installing from npm, use the published CLI smoke path instead of workspace scripts:
|
|
60
94
|
|
|
61
95
|
```bash
|
|
62
96
|
opentray smoke daemon-tray
|
|
63
|
-
opentray smoke daemon-lynx
|
|
97
|
+
opentray smoke daemon-lynx --bundle ./research/lynx/app/dist/main.lynx.bundle
|
|
64
98
|
```
|
|
65
99
|
|
|
66
|
-
`opentray smoke daemon-lynx` now uses the package-owned review bundle by default so a fresh npm install can perform the final visual audit without a workspace checkout. Keep `--bundle <path-to-main.lynx.bundle>` only when you want to override that official audit asset with a custom bundle.
|
|
67
|
-
|
|
68
100
|
This example starts or reuses the same-version daemon automatically, creates a real tray through the public SDK, and prints broker-routed menu events. Use manual lifecycle commands only for operator/debug control:
|
|
69
101
|
|
|
70
102
|
```bash
|
|
@@ -73,14 +105,24 @@ pnpm --filter opentray cli -- daemon stop
|
|
|
73
105
|
pnpm --filter opentray cli -- daemon restart
|
|
74
106
|
```
|
|
75
107
|
|
|
76
|
-
The menu
|
|
108
|
+
The menu intentionally declares only one plain item: `Open WebView` with `primaryEvent: true`. On macOS, that single primary item lets clicking the status item direct-trigger the normal `menuClick` event without opening a menu, so the example can behave like a one-action launcher for a WebView-built surface.
|
|
77
109
|
|
|
78
|
-
|
|
110
|
+
On platforms that expose a direct tray activation gesture, the same item opens the WebView immediately while still remaining a normal native menu item on platforms or gestures that show a menu.
|
|
79
111
|
|
|
80
|
-
The
|
|
112
|
+
The host side of that example can call `await tray.getBounds()` to read the current tray geometry before opening the window. The rendered page can also opt into `navigator.opentray.tray.getBounds()` when it needs the same tray anchor for layout.
|
|
113
|
+
|
|
114
|
+
The opened WebView also enables the injected page bridge so the rendered page can call `navigator.window` / `navigator.opentrayWindow` and, for the demo only, opt into `window.close()` / `window.moveTo()` / `window.resizeTo()` overrides. Use the in-page buttons to verify `getCapabilities`, `getStyle`, `setStyle({ frameless })`, move, resize, close, and tray-bounds behavior visually instead of relying only on terminal logs.
|
|
115
|
+
|
|
116
|
+
The Lynx smoke path uses the same generic extension loader but launches a real `LynxExplorer.app.zip` runtime sidecar from `@opentray/ext-lynx-darwin-*`. It starts the requested `.lynx.bundle` immediately on run and exposes `Reload Bundle`, `Hide Window`, and `Quit Smoke` through tray-routed events.
|
|
81
117
|
|
|
82
118
|
First-stage platform packages are published for macOS, Linux, and Windows. macOS is the current human-visual acceptance path. Linux and Windows artifacts are present for package topology validation, but unsupported broker/WebView capability must fail explicitly rather than pretending a visible UI exists. Lynx is intentionally macOS-first for now and should fail honestly on other platforms instead of pretending the runtime exists.
|
|
83
119
|
|
|
120
|
+
If you are validating the current prerelease branch before stable publication, install from the alpha channel and treat that as alpha evidence rather than stable evidence:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm i opentray@alpha
|
|
124
|
+
```
|
|
125
|
+
|
|
84
126
|
For local native smoke before npm publish, stage the current platform artifacts first:
|
|
85
127
|
|
|
86
128
|
```bash
|
|
@@ -88,10 +130,18 @@ cargo build -p opentray-bin -p opentray-ext-webview -p opentray-ext-lynx
|
|
|
88
130
|
bun run scripts/binaries/stage-local.ts --kind daemon --source target/debug/opentray
|
|
89
131
|
bun run scripts/binaries/stage-local.ts --kind webview --source target/debug/libopentray_ext_webview.dylib
|
|
90
132
|
bun run scripts/binaries/stage-local.ts --kind lynx --source target/debug/libopentray_ext_lynx.dylib
|
|
91
|
-
bash scripts/release/build-lynx-runtime.sh /tmp/
|
|
92
|
-
bun run scripts/binaries/stage-local.ts --kind lynx-runtime --source /tmp/
|
|
133
|
+
bash scripts/release/build-lynx-runtime.sh /tmp/LynxExplorer.app.zip
|
|
134
|
+
bun run scripts/binaries/stage-local.ts --kind lynx-runtime --source /tmp/LynxExplorer.app.zip
|
|
93
135
|
OPENTRAY_EXAMPLE_WEBVIEW_SMOKE=1 pnpm --filter opentray cli -- smoke daemon-tray
|
|
94
|
-
pnpm --filter opentray cli -- smoke daemon-lynx
|
|
136
|
+
pnpm --filter opentray cli -- smoke daemon-lynx --bundle ./research/lynx/app/dist/main.lynx.bundle
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
During source-level daemon work, restart the daemon with the freshly built broker binary before testing tray behavior. Otherwise the CLI may reuse the already staged same-version daemon:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
cargo build -p opentray-bin
|
|
143
|
+
OPENTRAY_BROKER_BIN="$PWD/target/debug/opentray" pnpm --filter opentray cli -- daemon restart
|
|
144
|
+
OPENTRAY_BROKER_BIN="$PWD/target/debug/opentray" pnpm --filter opentray cli -- smoke daemon-tray
|
|
95
145
|
```
|
|
96
146
|
|
|
97
147
|
The daemon exits automatically after 30 seconds with no connected clients. Set `OPENTRAY_DAEMON_IDLE_TIMEOUT_MS=0` to keep it alive during debugging, or provide another millisecond value for a custom idle release window.
|
package/dist/cli.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.mts","names":[],"sources":["../src/cli.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cli.d.mts","names":[],"sources":["../src/cli.ts"],"mappings":";;;KAiBK,UAAA;EACC,IAAA;EAAgB,MAAA;AAAA;EAChB,IAAA;EAAe,IAAA;AAAA;EACf,IAAA;EAAe,IAAA;EAAqB,UAAA;AAAA;EACpC,IAAA;AAAA;AAAA,cAEO,eAAA,GAAmB,IAAA,eAAiB,UAmBhD;AAAA,cAEY,MAAA,GAAgB,IAAA,eAAiB,OAAO;AAAA,cAsFxC,wBAAA,GAA4B,MAAoB,EAAZ,YAAY;AAAA,cAoBhD,eAAA,GAAmB,aAAA,sBAAmC,UAAkB"}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as createClient } from "./client-
|
|
3
|
-
import { a as inspectDaemon, c as stopDaemon, i as createNodeDaemonDriver, n as resolveDaemonPaths, o as restartDaemon, r as readPackageVersion, s as startDaemon, t as connectLocalBroker } from "./local-broker-
|
|
2
|
+
import { t as createClient } from "./client-B_zxQOo5.mjs";
|
|
3
|
+
import { a as inspectDaemon, c as stopDaemon, i as createNodeDaemonDriver, n as resolveDaemonPaths, o as restartDaemon, r as readPackageVersion, s as startDaemon, t as connectLocalBroker } from "./local-broker-CEIHPBcK.mjs";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { existsSync, realpathSync } from "node:fs";
|
|
7
|
-
import {
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
8
|
//#region src/smoke/daemon-lynx.ts
|
|
9
9
|
const menuLabels$1 = new Map([
|
|
10
|
-
[1, "
|
|
11
|
-
[2, "
|
|
12
|
-
[3, "Hide Window"],
|
|
10
|
+
[1, "Reload Bundle"],
|
|
11
|
+
[2, "Hide Window"],
|
|
13
12
|
[99, "Quit Smoke"]
|
|
14
13
|
]);
|
|
15
14
|
const DEFAULT_LYNX_BUNDLE_ENV = "OPENTRAY_LYNX_BUNDLE";
|
|
16
|
-
const DEFAULT_REVIEW_BUNDLE_RELATIVE_PATH = "assets/lynx-review/main.lynx.bundle";
|
|
17
15
|
const runDaemonLynxSmoke = async (options = {}) => {
|
|
18
16
|
const bundlePath = resolveLynxBundlePath(options.bundlePath);
|
|
19
17
|
const connection = await connectLocalBroker();
|
|
@@ -37,16 +35,11 @@ const runDaemonLynxSmoke = async (options = {}) => {
|
|
|
37
35
|
{
|
|
38
36
|
type: "item",
|
|
39
37
|
id: 1,
|
|
40
|
-
title: "
|
|
38
|
+
title: "Reload Bundle"
|
|
41
39
|
},
|
|
42
40
|
{
|
|
43
41
|
type: "item",
|
|
44
42
|
id: 2,
|
|
45
|
-
title: "Show Fixed Window"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: "item",
|
|
49
|
-
id: 3,
|
|
50
43
|
title: "Hide Window"
|
|
51
44
|
},
|
|
52
45
|
{ type: "separator" },
|
|
@@ -69,21 +62,12 @@ const runDaemonLynxSmoke = async (options = {}) => {
|
|
|
69
62
|
let closed = false;
|
|
70
63
|
let exitTimer;
|
|
71
64
|
let resolveClosed;
|
|
72
|
-
const show = async (
|
|
65
|
+
const show = async () => {
|
|
73
66
|
await tray.commandExtension("lynx", {
|
|
74
67
|
type: "show",
|
|
75
|
-
bundlePath
|
|
76
|
-
fitContentSize: mode === "fit",
|
|
77
|
-
width: mode === "fixed" ? 720 : void 0,
|
|
78
|
-
height: mode === "fixed" ? 420 : void 0,
|
|
79
|
-
minWidth: 320,
|
|
80
|
-
minHeight: 220,
|
|
81
|
-
maxWidth: 960,
|
|
82
|
-
maxHeight: 720,
|
|
83
|
-
nativeWindowApi: true,
|
|
84
|
-
bindWindowGlobals: true
|
|
68
|
+
bundlePath
|
|
85
69
|
});
|
|
86
|
-
console.log(`lynx command: show
|
|
70
|
+
console.log(`lynx command: show bundle=${bundlePath}`);
|
|
87
71
|
};
|
|
88
72
|
const hide = async () => {
|
|
89
73
|
await tray.commandExtension("lynx", { type: "hide" });
|
|
@@ -106,12 +90,9 @@ const runDaemonLynxSmoke = async (options = {}) => {
|
|
|
106
90
|
const handleMenuClick = async (itemId) => {
|
|
107
91
|
switch (itemId) {
|
|
108
92
|
case 1:
|
|
109
|
-
await show(
|
|
93
|
+
await show();
|
|
110
94
|
return;
|
|
111
95
|
case 2:
|
|
112
|
-
await show("fixed");
|
|
113
|
-
return;
|
|
114
|
-
case 3:
|
|
115
96
|
await hide();
|
|
116
97
|
return;
|
|
117
98
|
case 99:
|
|
@@ -143,8 +124,8 @@ const runDaemonLynxSmoke = async (options = {}) => {
|
|
|
143
124
|
}, duration);
|
|
144
125
|
}
|
|
145
126
|
try {
|
|
146
|
-
await show(
|
|
147
|
-
console.log("use the tray menu to
|
|
127
|
+
await show();
|
|
128
|
+
console.log("use the tray menu to reload or hide the Lynx window, or press Ctrl+C to exit");
|
|
148
129
|
} catch (error) {
|
|
149
130
|
await connection.close();
|
|
150
131
|
process.off("SIGINT", onSignal);
|
|
@@ -157,24 +138,11 @@ const runDaemonLynxSmoke = async (options = {}) => {
|
|
|
157
138
|
};
|
|
158
139
|
const resolveLynxBundlePath = (value) => {
|
|
159
140
|
const resolved = value ?? process.env[DEFAULT_LYNX_BUNDLE_ENV];
|
|
160
|
-
if (resolved === void 0 || resolved.length === 0) {
|
|
161
|
-
const bundledReviewBundle = resolveBundledReviewBundlePath();
|
|
162
|
-
if (!existsSync(bundledReviewBundle)) throw new Error(`lynx smoke requires --bundle <path>, ${DEFAULT_LYNX_BUNDLE_ENV}=<path-to-main.lynx.bundle>, or a packaged review bundle at ${bundledReviewBundle}`);
|
|
163
|
-
return realpathSync(bundledReviewBundle);
|
|
164
|
-
}
|
|
141
|
+
if (resolved === void 0 || resolved.length === 0) throw new Error(`lynx smoke requires --bundle <path> or ${DEFAULT_LYNX_BUNDLE_ENV}=<path-to-main.lynx.bundle>`);
|
|
165
142
|
const absolutePath = resolve(process.env.INIT_CWD ?? process.cwd(), resolved);
|
|
166
143
|
if (!existsSync(absolutePath)) throw new Error(`lynx smoke bundle does not exist: ${absolutePath}`);
|
|
167
144
|
return realpathSync(absolutePath);
|
|
168
145
|
};
|
|
169
|
-
const resolveBundledReviewBundlePath = (moduleUrl = import.meta.url) => {
|
|
170
|
-
let currentDir = dirname(fileURLToPath(moduleUrl));
|
|
171
|
-
while (true) {
|
|
172
|
-
if (existsSync(join(currentDir, "package.json"))) return join(currentDir, DEFAULT_REVIEW_BUNDLE_RELATIVE_PATH);
|
|
173
|
-
const parent = dirname(currentDir);
|
|
174
|
-
if (parent === currentDir) throw new Error(`failed to resolve opentray package root from ${moduleUrl}`);
|
|
175
|
-
currentDir = parent;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
146
|
function createVisibleIcon$1() {
|
|
179
147
|
const width = 32;
|
|
180
148
|
const height = 32;
|
|
@@ -194,20 +162,7 @@ function createVisibleIcon$1() {
|
|
|
194
162
|
}
|
|
195
163
|
//#endregion
|
|
196
164
|
//#region src/smoke/daemon-tray.ts
|
|
197
|
-
const menuLabels = new Map([
|
|
198
|
-
[1, "Primary Action"],
|
|
199
|
-
[3, "Checked Capability"],
|
|
200
|
-
[4, "Radio: Active"],
|
|
201
|
-
[5, "Radio: Passive"],
|
|
202
|
-
[6, "Nested Action"],
|
|
203
|
-
[7, "Nested Check"],
|
|
204
|
-
[8, "WebView: Show HTML"],
|
|
205
|
-
[9, "WebView: Navigate"],
|
|
206
|
-
[10, "WebView: Post Message"],
|
|
207
|
-
[11, "WebView: Evaluate"],
|
|
208
|
-
[12, "WebView: Hide"],
|
|
209
|
-
[99, "Quit Demo"]
|
|
210
|
-
]);
|
|
165
|
+
const menuLabels = new Map([[1, "Open WebView"]]);
|
|
211
166
|
const runDaemonTraySmoke = async () => {
|
|
212
167
|
const connection = await connectLocalBroker();
|
|
213
168
|
const client = createClient(connection, { requestIdPrefix: "daemon-smoke" });
|
|
@@ -223,93 +178,15 @@ const runDaemonTraySmoke = async () => {
|
|
|
223
178
|
title: "OpenTray",
|
|
224
179
|
tooltip: {
|
|
225
180
|
title: "OpenTray",
|
|
226
|
-
description: "
|
|
181
|
+
description: "Single primary tray action; macOS direct-triggers without opening a menu"
|
|
227
182
|
},
|
|
228
183
|
icon: createVisibleIcon(),
|
|
229
|
-
menu: { items: [
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
{
|
|
236
|
-
type: "item",
|
|
237
|
-
id: 2,
|
|
238
|
-
title: "Disabled Action",
|
|
239
|
-
enabled: false
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
type: "check",
|
|
243
|
-
id: 3,
|
|
244
|
-
title: "Checked Capability",
|
|
245
|
-
checked: true
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
type: "radio",
|
|
249
|
-
id: 4,
|
|
250
|
-
title: "Radio: Active",
|
|
251
|
-
group: 1,
|
|
252
|
-
checked: true
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
type: "radio",
|
|
256
|
-
id: 5,
|
|
257
|
-
title: "Radio: Passive",
|
|
258
|
-
group: 1
|
|
259
|
-
},
|
|
260
|
-
{ type: "separator" },
|
|
261
|
-
{
|
|
262
|
-
type: "submenu",
|
|
263
|
-
title: "Nested Actions",
|
|
264
|
-
items: [{
|
|
265
|
-
type: "item",
|
|
266
|
-
id: 6,
|
|
267
|
-
title: "Nested Action"
|
|
268
|
-
}, {
|
|
269
|
-
type: "check",
|
|
270
|
-
id: 7,
|
|
271
|
-
title: "Nested Check",
|
|
272
|
-
checked: false
|
|
273
|
-
}]
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
type: "submenu",
|
|
277
|
-
title: "WebView Commands",
|
|
278
|
-
items: [
|
|
279
|
-
{
|
|
280
|
-
type: "item",
|
|
281
|
-
id: 8,
|
|
282
|
-
title: "Show HTML"
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
type: "item",
|
|
286
|
-
id: 9,
|
|
287
|
-
title: "Navigate"
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
type: "item",
|
|
291
|
-
id: 10,
|
|
292
|
-
title: "Post Message"
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
type: "item",
|
|
296
|
-
id: 11,
|
|
297
|
-
title: "Evaluate JS"
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
type: "item",
|
|
301
|
-
id: 12,
|
|
302
|
-
title: "Hide"
|
|
303
|
-
}
|
|
304
|
-
]
|
|
305
|
-
},
|
|
306
|
-
{ type: "separator" },
|
|
307
|
-
{
|
|
308
|
-
type: "item",
|
|
309
|
-
id: 99,
|
|
310
|
-
title: "Quit Demo"
|
|
311
|
-
}
|
|
312
|
-
] }
|
|
184
|
+
menu: { items: [{
|
|
185
|
+
type: "item",
|
|
186
|
+
id: 1,
|
|
187
|
+
title: "Open WebView",
|
|
188
|
+
primaryEvent: true
|
|
189
|
+
}] }
|
|
313
190
|
});
|
|
314
191
|
console.log(`tray: ${tray.trayId}`);
|
|
315
192
|
await connection.request({
|
|
@@ -320,10 +197,8 @@ const runDaemonTraySmoke = async () => {
|
|
|
320
197
|
path: "@opentray/ext-webview"
|
|
321
198
|
});
|
|
322
199
|
console.log("webview extension requested through the generic load-ext path");
|
|
323
|
-
console.log("
|
|
200
|
+
console.log("click the tray icon: macOS should direct-trigger the single primary action without opening a menu");
|
|
324
201
|
let closed = false;
|
|
325
|
-
let messageCount = 0;
|
|
326
|
-
let evalCount = 0;
|
|
327
202
|
let exitTimer;
|
|
328
203
|
const shutdown = async () => {
|
|
329
204
|
if (closed) return;
|
|
@@ -335,63 +210,56 @@ const runDaemonTraySmoke = async () => {
|
|
|
335
210
|
await tray.commandExtension("webview", command);
|
|
336
211
|
};
|
|
337
212
|
const handleMenuClick = async (itemId) => {
|
|
338
|
-
if (itemId ===
|
|
339
|
-
|
|
340
|
-
|
|
213
|
+
if (itemId === 1) {
|
|
214
|
+
const trayBounds = await tray.getBounds();
|
|
215
|
+
console.log(`tray bounds: ${JSON.stringify(trayBounds)}`);
|
|
216
|
+
await commandWebview({
|
|
217
|
+
type: "show",
|
|
218
|
+
html: createWebviewDemoHtml(),
|
|
219
|
+
width: 420,
|
|
220
|
+
height: 260,
|
|
221
|
+
title: "OpenTray WebView Smoke",
|
|
222
|
+
icon: {
|
|
223
|
+
type: "href",
|
|
224
|
+
href: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII="
|
|
225
|
+
},
|
|
226
|
+
style: {
|
|
227
|
+
frameless: true,
|
|
228
|
+
transparent: true,
|
|
229
|
+
keepOnTop: true,
|
|
230
|
+
platform: { macos: {
|
|
231
|
+
material: "hudWindow",
|
|
232
|
+
materialState: "active"
|
|
233
|
+
} }
|
|
234
|
+
},
|
|
235
|
+
fallbackRect: trayBounds.rect ?? {
|
|
236
|
+
x: 0,
|
|
237
|
+
y: 0,
|
|
238
|
+
width: 1,
|
|
239
|
+
height: 1
|
|
240
|
+
},
|
|
241
|
+
nativeWindowApi: true,
|
|
242
|
+
bindWindowGlobals: true,
|
|
243
|
+
nativeScreenApi: true,
|
|
244
|
+
bindScreenGlobals: true,
|
|
245
|
+
nativeTrayApi: true,
|
|
246
|
+
titleSync: {
|
|
247
|
+
documentToWindow: true,
|
|
248
|
+
windowToDocument: true
|
|
249
|
+
},
|
|
250
|
+
iconSync: true,
|
|
251
|
+
nativeApiPolicy: {
|
|
252
|
+
defaultSrc: ["'local'"],
|
|
253
|
+
window: ["https://example.com"],
|
|
254
|
+
screen: ["https://example.com"],
|
|
255
|
+
tray: ["https://example.com"],
|
|
256
|
+
titleSync: ["https://example.com"],
|
|
257
|
+
iconSync: ["https://example.com"]
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
console.log("primary tray action: webview show");
|
|
341
261
|
return;
|
|
342
262
|
}
|
|
343
|
-
if (itemId < 8 || itemId > 12) return;
|
|
344
|
-
switch (itemId) {
|
|
345
|
-
case 8:
|
|
346
|
-
await commandWebview({
|
|
347
|
-
type: "show",
|
|
348
|
-
html: createWebviewDemoHtml(),
|
|
349
|
-
width: 420,
|
|
350
|
-
height: 260,
|
|
351
|
-
fallbackRect: {
|
|
352
|
-
x: 0,
|
|
353
|
-
y: 0,
|
|
354
|
-
width: 1,
|
|
355
|
-
height: 1
|
|
356
|
-
},
|
|
357
|
-
nativeWindowApi: true,
|
|
358
|
-
bindWindowGlobals: true
|
|
359
|
-
});
|
|
360
|
-
console.log("webview command: show");
|
|
361
|
-
break;
|
|
362
|
-
case 9:
|
|
363
|
-
await commandWebview({
|
|
364
|
-
type: "navigate",
|
|
365
|
-
url: "https://example.com/opentray-status"
|
|
366
|
-
});
|
|
367
|
-
console.log("webview command: navigate");
|
|
368
|
-
break;
|
|
369
|
-
case 10:
|
|
370
|
-
messageCount += 1;
|
|
371
|
-
await commandWebview({
|
|
372
|
-
type: "postMessage",
|
|
373
|
-
payload: {
|
|
374
|
-
kind: "ping",
|
|
375
|
-
source: "opentray smoke daemon-tray",
|
|
376
|
-
count: messageCount,
|
|
377
|
-
sentAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
console.log("webview command: postMessage");
|
|
381
|
-
break;
|
|
382
|
-
case 11:
|
|
383
|
-
evalCount += 1;
|
|
384
|
-
await commandWebview({
|
|
385
|
-
type: "evaluate",
|
|
386
|
-
js: createVisibleEvaluateScript(evalCount)
|
|
387
|
-
});
|
|
388
|
-
console.log("webview command: evaluate");
|
|
389
|
-
break;
|
|
390
|
-
case 12:
|
|
391
|
-
await commandWebview({ type: "hide" });
|
|
392
|
-
console.log("webview command: hide");
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
263
|
};
|
|
396
264
|
connection.onEvent((frame) => {
|
|
397
265
|
console.log(`broker -> client ${JSON.stringify(frame)}`);
|
|
@@ -409,19 +277,12 @@ const runDaemonTraySmoke = async () => {
|
|
|
409
277
|
}
|
|
410
278
|
const webviewSmoke = process.env.OPENTRAY_EXAMPLE_WEBVIEW_SMOKE;
|
|
411
279
|
try {
|
|
412
|
-
if (webviewSmoke === "show") await handleMenuClick(
|
|
413
|
-
|
|
280
|
+
if (webviewSmoke === "show" || webviewSmoke === "1") await handleMenuClick(1);
|
|
281
|
+
if (webviewSmoke === "1") {
|
|
414
282
|
if (exitTimer !== void 0) {
|
|
415
283
|
clearTimeout(exitTimer);
|
|
416
284
|
exitTimer = void 0;
|
|
417
285
|
}
|
|
418
|
-
for (const itemId of [
|
|
419
|
-
8,
|
|
420
|
-
10,
|
|
421
|
-
11,
|
|
422
|
-
9,
|
|
423
|
-
12
|
|
424
|
-
]) await handleMenuClick(itemId);
|
|
425
286
|
await sleep(300);
|
|
426
287
|
await shutdown();
|
|
427
288
|
}
|
|
@@ -510,47 +371,17 @@ function createWebviewDemoHtml() {
|
|
|
510
371
|
<body>
|
|
511
372
|
<main>
|
|
512
373
|
<h1>OpenTray WebView</h1>
|
|
513
|
-
<p>
|
|
374
|
+
<p>This window was opened by the single primary tray action.</p>
|
|
514
375
|
<section>
|
|
515
376
|
<div class="card">
|
|
516
|
-
<div class="label">
|
|
517
|
-
<code
|
|
518
|
-
</div>
|
|
519
|
-
<div class="card">
|
|
520
|
-
<div class="label">evaluate JS</div>
|
|
521
|
-
<code id="eval-status">Waiting for WebView Commands -> Evaluate JS</code>
|
|
377
|
+
<div class="label">primary event</div>
|
|
378
|
+
<code>macOS single primary item direct-triggered menuClick -> WebView show</code>
|
|
522
379
|
</div>
|
|
523
380
|
</section>
|
|
524
381
|
</main>
|
|
525
|
-
<script>
|
|
526
|
-
window.addEventListener("message", (event) => {
|
|
527
|
-
const target = document.getElementById("message-status");
|
|
528
|
-
if (target) {
|
|
529
|
-
target.textContent = JSON.stringify(event.data, null, 2);
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
<\/script>
|
|
533
382
|
</body>
|
|
534
383
|
</html>`;
|
|
535
384
|
}
|
|
536
|
-
function createVisibleEvaluateScript(count) {
|
|
537
|
-
return `(() => {
|
|
538
|
-
let target = document.getElementById("eval-status");
|
|
539
|
-
if (!target) {
|
|
540
|
-
const panel = document.createElement("div");
|
|
541
|
-
panel.style.cssText = "position:fixed;left:16px;right:16px;bottom:16px;z-index:2147483647;padding:12px;border-radius:12px;background:#fff8e7;color:#18220f;box-shadow:0 12px 30px rgba(0,0,0,.18);font:14px ui-rounded, sans-serif;";
|
|
542
|
-
panel.textContent = "OpenTray Evaluate JS: ";
|
|
543
|
-
target = document.createElement("code");
|
|
544
|
-
target.id = "eval-status";
|
|
545
|
-
panel.appendChild(target);
|
|
546
|
-
document.body.appendChild(panel);
|
|
547
|
-
}
|
|
548
|
-
if (target) {
|
|
549
|
-
target.textContent = "Evaluate JS updated the WebView, count=${count}, at " + new Date().toLocaleTimeString();
|
|
550
|
-
}
|
|
551
|
-
window.__OPENTRAY_DEMO__ = { evaluated: true, count: ${count} };
|
|
552
|
-
})();`;
|
|
553
|
-
}
|
|
554
385
|
function sleep(ms) {
|
|
555
386
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
556
387
|
}
|
|
@@ -657,8 +488,7 @@ const runCli = async (argv) => {
|
|
|
657
488
|
const printHelp = () => {
|
|
658
489
|
console.error("Usage: opentray daemon <start|stop|restart|health>");
|
|
659
490
|
console.error(" opentray smoke daemon-tray");
|
|
660
|
-
console.error(" opentray smoke daemon-lynx
|
|
661
|
-
console.error(" default Lynx smoke uses the packaged review bundle");
|
|
491
|
+
console.error(" opentray smoke daemon-lynx --bundle <path-to-main.lynx.bundle>");
|
|
662
492
|
};
|
|
663
493
|
const formatDaemonHealthOutput = (health) => {
|
|
664
494
|
const lines = [
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":["menuLabels","createVisibleIcon"],"sources":["../src/smoke/daemon-lynx.ts","../src/smoke/daemon-tray.ts","../src/cli.ts"],"sourcesContent":["import { existsSync, realpathSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { createClient } from \"../client\";\nimport { connectLocalBroker } from \"../local-broker\";\n\nconst menuLabels = new Map<number, string>([\n [1, \"Show Fit Window\"],\n [2, \"Show Fixed Window\"],\n [3, \"Hide Window\"],\n [99, \"Quit Smoke\"],\n]);\n\nconst DEFAULT_LYNX_BUNDLE_ENV = \"OPENTRAY_LYNX_BUNDLE\";\nconst DEFAULT_REVIEW_BUNDLE_RELATIVE_PATH =\n \"assets/lynx-review/main.lynx.bundle\";\n\nexport interface DaemonLynxSmokeOptions {\n bundlePath?: string;\n}\n\nexport const runDaemonLynxSmoke = async (\n options: DaemonLynxSmokeOptions = {}\n): Promise<void> => {\n const bundlePath = resolveLynxBundlePath(options.bundlePath);\n const connection = await connectLocalBroker();\n const client = createClient(connection, { requestIdPrefix: \"daemon-lynx\" });\n console.log(\n `connected: endpoint=${connection.endpoint} session=${connection.sessionId}`\n );\n\n const space = await client.createSpace({\n id: \"com.example.opentray.daemon-lynx\",\n title: \"OpenTray Lynx Smoke\",\n default: true,\n });\n console.log(`space: ${JSON.stringify(space.space)}`);\n\n const tray = await space.createTray({\n trayId: \"daemon-lynx-status\",\n title: \"OpenTray Lynx\",\n tooltip: {\n title: \"OpenTray Lynx\",\n description: \"Generic extension smoke for a real Lynx runtime window\",\n },\n icon: createVisibleIcon(),\n menu: {\n items: [\n { type: \"item\", id: 1, title: \"Show Fit Window\" },\n { type: \"item\", id: 2, title: \"Show Fixed Window\" },\n { type: \"item\", id: 3, title: \"Hide Window\" },\n { type: \"separator\" },\n { type: \"item\", id: 99, title: \"Quit Smoke\" },\n ],\n },\n });\n console.log(`tray: ${tray.trayId}`);\n\n await connection.request({\n type: \"load-ext\",\n requestId: \"daemon-lynx-load\",\n spaceId: space.space.spaceId,\n name: \"lynx\",\n path: \"@opentray/ext-lynx\",\n });\n console.log(\"lynx extension requested through the generic load-ext path\");\n\n let closed = false;\n let exitTimer: NodeJS.Timeout | undefined;\n let resolveClosed: (() => void) | undefined;\n\n const show = async (mode: \"fit\" | \"fixed\"): Promise<void> => {\n await tray.commandExtension(\"lynx\", {\n type: \"show\",\n bundlePath,\n fitContentSize: mode === \"fit\",\n width: mode === \"fixed\" ? 720 : undefined,\n height: mode === \"fixed\" ? 420 : undefined,\n minWidth: 320,\n minHeight: 220,\n maxWidth: 960,\n maxHeight: 720,\n nativeWindowApi: true,\n bindWindowGlobals: true,\n });\n console.log(`lynx command: show mode=${mode} bundle=${bundlePath}`);\n };\n\n const hide = async (): Promise<void> => {\n await tray.commandExtension(\"lynx\", { type: \"hide\" });\n console.log(\"lynx command: hide\");\n };\n\n const shutdown = async (): Promise<void> => {\n if (closed) {\n return;\n }\n closed = true;\n if (exitTimer !== undefined) {\n clearTimeout(exitTimer);\n }\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n try {\n await hide();\n } catch (error) {\n console.error(`lynx hide during shutdown failed: ${String(error)}`);\n }\n await connection.close();\n resolveClosed?.();\n };\n\n const handleMenuClick = async (itemId: number): Promise<void> => {\n switch (itemId) {\n case 1:\n await show(\"fit\");\n return;\n case 2:\n await show(\"fixed\");\n return;\n case 3:\n await hide();\n return;\n case 99:\n console.log(\"quit item routed; closing lynx smoke connection\");\n await shutdown();\n return;\n default:\n return;\n }\n };\n\n connection.onEvent((frame) => {\n console.log(`broker -> client ${JSON.stringify(frame)}`);\n if (frame.type === \"event\" && frame.event.type === \"menuClick\") {\n console.log(\n `menu click: ${\n menuLabels.get(frame.event.itemId) ?? frame.event.itemId\n }`\n );\n void handleMenuClick(frame.event.itemId);\n return;\n }\n if (frame.type === \"ext-event\" && frame.ext === \"lynx\") {\n console.log(`lynx event: ${JSON.stringify(frame.data)}`);\n }\n });\n\n const onSignal = (): void => {\n void shutdown();\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n\n const exitAfter = process.env.OPENTRAY_EXAMPLE_EXIT_AFTER_MS;\n if (exitAfter !== undefined && exitAfter.length > 0) {\n const duration = Number.parseInt(exitAfter, 10);\n if (Number.isInteger(duration) && duration > 0) {\n exitTimer = setTimeout(() => {\n void shutdown();\n }, duration);\n }\n }\n\n try {\n await show(\"fit\");\n console.log(\n \"use the tray menu to switch between fit-content and fixed sizing, or press Ctrl+C to exit\"\n );\n } catch (error) {\n await connection.close();\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n throw error;\n }\n\n await new Promise<void>((resolve) => {\n resolveClosed = resolve;\n });\n};\n\nexport const resolveLynxBundlePath = (value?: string): string => {\n const resolved = value ?? process.env[DEFAULT_LYNX_BUNDLE_ENV];\n if (resolved === undefined || resolved.length === 0) {\n const bundledReviewBundle = resolveBundledReviewBundlePath();\n if (!existsSync(bundledReviewBundle)) {\n throw new Error(\n `lynx smoke requires --bundle <path>, ${DEFAULT_LYNX_BUNDLE_ENV}=<path-to-main.lynx.bundle>, or a packaged review bundle at ${bundledReviewBundle}`\n );\n }\n return realpathSync(bundledReviewBundle);\n }\n const baseDir = process.env.INIT_CWD ?? process.cwd();\n const absolutePath = resolve(baseDir, resolved);\n if (!existsSync(absolutePath)) {\n throw new Error(`lynx smoke bundle does not exist: ${absolutePath}`);\n }\n return realpathSync(absolutePath);\n};\n\nexport const resolveBundledReviewBundlePath = (\n moduleUrl = import.meta.url\n): string => {\n let currentDir = dirname(fileURLToPath(moduleUrl));\n\n while (true) {\n const packageJson = join(currentDir, \"package.json\");\n if (existsSync(packageJson)) {\n return join(currentDir, DEFAULT_REVIEW_BUNDLE_RELATIVE_PATH);\n }\n\n const parent = dirname(currentDir);\n if (parent === currentDir) {\n throw new Error(\n `failed to resolve opentray package root from ${moduleUrl}`\n );\n }\n currentDir = parent;\n }\n};\n\nfunction createVisibleIcon(): {\n type: \"rgba\";\n width: number;\n height: number;\n data: number[];\n} {\n const width = 32;\n const height = 32;\n const data: number[] = [];\n\n for (let y = 0; y < height; y += 1) {\n for (let x = 0; x < width; x += 1) {\n const inStroke = x <= 5 || (x >= 13 && x <= 18) || y >= 26;\n const inDiagonal = y >= x + 10 && x <= 18;\n const alpha = inStroke || inDiagonal ? 255 : 0;\n data.push(34, 92, 56, alpha);\n }\n }\n\n return { type: \"rgba\", width, height, data };\n}\n","import type { Rect } from \"@opentray/spec\";\n\nimport { createClient } from \"../client\";\nimport { connectLocalBroker } from \"../local-broker\";\n\nconst menuLabels = new Map<number, string>([\n [1, \"Primary Action\"],\n [3, \"Checked Capability\"],\n [4, \"Radio: Active\"],\n [5, \"Radio: Passive\"],\n [6, \"Nested Action\"],\n [7, \"Nested Check\"],\n [8, \"WebView: Show HTML\"],\n [9, \"WebView: Navigate\"],\n [10, \"WebView: Post Message\"],\n [11, \"WebView: Evaluate\"],\n [12, \"WebView: Hide\"],\n [99, \"Quit Demo\"],\n]);\n\ninterface WebviewShowCommand {\n type: \"show\";\n html?: string;\n url?: string;\n width?: number;\n height?: number;\n fallbackRect?: Rect;\n nativeWindowApi?: boolean;\n bindWindowGlobals?: boolean;\n}\n\nexport const runDaemonTraySmoke = async (): Promise<void> => {\n const connection = await connectLocalBroker();\n const client = createClient(connection, { requestIdPrefix: \"daemon-smoke\" });\n console.log(`connected: endpoint=${connection.endpoint} session=${connection.sessionId}`);\n\n const space = await client.createSpace({\n id: \"com.example.opentray.daemon-smoke\",\n title: \"OpenTray Daemon Smoke\",\n default: true,\n });\n console.log(`space: ${JSON.stringify(space.space)}`);\n\n const tray = await space.createTray({\n trayId: \"daemon-smoke-status\",\n title: \"OpenTray\",\n tooltip: {\n title: \"OpenTray\",\n description: \"npm-installed daemon smoke with broker-routed menu events\",\n },\n icon: createVisibleIcon(),\n menu: {\n items: [\n { type: \"item\", id: 1, title: \"Primary Action\" },\n { type: \"item\", id: 2, title: \"Disabled Action\", enabled: false },\n { type: \"check\", id: 3, title: \"Checked Capability\", checked: true },\n { type: \"radio\", id: 4, title: \"Radio: Active\", group: 1, checked: true },\n { type: \"radio\", id: 5, title: \"Radio: Passive\", group: 1 },\n { type: \"separator\" },\n {\n type: \"submenu\",\n title: \"Nested Actions\",\n items: [\n { type: \"item\", id: 6, title: \"Nested Action\" },\n { type: \"check\", id: 7, title: \"Nested Check\", checked: false },\n ],\n },\n {\n type: \"submenu\",\n title: \"WebView Commands\",\n items: [\n { type: \"item\", id: 8, title: \"Show HTML\" },\n { type: \"item\", id: 9, title: \"Navigate\" },\n { type: \"item\", id: 10, title: \"Post Message\" },\n { type: \"item\", id: 11, title: \"Evaluate JS\" },\n { type: \"item\", id: 12, title: \"Hide\" },\n ],\n },\n { type: \"separator\" },\n { type: \"item\", id: 99, title: \"Quit Demo\" },\n ],\n },\n });\n console.log(`tray: ${tray.trayId}`);\n\n await connection.request({\n type: \"load-ext\",\n requestId: \"daemon-smoke-load-webview\",\n spaceId: space.space.spaceId,\n name: \"webview\",\n path: \"@opentray/ext-webview\",\n });\n console.log(\"webview extension requested through the generic load-ext path\");\n console.log(\"open the system tray item and choose any enabled menu item to see routed events\");\n\n let closed = false;\n let messageCount = 0;\n let evalCount = 0;\n let exitTimer: NodeJS.Timeout | undefined;\n\n const shutdown = async (): Promise<void> => {\n if (closed) {\n return;\n }\n closed = true;\n if (exitTimer !== undefined) {\n clearTimeout(exitTimer);\n }\n await connection.close();\n };\n\n const commandWebview = async (command: WebviewShowCommand | Record<string, unknown>): Promise<void> => {\n await tray.commandExtension(\"webview\", command);\n };\n\n const handleMenuClick = async (itemId: number): Promise<void> => {\n if (itemId === 99) {\n console.log(\"quit item routed; closing smoke connection\");\n await shutdown();\n return;\n }\n\n if (itemId < 8 || itemId > 12) {\n return;\n }\n\n switch (itemId) {\n case 8:\n await commandWebview({\n type: \"show\",\n html: createWebviewDemoHtml(),\n width: 420,\n height: 260,\n fallbackRect: { x: 0, y: 0, width: 1, height: 1 },\n nativeWindowApi: true,\n bindWindowGlobals: true,\n });\n console.log(\"webview command: show\");\n break;\n case 9:\n await commandWebview({ type: \"navigate\", url: \"https://example.com/opentray-status\" });\n console.log(\"webview command: navigate\");\n break;\n case 10:\n messageCount += 1;\n await commandWebview({\n type: \"postMessage\",\n payload: {\n kind: \"ping\",\n source: \"opentray smoke daemon-tray\",\n count: messageCount,\n sentAt: new Date().toISOString(),\n },\n });\n console.log(\"webview command: postMessage\");\n break;\n case 11:\n evalCount += 1;\n await commandWebview({ type: \"evaluate\", js: createVisibleEvaluateScript(evalCount) });\n console.log(\"webview command: evaluate\");\n break;\n case 12:\n await commandWebview({ type: \"hide\" });\n console.log(\"webview command: hide\");\n break;\n }\n };\n\n connection.onEvent((frame) => {\n console.log(`broker -> client ${JSON.stringify(frame)}`);\n if (frame.type === \"event\" && frame.event.type === \"menuClick\") {\n console.log(`menu click: ${menuLabels.get(frame.event.itemId) ?? frame.event.itemId}`);\n void handleMenuClick(frame.event.itemId);\n }\n });\n\n const exitAfter = process.env.OPENTRAY_EXAMPLE_EXIT_AFTER_MS;\n if (exitAfter !== undefined && exitAfter.length > 0) {\n const duration = Number.parseInt(exitAfter, 10);\n if (Number.isInteger(duration) && duration > 0) {\n exitTimer = setTimeout(() => {\n void shutdown();\n }, duration);\n }\n }\n\n const webviewSmoke = process.env.OPENTRAY_EXAMPLE_WEBVIEW_SMOKE;\n try {\n if (webviewSmoke === \"show\") {\n await handleMenuClick(8);\n } else if (webviewSmoke === \"1\") {\n if (exitTimer !== undefined) {\n clearTimeout(exitTimer);\n exitTimer = undefined;\n }\n for (const itemId of [8, 10, 11, 9, 12]) {\n await handleMenuClick(itemId);\n }\n await sleep(300);\n await shutdown();\n }\n } catch (error) {\n await shutdown();\n throw error;\n }\n};\n\nfunction createVisibleIcon(): { type: \"rgba\"; width: number; height: number; data: number[] } {\n const width = 32;\n const height = 32;\n const data: number[] = [];\n\n for (let y = 0; y < height; y += 1) {\n for (let x = 0; x < width; x += 1) {\n const dx = x - 15.5;\n const dy = y - 15.5;\n const distance = Math.sqrt(dx * dx + dy * dy);\n const inRing = distance >= 9 && distance <= 14;\n const inCore = distance <= 5;\n const inNeedle = Math.abs(dx + dy) <= 1.2 && x >= 9 && x <= 23 && y >= 9 && y <= 23;\n\n if (inRing || inCore || inNeedle) {\n data.push(inCore ? 255 : 24, inNeedle ? 240 : 132, inRing ? 72 : 96, 255);\n } else {\n data.push(0, 0, 0, 0);\n }\n }\n }\n\n return { type: \"rgba\", width, height, data };\n}\n\nfunction createWebviewDemoHtml(): string {\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <title>OpenTray WebView</title>\n <style>\n :root {\n color: #18220f;\n background: #f6edd8;\n font: 15px ui-rounded, \"SF Pro Rounded\", \"Avenir Next\", sans-serif;\n }\n body {\n margin: 0;\n }\n main {\n min-height: 100vh;\n box-sizing: border-box;\n padding: 22px;\n background:\n radial-gradient(circle at 84% 10%, rgba(34, 132, 96, 0.22), transparent 34%),\n linear-gradient(135deg, #fff8e7 0%, #e9f0d8 100%);\n }\n h1 {\n margin: 0 0 8px;\n font-size: 24px;\n letter-spacing: -0.04em;\n }\n p {\n margin: 0 0 16px;\n color: #526044;\n }\n section {\n display: grid;\n gap: 10px;\n }\n .card {\n border: 1px solid rgba(24, 34, 15, 0.16);\n border-radius: 14px;\n padding: 12px;\n background: rgba(255, 255, 255, 0.72);\n box-shadow: 0 12px 30px rgba(56, 72, 36, 0.12);\n }\n .label {\n margin-bottom: 5px;\n color: #7b5b1d;\n font-size: 12px;\n font-weight: 700;\n letter-spacing: 0.08em;\n text-transform: uppercase;\n }\n code {\n word-break: break-word;\n }\n </style>\n </head>\n <body>\n <main>\n <h1>OpenTray WebView</h1>\n <p>Use the tray menu to mutate this native WebView through extension commands.</p>\n <section>\n <div class=\"card\">\n <div class=\"label\">postMessage</div>\n <code id=\"message-status\">Waiting for WebView Commands -> Post Message</code>\n </div>\n <div class=\"card\">\n <div class=\"label\">evaluate JS</div>\n <code id=\"eval-status\">Waiting for WebView Commands -> Evaluate JS</code>\n </div>\n </section>\n </main>\n <script>\n window.addEventListener(\"message\", (event) => {\n const target = document.getElementById(\"message-status\");\n if (target) {\n target.textContent = JSON.stringify(event.data, null, 2);\n }\n });\n </script>\n </body>\n</html>`;\n}\n\nfunction createVisibleEvaluateScript(count: number): string {\n return `(() => {\n let target = document.getElementById(\"eval-status\");\n if (!target) {\n const panel = document.createElement(\"div\");\n panel.style.cssText = \"position:fixed;left:16px;right:16px;bottom:16px;z-index:2147483647;padding:12px;border-radius:12px;background:#fff8e7;color:#18220f;box-shadow:0 12px 30px rgba(0,0,0,.18);font:14px ui-rounded, sans-serif;\";\n panel.textContent = \"OpenTray Evaluate JS: \";\n target = document.createElement(\"code\");\n target.id = \"eval-status\";\n panel.appendChild(target);\n document.body.appendChild(panel);\n }\n if (target) {\n target.textContent = \"Evaluate JS updated the WebView, count=${count}, at \" + new Date().toLocaleTimeString();\n }\n window.__OPENTRAY_DEMO__ = { evaluated: true, count: ${count} };\n })();`;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","#!/usr/bin/env node\nimport { realpathSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { DaemonHealth } from \"@opentray/spec\";\n\nimport {\n createNodeDaemonDriver,\n inspectDaemon,\n restartDaemon,\n startDaemon,\n stopDaemon,\n} from \"./daemon/lifecycle\";\nimport { readPackageVersion } from \"./daemon/package-version\";\nimport { resolveDaemonPaths } from \"./daemon/paths\";\nimport { connectLocalBroker } from \"./local-broker\";\nimport { runDaemonLynxSmoke } from \"./smoke/daemon-lynx\";\nimport { runDaemonTraySmoke } from \"./smoke/daemon-tray\";\n\nconst packageJsonUrl = new URL(\"../package.json\", import.meta.url);\nconst cliModulePath = fileURLToPath(import.meta.url);\n\ntype CliCommand =\n | { type: \"daemon\"; action: \"start\" | \"stop\" | \"restart\" | \"health\" }\n | { type: \"smoke\"; name: \"daemon-tray\" }\n | { type: \"smoke\"; name: \"daemon-lynx\"; bundlePath?: string }\n | { type: \"help\" };\n\nexport const parseCliCommand = (argv: string[]): CliCommand => {\n const [group, action, ...rest] = argv;\n if (group !== \"daemon\") {\n if (group === \"smoke\" && action === \"daemon-tray\") {\n return { type: \"smoke\", name: \"daemon-tray\" };\n }\n if (group === \"smoke\" && action === \"daemon-lynx\") {\n const bundlePath = parseSmokeBundlePath(rest);\n return bundlePath === undefined\n ? { type: \"smoke\", name: \"daemon-lynx\" }\n : { type: \"smoke\", name: \"daemon-lynx\", bundlePath };\n }\n return { type: \"help\" };\n }\n if (\n action === \"start\" ||\n action === \"stop\" ||\n action === \"restart\" ||\n action === \"health\"\n ) {\n return { type: \"daemon\", action };\n }\n\n return { type: \"help\" };\n};\n\nexport const runCli = async (argv: string[]): Promise<number> => {\n const command = parseCliCommand(argv);\n const packageVersion =\n process.env.OPENTRAY_DAEMON_PACKAGE_VERSION ??\n (await readPackageVersion(packageJsonUrl));\n const paths = resolveDaemonPaths({\n homeDir: process.env.OPENTRAY_HOME ?? homedir(),\n packageVersion,\n });\n\n if (command.type === \"help\") {\n printHelp();\n return 1;\n }\n\n if (command.type === \"smoke\") {\n if (command.name === \"daemon-tray\") {\n await runDaemonTraySmoke();\n } else {\n await runDaemonLynxSmoke(\n command.bundlePath === undefined\n ? {}\n : { bundlePath: command.bundlePath }\n );\n }\n return 0;\n }\n\n const driver = createNodeDaemonDriver(cliModulePath);\n\n if (command.action === \"start\") {\n const result = await startDaemon({ paths, driver });\n console.log(\n `opentray daemon ${result.status}: pid=${result.pid} endpoint=${result.paths.endpoint}`\n );\n return 0;\n }\n\n if (command.action === \"stop\") {\n const result = await stopDaemon({ paths, driver });\n console.log(\n result.status === \"stopped\"\n ? `opentray daemon stopped: pid=${result.pid}`\n : \"opentray daemon not running\"\n );\n return 0;\n }\n\n if (command.action === \"restart\") {\n const result = await restartDaemon({ paths, driver });\n console.log(\n `opentray daemon ${result.status}: pid=${result.pid} endpoint=${result.paths.endpoint}`\n );\n return 0;\n }\n\n if (command.action === \"health\") {\n const inspected = await inspectDaemon({ paths, driver });\n if (inspected.status === \"not-running\") {\n console.log(\"opentray daemon not running\");\n return 0;\n }\n\n const connection = await connectLocalBroker({\n autoStart: false,\n endpoint: paths.endpoint,\n homeDir: paths.homeDir,\n packageVersion,\n });\n try {\n const response = await connection.request({\n type: \"health\",\n requestId: \"opentray-daemon-health\",\n });\n if (response.type !== \"daemon-health\") {\n throw new Error(\n `expected daemon-health response, received ${response.type}`\n );\n }\n console.log(formatDaemonHealthOutput(response.health));\n } finally {\n await connection.close();\n }\n return 0;\n }\n\n printHelp();\n return 1;\n};\n\nconst printHelp = (): void => {\n console.error(\"Usage: opentray daemon <start|stop|restart|health>\");\n console.error(\" opentray smoke daemon-tray\");\n console.error(\n \" opentray smoke daemon-lynx [--bundle <path-to-main.lynx.bundle>]\"\n );\n console.error(\" default Lynx smoke uses the packaged review bundle\");\n};\n\nexport const formatDaemonHealthOutput = (health: DaemonHealth): string => {\n const lines = [\n \"opentray daemon running\",\n `pid: ${health.pid}`,\n `endpoint: ${health.endpoint}`,\n `packageVersion: ${health.packageVersion}`,\n `protocolVersion: ${health.protocolVersion}`,\n `sessions: ${health.sessionCount}`,\n ];\n\n for (const session of health.sessions) {\n const internalLease = session.internalLeaseId ?? \"(pending)\";\n lines.push(\n `- sessionId=${session.sessionId} initialized=${session.initialized} internalLeaseId=${internalLease}`\n );\n }\n\n return lines.join(\"\\n\");\n};\n\nexport const isCliEntrypoint = (\n argvEntryPath: string | undefined,\n modulePath: string\n): boolean => {\n if (argvEntryPath === undefined) return false;\n try {\n return realpathSync(argvEntryPath) === realpathSync(modulePath);\n } catch {\n return argvEntryPath === modulePath;\n }\n};\n\nfunction parseSmokeBundlePath(argv: string[]): string | undefined {\n for (let index = 0; index < argv.length; index += 1) {\n if (argv[index] === \"--bundle\") {\n return argv[index + 1];\n }\n }\n return undefined;\n}\n\nif (isCliEntrypoint(process.argv[1], cliModulePath)) {\n runCli(process.argv.slice(2)).then((code) => {\n process.exitCode = code;\n });\n}\n"],"mappings":";;;;;;;;AAOA,MAAMA,eAAa,IAAI,IAAoB;CACzC,CAAC,GAAG,iBAAiB;CACrB,CAAC,GAAG,mBAAmB;CACvB,CAAC,GAAG,aAAa;CACjB,CAAC,IAAI,YAAY;AACnB,CAAC;AAED,MAAM,0BAA0B;AAChC,MAAM,sCACJ;AAMF,MAAa,qBAAqB,OAChC,UAAkC,CAAC,MACjB;CAClB,MAAM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AClE,QAAQ,MAAM,mCAAmC;CACjD,QAAQ,MACN,yEACF;CACA,QAAQ,MAAM,2DAA2D;AAC3E;AAEA,MAAa,4BAA4B,WAAiC;CACxE,MAAM,QAAQ;EACZ;EACA,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,mBAAmB,OAAO;EAC1B,oBAAoB,OAAO;EAC3B,aAAa,OAAO;CACtB;CAEA,KAAK,MAAM,WAAW,OAAO,UAAU;EACrC,MAAM,gBAAgB,QAAQ,mBAAmB;EACjD,MAAM,KACJ,eAAe,QAAQ,UAAU,eAAe,QAAQ,YAAY,mBAAmB,eACzF;CACF;CAEA,OAAO,MAAM,KAAK,IAAI;AACxB;AAEA,MAAa,mBACX,eACA,eACY;CACZ,IAAI,kBAAkB,KAAA,GAAW,OAAO;CACxC,IAAI;EACF,OAAO,aAAa,aAAa,MAAM,aAAa,UAAU;CAChE,QAAQ;EACN,OAAO,kBAAkB;CAC3B;AACF;AAEA,SAAS,qBAAqB,MAAoC;CAChE,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAChD,IAAI,KAAK,WAAW,YAClB,OAAO,KAAK,QAAQ;AAI1B;AAEA,IAAI,gBAAgB,QAAQ,KAAK,IAAI,aAAa,GAChD,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE,MAAM,SAAS;CAC3C,QAAQ,WAAW;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["menuLabels","createVisibleIcon"],"sources":["../src/smoke/daemon-lynx.ts","../src/smoke/daemon-tray.ts","../src/cli.ts"],"sourcesContent":["import { existsSync, realpathSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport { createClient } from \"../client\";\nimport { connectLocalBroker } from \"../local-broker\";\n\nconst menuLabels = new Map<number, string>([\n [1, \"Reload Bundle\"],\n [2, \"Hide Window\"],\n [99, \"Quit Smoke\"],\n]);\n\nconst DEFAULT_LYNX_BUNDLE_ENV = \"OPENTRAY_LYNX_BUNDLE\";\n\nexport interface DaemonLynxSmokeOptions {\n bundlePath?: string;\n}\n\nexport const runDaemonLynxSmoke = async (\n options: DaemonLynxSmokeOptions = {},\n): Promise<void> => {\n const bundlePath = resolveLynxBundlePath(options.bundlePath);\n const connection = await connectLocalBroker();\n const client = createClient(connection, { requestIdPrefix: \"daemon-lynx\" });\n console.log(`connected: endpoint=${connection.endpoint} session=${connection.sessionId}`);\n\n const space = await client.createSpace({\n id: \"com.example.opentray.daemon-lynx\",\n title: \"OpenTray Lynx Smoke\",\n default: true,\n });\n console.log(`space: ${JSON.stringify(space.space)}`);\n\n const tray = await space.createTray({\n trayId: \"daemon-lynx-status\",\n title: \"OpenTray Lynx\",\n tooltip: {\n title: \"OpenTray Lynx\",\n description: \"Generic extension smoke for a real Lynx runtime window\",\n },\n icon: createVisibleIcon(),\n menu: {\n items: [\n { type: \"item\", id: 1, title: \"Reload Bundle\" },\n { type: \"item\", id: 2, title: \"Hide Window\" },\n { type: \"separator\" },\n { type: \"item\", id: 99, title: \"Quit Smoke\" },\n ],\n },\n });\n console.log(`tray: ${tray.trayId}`);\n\n await connection.request({\n type: \"load-ext\",\n requestId: \"daemon-lynx-load\",\n spaceId: space.space.spaceId,\n name: \"lynx\",\n path: \"@opentray/ext-lynx\",\n });\n console.log(\"lynx extension requested through the generic load-ext path\");\n\n let closed = false;\n let exitTimer: NodeJS.Timeout | undefined;\n let resolveClosed: (() => void) | undefined;\n\n const show = async (): Promise<void> => {\n await tray.commandExtension(\"lynx\", {\n type: \"show\",\n bundlePath,\n });\n console.log(`lynx command: show bundle=${bundlePath}`);\n };\n\n const hide = async (): Promise<void> => {\n await tray.commandExtension(\"lynx\", { type: \"hide\" });\n console.log(\"lynx command: hide\");\n };\n\n const shutdown = async (): Promise<void> => {\n if (closed) {\n return;\n }\n closed = true;\n if (exitTimer !== undefined) {\n clearTimeout(exitTimer);\n }\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n try {\n await hide();\n } catch (error) {\n console.error(`lynx hide during shutdown failed: ${String(error)}`);\n }\n await connection.close();\n resolveClosed?.();\n };\n\n const handleMenuClick = async (itemId: number): Promise<void> => {\n switch (itemId) {\n case 1:\n await show();\n return;\n case 2:\n await hide();\n return;\n case 99:\n console.log(\"quit item routed; closing lynx smoke connection\");\n await shutdown();\n return;\n default:\n return;\n }\n };\n\n connection.onEvent((frame) => {\n console.log(`broker -> client ${JSON.stringify(frame)}`);\n if (frame.type === \"event\" && frame.event.type === \"menuClick\") {\n console.log(`menu click: ${menuLabels.get(frame.event.itemId) ?? frame.event.itemId}`);\n void handleMenuClick(frame.event.itemId);\n return;\n }\n if (frame.type === \"ext-event\" && frame.ext === \"lynx\") {\n console.log(`lynx event: ${JSON.stringify(frame.data)}`);\n }\n });\n\n const onSignal = (): void => {\n void shutdown();\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n\n const exitAfter = process.env.OPENTRAY_EXAMPLE_EXIT_AFTER_MS;\n if (exitAfter !== undefined && exitAfter.length > 0) {\n const duration = Number.parseInt(exitAfter, 10);\n if (Number.isInteger(duration) && duration > 0) {\n exitTimer = setTimeout(() => {\n void shutdown();\n }, duration);\n }\n }\n\n try {\n await show();\n console.log(\"use the tray menu to reload or hide the Lynx window, or press Ctrl+C to exit\");\n } catch (error) {\n await connection.close();\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n throw error;\n }\n\n await new Promise<void>((resolve) => {\n resolveClosed = resolve;\n });\n};\n\nexport const resolveLynxBundlePath = (value?: string): string => {\n const resolved = value ?? process.env[DEFAULT_LYNX_BUNDLE_ENV];\n if (resolved === undefined || resolved.length === 0) {\n throw new Error(\n `lynx smoke requires --bundle <path> or ${DEFAULT_LYNX_BUNDLE_ENV}=<path-to-main.lynx.bundle>`,\n );\n }\n const baseDir = process.env.INIT_CWD ?? process.cwd();\n const absolutePath = resolve(baseDir, resolved);\n if (!existsSync(absolutePath)) {\n throw new Error(`lynx smoke bundle does not exist: ${absolutePath}`);\n }\n return realpathSync(absolutePath);\n};\n\nfunction createVisibleIcon(): { type: \"rgba\"; width: number; height: number; data: number[] } {\n const width = 32;\n const height = 32;\n const data: number[] = [];\n\n for (let y = 0; y < height; y += 1) {\n for (let x = 0; x < width; x += 1) {\n const inStroke = x <= 5 || (x >= 13 && x <= 18) || y >= 26;\n const inDiagonal = y >= x + 10 && x <= 18;\n const alpha = inStroke || inDiagonal ? 255 : 0;\n data.push(34, 92, 56, alpha);\n }\n }\n\n return { type: \"rgba\", width, height, data };\n}\n","import type { Rect } from \"@opentray/spec\";\n\nimport { createClient } from \"../client\";\nimport { connectLocalBroker } from \"../local-broker\";\n\nconst menuLabels = new Map<number, string>([\n [1, \"Open WebView\"],\n]);\n\ninterface WebviewShowCommand {\n type: \"show\";\n html?: string;\n url?: string;\n width?: number;\n height?: number;\n fallbackRect?: Rect;\n nativeWindowApi?: boolean;\n bindWindowGlobals?: boolean;\n nativeScreenApi?: boolean;\n bindScreenGlobals?: boolean;\n nativeTrayApi?: boolean;\n title?: string;\n icon?: { type: \"href\"; href: string };\n style?: {\n frameless?: boolean;\n transparent?: boolean;\n keepOnTop?: boolean;\n platform?: {\n macos?: {\n material?: string | null;\n materialState?: \"followsWindowActiveState\" | \"active\" | \"inactive\";\n cornerRadius?: number | null;\n };\n };\n };\n titleSync?: boolean | { documentToWindow?: boolean; windowToDocument?: boolean };\n iconSync?: boolean | { faviconToWindow?: boolean; windowToFavicon?: boolean };\n nativeApiPolicy?: {\n defaultSrc?: string[];\n window?: string[];\n screen?: string[];\n tray?: string[];\n windowGlobals?: string[];\n screenGlobals?: string[];\n titleSync?: string[];\n iconSync?: string[];\n };\n}\n\nexport const runDaemonTraySmoke = async (): Promise<void> => {\n const connection = await connectLocalBroker();\n const client = createClient(connection, { requestIdPrefix: \"daemon-smoke\" });\n console.log(`connected: endpoint=${connection.endpoint} session=${connection.sessionId}`);\n\n const space = await client.createSpace({\n id: \"com.example.opentray.daemon-smoke\",\n title: \"OpenTray Daemon Smoke\",\n default: true,\n });\n console.log(`space: ${JSON.stringify(space.space)}`);\n\n const tray = await space.createTray({\n trayId: \"daemon-smoke-status\",\n title: \"OpenTray\",\n tooltip: {\n title: \"OpenTray\",\n description: \"Single primary tray action; macOS direct-triggers without opening a menu\",\n },\n icon: createVisibleIcon(),\n menu: {\n items: [\n { type: \"item\", id: 1, title: \"Open WebView\", primaryEvent: true },\n ],\n },\n });\n console.log(`tray: ${tray.trayId}`);\n\n await connection.request({\n type: \"load-ext\",\n requestId: \"daemon-smoke-load-webview\",\n spaceId: space.space.spaceId,\n name: \"webview\",\n path: \"@opentray/ext-webview\",\n });\n console.log(\"webview extension requested through the generic load-ext path\");\n console.log(\"click the tray icon: macOS should direct-trigger the single primary action without opening a menu\");\n\n let closed = false;\n let exitTimer: NodeJS.Timeout | undefined;\n\n const shutdown = async (): Promise<void> => {\n if (closed) {\n return;\n }\n closed = true;\n if (exitTimer !== undefined) {\n clearTimeout(exitTimer);\n }\n await connection.close();\n };\n\n const commandWebview = async (command: WebviewShowCommand | Record<string, unknown>): Promise<void> => {\n await tray.commandExtension(\"webview\", command);\n };\n\n const handleMenuClick = async (itemId: number): Promise<void> => {\n if (itemId === 1) {\n const trayBounds = await tray.getBounds();\n console.log(`tray bounds: ${JSON.stringify(trayBounds)}`);\n await commandWebview({\n type: \"show\",\n html: createWebviewDemoHtml(),\n width: 420,\n height: 260,\n title: \"OpenTray WebView Smoke\",\n icon: {\n type: \"href\",\n href: \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=\",\n },\n style: {\n frameless: true,\n transparent: true,\n keepOnTop: true,\n platform: {\n macos: {\n material: \"hudWindow\",\n materialState: \"active\",\n },\n },\n },\n fallbackRect: trayBounds.rect ?? { x: 0, y: 0, width: 1, height: 1 },\n nativeWindowApi: true,\n bindWindowGlobals: true,\n nativeScreenApi: true,\n bindScreenGlobals: true,\n nativeTrayApi: true,\n titleSync: {\n documentToWindow: true,\n windowToDocument: true,\n },\n iconSync: true,\n nativeApiPolicy: {\n defaultSrc: [\"'local'\"],\n window: [\"https://example.com\"],\n screen: [\"https://example.com\"],\n tray: [\"https://example.com\"],\n titleSync: [\"https://example.com\"],\n iconSync: [\"https://example.com\"],\n },\n });\n console.log(\"primary tray action: webview show\");\n return;\n }\n };\n\n connection.onEvent((frame) => {\n console.log(`broker -> client ${JSON.stringify(frame)}`);\n if (frame.type === \"event\" && frame.event.type === \"menuClick\") {\n console.log(`menu click: ${menuLabels.get(frame.event.itemId) ?? frame.event.itemId}`);\n void handleMenuClick(frame.event.itemId);\n }\n });\n\n const exitAfter = process.env.OPENTRAY_EXAMPLE_EXIT_AFTER_MS;\n if (exitAfter !== undefined && exitAfter.length > 0) {\n const duration = Number.parseInt(exitAfter, 10);\n if (Number.isInteger(duration) && duration > 0) {\n exitTimer = setTimeout(() => {\n void shutdown();\n }, duration);\n }\n }\n\n const webviewSmoke = process.env.OPENTRAY_EXAMPLE_WEBVIEW_SMOKE;\n try {\n if (webviewSmoke === \"show\" || webviewSmoke === \"1\") {\n await handleMenuClick(1);\n }\n if (webviewSmoke === \"1\") {\n if (exitTimer !== undefined) {\n clearTimeout(exitTimer);\n exitTimer = undefined;\n }\n await sleep(300);\n await shutdown();\n }\n } catch (error) {\n await shutdown();\n throw error;\n }\n};\n\nfunction createVisibleIcon(): { type: \"rgba\"; width: number; height: number; data: number[] } {\n const width = 32;\n const height = 32;\n const data: number[] = [];\n\n for (let y = 0; y < height; y += 1) {\n for (let x = 0; x < width; x += 1) {\n const dx = x - 15.5;\n const dy = y - 15.5;\n const distance = Math.sqrt(dx * dx + dy * dy);\n const inRing = distance >= 9 && distance <= 14;\n const inCore = distance <= 5;\n const inNeedle = Math.abs(dx + dy) <= 1.2 && x >= 9 && x <= 23 && y >= 9 && y <= 23;\n\n if (inRing || inCore || inNeedle) {\n data.push(inCore ? 255 : 24, inNeedle ? 240 : 132, inRing ? 72 : 96, 255);\n } else {\n data.push(0, 0, 0, 0);\n }\n }\n }\n\n return { type: \"rgba\", width, height, data };\n}\n\nfunction createWebviewDemoHtml(): string {\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <title>OpenTray WebView</title>\n <style>\n :root {\n color: #18220f;\n background: #f6edd8;\n font: 15px ui-rounded, \"SF Pro Rounded\", \"Avenir Next\", sans-serif;\n }\n body {\n margin: 0;\n }\n main {\n min-height: 100vh;\n box-sizing: border-box;\n padding: 22px;\n background:\n radial-gradient(circle at 84% 10%, rgba(34, 132, 96, 0.22), transparent 34%),\n linear-gradient(135deg, #fff8e7 0%, #e9f0d8 100%);\n }\n h1 {\n margin: 0 0 8px;\n font-size: 24px;\n letter-spacing: -0.04em;\n }\n p {\n margin: 0 0 16px;\n color: #526044;\n }\n section {\n display: grid;\n gap: 10px;\n }\n .card {\n border: 1px solid rgba(24, 34, 15, 0.16);\n border-radius: 14px;\n padding: 12px;\n background: rgba(255, 255, 255, 0.72);\n box-shadow: 0 12px 30px rgba(56, 72, 36, 0.12);\n }\n .label {\n margin-bottom: 5px;\n color: #7b5b1d;\n font-size: 12px;\n font-weight: 700;\n letter-spacing: 0.08em;\n text-transform: uppercase;\n }\n code {\n word-break: break-word;\n }\n </style>\n </head>\n <body>\n <main>\n <h1>OpenTray WebView</h1>\n <p>This window was opened by the single primary tray action.</p>\n <section>\n <div class=\"card\">\n <div class=\"label\">primary event</div>\n <code>macOS single primary item direct-triggered menuClick -> WebView show</code>\n </div>\n </section>\n </main>\n </body>\n</html>`;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","#!/usr/bin/env node\nimport { realpathSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { DaemonHealth } from \"@opentray/spec\";\n\nimport { createNodeDaemonDriver, inspectDaemon, restartDaemon, startDaemon, stopDaemon } from \"./daemon/lifecycle\";\nimport { readPackageVersion } from \"./daemon/package-version\";\nimport { resolveDaemonPaths } from \"./daemon/paths\";\nimport { connectLocalBroker } from \"./local-broker\";\nimport { runDaemonLynxSmoke } from \"./smoke/daemon-lynx\";\nimport { runDaemonTraySmoke } from \"./smoke/daemon-tray\";\n\nconst packageJsonUrl = new URL(\"../package.json\", import.meta.url);\nconst cliModulePath = fileURLToPath(import.meta.url);\n\ntype CliCommand =\n | { type: \"daemon\"; action: \"start\" | \"stop\" | \"restart\" | \"health\" }\n | { type: \"smoke\"; name: \"daemon-tray\" }\n | { type: \"smoke\"; name: \"daemon-lynx\"; bundlePath?: string }\n | { type: \"help\" };\n\nexport const parseCliCommand = (argv: string[]): CliCommand => {\n const [group, action, ...rest] = argv;\n if (group !== \"daemon\") {\n if (group === \"smoke\" && action === \"daemon-tray\") {\n return { type: \"smoke\", name: \"daemon-tray\" };\n }\n if (group === \"smoke\" && action === \"daemon-lynx\") {\n const bundlePath = parseSmokeBundlePath(rest);\n return bundlePath === undefined\n ? { type: \"smoke\", name: \"daemon-lynx\" }\n : { type: \"smoke\", name: \"daemon-lynx\", bundlePath };\n }\n return { type: \"help\" };\n }\n if (action === \"start\" || action === \"stop\" || action === \"restart\" || action === \"health\") {\n return { type: \"daemon\", action };\n }\n\n return { type: \"help\" };\n};\n\nexport const runCli = async (argv: string[]): Promise<number> => {\n const command = parseCliCommand(argv);\n const packageVersion = process.env.OPENTRAY_DAEMON_PACKAGE_VERSION ?? (await readPackageVersion(packageJsonUrl));\n const paths = resolveDaemonPaths({\n homeDir: process.env.OPENTRAY_HOME ?? homedir(),\n packageVersion,\n });\n\n if (command.type === \"help\") {\n printHelp();\n return 1;\n }\n\n if (command.type === \"smoke\") {\n if (command.name === \"daemon-tray\") {\n await runDaemonTraySmoke();\n } else {\n await runDaemonLynxSmoke(\n command.bundlePath === undefined ? {} : { bundlePath: command.bundlePath },\n );\n }\n return 0;\n }\n\n const driver = createNodeDaemonDriver(cliModulePath);\n\n if (command.action === \"start\") {\n const result = await startDaemon({ paths, driver });\n console.log(`opentray daemon ${result.status}: pid=${result.pid} endpoint=${result.paths.endpoint}`);\n return 0;\n }\n\n if (command.action === \"stop\") {\n const result = await stopDaemon({ paths, driver });\n console.log(\n result.status === \"stopped\"\n ? `opentray daemon stopped: pid=${result.pid}`\n : \"opentray daemon not running\",\n );\n return 0;\n }\n\n if (command.action === \"restart\") {\n const result = await restartDaemon({ paths, driver });\n console.log(`opentray daemon ${result.status}: pid=${result.pid} endpoint=${result.paths.endpoint}`);\n return 0;\n }\n\n if (command.action === \"health\") {\n const inspected = await inspectDaemon({ paths, driver });\n if (inspected.status === \"not-running\") {\n console.log(\"opentray daemon not running\");\n return 0;\n }\n\n const connection = await connectLocalBroker({\n autoStart: false,\n endpoint: paths.endpoint,\n homeDir: paths.homeDir,\n packageVersion,\n });\n try {\n const response = await connection.request({\n type: \"health\",\n requestId: \"opentray-daemon-health\",\n });\n if (response.type !== \"daemon-health\") {\n throw new Error(`expected daemon-health response, received ${response.type}`);\n }\n console.log(formatDaemonHealthOutput(response.health));\n } finally {\n await connection.close();\n }\n return 0;\n }\n\n printHelp();\n return 1;\n};\n\nconst printHelp = (): void => {\n console.error(\"Usage: opentray daemon <start|stop|restart|health>\");\n console.error(\" opentray smoke daemon-tray\");\n console.error(\" opentray smoke daemon-lynx --bundle <path-to-main.lynx.bundle>\");\n};\n\nexport const formatDaemonHealthOutput = (health: DaemonHealth): string => {\n const lines = [\n \"opentray daemon running\",\n `pid: ${health.pid}`,\n `endpoint: ${health.endpoint}`,\n `packageVersion: ${health.packageVersion}`,\n `protocolVersion: ${health.protocolVersion}`,\n `sessions: ${health.sessionCount}`,\n ];\n\n for (const session of health.sessions) {\n const internalLease = session.internalLeaseId ?? \"(pending)\";\n lines.push(\n `- sessionId=${session.sessionId} initialized=${session.initialized} internalLeaseId=${internalLease}`,\n );\n }\n\n return lines.join(\"\\n\");\n};\n\nexport const isCliEntrypoint = (argvEntryPath: string | undefined, modulePath: string): boolean => {\n if (argvEntryPath === undefined) return false;\n try {\n return realpathSync(argvEntryPath) === realpathSync(modulePath);\n } catch {\n return argvEntryPath === modulePath;\n }\n};\n\nfunction parseSmokeBundlePath(argv: string[]): string | undefined {\n for (let index = 0; index < argv.length; index += 1) {\n if (argv[index] === \"--bundle\") {\n return argv[index + 1];\n }\n }\n return undefined;\n}\n\nif (isCliEntrypoint(process.argv[1], cliModulePath)) {\n runCli(process.argv.slice(2)).then((code) => {\n process.exitCode = code;\n });\n}\n"],"mappings":";;;;;;;;AAMA,MAAMA,eAAa,IAAI,IAAoB;CACzC,CAAC,GAAG,eAAe;CACnB,CAAC,GAAG,aAAa;CACjB,CAAC,IAAI,YAAY;AACnB,CAAC;AAED,MAAM,0BAA0B;AAMhC,MAAa,qBAAqB,OAChC,UAAkC,CAAC,MACjB;CAClB,MAAM,aAAa,sBAAsB,QAAQ,UAAU;CAC3D,MAAM,aAAa,MAAM,mBAAmB;CAC5C,MAAM,SAAS,aAAa,YAAY,EAAE,iBAAiB,cAAc,CAAC;CAC1E,QAAQ,IAAI,uBAAuB,WAAW,SAAS,WAAW,WAAW,WAAW;CAExF,MAAM,QAAQ,MAAM,OAAO,YAAY;EACrC,IAAI;EACJ,OAAO;EACP,SAAS;CACX,CAAC;CACD,QAAQ,IAAI,UAAU,KAAK,UAAU,MAAM,KAAK,GAAG;CAEnD,MAAM,OAAO,MAAM,MAAM,WAAW;EAClC,QAAQ;EACR,OAAO;EACP,SAAS;GACP,OAAO;GACP,aAAa;EACf;EACA,MAAMC,oBAAkB;EACxB,MAAM,EACJ,OAAO;GACL;IAAE,MAAM;IAAQ,IAAI;IAAG,OAAO;GAAgB;GAC9C;IAAE,MAAM;IAAQ,IAAI;IAAG,OAAO;GAAc;GAC5C,EAAE,MAAM,YAAY;GACpB;IAAE,MAAM;IAAQ,IAAI;IAAI,OAAO;GAAa;EAC9C,EACF;CACF,CA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AM,WAAW,OAAO,UAAU;EACrC,MAAM,gBAAgB,QAAQ,mBAAmB;EACjD,MAAM,KACJ,eAAe,QAAQ,UAAU,eAAe,QAAQ,YAAY,mBAAmB,eACzF;CACF;CAEA,OAAO,MAAM,KAAK,IAAI;AACxB;AAEA,MAAa,mBAAmB,eAAmC,eAAgC;CACjG,IAAI,kBAAkB,KAAA,GAAW,OAAO;CACxC,IAAI;EACF,OAAO,aAAa,aAAa,MAAM,aAAa,UAAU;CAChE,QAAQ;EACN,OAAO,kBAAkB;CAC3B;AACF;AAEA,SAAS,qBAAqB,MAAoC;CAChE,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAChD,IAAI,KAAK,WAAW,YAClB,OAAO,KAAK,QAAQ;AAI1B;AAEA,IAAI,gBAAgB,QAAQ,KAAK,IAAI,aAAa,GAChD,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE,MAAM,SAAS;CAC3C,QAAQ,WAAW;AACrB,CAAC"}
|
|
@@ -47,6 +47,15 @@ const createSurfaceHandle = createSpaceHandle;
|
|
|
47
47
|
const createTrayHandle = (transport, space, trayId, nextRequestId = createRequestIdFactory("opentray")) => ({
|
|
48
48
|
space,
|
|
49
49
|
trayId,
|
|
50
|
+
async getBounds() {
|
|
51
|
+
const requestId = nextRequestId();
|
|
52
|
+
return expectResponse(await transport.request({
|
|
53
|
+
type: "get-tray-bounds",
|
|
54
|
+
requestId,
|
|
55
|
+
spaceId: space.spaceId,
|
|
56
|
+
trayId
|
|
57
|
+
}), requestId, "tray-bounds").bounds;
|
|
58
|
+
},
|
|
50
59
|
async commandExtension(ext, data) {
|
|
51
60
|
const requestId = nextRequestId();
|
|
52
61
|
expectResponse(await transport.request({
|
|
@@ -87,6 +96,7 @@ const requestIdOf = (frame) => {
|
|
|
87
96
|
case "space-created":
|
|
88
97
|
case "default-space":
|
|
89
98
|
case "tray-created":
|
|
99
|
+
case "tray-bounds":
|
|
90
100
|
case "ack":
|
|
91
101
|
case "daemon-health": return frame.requestId;
|
|
92
102
|
case "error": return frame.requestId;
|
|
@@ -98,4 +108,4 @@ const requestIdOf = (frame) => {
|
|
|
98
108
|
//#endregion
|
|
99
109
|
export { createTrayHandle as a, createSurfaceHandle as i, createInitFrame as n, createSpaceHandle as r, createClient as t };
|
|
100
110
|
|
|
101
|
-
//# sourceMappingURL=client-
|
|
111
|
+
//# sourceMappingURL=client-B_zxQOo5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-B_zxQOo5.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n PROTOCOL_VERSION,\n type ClientFrame,\n type ClientRequestFrame,\n type RequestId,\n type ServerFrame,\n type SpaceOptions,\n type SpaceRef,\n type TrayBoundsResult,\n type TrayId,\n type TrayOptions,\n} from \"@opentray/spec\";\n\nexport interface OpenTrayTransport {\n request(frame: ClientRequestFrame): Promise<ServerFrame>;\n}\n\nexport interface OpenTrayClient {\n createSpace(options: SpaceOptions): Promise<SpaceHandle>;\n resolveDefaultSpace(): Promise<SpaceHandle>;\n /** @deprecated Use `createSpace`. */\n createSurface(options: SpaceOptions): Promise<SpaceHandle>;\n}\n\nexport interface SpaceHandle {\n space: SpaceRef;\n createTray(options: TrayOptions): Promise<TrayHandle>;\n}\n\n/** @deprecated Use `SpaceHandle`. */\nexport type SurfaceHandle = SpaceHandle;\n\nexport interface TrayHandle {\n space: SpaceRef;\n trayId: TrayId;\n getBounds(): Promise<TrayBoundsResult>;\n commandExtension(ext: string, data: unknown): Promise<void>;\n destroy(): Promise<void>;\n}\n\nexport const createInitFrame = (clientVersion: string): ClientFrame => ({\n type: \"init\",\n protocolVersion: PROTOCOL_VERSION,\n clientVersion,\n});\n\nexport interface CreateClientOptions {\n requestIdPrefix?: string;\n}\n\nexport const createClient = (\n transport: OpenTrayTransport,\n options: CreateClientOptions = {},\n): OpenTrayClient => {\n const nextRequestId = createRequestIdFactory(options.requestIdPrefix ?? \"opentray\");\n\n return {\n async createSpace(spaceOptions): Promise<SpaceHandle> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"create-space\",\n requestId,\n ...spaceOptions,\n });\n const space = expectResponse(response, requestId, \"space-created\").space;\n return createSpaceHandle(transport, space, nextRequestId);\n },\n async resolveDefaultSpace(): Promise<SpaceHandle> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"resolve-default-space\",\n requestId,\n });\n const space = expectResponse(response, requestId, \"default-space\").space;\n return createSpaceHandle(transport, space, nextRequestId);\n },\n async createSurface(spaceOptions): Promise<SpaceHandle> {\n return this.createSpace(spaceOptions);\n },\n };\n};\n\nexport const createSpaceHandle = (\n transport: OpenTrayTransport,\n space: SpaceRef,\n nextRequestId: () => RequestId = createRequestIdFactory(\"opentray\"),\n): SpaceHandle => ({\n space,\n async createTray(options: TrayOptions): Promise<TrayHandle> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"create-tray\",\n requestId,\n space,\n tray: options,\n });\n const frame = expectResponse(response, requestId, \"tray-created\");\n return createTrayHandle(transport, space, frame.trayId, nextRequestId);\n },\n});\n\n/** @deprecated Use `createSpaceHandle`. */\nexport const createSurfaceHandle = createSpaceHandle;\n\nexport const createTrayHandle = (\n transport: OpenTrayTransport,\n space: SpaceRef,\n trayId: TrayId,\n nextRequestId: () => RequestId = createRequestIdFactory(\"opentray\"),\n): TrayHandle => ({\n space,\n trayId,\n async getBounds(): Promise<TrayBoundsResult> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"get-tray-bounds\",\n requestId,\n spaceId: space.spaceId,\n trayId,\n });\n return expectResponse(response, requestId, \"tray-bounds\").bounds;\n },\n async commandExtension(ext: string, data: unknown): Promise<void> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"ext-command\",\n requestId,\n spaceId: space.spaceId,\n trayId,\n ext,\n data,\n });\n expectResponse(response, requestId, \"ack\");\n },\n async destroy(): Promise<void> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"destroy-tray\",\n requestId,\n spaceId: space.spaceId,\n trayId,\n });\n expectResponse(response, requestId, \"ack\");\n },\n});\n\nconst createRequestIdFactory = (prefix: string): (() => RequestId) => {\n let next = 1;\n return () => {\n const requestId = `${prefix}-${next}`;\n next += 1;\n return requestId;\n };\n};\n\nconst expectResponse = <TType extends ServerFrame[\"type\"]>(\n frame: ServerFrame,\n requestId: RequestId,\n type: TType,\n): Extract<ServerFrame, { type: TType }> => {\n if (frame.type === \"error\") {\n throw new Error(`${frame.code}: ${frame.message}`);\n }\n if (frame.type !== type) {\n throw new Error(`expected ${type} for ${requestId}, received ${frame.type}`);\n }\n if (requestIdOf(frame) !== requestId) {\n throw new Error(`expected response for ${requestId}, received ${requestIdOf(frame) ?? \"none\"}`);\n }\n return frame as Extract<ServerFrame, { type: TType }>;\n};\n\nconst requestIdOf = (frame: ServerFrame): RequestId | undefined => {\n switch (frame.type) {\n case \"space-created\":\n case \"default-space\":\n case \"tray-created\":\n case \"tray-bounds\":\n case \"ack\":\n case \"daemon-health\":\n return frame.requestId;\n case \"error\":\n return frame.requestId;\n case \"ready\":\n case \"event\":\n case \"ext-event\":\n return undefined;\n }\n};\n"],"mappings":";;AAwCA,MAAa,mBAAmB,mBAAwC;CACtE,MAAM;CACN,iBAAiB;CACjB;AACF;AAMA,MAAa,gBACX,WACA,UAA+B,CAAC,MACb;CACnB,MAAM,gBAAgB,uBAAuB,QAAQ,mBAAmB,UAAU;CAElF,OAAO;EACL,MAAM,YAAY,cAAoC;GACpD,MAAM,YAAY,cAAc;GAMhC,MAAM,QAAQ,eAAe,MALN,UAAU,QAAQ;IACvC,MAAM;IACN;IACA,GAAG;GACL,CAAC,GACsC,WAAW,eAAe,EAAE;GACnE,OAAO,kBAAkB,WAAW,OAAO,aAAa;EAC1D;EACA,MAAM,sBAA4C;GAChD,MAAM,YAAY,cAAc;GAKhC,MAAM,QAAQ,eAAe,MAJN,UAAU,QAAQ;IACvC,MAAM;IACN;GACF,CAAC,GACsC,WA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IAAI,MAAM,SAAS,MACjB,MAAM,IAAI,MAAM,YAAY,KAAK,OAAO,UAAU,aAAa,MAAM,MAAM;CAE7E,IAAI,YAAY,KAAK,MAAM,WACzB,MAAM,IAAI,MAAM,yBAAyB,UAAU,aAAa,YAAY,KAAK,KAAK,QAAQ;CAEhG,OAAO;AACT;AAEA,MAAM,eAAe,UAA8C;CACjE,QAAQ,MAAM,MAAd;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,iBACH,OAAO,MAAM;EACf,KAAK,SACH,OAAO,MAAM;EACf,KAAK;EACL,KAAK;EACL,KAAK,aACH;CACJ;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientFrame, ClientRequestFrame, RequestId, ServerFrame, SpaceOptions, SpaceRef, TrayId, TrayOptions } from "@opentray/spec";
|
|
1
|
+
import { ClientFrame, ClientRequestFrame, RequestId, ServerFrame, SpaceOptions, SpaceRef, TrayBoundsResult, TrayId, TrayOptions } from "@opentray/spec";
|
|
2
2
|
|
|
3
3
|
//#region src/client.d.ts
|
|
4
4
|
interface OpenTrayTransport {
|
|
@@ -19,6 +19,7 @@ type SurfaceHandle = SpaceHandle;
|
|
|
19
19
|
interface TrayHandle {
|
|
20
20
|
space: SpaceRef;
|
|
21
21
|
trayId: TrayId;
|
|
22
|
+
getBounds(): Promise<TrayBoundsResult>;
|
|
22
23
|
commandExtension(ext: string, data: unknown): Promise<void>;
|
|
23
24
|
destroy(): Promise<void>;
|
|
24
25
|
}
|
|
@@ -33,4 +34,4 @@ declare const createSurfaceHandle: (transport: OpenTrayTransport, space: SpaceRe
|
|
|
33
34
|
declare const createTrayHandle: (transport: OpenTrayTransport, space: SpaceRef, trayId: TrayId, nextRequestId?: () => RequestId) => TrayHandle;
|
|
34
35
|
//#endregion
|
|
35
36
|
export { SurfaceHandle as a, createInitFrame as c, createTrayHandle as d, SpaceHandle as i, createSpaceHandle as l, OpenTrayClient as n, TrayHandle as o, OpenTrayTransport as r, createClient as s, CreateClientOptions as t, createSurfaceHandle as u };
|
|
36
|
-
//# sourceMappingURL=client-
|
|
37
|
+
//# sourceMappingURL=client-h6gZdeOk.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-h6gZdeOk.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;UAaiB,iBAAA;EACf,OAAA,CAAQ,KAAA,EAAO,kBAAA,GAAqB,OAAA,CAAQ,WAAA;AAAA;AAAA,UAG7B,cAAA;EACf,WAAA,CAAY,OAAA,EAAS,YAAA,GAAe,OAAA,CAAQ,WAAA;EAC5C,mBAAA,IAAuB,OAAA,CAAQ,WAAA;EALa;EAO5C,aAAA,CAAc,OAAA,EAAS,YAAA,GAAe,OAAA,CAAQ,WAAA;AAAA;AAAA,UAG/B,WAAA;EACf,KAAA,EAAO,QAAA;EACP,UAAA,CAAW,OAAA,EAAS,WAAA,GAAc,OAAA,CAAQ,UAAA;AAAA;;KAIhC,aAAA,GAAgB,WAAW;AAAA,UAEtB,UAAA;EACf,KAAA,EAAO,QAAA;EACP,MAAA,EAAQ,MAAA;EACR,SAAA,IAAa,OAAA,CAAQ,gBAAA;EACrB,gBAAA,CAAiB,GAAA,UAAa,IAAA,YAAgB,OAAA;EAC9C,OAAA,IAAW,OAAA;AAAA;AAAA,cAGA,eAAA,GAAmB,aAAA,aAAwB,WAItD;AAAA,UAEe,mBAAA;EACf,eAAe;AAAA;AAAA,cAGJ,YAAA,GACX,SAAA,EAAW,iBAAA,EACX,OAAA,GAAS,mBAAA,KACR,cAAA;AAAA,cA6BU,iBAAA,GACX,SAAA,EAAW,iBAAA,EACX,KAAA,EAAO,QAAA,EACP,aAAA,SAAqB,SAAA,KACpB,WAAA;;cAgBU,mBAAA,GAAmB,SAAA,EAnBnB,iBAAA,EAAiB,KAAA,EACrB,QAAA,EAAQ,aAAA,SACM,SAAA,KACpB,WAAA;AAAA,cAkBU,gBAAA,GACX,SAAA,EAAW,iBAAA,EACX,KAAA,EAAO,QAAA,EACP,MAAA,EAAQ,MAAA,EACR,aAAA,SAAqB,SAAA,KACpB,UAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SurfaceHandle, c as createInitFrame, d as createTrayHandle, i as SpaceHandle, l as createSpaceHandle, n as OpenTrayClient, o as TrayHandle, r as OpenTrayTransport, s as createClient, t as CreateClientOptions, u as createSurfaceHandle } from "./client-
|
|
1
|
+
import { a as SurfaceHandle, c as createInitFrame, d as createTrayHandle, i as SpaceHandle, l as createSpaceHandle, n as OpenTrayClient, o as TrayHandle, r as OpenTrayTransport, s as createClient, t as CreateClientOptions, u as createSurfaceHandle } from "./client-h6gZdeOk.mjs";
|
|
2
2
|
import { BrokerEndpointIdentity, BrokerEndpointIdentityOptions, PROTOCOL_VERSION, SpaceOptions, SpaceRef, TrayOptions, createBrokerEndpointIdentity, formatBrokerEndpointName, formatBrokerStateRoot, formatUnixSocketPath, formatWindowsPipeName, isSupportedProtocolVersion } from "@opentray/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/sdk.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as createTrayHandle, i as createSurfaceHandle, n as createInitFrame, r as createSpaceHandle, t as createClient } from "./client-
|
|
2
|
-
import { t as connectLocalBroker } from "./local-broker-
|
|
1
|
+
import { a as createTrayHandle, i as createSurfaceHandle, n as createInitFrame, r as createSpaceHandle, t as createClient } from "./client-B_zxQOo5.mjs";
|
|
2
|
+
import { t as connectLocalBroker } from "./local-broker-CEIHPBcK.mjs";
|
|
3
3
|
import { PROTOCOL_VERSION, createBrokerEndpointIdentity, formatBrokerEndpointName, formatBrokerStateRoot, formatUnixSocketPath, formatWindowsPipeName, isSupportedProtocolVersion } from "@opentray/spec";
|
|
4
4
|
//#region src/sdk.ts
|
|
5
5
|
const createSpace = async (options, brokerOptions = {}) => {
|
|
@@ -52,24 +52,17 @@ const requireFromSource = createRequire(sourceUrl);
|
|
|
52
52
|
const resolveBrokerCommand = async (paths, options = {}) => {
|
|
53
53
|
const explicit = (options.env ?? process.env).OPENTRAY_BROKER_BIN;
|
|
54
54
|
if (explicit !== void 0 && explicit.length > 0) return commandForBinary(explicit, paths);
|
|
55
|
-
const platform = options.platform ?? process.platform;
|
|
56
|
-
const arch = options.arch ?? process.arch;
|
|
57
|
-
let installedBinaryError;
|
|
58
|
-
try {
|
|
59
|
-
const installedBinary = await resolveInstalledBrokerBinary({
|
|
60
|
-
platform,
|
|
61
|
-
arch,
|
|
62
|
-
resolvePackageJson: options.resolvePackageJson ?? resolvePackageJson
|
|
63
|
-
});
|
|
64
|
-
if (installedBinary !== void 0) return commandForBinary(installedBinary, paths);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
if (!(error instanceof MissingPlatformBrokerBinaryError)) throw error;
|
|
67
|
-
installedBinaryError = error;
|
|
68
|
-
}
|
|
69
55
|
const sourceDir = options.sourceDir ?? dirname(fileURLToPath(sourceUrl));
|
|
70
56
|
const workspaceRoot = await (options.findWorkspaceRoot ?? findWorkspaceRoot)(sourceDir);
|
|
71
57
|
if (workspaceRoot !== void 0) return commandForBinary(await (options.ensureDevBrokerBinary ?? ensureDevBrokerBinary)(workspaceRoot), paths, workspaceRoot);
|
|
72
|
-
|
|
58
|
+
const platform = options.platform ?? process.platform;
|
|
59
|
+
const arch = options.arch ?? process.arch;
|
|
60
|
+
const installedBinary = await resolveInstalledBrokerBinary({
|
|
61
|
+
platform,
|
|
62
|
+
arch,
|
|
63
|
+
resolvePackageJson: options.resolvePackageJson ?? resolvePackageJson
|
|
64
|
+
});
|
|
65
|
+
if (installedBinary !== void 0) return commandForBinary(installedBinary, paths);
|
|
73
66
|
const target = resolveBrokerNativeTarget(platform, arch);
|
|
74
67
|
throw new MissingPlatformBrokerBinaryError(`unable to resolve OpenTray broker binary for ${platform}/${arch}; install ${target.packageName} or set OPENTRAY_BROKER_BIN`, platform, arch, { packageName: target.packageName });
|
|
75
68
|
};
|
|
@@ -156,6 +149,7 @@ const exists = async (path) => {
|
|
|
156
149
|
const isNodeError$1 = (error) => error instanceof Error && "code" in error;
|
|
157
150
|
//#endregion
|
|
158
151
|
//#region src/daemon/lifecycle.ts
|
|
152
|
+
const DAEMON_STDIO_ENV = "OPENTRAY_DAEMON_STDIO";
|
|
159
153
|
const createNodeDaemonDriver = (cliEntrypoint) => ({
|
|
160
154
|
async isAlive(pid) {
|
|
161
155
|
return isProcessAlive(pid);
|
|
@@ -171,7 +165,7 @@ const createNodeDaemonDriver = (cliEntrypoint) => ({
|
|
|
171
165
|
OPENTRAY_DAEMON_PACKAGE_VERSION: paths.packageVersion,
|
|
172
166
|
OPENTRAY_DAEMON_CLI_ENTRYPOINT: cliEntrypoint
|
|
173
167
|
},
|
|
174
|
-
stdio:
|
|
168
|
+
stdio: resolveBrokerStdio(process.env[DAEMON_STDIO_ENV])
|
|
175
169
|
});
|
|
176
170
|
child.unref();
|
|
177
171
|
return child.pid ?? 0;
|
|
@@ -180,6 +174,9 @@ const createNodeDaemonDriver = (cliEntrypoint) => ({
|
|
|
180
174
|
process.kill(pid, "SIGTERM");
|
|
181
175
|
}
|
|
182
176
|
});
|
|
177
|
+
const resolveBrokerStdio = (value) => {
|
|
178
|
+
return value === "inherit" ? "inherit" : "ignore";
|
|
179
|
+
};
|
|
183
180
|
const startDaemon = async ({ paths, driver, lockTimeoutMs = 1e3 }) => {
|
|
184
181
|
await mkdir(paths.runtimeDir, { recursive: true });
|
|
185
182
|
const lock = await acquireLock(paths.lockFile, lockTimeoutMs);
|
|
@@ -488,6 +485,7 @@ const responseRequestId = (frame) => {
|
|
|
488
485
|
case "space-created":
|
|
489
486
|
case "default-space":
|
|
490
487
|
case "tray-created":
|
|
488
|
+
case "tray-bounds":
|
|
491
489
|
case "ack":
|
|
492
490
|
case "daemon-health": return frame.requestId;
|
|
493
491
|
case "ready":
|
|
@@ -503,4 +501,4 @@ const resolveCliEntrypoint = () => {
|
|
|
503
501
|
//#endregion
|
|
504
502
|
export { inspectDaemon as a, stopDaemon as c, createNodeDaemonDriver as i, resolveDaemonPaths as n, restartDaemon as o, readPackageVersion as r, startDaemon as s, connectLocalBroker as t };
|
|
505
503
|
|
|
506
|
-
//# sourceMappingURL=local-broker-
|
|
504
|
+
//# sourceMappingURL=local-broker-CEIHPBcK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-broker-CEIHPBcK.mjs","names":["isNodeError"],"sources":["../src/daemon/native-target.ts","../src/daemon/broker-command.ts","../src/daemon/lifecycle.ts","../src/daemon/package-version.ts","../src/daemon/paths.ts","../src/local-broker.ts"],"sourcesContent":["export type BrokerPackageOs = \"darwin\" | \"linux\" | \"windows\";\nexport type BrokerArch = \"arm64\" | \"x64\";\n\nexport interface BrokerNativeTarget {\n packageName: string;\n binaryRelativePath: string;\n}\n\nexport const resolveBrokerNativeTarget = (\n platform: string = process.platform,\n arch: string = process.arch,\n): BrokerNativeTarget => {\n const packageOs = platformToPackageOs(platform);\n const nativeArch = normalizeArch(arch);\n return {\n packageName: `@opentray/${packageOs}-${nativeArch}`,\n binaryRelativePath: `bin/${packageOs === \"windows\" ? \"opentray.exe\" : \"opentray\"}`,\n };\n};\n\nconst platformToPackageOs = (platform: string): BrokerPackageOs => {\n switch (platform) {\n case \"darwin\":\n case \"linux\":\n return platform;\n case \"win32\":\n return \"windows\";\n default:\n throw new MissingPlatformBrokerBinaryError(\n `unsupported OpenTray broker platform: ${platform}`,\n platform,\n process.arch,\n );\n }\n};\n\nconst normalizeArch = (arch: string): BrokerArch => {\n switch (arch) {\n case \"arm64\":\n case \"x64\":\n return arch;\n default:\n throw new MissingPlatformBrokerBinaryError(\n `unsupported OpenTray broker architecture: ${arch}`,\n process.platform,\n arch,\n );\n }\n};\n\nexport class MissingPlatformBrokerBinaryError extends Error {\n readonly code = \"OPENTRAY_MISSING_PLATFORM_BROKER_BINARY\";\n readonly platform: string;\n readonly arch: string;\n readonly packageName: string | undefined;\n readonly binaryPath: string | undefined;\n\n constructor(\n message: string,\n platform: string,\n arch: string,\n options: {\n packageName?: string;\n binaryPath?: string;\n cause?: unknown;\n } = {},\n ) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = \"MissingPlatformBrokerBinaryError\";\n this.platform = platform;\n this.arch = arch;\n this.packageName = options.packageName;\n this.binaryPath = options.binaryPath;\n }\n}\n","import { access, chmod } from \"node:fs/promises\";\nimport { constants } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { fileURLToPath } from \"node:url\";\nimport { spawn } from \"node:child_process\";\n\nimport type { DaemonPaths } from \"./paths\";\nimport { MissingPlatformBrokerBinaryError, resolveBrokerNativeTarget } from \"./native-target\";\n\nexport interface BrokerCommand {\n command: string;\n args: string[];\n cwd?: string;\n}\n\nconst sourceUrl = import.meta.url;\nconst requireFromSource = createRequire(sourceUrl);\n\nexport interface ResolveBrokerCommandOptions {\n env?: NodeJS.ProcessEnv;\n platform?: NodeJS.Platform;\n arch?: string;\n sourceDir?: string;\n resolvePackageJson?: (packageName: string) => string | undefined;\n findWorkspaceRoot?: (start: string) => Promise<string | undefined>;\n ensureDevBrokerBinary?: (workspaceRoot: string) => Promise<string>;\n}\n\nexport const resolveBrokerCommand = async (\n paths: DaemonPaths,\n options: ResolveBrokerCommandOptions = {},\n): Promise<BrokerCommand> => {\n const env = options.env ?? process.env;\n const explicit = env.OPENTRAY_BROKER_BIN;\n if (explicit !== undefined && explicit.length > 0) {\n return commandForBinary(explicit, paths);\n }\n\n const sourceDir = options.sourceDir ?? dirname(fileURLToPath(sourceUrl));\n const workspaceRoot = await (options.findWorkspaceRoot ?? findWorkspaceRoot)(sourceDir);\n if (workspaceRoot !== undefined) {\n const binary = await (options.ensureDevBrokerBinary ?? ensureDevBrokerBinary)(workspaceRoot);\n return commandForBinary(binary, paths, workspaceRoot);\n }\n\n const platform = options.platform ?? process.platform;\n const arch = options.arch ?? process.arch;\n const installedBinary = await resolveInstalledBrokerBinary({\n platform,\n arch,\n resolvePackageJson: options.resolvePackageJson ?? resolvePackageJson,\n });\n if (installedBinary !== undefined) {\n return commandForBinary(installedBinary, paths);\n }\n\n const target = resolveBrokerNativeTarget(platform, arch);\n throw new MissingPlatformBrokerBinaryError(\n `unable to resolve OpenTray broker binary for ${platform}/${arch}; install ${target.packageName} or set OPENTRAY_BROKER_BIN`,\n platform,\n arch,\n { packageName: target.packageName },\n );\n};\n\nconst commandForBinary = (binary: string, paths: DaemonPaths, cwd?: string): BrokerCommand => {\n const command: BrokerCommand = {\n command: binary,\n args: [\n \"broker\",\n \"--endpoint\",\n paths.endpoint,\n \"--ready-file\",\n paths.readyFile,\n \"--package-version\",\n paths.packageVersion,\n \"--protocol-version\",\n `${paths.protocolVersion}`,\n ],\n };\n if (cwd !== undefined) {\n command.cwd = cwd;\n }\n return command;\n};\n\ninterface ResolveInstalledBrokerBinaryOptions {\n platform: NodeJS.Platform;\n arch: string;\n resolvePackageJson: (packageName: string) => string | undefined;\n}\n\nexport const resolveInstalledBrokerBinary = async ({\n platform,\n arch,\n resolvePackageJson,\n}: ResolveInstalledBrokerBinaryOptions): Promise<string | undefined> => {\n const target = resolveBrokerNativeTarget(platform, arch);\n const packageJsonPath = resolvePackageJson(target.packageName);\n if (packageJsonPath === undefined) {\n return undefined;\n }\n\n const binary = join(dirname(packageJsonPath), target.binaryRelativePath);\n if (!(await exists(binary))) {\n throw new MissingPlatformBrokerBinaryError(\n `OpenTray broker package ${target.packageName} is installed but missing ${target.binaryRelativePath}`,\n platform,\n arch,\n {\n packageName: target.packageName,\n binaryPath: binary,\n },\n );\n }\n\n if (platform !== \"win32\") {\n await chmod(binary, 0o755);\n }\n\n return binary;\n};\n\nconst resolvePackageJson = (packageName: string): string | undefined => {\n try {\n return requireFromSource.resolve(`${packageName}/package.json`);\n } catch (error) {\n if (isNodeError(error) && error.code === \"MODULE_NOT_FOUND\") {\n return undefined;\n }\n throw error;\n }\n};\n\nconst findWorkspaceRoot = async (start: string): Promise<string | undefined> => {\n let current = start;\n while (true) {\n if (await exists(join(current, \"Cargo.toml\"))) {\n if (await exists(join(current, \"crates\", \"opentray-bin\", \"Cargo.toml\"))) {\n return current;\n }\n }\n\n const parent = dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n};\n\nconst ensureDevBrokerBinary = async (workspaceRoot: string): Promise<string> => {\n const binary = join(\n workspaceRoot,\n \"target\",\n \"debug\",\n process.platform === \"win32\" ? \"opentray.exe\" : \"opentray\",\n );\n await runCargoBuild(workspaceRoot);\n return binary;\n};\n\nconst runCargoBuild = (workspaceRoot: string): Promise<void> =>\n new Promise((resolve, reject) => {\n const child = spawn(\"cargo\", [\"build\", \"-p\", \"opentray-bin\"], {\n cwd: workspaceRoot,\n stdio: process.env.OPENTRAY_BROKER_BUILD_LOGS === \"1\" ? \"inherit\" : \"ignore\",\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n return;\n }\n reject(new Error(`cargo build -p opentray-bin failed with code ${code ?? \"unknown\"}`));\n });\n });\n\nconst exists = async (path: string): Promise<boolean> => {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException =>\n error instanceof Error && \"code\" in error;\n","import { constants } from \"node:fs\";\nimport { mkdir, open, readFile, rm, unlink, writeFile } from \"node:fs/promises\";\nimport { spawn } from \"node:child_process\";\n\nimport { resolveBrokerCommand } from \"./broker-command\";\nimport type { DaemonPaths } from \"./paths\";\n\nconst DAEMON_STDIO_ENV = \"OPENTRAY_DAEMON_STDIO\";\n\nexport type DaemonStartResult =\n | { status: \"started\"; pid: number; paths: DaemonPaths }\n | { status: \"already-running\"; pid: number; paths: DaemonPaths };\n\nexport type DaemonStopResult =\n | { status: \"stopped\"; pid: number; paths: DaemonPaths }\n | { status: \"not-running\"; paths: DaemonPaths };\n\nexport type DaemonInspectResult =\n | { status: \"running\"; pid: number; paths: DaemonPaths }\n | { status: \"not-running\"; paths: DaemonPaths; stalePid?: number };\n\nexport interface DaemonDriver {\n isAlive(pid: number): Promise<boolean>;\n spawnBroker(paths: DaemonPaths): Promise<number>;\n stop(pid: number): Promise<void>;\n}\n\nexport interface StartDaemonOptions {\n paths: DaemonPaths;\n driver: DaemonDriver;\n lockTimeoutMs?: number;\n}\n\nexport interface StopDaemonOptions {\n paths: DaemonPaths;\n driver: DaemonDriver;\n}\n\nexport interface InspectDaemonOptions {\n paths: DaemonPaths;\n driver: DaemonDriver;\n}\n\nexport const createNodeDaemonDriver = (cliEntrypoint: string): DaemonDriver => ({\n async isAlive(pid) {\n return isProcessAlive(pid);\n },\n async spawnBroker(paths) {\n const broker = await resolveBrokerCommand(paths);\n const child = spawn(broker.command, broker.args, {\n cwd: broker.cwd,\n detached: true,\n env: {\n ...process.env,\n OPENTRAY_DAEMON_HOME: paths.homeDir,\n OPENTRAY_DAEMON_PACKAGE_VERSION: paths.packageVersion,\n OPENTRAY_DAEMON_CLI_ENTRYPOINT: cliEntrypoint,\n },\n stdio: resolveBrokerStdio(process.env[DAEMON_STDIO_ENV]),\n });\n\n child.unref();\n return child.pid ?? 0;\n },\n async stop(pid) {\n process.kill(pid, \"SIGTERM\");\n },\n});\n\nexport const resolveBrokerStdio = (\n value: string | undefined,\n): \"ignore\" | \"inherit\" => {\n return value === \"inherit\" ? \"inherit\" : \"ignore\";\n};\n\nexport const startDaemon = async ({\n paths,\n driver,\n lockTimeoutMs = 1_000,\n}: StartDaemonOptions): Promise<DaemonStartResult> => {\n await mkdir(paths.runtimeDir, { recursive: true });\n\n const lock = await acquireLock(paths.lockFile, lockTimeoutMs);\n try {\n const existingPid = await readPid(paths.pidFile);\n if (existingPid !== undefined && (await driver.isAlive(existingPid))) {\n return { status: \"already-running\", pid: existingPid, paths };\n }\n\n await cleanupRuntimeFiles(paths);\n const pid = await driver.spawnBroker(paths);\n if (!Number.isInteger(pid) || pid <= 0) {\n throw new Error(\"daemon broker process did not expose a valid pid\");\n }\n await writeFile(paths.pidFile, `${pid}\\n`, \"utf8\");\n await waitForReadyFile(paths.readyFile);\n return { status: \"started\", pid, paths };\n } finally {\n await lock.release();\n }\n};\n\nexport const stopDaemon = async ({ paths, driver }: StopDaemonOptions): Promise<DaemonStopResult> => {\n const pid = await readPid(paths.pidFile);\n if (pid === undefined || !(await driver.isAlive(pid))) {\n await cleanupRuntimeFiles(paths);\n return { status: \"not-running\", paths };\n }\n\n await driver.stop(pid);\n await waitUntilStopped(driver, pid);\n await cleanupRuntimeFiles(paths);\n return { status: \"stopped\", pid, paths };\n};\n\nexport const restartDaemon = async (options: StartDaemonOptions): Promise<DaemonStartResult> => {\n await stopDaemon({ paths: options.paths, driver: options.driver });\n return startDaemon(options);\n};\n\nexport const inspectDaemon = async ({ paths, driver }: InspectDaemonOptions): Promise<DaemonInspectResult> => {\n const pid = await readPid(paths.pidFile);\n if (pid !== undefined && (await driver.isAlive(pid))) {\n return { status: \"running\", pid, paths };\n }\n\n await cleanupRuntimeFiles(paths);\n return pid === undefined\n ? { status: \"not-running\", paths }\n : { status: \"not-running\", paths, stalePid: pid };\n};\n\nconst readPid = async (pidFile: string): Promise<number | undefined> => {\n try {\n const content = await readFile(pidFile, \"utf8\");\n const pid = Number.parseInt(content.trim(), 10);\n return Number.isInteger(pid) && pid > 0 ? pid : undefined;\n } catch (error) {\n if (isNodeError(error) && error.code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n};\n\nconst cleanupRuntimeFiles = async (paths: DaemonPaths): Promise<void> => {\n await rm(paths.readyFile, { force: true });\n await rm(paths.pidFile, { force: true });\n if (process.platform !== \"win32\") {\n await rm(paths.endpoint, { force: true });\n }\n};\n\nconst waitUntilStopped = async (driver: DaemonDriver, pid: number): Promise<void> => {\n for (let attempt = 0; attempt < 20; attempt += 1) {\n if (!(await driver.isAlive(pid))) {\n return;\n }\n await sleep(50);\n }\n};\n\nconst waitForReadyFile = async (readyFile: string): Promise<void> => {\n for (let attempt = 0; attempt < 40; attempt += 1) {\n try {\n await readFile(readyFile, \"utf8\");\n return;\n } catch (error) {\n if (!isNodeError(error) || error.code !== \"ENOENT\") {\n throw error;\n }\n await sleep(50);\n }\n }\n\n throw new Error(`timed out waiting for daemon readiness: ${readyFile}`);\n};\n\nconst acquireLock = async (\n lockFile: string,\n timeoutMs: number,\n): Promise<{\n release(): Promise<void>;\n}> => {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() <= deadline) {\n try {\n const handle = await open(lockFile, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY);\n await handle.writeFile(`${process.pid}\\n`, \"utf8\");\n return {\n async release() {\n await handle.close();\n await unlink(lockFile).catch((error: unknown) => {\n if (!isNodeError(error) || error.code !== \"ENOENT\") {\n throw error;\n }\n });\n },\n };\n } catch (error) {\n if (isNodeError(error) && error.code === \"EEXIST\") {\n await sleep(25);\n continue;\n }\n throw error;\n }\n }\n\n throw new Error(`timed out acquiring daemon lock: ${lockFile}`);\n};\n\nconst isProcessAlive = (pid: number): boolean => {\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n};\n\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException =>\n error instanceof Error && \"code\" in error;\n","import { readFile } from \"node:fs/promises\";\n\nexport const readPackageVersion = async (packageJsonUrl: URL): Promise<string> => {\n const value: unknown = JSON.parse(await readFile(packageJsonUrl, \"utf8\"));\n if (!isPackageJsonWithVersion(value)) {\n throw new Error(`package.json is missing a string version: ${packageJsonUrl.href}`);\n }\n\n return value.version;\n};\n\nconst isPackageJsonWithVersion = (value: unknown): value is { version: string } =>\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n \"version\" in value &&\n typeof value.version === \"string\";\n","import { createBrokerEndpointIdentity, formatUnixSocketPath, formatWindowsPipeName } from \"@opentray/spec\";\n\nexport interface DaemonPathOptions {\n homeDir: string;\n packageVersion: string;\n platform?: NodeJS.Platform;\n}\n\nexport interface DaemonPaths {\n homeDir: string;\n packageVersion: string;\n protocolVersion: number;\n stateRoot: string;\n runtimeDir: string;\n endpoint: string;\n pidFile: string;\n lockFile: string;\n readyFile: string;\n}\n\nexport const resolveDaemonPaths = ({\n homeDir,\n packageVersion,\n platform = process.platform,\n}: DaemonPathOptions): DaemonPaths => {\n const identity = createBrokerEndpointIdentity({ packageVersion });\n const normalizedHome = homeDir.replace(/[\\\\/]+$/u, \"\");\n const stateRoot = `${normalizedHome}/.opentray/${identity.packageVersion}`;\n const runtimeDir = `${stateRoot}/runtime`;\n const endpoint =\n platform === \"win32\" ? formatWindowsPipeName(identity) : formatUnixSocketPath(normalizedHome, identity);\n\n return {\n homeDir: normalizedHome,\n packageVersion: identity.packageVersion,\n protocolVersion: identity.protocolVersion,\n stateRoot,\n runtimeDir,\n endpoint,\n pidFile: `${runtimeDir}/broker.pid`,\n lockFile: `${runtimeDir}/broker.lock`,\n readyFile: `${runtimeDir}/ready.json`,\n };\n};\n","import { createConnection, type Socket } from \"node:net\";\nimport { homedir } from \"node:os\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n PROTOCOL_VERSION,\n parseServerFrame,\n type BrokerEndpointIdentityOptions,\n type ClientRequestFrame,\n type RequestId,\n type ServerFrame,\n} from \"@opentray/spec\";\n\nimport type { OpenTrayTransport } from \"./client\";\nimport { createNodeDaemonDriver, startDaemon, type DaemonDriver } from \"./daemon/lifecycle\";\nimport { readPackageVersion } from \"./daemon/package-version\";\nimport { resolveDaemonPaths } from \"./daemon/paths\";\n\nconst packageJsonUrl = new URL(\"../package.json\", import.meta.url);\n\nexport type BrokerEventFrame = Extract<ServerFrame, { type: \"event\" | \"ext-event\" }>;\n\nexport interface LocalBrokerClient extends OpenTrayTransport {\n readonly endpoint: string;\n readonly sessionId: string;\n /** @deprecated Use `sessionId`. */\n readonly leaseId: string;\n onEvent(listener: (frame: BrokerEventFrame) => void): () => void;\n close(): Promise<void>;\n}\n\nexport interface ConnectLocalBrokerOptions extends Partial<BrokerEndpointIdentityOptions> {\n endpoint?: string;\n homeDir?: string;\n clientVersion?: string;\n autoStart?: boolean;\n daemonDriver?: DaemonDriver;\n cliEntrypoint?: string;\n}\n\ninterface PendingRequest {\n resolve(frame: ServerFrame): void;\n reject(error: Error): void;\n}\n\ninterface BrokerSocket {\n setEncoding(encoding: BufferEncoding): void;\n on(event: \"data\", listener: (chunk: Buffer | string) => void): void;\n on(event: \"error\", listener: (error: Error) => void): void;\n on(event: \"close\", listener: () => void): void;\n once(event: \"connect\", listener: () => void): void;\n once(event: \"error\", listener: (error: Error) => void): void;\n off(event: \"error\", listener: (error: Error) => void): void;\n write(data: string): void;\n end(callback: () => void): void;\n}\n\nexport const connectLocalBroker = async (\n options: ConnectLocalBrokerOptions = {},\n): Promise<LocalBrokerClient> => {\n const packageVersion = options.packageVersion ?? (await readPackageVersion(packageJsonUrl));\n const clientVersion = options.clientVersion ?? packageVersion;\n const paths = resolveDaemonPaths({\n homeDir: options.homeDir ?? process.env.OPENTRAY_HOME ?? homedir(),\n packageVersion,\n });\n const endpoint = options.endpoint ?? paths.endpoint;\n const autoStart = options.autoStart ?? endpoint === paths.endpoint;\n if (autoStart && endpoint !== paths.endpoint) {\n throw new Error(\"local broker autoStart requires the derived same-version endpoint\");\n }\n if (autoStart) {\n const cliEntrypoint = options.cliEntrypoint ?? resolveCliEntrypoint();\n const driver = options.daemonDriver ?? createNodeDaemonDriver(cliEntrypoint);\n await startDaemon({ paths, driver });\n }\n const socket = await connectSocket(endpoint);\n const connection = new LocalBrokerConnection(socket, endpoint);\n\n await connection.init(clientVersion, options.protocolVersion ?? PROTOCOL_VERSION);\n return connection;\n};\n\nclass LocalBrokerConnection implements LocalBrokerClient {\n readonly endpoint: string;\n sessionId = \"\";\n /** @deprecated Use `sessionId`. */\n leaseId = \"\";\n\n private buffer = \"\";\n private readonly listeners = new Set<(frame: BrokerEventFrame) => void>();\n private readonly pending = new Map<RequestId, PendingRequest>();\n private ready:\n | {\n resolve(frame: Extract<ServerFrame, { type: \"ready\" }>): void;\n reject(error: Error): void;\n }\n | undefined;\n\n constructor(\n private readonly socket: BrokerSocket,\n endpoint: string,\n ) {\n this.endpoint = endpoint;\n socket.setEncoding(\"utf8\");\n socket.on(\"data\", (chunk: Buffer | string) => {\n this.consume(String(chunk));\n });\n socket.on(\"error\", (error) => {\n this.rejectAll(error);\n });\n socket.on(\"close\", () => {\n this.rejectAll(new Error(\"broker connection closed\"));\n });\n }\n\n async init(clientVersion: string, protocolVersion: number): Promise<void> {\n const ready = new Promise<Extract<ServerFrame, { type: \"ready\" }>>((resolve, reject) => {\n this.ready = { resolve, reject };\n });\n this.write({\n type: \"init\",\n protocolVersion,\n clientVersion,\n });\n const frame = await ready;\n this.sessionId = frame.sessionId;\n this.leaseId = frame.sessionId;\n }\n\n async request(frame: ClientRequestFrame): Promise<ServerFrame> {\n if (this.pending.has(frame.requestId)) {\n throw new Error(`duplicate requestId: ${frame.requestId}`);\n }\n\n const response = new Promise<ServerFrame>((resolve, reject) => {\n this.pending.set(frame.requestId, { resolve, reject });\n });\n this.write(frame);\n return response;\n }\n\n onEvent(listener: (frame: BrokerEventFrame) => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n async close(): Promise<void> {\n this.write({ type: \"exit\" });\n await new Promise<void>((resolve) => {\n this.socket.end(resolve);\n });\n }\n\n private consume(chunk: string): void {\n this.buffer += chunk;\n while (true) {\n const newline = this.buffer.indexOf(\"\\n\");\n if (newline < 0) {\n return;\n }\n\n const line = this.buffer.slice(0, newline).trim();\n this.buffer = this.buffer.slice(newline + 1);\n if (line.length > 0) {\n this.dispatchLine(line);\n }\n }\n }\n\n private dispatchLine(line: string): void {\n const parsed = parseServerFrame(line);\n if (!parsed.ok || parsed.frame === undefined) {\n this.rejectAll(new Error(parsed.error ?? \"invalid server frame\"));\n return;\n }\n\n this.dispatchFrame(parsed.frame);\n }\n\n private dispatchFrame(frame: ServerFrame): void {\n if (frame.type === \"ready\") {\n this.ready?.resolve(frame);\n this.ready = undefined;\n return;\n }\n\n if (frame.type === \"error\") {\n const error = new Error(`${frame.code}: ${frame.message}`);\n if (frame.requestId !== undefined) {\n this.pending.get(frame.requestId)?.reject(error);\n this.pending.delete(frame.requestId);\n return;\n }\n this.ready?.reject(error);\n this.ready = undefined;\n return;\n }\n\n const requestId = responseRequestId(frame);\n if (requestId !== undefined) {\n // Request responses and broker events are separate streams even on one socket.\n this.pending.get(requestId)?.resolve(frame);\n this.pending.delete(requestId);\n return;\n }\n\n if (frame.type === \"event\" || frame.type === \"ext-event\") {\n for (const listener of this.listeners) {\n listener(frame);\n }\n }\n }\n\n private write(frame: unknown): void {\n this.socket.write(`${JSON.stringify(frame)}\\n`);\n }\n\n private rejectAll(error: Error): void {\n this.ready?.reject(error);\n this.ready = undefined;\n for (const pending of this.pending.values()) {\n pending.reject(error);\n }\n this.pending.clear();\n }\n}\n\nconst connectSocket = (endpoint: string): Promise<BrokerSocket> =>\n new Promise((resolve, reject) => {\n const socket = createConnection(endpoint);\n socket.once(\"connect\", () => {\n socket.off(\"error\", reject);\n resolve(socket);\n });\n socket.once(\"error\", reject);\n });\n\nconst responseRequestId = (frame: ServerFrame): RequestId | undefined => {\n switch (frame.type) {\n case \"space-created\":\n case \"default-space\":\n case \"tray-created\":\n case \"tray-bounds\":\n case \"ack\":\n case \"daemon-health\":\n return frame.requestId;\n case \"ready\":\n case \"event\":\n case \"ext-event\":\n case \"error\":\n return undefined;\n }\n};\n\nconst resolveCliEntrypoint = (): string => {\n const suffix = fileURLToPath(import.meta.url).endsWith(\".ts\") ? \"cli.ts\" : \"cli.mjs\";\n return fileURLToPath(new URL(`./${suffix}`, import.meta.url));\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAa,6BACX,WAAmB,QAAQ,UAC3B,OAAe,QAAQ,SACA;CACvB,MAAM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,MAAM,SAAS,WAAW,MAAM,SAAS,aAC3C,KAAK,MAAM,YAAY,KAAK,WAC1B,SAAS,KAAK;CAGpB;CAEA,MAAc,OAAsB;EAClC,KAAK,OAAO,MAAM,GAAG,KAAK,UAAU,KAAK,EAAE,GAAG;CAChD;CAEA,UAAkB,OAAoB;EACpC,KAAK,OAAO,OAAO,KAAK;EACxB,KAAK,QAAQ,KAAA;EACb,KAAK,MAAM,WAAW,KAAK,QAAQ,OAAO,GACxC,QAAQ,OAAO,KAAK;EAEtB,KAAK,QAAQ,MAAM;CACrB;AACF;AAEA,MAAM,iBAAiB,aACrB,IAAI,SAAS,SAAS,WAAW;CAC/B,MAAM,SAAS,iBAAiB,QAAQ;CACxC,OAAO,KAAK,iBAAiB;EAC3B,OAAO,IAAI,SAAS,MAAM;EAC1B,QAAQ,MAAM;CAChB,CAAC;CACD,OAAO,KAAK,SAAS,MAAM;AAC7B,CAAC;AAEH,MAAM,qBAAqB,UAA8C;CACvE,QAAQ,MAAM,MAAd;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,iBACH,OAAO,MAAM;EACf,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH;CACJ;AACF;AAEA,MAAM,6BAAqC;CACzC,MAAM,SAAS,cAAc,OAAO,KAAK,GAAG,EAAE,SAAS,KAAK,IAAI,WAAW;CAC3E,OAAO,cAAc,IAAI,IAAI,KAAK,UAAU,OAAO,KAAK,GAAG,CAAC;AAC9D"}
|
package/dist/node.d.mts
CHANGED
package/dist/node.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/daemon/paths.ts","../src/daemon/lifecycle.ts","../src/local-broker.ts"],"mappings":";;;;UAQiB,WAAA;EACf,OAAA;EACA,cAAA;EACA,eAAA;EACA,SAAA;EACA,UAAA;EACA,QAAA;EACA,OAAA;EACA,QAAA;EACA,SAAA;AAAA;;;
|
|
1
|
+
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/daemon/paths.ts","../src/daemon/lifecycle.ts","../src/local-broker.ts"],"mappings":";;;;UAQiB,WAAA;EACf,OAAA;EACA,cAAA;EACA,eAAA;EACA,SAAA;EACA,UAAA;EACA,QAAA;EACA,OAAA;EACA,QAAA;EACA,SAAA;AAAA;;;UCIe,YAAA;EACf,OAAA,CAAQ,GAAA,WAAc,OAAA;EACtB,WAAA,CAAY,KAAA,EAAO,WAAA,GAAc,OAAA;EACjC,IAAA,CAAK,GAAA,WAAc,OAAA;AAAA;;;KCJT,gBAAA,GAAmB,OAAO,CAAC,WAAA;EAAe,IAAA;AAAA;AAAA,UAErC,iBAAA,SAA0B,iBAAA;EAAA,SAChC,QAAA;EAAA,SACA,SAAA;EFdT;EAAA,SEgBS,OAAA;EACT,OAAA,CAAQ,QAAA,GAAW,KAAA,EAAO,gBAAA;EAC1B,KAAA,IAAS,OAAA;AAAA;AAAA,UAGM,yBAAA,SAAkC,OAAA,CAAQ,6BAAA;EACzD,QAAA;EACA,OAAA;EACA,aAAA;EACA,SAAA;EACA,YAAA,GAAe,YAAA;EACf,aAAA;AAAA;AAAA,cAoBW,kBAAA,GACX,OAAA,GAAS,yBAAA,KACR,OAAA,CAAQ,iBAAA"}
|
package/dist/node.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as connectLocalBroker } from "./local-broker-
|
|
1
|
+
import { t as connectLocalBroker } from "./local-broker-CEIHPBcK.mjs";
|
|
2
2
|
export { connectLocalBroker };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opentray",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Developer-facing OpenTray SDK and CLI package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,12 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
|
-
"assets",
|
|
28
27
|
"README.md"
|
|
29
28
|
],
|
|
30
29
|
"sideEffects": false,
|
|
31
30
|
"dependencies": {
|
|
32
|
-
"@opentray/spec": "0.
|
|
31
|
+
"@opentray/spec": "0.4.0"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"tsdown": "^0.22.1",
|
|
@@ -37,12 +36,12 @@
|
|
|
37
36
|
"vitest": "^4.1.7"
|
|
38
37
|
},
|
|
39
38
|
"optionalDependencies": {
|
|
40
|
-
"@opentray/darwin-arm64": "0.
|
|
41
|
-
"@opentray/darwin-x64": "0.
|
|
42
|
-
"@opentray/linux-arm64": "0.
|
|
43
|
-
"@opentray/linux-x64": "0.
|
|
44
|
-
"@opentray/windows-arm64": "0.
|
|
45
|
-
"@opentray/windows-x64": "0.
|
|
39
|
+
"@opentray/darwin-arm64": "0.5.0",
|
|
40
|
+
"@opentray/darwin-x64": "0.5.0",
|
|
41
|
+
"@opentray/linux-arm64": "0.5.0",
|
|
42
|
+
"@opentray/linux-x64": "0.5.0",
|
|
43
|
+
"@opentray/windows-arm64": "0.5.0",
|
|
44
|
+
"@opentray/windows-x64": "0.5.0"
|
|
46
45
|
},
|
|
47
46
|
"scripts": {
|
|
48
47
|
"build": "tsdown src/index.ts src/node.ts src/cli.ts --format esm --dts",
|
|
@@ -50,6 +49,8 @@
|
|
|
50
49
|
"example:basic": "bun run examples/basic-space.ts",
|
|
51
50
|
"example:daemon-lynx": "bun run examples/daemon-lynx.ts",
|
|
52
51
|
"example:daemon-tray": "bun run examples/daemon-tray.ts",
|
|
52
|
+
"example:tray-panel": "bun run examples/tray-panel.ts",
|
|
53
|
+
"example:webview-control": "bun run examples/webview-control.ts",
|
|
53
54
|
"test": "vitest run",
|
|
54
55
|
"typecheck": "tsc --noEmit"
|
|
55
56
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
## Lynx Review Bundle
|
|
2
|
-
|
|
3
|
-
This directory contains the package-owned Lynx review bundle used by the public CLI smoke:
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
opentray smoke daemon-lynx
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
The goal is post-publish human verification. A fresh npm install must be able to open a real Lynx window without depending on a workspace checkout or `research/` paths.
|
|
10
|
-
|
|
11
|
-
TODO:
|
|
12
|
-
|
|
13
|
-
- move the source of this review app into a tracked repo-owned source root instead of relying on a copied research build artifact
|
|
14
|
-
- keep the bundle focused on visual/runtime acceptance, not on product features unrelated to extension-host verification
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-C_zT7PEt.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;UAYiB,iBAAA;EACf,OAAA,CAAQ,KAAA,EAAO,kBAAA,GAAqB,OAAA,CAAQ,WAAA;AAAA;AAAA,UAG7B,cAAA;EACf,WAAA,CAAY,OAAA,EAAS,YAAA,GAAe,OAAA,CAAQ,WAAA;EAC5C,mBAAA,IAAuB,OAAA,CAAQ,WAAA;EALa;EAO5C,aAAA,CAAc,OAAA,EAAS,YAAA,GAAe,OAAA,CAAQ,WAAA;AAAA;AAAA,UAG/B,WAAA;EACf,KAAA,EAAO,QAAA;EACP,UAAA,CAAW,OAAA,EAAS,WAAA,GAAc,OAAA,CAAQ,UAAA;AAAA;;KAIhC,aAAA,GAAgB,WAAW;AAAA,UAEtB,UAAA;EACf,KAAA,EAAO,QAAA;EACP,MAAA,EAAQ,MAAA;EACR,gBAAA,CAAiB,GAAA,UAAa,IAAA,YAAgB,OAAA;EAC9C,OAAA,IAAW,OAAA;AAAA;AAAA,cAGA,eAAA,GAAmB,aAAA,aAAwB,WAItD;AAAA,UAEe,mBAAA;EACf,eAAe;AAAA;AAAA,cAGJ,YAAA,GACX,SAAA,EAAW,iBAAA,EACX,OAAA,GAAS,mBAAA,KACR,cAAA;AAAA,cA6BU,iBAAA,GACX,SAAA,EAAW,iBAAA,EACX,KAAA,EAAO,QAAA,EACP,aAAA,SAAqB,SAAA,KACpB,WAAA;;cAgBU,mBAAA,GAAmB,SAAA,EAnBnB,iBAAA,EAAiB,KAAA,EACrB,QAAA,EAAQ,aAAA,SACM,SAAA,KACpB,WAAA;AAAA,cAkBU,gBAAA,GACX,SAAA,EAAW,iBAAA,EACX,KAAA,EAAO,QAAA,EACP,MAAA,EAAQ,MAAA,EACR,aAAA,SAAqB,SAAA,KACpB,UAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-Db-tztnj.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n PROTOCOL_VERSION,\n type ClientFrame,\n type ClientRequestFrame,\n type RequestId,\n type ServerFrame,\n type SpaceOptions,\n type SpaceRef,\n type TrayId,\n type TrayOptions,\n} from \"@opentray/spec\";\n\nexport interface OpenTrayTransport {\n request(frame: ClientRequestFrame): Promise<ServerFrame>;\n}\n\nexport interface OpenTrayClient {\n createSpace(options: SpaceOptions): Promise<SpaceHandle>;\n resolveDefaultSpace(): Promise<SpaceHandle>;\n /** @deprecated Use `createSpace`. */\n createSurface(options: SpaceOptions): Promise<SpaceHandle>;\n}\n\nexport interface SpaceHandle {\n space: SpaceRef;\n createTray(options: TrayOptions): Promise<TrayHandle>;\n}\n\n/** @deprecated Use `SpaceHandle`. */\nexport type SurfaceHandle = SpaceHandle;\n\nexport interface TrayHandle {\n space: SpaceRef;\n trayId: TrayId;\n commandExtension(ext: string, data: unknown): Promise<void>;\n destroy(): Promise<void>;\n}\n\nexport const createInitFrame = (clientVersion: string): ClientFrame => ({\n type: \"init\",\n protocolVersion: PROTOCOL_VERSION,\n clientVersion,\n});\n\nexport interface CreateClientOptions {\n requestIdPrefix?: string;\n}\n\nexport const createClient = (\n transport: OpenTrayTransport,\n options: CreateClientOptions = {},\n): OpenTrayClient => {\n const nextRequestId = createRequestIdFactory(options.requestIdPrefix ?? \"opentray\");\n\n return {\n async createSpace(spaceOptions): Promise<SpaceHandle> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"create-space\",\n requestId,\n ...spaceOptions,\n });\n const space = expectResponse(response, requestId, \"space-created\").space;\n return createSpaceHandle(transport, space, nextRequestId);\n },\n async resolveDefaultSpace(): Promise<SpaceHandle> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"resolve-default-space\",\n requestId,\n });\n const space = expectResponse(response, requestId, \"default-space\").space;\n return createSpaceHandle(transport, space, nextRequestId);\n },\n async createSurface(spaceOptions): Promise<SpaceHandle> {\n return this.createSpace(spaceOptions);\n },\n };\n};\n\nexport const createSpaceHandle = (\n transport: OpenTrayTransport,\n space: SpaceRef,\n nextRequestId: () => RequestId = createRequestIdFactory(\"opentray\"),\n): SpaceHandle => ({\n space,\n async createTray(options: TrayOptions): Promise<TrayHandle> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"create-tray\",\n requestId,\n space,\n tray: options,\n });\n const frame = expectResponse(response, requestId, \"tray-created\");\n return createTrayHandle(transport, space, frame.trayId, nextRequestId);\n },\n});\n\n/** @deprecated Use `createSpaceHandle`. */\nexport const createSurfaceHandle = createSpaceHandle;\n\nexport const createTrayHandle = (\n transport: OpenTrayTransport,\n space: SpaceRef,\n trayId: TrayId,\n nextRequestId: () => RequestId = createRequestIdFactory(\"opentray\"),\n): TrayHandle => ({\n space,\n trayId,\n async commandExtension(ext: string, data: unknown): Promise<void> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"ext-command\",\n requestId,\n spaceId: space.spaceId,\n trayId,\n ext,\n data,\n });\n expectResponse(response, requestId, \"ack\");\n },\n async destroy(): Promise<void> {\n const requestId = nextRequestId();\n const response = await transport.request({\n type: \"destroy-tray\",\n requestId,\n spaceId: space.spaceId,\n trayId,\n });\n expectResponse(response, requestId, \"ack\");\n },\n});\n\nconst createRequestIdFactory = (prefix: string): (() => RequestId) => {\n let next = 1;\n return () => {\n const requestId = `${prefix}-${next}`;\n next += 1;\n return requestId;\n };\n};\n\nconst expectResponse = <TType extends ServerFrame[\"type\"]>(\n frame: ServerFrame,\n requestId: RequestId,\n type: TType,\n): Extract<ServerFrame, { type: TType }> => {\n if (frame.type === \"error\") {\n throw new Error(`${frame.code}: ${frame.message}`);\n }\n if (frame.type !== type) {\n throw new Error(`expected ${type} for ${requestId}, received ${frame.type}`);\n }\n if (requestIdOf(frame) !== requestId) {\n throw new Error(`expected response for ${requestId}, received ${requestIdOf(frame) ?? \"none\"}`);\n }\n return frame as Extract<ServerFrame, { type: TType }>;\n};\n\nconst requestIdOf = (frame: ServerFrame): RequestId | undefined => {\n switch (frame.type) {\n case \"space-created\":\n case \"default-space\":\n case \"tray-created\":\n case \"ack\":\n case \"daemon-health\":\n return frame.requestId;\n case \"error\":\n return frame.requestId;\n case \"ready\":\n case \"event\":\n case \"ext-event\":\n return undefined;\n }\n};\n"],"mappings":";;AAsCA,MAAa,mBAAmB,mBAAwC;CACtE,MAAM;CACN,iBAAiB;CACjB;AACF;AAMA,MAAa,gBACX,WACA,UAA+B,CAAC,MACb;CACnB,MAAM,gBAAgB,uBAAuB,QAAQ,mBAAmB,UAAU;CAElF,OAAO;EACL,MAAM,YAAY,cAAoC;GACpD,MAAM,YAAY,cAAc;GAMhC,MAAM,QAAQ,eAAe,MALN,UAAU,QAAQ;IACvC,MAAM;IACN;IACA,GAAG;GACL,CAAC,GACsC,WAAW,eAAe,EAAE;GACnE,OAAO,kBAAkB,WAAW,OAAO,aAAa;EAC1D;EACA,MAAM,sBAA4C;GAChD,MAAM,YAAY,cAAc;GAKhC,MAAM,QAAQ,eAAe,MAJN,UAAU,QAAQ;IACvC,MAAM;IACN;GACF,CAAC,GACsC,WAAW,eAAe,EAAE;GACnE,OAAO,kBAAkB,WAAW,OAAO,aAAa;EAC1D;EACA,MAAM,cAAc,cAAoC;GACtD,OAAO,KAAK,YAAY,YAAY;EACtC;CACF;AACF;AAEA,MAAa,qBACX,WACA,OACA,gBAAiC,uBAAuB,UAAU,OACjD;CACjB;CACA,MAAM,WA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KAAK;EACL,KAAK,aACH;CACJ;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-broker-mQmeVLF5.mjs","names":["isNodeError"],"sources":["../src/daemon/native-target.ts","../src/daemon/broker-command.ts","../src/daemon/lifecycle.ts","../src/daemon/package-version.ts","../src/daemon/paths.ts","../src/local-broker.ts"],"sourcesContent":["export type BrokerPackageOs = \"darwin\" | \"linux\" | \"windows\";\nexport type BrokerArch = \"arm64\" | \"x64\";\n\nexport interface BrokerNativeTarget {\n packageName: string;\n binaryRelativePath: string;\n}\n\nexport const resolveBrokerNativeTarget = (\n platform: string = process.platform,\n arch: string = process.arch,\n): BrokerNativeTarget => {\n const packageOs = platformToPackageOs(platform);\n const nativeArch = normalizeArch(arch);\n return {\n packageName: `@opentray/${packageOs}-${nativeArch}`,\n binaryRelativePath: `bin/${packageOs === \"windows\" ? \"opentray.exe\" : \"opentray\"}`,\n };\n};\n\nconst platformToPackageOs = (platform: string): BrokerPackageOs => {\n switch (platform) {\n case \"darwin\":\n case \"linux\":\n return platform;\n case \"win32\":\n return \"windows\";\n default:\n throw new MissingPlatformBrokerBinaryError(\n `unsupported OpenTray broker platform: ${platform}`,\n platform,\n process.arch,\n );\n }\n};\n\nconst normalizeArch = (arch: string): BrokerArch => {\n switch (arch) {\n case \"arm64\":\n case \"x64\":\n return arch;\n default:\n throw new MissingPlatformBrokerBinaryError(\n `unsupported OpenTray broker architecture: ${arch}`,\n process.platform,\n arch,\n );\n }\n};\n\nexport class MissingPlatformBrokerBinaryError extends Error {\n readonly code = \"OPENTRAY_MISSING_PLATFORM_BROKER_BINARY\";\n readonly platform: string;\n readonly arch: string;\n readonly packageName: string | undefined;\n readonly binaryPath: string | undefined;\n\n constructor(\n message: string,\n platform: string,\n arch: string,\n options: {\n packageName?: string;\n binaryPath?: string;\n cause?: unknown;\n } = {},\n ) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = \"MissingPlatformBrokerBinaryError\";\n this.platform = platform;\n this.arch = arch;\n this.packageName = options.packageName;\n this.binaryPath = options.binaryPath;\n }\n}\n","import { access, chmod } from \"node:fs/promises\";\nimport { constants } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { fileURLToPath } from \"node:url\";\nimport { spawn } from \"node:child_process\";\n\nimport type { DaemonPaths } from \"./paths\";\nimport { MissingPlatformBrokerBinaryError, resolveBrokerNativeTarget } from \"./native-target\";\n\nexport interface BrokerCommand {\n command: string;\n args: string[];\n cwd?: string;\n}\n\nconst sourceUrl = import.meta.url;\nconst requireFromSource = createRequire(sourceUrl);\n\nexport interface ResolveBrokerCommandOptions {\n env?: NodeJS.ProcessEnv;\n platform?: NodeJS.Platform;\n arch?: string;\n sourceDir?: string;\n resolvePackageJson?: (packageName: string) => string | undefined;\n findWorkspaceRoot?: (start: string) => Promise<string | undefined>;\n ensureDevBrokerBinary?: (workspaceRoot: string) => Promise<string>;\n}\n\nexport const resolveBrokerCommand = async (\n paths: DaemonPaths,\n options: ResolveBrokerCommandOptions = {},\n): Promise<BrokerCommand> => {\n const env = options.env ?? process.env;\n const explicit = env.OPENTRAY_BROKER_BIN;\n if (explicit !== undefined && explicit.length > 0) {\n return commandForBinary(explicit, paths);\n }\n\n const platform = options.platform ?? process.platform;\n const arch = options.arch ?? process.arch;\n let installedBinaryError: MissingPlatformBrokerBinaryError | undefined;\n try {\n const installedBinary = await resolveInstalledBrokerBinary({\n platform,\n arch,\n resolvePackageJson: options.resolvePackageJson ?? resolvePackageJson,\n });\n if (installedBinary !== undefined) {\n return commandForBinary(installedBinary, paths);\n }\n } catch (error) {\n if (!(error instanceof MissingPlatformBrokerBinaryError)) {\n throw error;\n }\n installedBinaryError = error;\n }\n\n const sourceDir = options.sourceDir ?? dirname(fileURLToPath(sourceUrl));\n const workspaceRoot = await (options.findWorkspaceRoot ?? findWorkspaceRoot)(sourceDir);\n if (workspaceRoot !== undefined) {\n const binary = await (options.ensureDevBrokerBinary ?? ensureDevBrokerBinary)(workspaceRoot);\n return commandForBinary(binary, paths, workspaceRoot);\n }\n\n if (installedBinaryError !== undefined) {\n throw installedBinaryError;\n }\n\n const target = resolveBrokerNativeTarget(platform, arch);\n throw new MissingPlatformBrokerBinaryError(\n `unable to resolve OpenTray broker binary for ${platform}/${arch}; install ${target.packageName} or set OPENTRAY_BROKER_BIN`,\n platform,\n arch,\n { packageName: target.packageName },\n );\n};\n\nconst commandForBinary = (binary: string, paths: DaemonPaths, cwd?: string): BrokerCommand => {\n const command: BrokerCommand = {\n command: binary,\n args: [\n \"broker\",\n \"--endpoint\",\n paths.endpoint,\n \"--ready-file\",\n paths.readyFile,\n \"--package-version\",\n paths.packageVersion,\n \"--protocol-version\",\n `${paths.protocolVersion}`,\n ],\n };\n if (cwd !== undefined) {\n command.cwd = cwd;\n }\n return command;\n};\n\ninterface ResolveInstalledBrokerBinaryOptions {\n platform: NodeJS.Platform;\n arch: string;\n resolvePackageJson: (packageName: string) => string | undefined;\n}\n\nexport const resolveInstalledBrokerBinary = async ({\n platform,\n arch,\n resolvePackageJson,\n}: ResolveInstalledBrokerBinaryOptions): Promise<string | undefined> => {\n const target = resolveBrokerNativeTarget(platform, arch);\n const packageJsonPath = resolvePackageJson(target.packageName);\n if (packageJsonPath === undefined) {\n return undefined;\n }\n\n const binary = join(dirname(packageJsonPath), target.binaryRelativePath);\n if (!(await exists(binary))) {\n throw new MissingPlatformBrokerBinaryError(\n `OpenTray broker package ${target.packageName} is installed but missing ${target.binaryRelativePath}`,\n platform,\n arch,\n {\n packageName: target.packageName,\n binaryPath: binary,\n },\n );\n }\n\n if (platform !== \"win32\") {\n await chmod(binary, 0o755);\n }\n\n return binary;\n};\n\nconst resolvePackageJson = (packageName: string): string | undefined => {\n try {\n return requireFromSource.resolve(`${packageName}/package.json`);\n } catch (error) {\n if (isNodeError(error) && error.code === \"MODULE_NOT_FOUND\") {\n return undefined;\n }\n throw error;\n }\n};\n\nconst findWorkspaceRoot = async (start: string): Promise<string | undefined> => {\n let current = start;\n while (true) {\n if (await exists(join(current, \"Cargo.toml\"))) {\n if (await exists(join(current, \"crates\", \"opentray-bin\", \"Cargo.toml\"))) {\n return current;\n }\n }\n\n const parent = dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n};\n\nconst ensureDevBrokerBinary = async (workspaceRoot: string): Promise<string> => {\n const binary = join(\n workspaceRoot,\n \"target\",\n \"debug\",\n process.platform === \"win32\" ? \"opentray.exe\" : \"opentray\",\n );\n await runCargoBuild(workspaceRoot);\n return binary;\n};\n\nconst runCargoBuild = (workspaceRoot: string): Promise<void> =>\n new Promise((resolve, reject) => {\n const child = spawn(\"cargo\", [\"build\", \"-p\", \"opentray-bin\"], {\n cwd: workspaceRoot,\n stdio: process.env.OPENTRAY_BROKER_BUILD_LOGS === \"1\" ? \"inherit\" : \"ignore\",\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n return;\n }\n reject(new Error(`cargo build -p opentray-bin failed with code ${code ?? \"unknown\"}`));\n });\n });\n\nconst exists = async (path: string): Promise<boolean> => {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException =>\n error instanceof Error && \"code\" in error;\n","import { constants } from \"node:fs\";\nimport { mkdir, open, readFile, rm, unlink, writeFile } from \"node:fs/promises\";\nimport { spawn } from \"node:child_process\";\n\nimport { resolveBrokerCommand } from \"./broker-command\";\nimport type { DaemonPaths } from \"./paths\";\n\nexport type DaemonStartResult =\n | { status: \"started\"; pid: number; paths: DaemonPaths }\n | { status: \"already-running\"; pid: number; paths: DaemonPaths };\n\nexport type DaemonStopResult =\n | { status: \"stopped\"; pid: number; paths: DaemonPaths }\n | { status: \"not-running\"; paths: DaemonPaths };\n\nexport type DaemonInspectResult =\n | { status: \"running\"; pid: number; paths: DaemonPaths }\n | { status: \"not-running\"; paths: DaemonPaths; stalePid?: number };\n\nexport interface DaemonDriver {\n isAlive(pid: number): Promise<boolean>;\n spawnBroker(paths: DaemonPaths): Promise<number>;\n stop(pid: number): Promise<void>;\n}\n\nexport interface StartDaemonOptions {\n paths: DaemonPaths;\n driver: DaemonDriver;\n lockTimeoutMs?: number;\n}\n\nexport interface StopDaemonOptions {\n paths: DaemonPaths;\n driver: DaemonDriver;\n}\n\nexport interface InspectDaemonOptions {\n paths: DaemonPaths;\n driver: DaemonDriver;\n}\n\nexport const createNodeDaemonDriver = (cliEntrypoint: string): DaemonDriver => ({\n async isAlive(pid) {\n return isProcessAlive(pid);\n },\n async spawnBroker(paths) {\n const broker = await resolveBrokerCommand(paths);\n const child = spawn(broker.command, broker.args, {\n cwd: broker.cwd,\n detached: true,\n env: {\n ...process.env,\n OPENTRAY_DAEMON_HOME: paths.homeDir,\n OPENTRAY_DAEMON_PACKAGE_VERSION: paths.packageVersion,\n OPENTRAY_DAEMON_CLI_ENTRYPOINT: cliEntrypoint,\n },\n stdio: \"ignore\",\n });\n\n child.unref();\n return child.pid ?? 0;\n },\n async stop(pid) {\n process.kill(pid, \"SIGTERM\");\n },\n});\n\nexport const startDaemon = async ({\n paths,\n driver,\n lockTimeoutMs = 1_000,\n}: StartDaemonOptions): Promise<DaemonStartResult> => {\n await mkdir(paths.runtimeDir, { recursive: true });\n\n const lock = await acquireLock(paths.lockFile, lockTimeoutMs);\n try {\n const existingPid = await readPid(paths.pidFile);\n if (existingPid !== undefined && (await driver.isAlive(existingPid))) {\n return { status: \"already-running\", pid: existingPid, paths };\n }\n\n await cleanupRuntimeFiles(paths);\n const pid = await driver.spawnBroker(paths);\n if (!Number.isInteger(pid) || pid <= 0) {\n throw new Error(\"daemon broker process did not expose a valid pid\");\n }\n await writeFile(paths.pidFile, `${pid}\\n`, \"utf8\");\n await waitForReadyFile(paths.readyFile);\n return { status: \"started\", pid, paths };\n } finally {\n await lock.release();\n }\n};\n\nexport const stopDaemon = async ({ paths, driver }: StopDaemonOptions): Promise<DaemonStopResult> => {\n const pid = await readPid(paths.pidFile);\n if (pid === undefined || !(await driver.isAlive(pid))) {\n await cleanupRuntimeFiles(paths);\n return { status: \"not-running\", paths };\n }\n\n await driver.stop(pid);\n await waitUntilStopped(driver, pid);\n await cleanupRuntimeFiles(paths);\n return { status: \"stopped\", pid, paths };\n};\n\nexport const restartDaemon = async (options: StartDaemonOptions): Promise<DaemonStartResult> => {\n await stopDaemon({ paths: options.paths, driver: options.driver });\n return startDaemon(options);\n};\n\nexport const inspectDaemon = async ({ paths, driver }: InspectDaemonOptions): Promise<DaemonInspectResult> => {\n const pid = await readPid(paths.pidFile);\n if (pid !== undefined && (await driver.isAlive(pid))) {\n return { status: \"running\", pid, paths };\n }\n\n await cleanupRuntimeFiles(paths);\n return pid === undefined\n ? { status: \"not-running\", paths }\n : { status: \"not-running\", paths, stalePid: pid };\n};\n\nconst readPid = async (pidFile: string): Promise<number | undefined> => {\n try {\n const content = await readFile(pidFile, \"utf8\");\n const pid = Number.parseInt(content.trim(), 10);\n return Number.isInteger(pid) && pid > 0 ? pid : undefined;\n } catch (error) {\n if (isNodeError(error) && error.code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n};\n\nconst cleanupRuntimeFiles = async (paths: DaemonPaths): Promise<void> => {\n await rm(paths.readyFile, { force: true });\n await rm(paths.pidFile, { force: true });\n if (process.platform !== \"win32\") {\n await rm(paths.endpoint, { force: true });\n }\n};\n\nconst waitUntilStopped = async (driver: DaemonDriver, pid: number): Promise<void> => {\n for (let attempt = 0; attempt < 20; attempt += 1) {\n if (!(await driver.isAlive(pid))) {\n return;\n }\n await sleep(50);\n }\n};\n\nconst waitForReadyFile = async (readyFile: string): Promise<void> => {\n for (let attempt = 0; attempt < 40; attempt += 1) {\n try {\n await readFile(readyFile, \"utf8\");\n return;\n } catch (error) {\n if (!isNodeError(error) || error.code !== \"ENOENT\") {\n throw error;\n }\n await sleep(50);\n }\n }\n\n throw new Error(`timed out waiting for daemon readiness: ${readyFile}`);\n};\n\nconst acquireLock = async (\n lockFile: string,\n timeoutMs: number,\n): Promise<{\n release(): Promise<void>;\n}> => {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() <= deadline) {\n try {\n const handle = await open(lockFile, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY);\n await handle.writeFile(`${process.pid}\\n`, \"utf8\");\n return {\n async release() {\n await handle.close();\n await unlink(lockFile).catch((error: unknown) => {\n if (!isNodeError(error) || error.code !== \"ENOENT\") {\n throw error;\n }\n });\n },\n };\n } catch (error) {\n if (isNodeError(error) && error.code === \"EEXIST\") {\n await sleep(25);\n continue;\n }\n throw error;\n }\n }\n\n throw new Error(`timed out acquiring daemon lock: ${lockFile}`);\n};\n\nconst isProcessAlive = (pid: number): boolean => {\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n};\n\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\nconst isNodeError = (error: unknown): error is NodeJS.ErrnoException =>\n error instanceof Error && \"code\" in error;\n","import { readFile } from \"node:fs/promises\";\n\nexport const readPackageVersion = async (packageJsonUrl: URL): Promise<string> => {\n const value: unknown = JSON.parse(await readFile(packageJsonUrl, \"utf8\"));\n if (!isPackageJsonWithVersion(value)) {\n throw new Error(`package.json is missing a string version: ${packageJsonUrl.href}`);\n }\n\n return value.version;\n};\n\nconst isPackageJsonWithVersion = (value: unknown): value is { version: string } =>\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n \"version\" in value &&\n typeof value.version === \"string\";\n","import { createBrokerEndpointIdentity, formatUnixSocketPath, formatWindowsPipeName } from \"@opentray/spec\";\n\nexport interface DaemonPathOptions {\n homeDir: string;\n packageVersion: string;\n platform?: NodeJS.Platform;\n}\n\nexport interface DaemonPaths {\n homeDir: string;\n packageVersion: string;\n protocolVersion: number;\n stateRoot: string;\n runtimeDir: string;\n endpoint: string;\n pidFile: string;\n lockFile: string;\n readyFile: string;\n}\n\nexport const resolveDaemonPaths = ({\n homeDir,\n packageVersion,\n platform = process.platform,\n}: DaemonPathOptions): DaemonPaths => {\n const identity = createBrokerEndpointIdentity({ packageVersion });\n const normalizedHome = homeDir.replace(/[\\\\/]+$/u, \"\");\n const stateRoot = `${normalizedHome}/.opentray/${identity.packageVersion}`;\n const runtimeDir = `${stateRoot}/runtime`;\n const endpoint =\n platform === \"win32\" ? formatWindowsPipeName(identity) : formatUnixSocketPath(normalizedHome, identity);\n\n return {\n homeDir: normalizedHome,\n packageVersion: identity.packageVersion,\n protocolVersion: identity.protocolVersion,\n stateRoot,\n runtimeDir,\n endpoint,\n pidFile: `${runtimeDir}/broker.pid`,\n lockFile: `${runtimeDir}/broker.lock`,\n readyFile: `${runtimeDir}/ready.json`,\n };\n};\n","import { createConnection, type Socket } from \"node:net\";\nimport { homedir } from \"node:os\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n PROTOCOL_VERSION,\n parseServerFrame,\n type BrokerEndpointIdentityOptions,\n type ClientRequestFrame,\n type RequestId,\n type ServerFrame,\n} from \"@opentray/spec\";\n\nimport type { OpenTrayTransport } from \"./client\";\nimport { createNodeDaemonDriver, startDaemon, type DaemonDriver } from \"./daemon/lifecycle\";\nimport { readPackageVersion } from \"./daemon/package-version\";\nimport { resolveDaemonPaths } from \"./daemon/paths\";\n\nconst packageJsonUrl = new URL(\"../package.json\", import.meta.url);\n\nexport type BrokerEventFrame = Extract<ServerFrame, { type: \"event\" | \"ext-event\" }>;\n\nexport interface LocalBrokerClient extends OpenTrayTransport {\n readonly endpoint: string;\n readonly sessionId: string;\n /** @deprecated Use `sessionId`. */\n readonly leaseId: string;\n onEvent(listener: (frame: BrokerEventFrame) => void): () => void;\n close(): Promise<void>;\n}\n\nexport interface ConnectLocalBrokerOptions extends Partial<BrokerEndpointIdentityOptions> {\n endpoint?: string;\n homeDir?: string;\n clientVersion?: string;\n autoStart?: boolean;\n daemonDriver?: DaemonDriver;\n cliEntrypoint?: string;\n}\n\ninterface PendingRequest {\n resolve(frame: ServerFrame): void;\n reject(error: Error): void;\n}\n\ninterface BrokerSocket {\n setEncoding(encoding: BufferEncoding): void;\n on(event: \"data\", listener: (chunk: Buffer | string) => void): void;\n on(event: \"error\", listener: (error: Error) => void): void;\n on(event: \"close\", listener: () => void): void;\n once(event: \"connect\", listener: () => void): void;\n once(event: \"error\", listener: (error: Error) => void): void;\n off(event: \"error\", listener: (error: Error) => void): void;\n write(data: string): void;\n end(callback: () => void): void;\n}\n\nexport const connectLocalBroker = async (\n options: ConnectLocalBrokerOptions = {},\n): Promise<LocalBrokerClient> => {\n const packageVersion = options.packageVersion ?? (await readPackageVersion(packageJsonUrl));\n const clientVersion = options.clientVersion ?? packageVersion;\n const paths = resolveDaemonPaths({\n homeDir: options.homeDir ?? process.env.OPENTRAY_HOME ?? homedir(),\n packageVersion,\n });\n const endpoint = options.endpoint ?? paths.endpoint;\n const autoStart = options.autoStart ?? endpoint === paths.endpoint;\n if (autoStart && endpoint !== paths.endpoint) {\n throw new Error(\"local broker autoStart requires the derived same-version endpoint\");\n }\n if (autoStart) {\n const cliEntrypoint = options.cliEntrypoint ?? resolveCliEntrypoint();\n const driver = options.daemonDriver ?? createNodeDaemonDriver(cliEntrypoint);\n await startDaemon({ paths, driver });\n }\n const socket = await connectSocket(endpoint);\n const connection = new LocalBrokerConnection(socket, endpoint);\n\n await connection.init(clientVersion, options.protocolVersion ?? PROTOCOL_VERSION);\n return connection;\n};\n\nclass LocalBrokerConnection implements LocalBrokerClient {\n readonly endpoint: string;\n sessionId = \"\";\n /** @deprecated Use `sessionId`. */\n leaseId = \"\";\n\n private buffer = \"\";\n private readonly listeners = new Set<(frame: BrokerEventFrame) => void>();\n private readonly pending = new Map<RequestId, PendingRequest>();\n private ready:\n | {\n resolve(frame: Extract<ServerFrame, { type: \"ready\" }>): void;\n reject(error: Error): void;\n }\n | undefined;\n\n constructor(\n private readonly socket: BrokerSocket,\n endpoint: string,\n ) {\n this.endpoint = endpoint;\n socket.setEncoding(\"utf8\");\n socket.on(\"data\", (chunk: Buffer | string) => {\n this.consume(String(chunk));\n });\n socket.on(\"error\", (error) => {\n this.rejectAll(error);\n });\n socket.on(\"close\", () => {\n this.rejectAll(new Error(\"broker connection closed\"));\n });\n }\n\n async init(clientVersion: string, protocolVersion: number): Promise<void> {\n const ready = new Promise<Extract<ServerFrame, { type: \"ready\" }>>((resolve, reject) => {\n this.ready = { resolve, reject };\n });\n this.write({\n type: \"init\",\n protocolVersion,\n clientVersion,\n });\n const frame = await ready;\n this.sessionId = frame.sessionId;\n this.leaseId = frame.sessionId;\n }\n\n async request(frame: ClientRequestFrame): Promise<ServerFrame> {\n if (this.pending.has(frame.requestId)) {\n throw new Error(`duplicate requestId: ${frame.requestId}`);\n }\n\n const response = new Promise<ServerFrame>((resolve, reject) => {\n this.pending.set(frame.requestId, { resolve, reject });\n });\n this.write(frame);\n return response;\n }\n\n onEvent(listener: (frame: BrokerEventFrame) => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n async close(): Promise<void> {\n this.write({ type: \"exit\" });\n await new Promise<void>((resolve) => {\n this.socket.end(resolve);\n });\n }\n\n private consume(chunk: string): void {\n this.buffer += chunk;\n while (true) {\n const newline = this.buffer.indexOf(\"\\n\");\n if (newline < 0) {\n return;\n }\n\n const line = this.buffer.slice(0, newline).trim();\n this.buffer = this.buffer.slice(newline + 1);\n if (line.length > 0) {\n this.dispatchLine(line);\n }\n }\n }\n\n private dispatchLine(line: string): void {\n const parsed = parseServerFrame(line);\n if (!parsed.ok || parsed.frame === undefined) {\n this.rejectAll(new Error(parsed.error ?? \"invalid server frame\"));\n return;\n }\n\n this.dispatchFrame(parsed.frame);\n }\n\n private dispatchFrame(frame: ServerFrame): void {\n if (frame.type === \"ready\") {\n this.ready?.resolve(frame);\n this.ready = undefined;\n return;\n }\n\n if (frame.type === \"error\") {\n const error = new Error(`${frame.code}: ${frame.message}`);\n if (frame.requestId !== undefined) {\n this.pending.get(frame.requestId)?.reject(error);\n this.pending.delete(frame.requestId);\n return;\n }\n this.ready?.reject(error);\n this.ready = undefined;\n return;\n }\n\n const requestId = responseRequestId(frame);\n if (requestId !== undefined) {\n // Request responses and broker events are separate streams even on one socket.\n this.pending.get(requestId)?.resolve(frame);\n this.pending.delete(requestId);\n return;\n }\n\n if (frame.type === \"event\" || frame.type === \"ext-event\") {\n for (const listener of this.listeners) {\n listener(frame);\n }\n }\n }\n\n private write(frame: unknown): void {\n this.socket.write(`${JSON.stringify(frame)}\\n`);\n }\n\n private rejectAll(error: Error): void {\n this.ready?.reject(error);\n this.ready = undefined;\n for (const pending of this.pending.values()) {\n pending.reject(error);\n }\n this.pending.clear();\n }\n}\n\nconst connectSocket = (endpoint: string): Promise<BrokerSocket> =>\n new Promise((resolve, reject) => {\n const socket = createConnection(endpoint);\n socket.once(\"connect\", () => {\n socket.off(\"error\", reject);\n resolve(socket);\n });\n socket.once(\"error\", reject);\n });\n\nconst responseRequestId = (frame: ServerFrame): RequestId | undefined => {\n switch (frame.type) {\n case \"space-created\":\n case \"default-space\":\n case \"tray-created\":\n case \"ack\":\n case \"daemon-health\":\n return frame.requestId;\n case \"ready\":\n case \"event\":\n case \"ext-event\":\n case \"error\":\n return undefined;\n }\n};\n\nconst resolveCliEntrypoint = (): string => {\n const suffix = fileURLToPath(import.meta.url).endsWith(\".ts\") ? \"cli.ts\" : \"cli.mjs\";\n return fileURLToPath(new URL(`./${suffix}`, import.meta.url));\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAa,6BACX,WAAmB,QAAQ,UAC3B,OAAe,QAAQ,SACA;CACvB,MAAM,YAAY,oBAAoB,QAAQ;CAE9C,OAAO;EACL,aAAa,aAAa,UAAU,GAFnB,cAAc,IAEiB;EAChD,oBAAoB,OAAO,cAAc,YAAY,iBAAiB;CACxE;AACF;AAEA,MAAM,uBAAuB,aAAsC;CACjE,QAAQ,UAAR;EACE,KAAK;EACL,KAAK,SACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,SACE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