@zenbu-labs/pixel 0.0.0 → 0.0.12
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/dist/bin.d.ts +2 -0
- package/dist/bin.js +166 -0
- package/dist/bootstrap.d.ts +1 -0
- package/dist/bootstrap.js +75 -0
- package/dist/context-menu.d.ts +20 -0
- package/dist/context-menu.js +57 -0
- package/dist/debug.d.ts +1 -0
- package/dist/debug.js +9 -0
- package/dist/devtools-layout.d.ts +21 -0
- package/dist/devtools-layout.js +45 -0
- package/dist/devtools.d.ts +33 -0
- package/dist/devtools.js +125 -0
- package/dist/electron/index.d.ts +3 -0
- package/dist/electron/index.js +4 -0
- package/dist/host/guest.d.ts +5 -0
- package/dist/host/guest.js +178 -0
- package/dist/host/server.d.ts +91 -0
- package/dist/host/server.js +296 -0
- package/dist/host/shell.d.ts +35 -0
- package/dist/host/shell.js +113 -0
- package/dist/host/strip.d.ts +6 -0
- package/dist/host/strip.js +63 -0
- package/dist/icons.d.ts +30 -0
- package/dist/icons.js +58 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +39 -0
- package/dist/instances.d.ts +30 -0
- package/dist/instances.js +177 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +34 -0
- package/dist/popup.d.ts +21 -0
- package/dist/popup.js +47 -0
- package/dist/preload/index.d.ts +15 -0
- package/dist/preload/index.js +3 -0
- package/dist/react/colors.d.ts +3 -0
- package/dist/react/colors.js +25 -0
- package/dist/react/components.d.ts +21 -0
- package/dist/react/components.js +45 -0
- package/dist/react/devtools/app.d.ts +3 -0
- package/dist/react/devtools/app.js +89 -0
- package/dist/react/devtools/console-capture.d.ts +1 -0
- package/dist/react/devtools/console-capture.js +41 -0
- package/dist/react/devtools/controller.d.ts +45 -0
- package/dist/react/devtools/controller.js +252 -0
- package/dist/react/devtools/elements.d.ts +4 -0
- package/dist/react/devtools/elements.js +152 -0
- package/dist/react/devtools/export-profile.d.ts +2 -0
- package/dist/react/devtools/export-profile.js +225 -0
- package/dist/react/devtools/fiber-hook.d.ts +1 -0
- package/dist/react/devtools/fiber-hook.js +89 -0
- package/dist/react/devtools/log-panel.d.ts +4 -0
- package/dist/react/devtools/log-panel.js +113 -0
- package/dist/react/devtools/profiler.d.ts +11 -0
- package/dist/react/devtools/profiler.js +374 -0
- package/dist/react/devtools/store.d.ts +27 -0
- package/dist/react/devtools/store.js +61 -0
- package/dist/react/devtools/stores.d.ts +92 -0
- package/dist/react/devtools/stores.js +41 -0
- package/dist/react/devtools/theme.d.ts +35 -0
- package/dist/react/devtools/theme.js +77 -0
- package/dist/react/devtools/ui.d.ts +24 -0
- package/dist/react/devtools/ui.js +59 -0
- package/dist/react/index.d.ts +110 -0
- package/dist/react/index.js +538 -0
- package/dist/react/markdown.d.ts +25 -0
- package/dist/react/markdown.js +270 -0
- package/dist/react/native.d.ts +116 -0
- package/dist/react/native.js +56 -0
- package/dist/react/reconciler-config.d.ts +241 -0
- package/dist/react/reconciler-config.js +412 -0
- package/dist/react/styles.d.ts +88 -0
- package/dist/react/styles.js +85 -0
- package/dist/react/surface.d.ts +55 -0
- package/dist/react/surface.js +74 -0
- package/dist/registry.d.ts +53 -0
- package/dist/registry.js +193 -0
- package/dist/root.d.ts +19 -0
- package/dist/root.js +342 -0
- package/dist/sandbox.d.ts +4 -0
- package/dist/sandbox.js +84 -0
- package/dist/scale.d.ts +7 -0
- package/dist/scale.js +31 -0
- package/dist/ssh/index.d.ts +58 -0
- package/dist/ssh/index.js +445 -0
- package/dist/terminal/applescript.d.ts +2 -0
- package/dist/terminal/applescript.js +20 -0
- package/dist/terminal/detect.d.ts +10 -0
- package/dist/terminal/detect.js +34 -0
- package/dist/terminal/graphics.d.ts +9 -0
- package/dist/terminal/graphics.js +142 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +23 -0
- package/dist/terminal/run.d.ts +2 -0
- package/dist/terminal/run.js +15 -0
- package/dist/terminal/shared.d.ts +20 -0
- package/dist/terminal/shared.js +88 -0
- package/dist/terminal/terminal.d.ts +66 -0
- package/dist/terminal/terminal.js +6 -0
- package/dist/terminal/terminals/cmux.d.ts +2 -0
- package/dist/terminal/terminals/cmux.js +98 -0
- package/dist/terminal/terminals/ghostty-script.d.ts +1 -0
- package/dist/terminal/terminals/ghostty-script.js +179 -0
- package/dist/terminal/terminals/ghostty.d.ts +2 -0
- package/dist/terminal/terminals/ghostty.js +336 -0
- package/dist/terminal/terminals/herdr.d.ts +2 -0
- package/dist/terminal/terminals/herdr.js +141 -0
- package/dist/terminal/terminals/index.d.ts +5 -0
- package/dist/terminal/terminals/index.js +26 -0
- package/dist/terminal/terminals/kitty.d.ts +2 -0
- package/dist/terminal/terminals/kitty.js +209 -0
- package/dist/terminal/terminals/supacode.d.ts +2 -0
- package/dist/terminal/terminals/supacode.js +79 -0
- package/dist/terminal/terminals/tmux.d.ts +2 -0
- package/dist/terminal/terminals/tmux.js +132 -0
- package/dist/terminal/terminals/tty7.d.ts +2 -0
- package/dist/terminal/terminals/tty7.js +58 -0
- package/dist/terminal/terminals/vscode.d.ts +2 -0
- package/dist/terminal/terminals/vscode.js +13 -0
- package/dist/terminal/terminals/wezterm.d.ts +2 -0
- package/dist/terminal/terminals/wezterm.js +59 -0
- package/dist/theme.d.ts +22 -0
- package/dist/theme.js +40 -0
- package/dist/web/browser-session.d.ts +13 -0
- package/dist/web/browser-session.js +186 -0
- package/dist/web/cursor.d.ts +1 -0
- package/dist/web/cursor.js +24 -0
- package/dist/web/devtools.d.ts +39 -0
- package/dist/web/devtools.js +300 -0
- package/dist/web/favicon.d.ts +7 -0
- package/dist/web/favicon.js +73 -0
- package/dist/web/frame-rate.d.ts +1 -0
- package/dist/web/frame-rate.js +12 -0
- package/dist/web/host.d.ts +123 -0
- package/dist/web/host.js +573 -0
- package/dist/web/input.d.ts +49 -0
- package/dist/web/input.js +468 -0
- package/dist/web/offscreen.d.ts +2 -0
- package/dist/web/offscreen.js +23 -0
- package/dist/web/paint.d.ts +11 -0
- package/dist/web/paint.js +128 -0
- package/dist/web/popup.d.ts +40 -0
- package/dist/web/popup.js +144 -0
- package/dist/web/session.d.ts +20 -0
- package/dist/web/session.js +110 -0
- package/dist/web/types.d.ts +38 -0
- package/dist/web/types.js +39 -0
- package/dist/web/zoom.d.ts +5 -0
- package/dist/web/zoom.js +36 -0
- package/dist/webview.d.ts +55 -0
- package/dist/webview.js +481 -0
- package/package.json +69 -3
- package/scripts/apparmor.sh +71 -0
- package/scripts/postinstall.mjs +150 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GuestView = GuestView;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const debug_1 = require("../debug");
|
|
11
|
+
const layout_1 = require("../layout");
|
|
12
|
+
const react_2 = require("../react");
|
|
13
|
+
const registry_1 = require("../registry");
|
|
14
|
+
function GuestView({ guest, active }) {
|
|
15
|
+
const registry = (0, react_1.useContext)(registry_1.RootContext);
|
|
16
|
+
if (!registry)
|
|
17
|
+
throw new Error("GuestView outside a root");
|
|
18
|
+
const colors = (0, registry_1.useRegistryColors)(registry);
|
|
19
|
+
const boxRef = (0, react_1.useRef)(null);
|
|
20
|
+
const rect = (0, layout_1.useNodeRect)(boxRef, registry);
|
|
21
|
+
const surface = (0, react_1.useRef)(null);
|
|
22
|
+
const hovered = (0, react_1.useRef)(false);
|
|
23
|
+
const wheel = (0, react_1.useRef)({ x: 0, y: 0 });
|
|
24
|
+
const greeted = (0, react_1.useRef)(false);
|
|
25
|
+
const entry = (0, react_1.useMemo)(() => ({
|
|
26
|
+
host: null,
|
|
27
|
+
handle: null,
|
|
28
|
+
devtoolsEnabled: false,
|
|
29
|
+
externalDevtools: false,
|
|
30
|
+
externalDevtoolsAction: null,
|
|
31
|
+
toggleDevtools: () => { },
|
|
32
|
+
handleKey: (event) => {
|
|
33
|
+
guest.send({ type: "key", ...event });
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
paste: (text) => guest.send({ type: "paste", text }),
|
|
37
|
+
setActive: (focused) => guest.send({ type: "focus", focused }),
|
|
38
|
+
}), [guest]);
|
|
39
|
+
const cell = registry.root.info;
|
|
40
|
+
const snapped = rect
|
|
41
|
+
? {
|
|
42
|
+
width: Math.floor(rect.width / cell.cellWidth) * cell.cellWidth,
|
|
43
|
+
height: Math.floor(rect.height / cell.cellHeight) * cell.cellHeight,
|
|
44
|
+
}
|
|
45
|
+
: null;
|
|
46
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
47
|
+
const created = registry.root.createSurface();
|
|
48
|
+
surface.current = created;
|
|
49
|
+
registry.register(entry);
|
|
50
|
+
guest.onFrame = (frame) => {
|
|
51
|
+
let fd;
|
|
52
|
+
try {
|
|
53
|
+
fd = node_fs_1.default.openSync(frame.path, "r");
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
(0, debug_1.debug)("guest frame unreadable", frame.path, String(error));
|
|
57
|
+
frame.ack();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const stride = frame.width * 4;
|
|
61
|
+
created.present({
|
|
62
|
+
shm: { fd, width: frame.width, height: frame.height, stride, size: stride * frame.height },
|
|
63
|
+
released: () => {
|
|
64
|
+
node_fs_1.default.closeSync(fd);
|
|
65
|
+
frame.ack();
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
guest.onPointer = (shape) => {
|
|
70
|
+
if (hovered.current)
|
|
71
|
+
registry.setPointerShape(shape);
|
|
72
|
+
};
|
|
73
|
+
guest.onClipboard = (text) => registry.root.setClipboard(text);
|
|
74
|
+
return () => {
|
|
75
|
+
guest.onFrame = null;
|
|
76
|
+
guest.onPointer = null;
|
|
77
|
+
guest.onClipboard = null;
|
|
78
|
+
registry.unregister(entry);
|
|
79
|
+
created.close();
|
|
80
|
+
surface.current = null;
|
|
81
|
+
};
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, [guest]);
|
|
84
|
+
(0, react_1.useEffect)(() => {
|
|
85
|
+
if (!snapped || snapped.width <= 0 || snapped.height <= 0)
|
|
86
|
+
return;
|
|
87
|
+
const size = {
|
|
88
|
+
cols: snapped.width / cell.cellWidth,
|
|
89
|
+
rows: snapped.height / cell.cellHeight,
|
|
90
|
+
width: snapped.width,
|
|
91
|
+
height: snapped.height,
|
|
92
|
+
};
|
|
93
|
+
if (!greeted.current) {
|
|
94
|
+
greeted.current = true;
|
|
95
|
+
guest.send({ type: "init", ...size, colors, focused: active });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
guest.send({ type: "size", ...size });
|
|
99
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
+
}, [snapped?.width, snapped?.height]);
|
|
101
|
+
(0, react_1.useEffect)(() => {
|
|
102
|
+
if (greeted.current)
|
|
103
|
+
guest.send({ type: "colors", colors });
|
|
104
|
+
}, [colors, guest]);
|
|
105
|
+
(0, react_1.useEffect)(() => {
|
|
106
|
+
if (active)
|
|
107
|
+
registry.focus(entry);
|
|
108
|
+
else
|
|
109
|
+
registry.blur(entry);
|
|
110
|
+
}, [active, entry, registry]);
|
|
111
|
+
const forward = (event, kind) => {
|
|
112
|
+
const pointer = event;
|
|
113
|
+
guest.send({
|
|
114
|
+
type: "mouse",
|
|
115
|
+
kind,
|
|
116
|
+
button: pointer.button ?? "none",
|
|
117
|
+
mods: pointer.mods ?? { shift: false, alt: false, ctrl: false, super: false },
|
|
118
|
+
x: Math.max(0, Math.round(event.x)),
|
|
119
|
+
y: Math.max(0, Math.round(event.y)),
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const scroll = (event) => {
|
|
123
|
+
if (event.precise) {
|
|
124
|
+
guest.send({
|
|
125
|
+
type: "wheel",
|
|
126
|
+
x: Math.max(0, Math.round(event.x)),
|
|
127
|
+
y: Math.max(0, Math.round(event.y)),
|
|
128
|
+
deltaX: event.deltaX,
|
|
129
|
+
deltaY: event.deltaY,
|
|
130
|
+
mods: event.mods,
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const acc = wheel.current;
|
|
135
|
+
acc.x += event.deltaX;
|
|
136
|
+
acc.y += event.deltaY;
|
|
137
|
+
const stepX = cell.cellWidth;
|
|
138
|
+
const stepY = cell.cellHeight;
|
|
139
|
+
const send = (kind) => guest.send({
|
|
140
|
+
type: "mouse",
|
|
141
|
+
kind,
|
|
142
|
+
button: "none",
|
|
143
|
+
mods: event.mods,
|
|
144
|
+
x: Math.max(0, Math.round(event.x)),
|
|
145
|
+
y: Math.max(0, Math.round(event.y)),
|
|
146
|
+
});
|
|
147
|
+
while (acc.y >= stepY) {
|
|
148
|
+
acc.y -= stepY;
|
|
149
|
+
send("scrolldown");
|
|
150
|
+
}
|
|
151
|
+
while (acc.y <= -stepY) {
|
|
152
|
+
acc.y += stepY;
|
|
153
|
+
send("scrollup");
|
|
154
|
+
}
|
|
155
|
+
while (acc.x >= stepX) {
|
|
156
|
+
acc.x -= stepX;
|
|
157
|
+
send("scrollright");
|
|
158
|
+
}
|
|
159
|
+
while (acc.x <= -stepX) {
|
|
160
|
+
acc.x += stepX;
|
|
161
|
+
send("scrollleft");
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return ((0, jsx_runtime_1.jsx)(react_2.Box, { ref: boxRef, style: { flexGrow: 1, flexBasis: 0, overflow: "hidden" }, hidden: !active, children: snapped && snapped.width > 0 && snapped.height > 0 && ((0, jsx_runtime_1.jsx)(react_2.Box, { surface: surface.current ?? undefined, style: {
|
|
165
|
+
position: "absolute",
|
|
166
|
+
inset: { top: 0, left: 0 },
|
|
167
|
+
width: snapped.width,
|
|
168
|
+
height: snapped.height,
|
|
169
|
+
}, onPointer: (event) => {
|
|
170
|
+
registry.focus(entry);
|
|
171
|
+
forward(event, event.kind);
|
|
172
|
+
}, onMouseMove: (event) => forward(event, "move"), onWheel: scroll, onMouseEnter: () => {
|
|
173
|
+
hovered.current = true;
|
|
174
|
+
}, onMouseLeave: () => {
|
|
175
|
+
hovered.current = false;
|
|
176
|
+
registry.setPointerShape("default");
|
|
177
|
+
} })) }));
|
|
178
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
import type { EngineKeyEvent, TerminalColors } from "../react";
|
|
3
|
+
export interface GuestFrame {
|
|
4
|
+
path: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
ack(): void;
|
|
8
|
+
}
|
|
9
|
+
export interface InitPayload {
|
|
10
|
+
cols: number;
|
|
11
|
+
rows: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
colors: TerminalColors;
|
|
15
|
+
focused: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type GuestMessage = ({
|
|
18
|
+
type: "key";
|
|
19
|
+
} & EngineKeyEvent) | {
|
|
20
|
+
type: "paste";
|
|
21
|
+
text: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "mouse";
|
|
24
|
+
kind: "down" | "up" | "move" | "scrollup" | "scrolldown" | "scrollleft" | "scrollright";
|
|
25
|
+
button: "left" | "middle" | "right" | "none";
|
|
26
|
+
mods: EngineKeyEvent["mods"];
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: "wheel";
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
deltaX: number;
|
|
34
|
+
deltaY: number;
|
|
35
|
+
mods: EngineKeyEvent["mods"];
|
|
36
|
+
} | {
|
|
37
|
+
type: "focus";
|
|
38
|
+
focused: boolean;
|
|
39
|
+
} | {
|
|
40
|
+
type: "colors";
|
|
41
|
+
colors: TerminalColors;
|
|
42
|
+
} | ({
|
|
43
|
+
type: "size";
|
|
44
|
+
} & Pick<InitPayload, "cols" | "rows" | "width" | "height">) | ({
|
|
45
|
+
type: "init";
|
|
46
|
+
} & InitPayload) | {
|
|
47
|
+
type: "adopt";
|
|
48
|
+
tty: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "rejoin";
|
|
51
|
+
socket: string;
|
|
52
|
+
};
|
|
53
|
+
export declare class Guest {
|
|
54
|
+
readonly pane: string;
|
|
55
|
+
readonly name: string;
|
|
56
|
+
pid: number;
|
|
57
|
+
private control;
|
|
58
|
+
private announce;
|
|
59
|
+
title: string | null;
|
|
60
|
+
onFrame: ((frame: GuestFrame) => void) | null;
|
|
61
|
+
onTitle: ((title: string) => void) | null;
|
|
62
|
+
onPointer: ((shape: string) => void) | null;
|
|
63
|
+
onClipboard: ((text: string) => void) | null;
|
|
64
|
+
onClose: (() => void) | null;
|
|
65
|
+
private closed;
|
|
66
|
+
private departed;
|
|
67
|
+
private greeted;
|
|
68
|
+
private queued;
|
|
69
|
+
constructor(pane: string, name: string, pid: number, control: net.Socket | null, announce: net.Socket | null);
|
|
70
|
+
get pending(): boolean;
|
|
71
|
+
attach(control: net.Socket, pid: number): void;
|
|
72
|
+
send(message: GuestMessage): void;
|
|
73
|
+
handleLine(line: string): void;
|
|
74
|
+
close(): void;
|
|
75
|
+
gone(): void;
|
|
76
|
+
}
|
|
77
|
+
export declare class OwnerServer {
|
|
78
|
+
readonly socketPath: string;
|
|
79
|
+
private readonly cell;
|
|
80
|
+
readonly frameDir: string;
|
|
81
|
+
onJoin: ((guest: Guest) => void) | null;
|
|
82
|
+
private readonly server;
|
|
83
|
+
private readonly guests;
|
|
84
|
+
constructor(socketPath: string, cell: () => {
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
});
|
|
88
|
+
stop(): void;
|
|
89
|
+
private serve;
|
|
90
|
+
private open;
|
|
91
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OwnerServer = exports.Guest = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
9
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const debug_1 = require("../debug");
|
|
12
|
+
class Guest {
|
|
13
|
+
pane;
|
|
14
|
+
name;
|
|
15
|
+
pid;
|
|
16
|
+
control;
|
|
17
|
+
announce;
|
|
18
|
+
title = null;
|
|
19
|
+
onFrame = null;
|
|
20
|
+
onTitle = null;
|
|
21
|
+
onPointer = null;
|
|
22
|
+
onClipboard = null;
|
|
23
|
+
onClose = null;
|
|
24
|
+
closed = false;
|
|
25
|
+
departed = false;
|
|
26
|
+
// Nothing may reach the guest before init; its engine reads init first.
|
|
27
|
+
greeted = false;
|
|
28
|
+
queued = [];
|
|
29
|
+
constructor(pane, name, pid,
|
|
30
|
+
// Null while only announced: the app's electron has not joined yet.
|
|
31
|
+
control, announce) {
|
|
32
|
+
this.pane = pane;
|
|
33
|
+
this.name = name;
|
|
34
|
+
this.pid = pid;
|
|
35
|
+
this.control = control;
|
|
36
|
+
this.announce = announce;
|
|
37
|
+
}
|
|
38
|
+
get pending() {
|
|
39
|
+
return this.control === null;
|
|
40
|
+
}
|
|
41
|
+
attach(control, pid) {
|
|
42
|
+
this.control = control;
|
|
43
|
+
if (pid > 0)
|
|
44
|
+
this.pid = pid;
|
|
45
|
+
this.greeted = false;
|
|
46
|
+
for (const waiting of this.queued.splice(0))
|
|
47
|
+
this.send(waiting);
|
|
48
|
+
}
|
|
49
|
+
send(message) {
|
|
50
|
+
if (this.closed)
|
|
51
|
+
return;
|
|
52
|
+
if (!this.control) {
|
|
53
|
+
this.queued.push(message);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!this.greeted) {
|
|
57
|
+
if (message.type !== "init") {
|
|
58
|
+
this.queued.push(message);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.greeted = true;
|
|
62
|
+
this.control.write(`${JSON.stringify(message)}\n`);
|
|
63
|
+
for (const waiting of this.queued.splice(0))
|
|
64
|
+
this.send(waiting);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.control.write(`${JSON.stringify(message)}\n`);
|
|
68
|
+
}
|
|
69
|
+
handleLine(line) {
|
|
70
|
+
let message;
|
|
71
|
+
try {
|
|
72
|
+
message = JSON.parse(line);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
switch (message.type) {
|
|
78
|
+
case "title":
|
|
79
|
+
this.title = message.text ?? null;
|
|
80
|
+
if (this.title != null)
|
|
81
|
+
this.onTitle?.(this.title);
|
|
82
|
+
break;
|
|
83
|
+
case "pointer":
|
|
84
|
+
if (message.shape)
|
|
85
|
+
this.onPointer?.(message.shape);
|
|
86
|
+
break;
|
|
87
|
+
case "clipboard":
|
|
88
|
+
if (typeof message.text === "string")
|
|
89
|
+
this.onClipboard?.(message.text);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Dropping the control connection ends the guest's engine; a guest that
|
|
94
|
+
// still lingers after that gets a signal.
|
|
95
|
+
close() {
|
|
96
|
+
if (this.closed)
|
|
97
|
+
return;
|
|
98
|
+
this.closed = true;
|
|
99
|
+
this.control?.destroy();
|
|
100
|
+
this.announce?.destroy();
|
|
101
|
+
if (this.pid > 0) {
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
if (this.departed)
|
|
104
|
+
return;
|
|
105
|
+
try {
|
|
106
|
+
process.kill(this.pid, "SIGTERM");
|
|
107
|
+
}
|
|
108
|
+
catch { }
|
|
109
|
+
}, 2000).unref();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
gone() {
|
|
113
|
+
if (this.departed)
|
|
114
|
+
return;
|
|
115
|
+
this.departed = true;
|
|
116
|
+
this.closed = true;
|
|
117
|
+
this.onClose?.();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.Guest = Guest;
|
|
121
|
+
function frameDirectory() {
|
|
122
|
+
const root = node_path_1.default.join(node_os_1.default.tmpdir(), "pixel-frames");
|
|
123
|
+
node_fs_1.default.mkdirSync(root, { recursive: true });
|
|
124
|
+
for (const entry of node_fs_1.default.readdirSync(root)) {
|
|
125
|
+
const pid = Number(entry);
|
|
126
|
+
if (!Number.isInteger(pid) || pid === process.pid)
|
|
127
|
+
continue;
|
|
128
|
+
try {
|
|
129
|
+
process.kill(pid, 0);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
node_fs_1.default.rmSync(node_path_1.default.join(root, entry), { recursive: true, force: true });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const dir = node_path_1.default.join(root, String(process.pid));
|
|
136
|
+
node_fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
137
|
+
node_fs_1.default.mkdirSync(dir, { mode: 0o700 });
|
|
138
|
+
return dir;
|
|
139
|
+
}
|
|
140
|
+
class OwnerServer {
|
|
141
|
+
socketPath;
|
|
142
|
+
cell;
|
|
143
|
+
frameDir;
|
|
144
|
+
onJoin = null;
|
|
145
|
+
server;
|
|
146
|
+
guests = new Map();
|
|
147
|
+
constructor(socketPath, cell) {
|
|
148
|
+
this.socketPath = socketPath;
|
|
149
|
+
this.cell = cell;
|
|
150
|
+
this.frameDir = frameDirectory();
|
|
151
|
+
node_fs_1.default.rmSync(socketPath, { force: true });
|
|
152
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(socketPath), { recursive: true });
|
|
153
|
+
this.server = node_net_1.default.createServer((connection) => this.serve(connection));
|
|
154
|
+
this.server.on("error", (error) => (0, debug_1.debug)("owner server error", error.message));
|
|
155
|
+
this.server.listen(socketPath);
|
|
156
|
+
}
|
|
157
|
+
stop() {
|
|
158
|
+
for (const guest of this.guests.values())
|
|
159
|
+
guest.close();
|
|
160
|
+
this.guests.clear();
|
|
161
|
+
this.server.close();
|
|
162
|
+
node_fs_1.default.rmSync(this.socketPath, { force: true });
|
|
163
|
+
node_fs_1.default.rmSync(this.frameDir, { recursive: true, force: true });
|
|
164
|
+
}
|
|
165
|
+
serve(connection) {
|
|
166
|
+
connection.setEncoding("utf8");
|
|
167
|
+
connection.on("error", () => { });
|
|
168
|
+
let buffer = "";
|
|
169
|
+
let route = null;
|
|
170
|
+
let owned = null;
|
|
171
|
+
connection.on("data", (chunk) => {
|
|
172
|
+
buffer += chunk;
|
|
173
|
+
let newline = buffer.indexOf("\n");
|
|
174
|
+
while (newline >= 0) {
|
|
175
|
+
const line = buffer.slice(0, newline);
|
|
176
|
+
buffer = buffer.slice(newline + 1);
|
|
177
|
+
newline = buffer.indexOf("\n");
|
|
178
|
+
if (!line.trim())
|
|
179
|
+
continue;
|
|
180
|
+
if (route) {
|
|
181
|
+
route(line);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const opened = this.open(connection, line);
|
|
185
|
+
route = opened.route;
|
|
186
|
+
owned = opened.guest;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
connection.on("close", () => {
|
|
190
|
+
if (owned) {
|
|
191
|
+
(0, debug_1.debug)("guest gone", { pane: owned.pane, name: owned.name });
|
|
192
|
+
this.guests.delete(owned.pane);
|
|
193
|
+
owned.gone();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
open(connection, line) {
|
|
198
|
+
let opening;
|
|
199
|
+
try {
|
|
200
|
+
opening = JSON.parse(line);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
connection.destroy();
|
|
204
|
+
return { route: () => { }, guest: null };
|
|
205
|
+
}
|
|
206
|
+
if (opening.method === "pane.graphics.info") {
|
|
207
|
+
const cell = this.cell();
|
|
208
|
+
const result = {
|
|
209
|
+
type: "pane_graphics_info",
|
|
210
|
+
cell_width_px: cell.width,
|
|
211
|
+
cell_height_px: cell.height,
|
|
212
|
+
pane_visible: true,
|
|
213
|
+
file_frame_directory: this.frameDir,
|
|
214
|
+
file_frame_formats: ["bgra"],
|
|
215
|
+
file_frame_transport: "direct-kitty",
|
|
216
|
+
};
|
|
217
|
+
connection.end(`${JSON.stringify({ id: opening.id ?? "info", result })}\n`);
|
|
218
|
+
return { route: () => { }, guest: null };
|
|
219
|
+
}
|
|
220
|
+
if (opening.method === "pane.graphics.stream") {
|
|
221
|
+
const pane = opening.params?.pane_id ?? "";
|
|
222
|
+
const id = opening.id ?? "stream";
|
|
223
|
+
connection.write(`${JSON.stringify({ id, result: { type: "ok" } })}\n`);
|
|
224
|
+
const ack = `${JSON.stringify({ id, result: { type: "pane_graphics_frame_ack" } })}\n`;
|
|
225
|
+
return {
|
|
226
|
+
guest: null,
|
|
227
|
+
route: (header) => {
|
|
228
|
+
const guest = this.guests.get(pane);
|
|
229
|
+
let frame;
|
|
230
|
+
try {
|
|
231
|
+
frame = JSON.parse(header);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const file = frame.file?.path;
|
|
237
|
+
if (!guest?.onFrame || !file || !frame.image_width || !frame.image_height) {
|
|
238
|
+
connection.write(ack);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
let acked = false;
|
|
242
|
+
guest.onFrame({
|
|
243
|
+
path: file,
|
|
244
|
+
width: frame.image_width,
|
|
245
|
+
height: frame.image_height,
|
|
246
|
+
ack: () => {
|
|
247
|
+
if (acked)
|
|
248
|
+
return;
|
|
249
|
+
acked = true;
|
|
250
|
+
connection.write(ack);
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const name = typeof opening.name === "string" && opening.name ? opening.name : "app";
|
|
257
|
+
const pid = typeof opening.pid === "number" ? opening.pid : 0;
|
|
258
|
+
if (opening.type === "announce" && typeof opening.pane === "string") {
|
|
259
|
+
if (this.guests.has(opening.pane)) {
|
|
260
|
+
connection.destroy();
|
|
261
|
+
return { route: () => { }, guest: null };
|
|
262
|
+
}
|
|
263
|
+
const guest = new Guest(opening.pane, name, pid, null, connection);
|
|
264
|
+
this.guests.set(guest.pane, guest);
|
|
265
|
+
(0, debug_1.debug)("guest announced", { pane: guest.pane, name });
|
|
266
|
+
this.onJoin?.(guest);
|
|
267
|
+
connection.on("close", () => {
|
|
268
|
+
if (guest.pending) {
|
|
269
|
+
this.guests.delete(guest.pane);
|
|
270
|
+
guest.gone();
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return { route: () => { }, guest: null };
|
|
274
|
+
}
|
|
275
|
+
if (opening.type === "join" && typeof opening.pane === "string") {
|
|
276
|
+
const announced = this.guests.get(opening.pane);
|
|
277
|
+
if (announced) {
|
|
278
|
+
if (!announced.pending) {
|
|
279
|
+
connection.destroy();
|
|
280
|
+
return { route: () => { }, guest: null };
|
|
281
|
+
}
|
|
282
|
+
announced.attach(connection, pid);
|
|
283
|
+
(0, debug_1.debug)("guest joined", { pane: announced.pane, name: announced.name, pid });
|
|
284
|
+
return { route: (line) => announced.handleLine(line), guest: announced };
|
|
285
|
+
}
|
|
286
|
+
const guest = new Guest(opening.pane, name, pid, connection, null);
|
|
287
|
+
this.guests.set(guest.pane, guest);
|
|
288
|
+
(0, debug_1.debug)("guest joined", { pane: guest.pane, name: guest.name, pid: guest.pid });
|
|
289
|
+
this.onJoin?.(guest);
|
|
290
|
+
return { route: (line) => guest.handleLine(line), guest };
|
|
291
|
+
}
|
|
292
|
+
connection.destroy();
|
|
293
|
+
return { route: () => { }, guest: null };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.OwnerServer = OwnerServer;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { EngineKeyEvent } from "../react";
|
|
2
|
+
import type { Guest } from "./server";
|
|
3
|
+
export interface ShellTab {
|
|
4
|
+
key: string;
|
|
5
|
+
guest: Guest | null;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class Shell {
|
|
9
|
+
private readonly ownerLabel;
|
|
10
|
+
private guests;
|
|
11
|
+
private activeIndex;
|
|
12
|
+
private restoreFocus;
|
|
13
|
+
private readonly listeners;
|
|
14
|
+
private snapshot;
|
|
15
|
+
constructor(ownerLabel: () => string);
|
|
16
|
+
subscribe: (listener: () => void) => () => void;
|
|
17
|
+
get: () => {
|
|
18
|
+
tabs: ShellTab[];
|
|
19
|
+
active: number;
|
|
20
|
+
};
|
|
21
|
+
get active(): number;
|
|
22
|
+
guestActive(): boolean;
|
|
23
|
+
hasGuests(): boolean;
|
|
24
|
+
activeGuest(): Guest | null;
|
|
25
|
+
add(guest: Guest): void;
|
|
26
|
+
remove(guest: Guest): void;
|
|
27
|
+
onCloseOwner: (() => void) | null;
|
|
28
|
+
close(index: number): void;
|
|
29
|
+
successor(): Guest | null;
|
|
30
|
+
others(except: Guest): Guest[];
|
|
31
|
+
activate(index: number): void;
|
|
32
|
+
rememberFocus(restore: () => void): void;
|
|
33
|
+
changed(): void;
|
|
34
|
+
handleKey(event: EngineKeyEvent): boolean;
|
|
35
|
+
}
|