glimpse-sdk 0.7.0 → 0.9.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/LICENSE +24 -17
- package/PROTOCOL.md +536 -0
- package/README.md +40 -115
- package/dist/index.d.ts +174 -0
- package/dist/index.js +78 -0
- package/dist/jsx-runtime.d.ts +16 -0
- package/dist/jsx-runtime.js +7 -0
- package/dist/reconciler.d.ts +30 -0
- package/dist/reconciler.js +583 -0
- package/package.json +40 -39
- package/dist/src/app.d.ts +0 -66
- package/dist/src/app.js +0 -272
- package/dist/src/events.d.ts +0 -36
- package/dist/src/events.js +0 -37
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.js +0 -5
- package/dist/src/ipc.d.ts +0 -28
- package/dist/src/ipc.js +0 -214
- package/dist/src/protocol.d.ts +0 -15
- package/dist/src/protocol.js +0 -22
- package/dist/src/widgets.d.ts +0 -528
- package/dist/src/widgets.js +0 -602
- package/src/app.ts +0 -347
- package/src/events.ts +0 -85
- package/src/index.ts +0 -68
- package/src/ipc.ts +0 -233
- package/src/protocol.ts +0 -27
- package/src/widgets.ts +0 -467
package/dist/src/app.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { type CallbackEvent, type ChangeEvent, type ClickEvent, type InitEvent, type InputEvent, type PopoverEvent, type ScrollEvent, type ToggleEvent } from "./events.js";
|
|
2
|
-
import { StatusItem } from "./protocol.js";
|
|
3
|
-
import { type TreeNode } from "./widgets.js";
|
|
4
|
-
type Handler<EventT> = (event: EventT) => void | Promise<void>;
|
|
5
|
-
interface OutgoingMessage {
|
|
6
|
-
command: string;
|
|
7
|
-
data: unknown;
|
|
8
|
-
line: string;
|
|
9
|
-
}
|
|
10
|
-
interface ShowNotificationOptions {
|
|
11
|
-
body?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface CommandResult {
|
|
14
|
-
stdout: string;
|
|
15
|
-
stderr: string;
|
|
16
|
-
rc: number;
|
|
17
|
-
}
|
|
18
|
-
interface DismissNotificationArgs {
|
|
19
|
-
id: number;
|
|
20
|
-
}
|
|
21
|
-
export declare abstract class Applet<State extends object> {
|
|
22
|
-
state: State;
|
|
23
|
-
private readonly handlerMap;
|
|
24
|
-
private inlineHandlerMap;
|
|
25
|
-
private readonly outgoing;
|
|
26
|
-
private flushPromise;
|
|
27
|
-
private renderQueued;
|
|
28
|
-
private lastStatus;
|
|
29
|
-
private lastTree;
|
|
30
|
-
private popoverOpen;
|
|
31
|
-
protected constructor();
|
|
32
|
-
protected abstract initialState(): State;
|
|
33
|
-
protected cssClass(): string | null;
|
|
34
|
-
protected onStart(): Promise<void>;
|
|
35
|
-
protected onInit(_event: InitEvent): Promise<void>;
|
|
36
|
-
protected onCallback(_event: CallbackEvent): Promise<void>;
|
|
37
|
-
protected status(_state: State): Promise<StatusItem[]>;
|
|
38
|
-
protected popover(_state: State): Promise<TreeNode | null>;
|
|
39
|
-
setState(patch: Partial<State>): Promise<void>;
|
|
40
|
-
onClick(id: string, handler: Handler<ClickEvent>): void;
|
|
41
|
-
onScroll(id: string, handler: Handler<ScrollEvent>): void;
|
|
42
|
-
onInput(id: string, handler: Handler<InputEvent>): void;
|
|
43
|
-
onChange(id: string, handler: Handler<ChangeEvent>): void;
|
|
44
|
-
onToggle(id: string, handler: Handler<ToggleEvent>): void;
|
|
45
|
-
onPopover(handler: Handler<PopoverEvent>): void;
|
|
46
|
-
isPopoverOpen(): boolean;
|
|
47
|
-
log(...args: unknown[]): void;
|
|
48
|
-
protected showNotification(summary: string, options?: ShowNotificationOptions): Promise<void>;
|
|
49
|
-
protected openUri(uri: string): Promise<void>;
|
|
50
|
-
protected copyToClipboard(text: string): Promise<void>;
|
|
51
|
-
protected runCommand(command: string[]): Promise<CommandResult>;
|
|
52
|
-
protected dismissNotification(args: DismissNotificationArgs): void;
|
|
53
|
-
protected closePopover(): void;
|
|
54
|
-
protected runDesktopCommand(command: string, args: string[], input?: string): Promise<void>;
|
|
55
|
-
run(): Promise<void>;
|
|
56
|
-
protected drainOutgoingForTest(): Promise<OutgoingMessage[]>;
|
|
57
|
-
private register;
|
|
58
|
-
private dispatchCallback;
|
|
59
|
-
private handleIncoming;
|
|
60
|
-
private scheduleRender;
|
|
61
|
-
private flushRender;
|
|
62
|
-
private emit;
|
|
63
|
-
private emitAction;
|
|
64
|
-
}
|
|
65
|
-
export declare function runCommand(command: string[]): Promise<CommandResult>;
|
|
66
|
-
export {};
|
package/dist/src/app.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { createInterface } from "node:readline";
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import { parseCallbackEvent, parseInitEvent, } from "./events.js";
|
|
4
|
-
import { InlineHandlerRegistry } from "./widgets.js";
|
|
5
|
-
export class Applet {
|
|
6
|
-
state;
|
|
7
|
-
handlerMap = new Map();
|
|
8
|
-
inlineHandlerMap = new Map();
|
|
9
|
-
outgoing = [];
|
|
10
|
-
flushPromise = null;
|
|
11
|
-
renderQueued = false;
|
|
12
|
-
lastStatus = null;
|
|
13
|
-
lastTree = null;
|
|
14
|
-
popoverOpen = false;
|
|
15
|
-
constructor() {
|
|
16
|
-
this.state = this.initialState();
|
|
17
|
-
}
|
|
18
|
-
cssClass() {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
async onStart() { }
|
|
22
|
-
async onInit(_event) { }
|
|
23
|
-
async onCallback(_event) { }
|
|
24
|
-
async status(_state) {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
async popover(_state) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
async setState(patch) {
|
|
31
|
-
this.state = { ...this.state, ...patch };
|
|
32
|
-
await this.scheduleRender();
|
|
33
|
-
}
|
|
34
|
-
onClick(id, handler) {
|
|
35
|
-
this.register("click", id, handler);
|
|
36
|
-
}
|
|
37
|
-
onScroll(id, handler) {
|
|
38
|
-
this.register("scroll", id, handler);
|
|
39
|
-
}
|
|
40
|
-
onInput(id, handler) {
|
|
41
|
-
this.register("input", id, handler);
|
|
42
|
-
}
|
|
43
|
-
onChange(id, handler) {
|
|
44
|
-
this.register("change", id, handler);
|
|
45
|
-
}
|
|
46
|
-
onToggle(id, handler) {
|
|
47
|
-
this.register("toggle", id, handler);
|
|
48
|
-
}
|
|
49
|
-
onPopover(handler) {
|
|
50
|
-
this.register("open", "popover", handler);
|
|
51
|
-
this.register("close", "popover", handler);
|
|
52
|
-
}
|
|
53
|
-
isPopoverOpen() {
|
|
54
|
-
return this.popoverOpen;
|
|
55
|
-
}
|
|
56
|
-
log(...args) {
|
|
57
|
-
process.stderr.write(args.map(String).join(" ") + "\n");
|
|
58
|
-
}
|
|
59
|
-
async showNotification(summary, options = {}) {
|
|
60
|
-
const args = [summary];
|
|
61
|
-
if (options.body !== undefined) {
|
|
62
|
-
args.push(options.body);
|
|
63
|
-
}
|
|
64
|
-
await this.runDesktopCommand("notify-send", args);
|
|
65
|
-
}
|
|
66
|
-
async openUri(uri) {
|
|
67
|
-
await this.runDesktopCommand("xdg-open", [uri]);
|
|
68
|
-
}
|
|
69
|
-
async copyToClipboard(text) {
|
|
70
|
-
await this.runDesktopCommand("wl-copy", [], text);
|
|
71
|
-
}
|
|
72
|
-
async runCommand(command) {
|
|
73
|
-
return await runCommand(command);
|
|
74
|
-
}
|
|
75
|
-
dismissNotification(args) {
|
|
76
|
-
this.emitAction("dismiss_notification", args);
|
|
77
|
-
}
|
|
78
|
-
closePopover() {
|
|
79
|
-
this.emitAction("close_popover", {});
|
|
80
|
-
}
|
|
81
|
-
async runDesktopCommand(command, args, input) {
|
|
82
|
-
await runDesktopCommand([command, ...args], input);
|
|
83
|
-
}
|
|
84
|
-
async run() {
|
|
85
|
-
process.stdout.on("error", (err) => {
|
|
86
|
-
if (err.code === "EPIPE") {
|
|
87
|
-
process.exit(0);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
await this.onStart();
|
|
91
|
-
const cssClass = this.cssClass();
|
|
92
|
-
if (cssClass !== null) {
|
|
93
|
-
process.stdout.write(`class ${cssClass}\n`);
|
|
94
|
-
}
|
|
95
|
-
await this.scheduleRender();
|
|
96
|
-
const rl = createInterface({
|
|
97
|
-
input: process.stdin,
|
|
98
|
-
crlfDelay: Infinity,
|
|
99
|
-
});
|
|
100
|
-
for await (const line of rl) {
|
|
101
|
-
if (!line) {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
let raw;
|
|
105
|
-
try {
|
|
106
|
-
raw = parseLine(line);
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
process.stderr.write(`glimpse-sdk: ignoring malformed input: ${err}\n`);
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
if (raw === null) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const data = raw.data;
|
|
116
|
-
try {
|
|
117
|
-
await this.handleIncoming(raw.command, data);
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
process.stderr.write(`glimpse-sdk: error handling input: ${err}\n`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async drainOutgoingForTest() {
|
|
125
|
-
await this.scheduleRender();
|
|
126
|
-
const drained = [...this.outgoing];
|
|
127
|
-
this.outgoing.length = 0;
|
|
128
|
-
return drained;
|
|
129
|
-
}
|
|
130
|
-
register(event, id, handler) {
|
|
131
|
-
this.handlerMap.set(`${event}:${id}`, handler);
|
|
132
|
-
}
|
|
133
|
-
async dispatchCallback(event) {
|
|
134
|
-
const key = `${event.event}:${event.id}`;
|
|
135
|
-
const inlineHandler = this.inlineHandlerMap.get(key);
|
|
136
|
-
if (inlineHandler !== undefined) {
|
|
137
|
-
await inlineHandler(event);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const handler = this.handlerMap.get(key);
|
|
141
|
-
if (handler !== undefined) {
|
|
142
|
-
await handler(event);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
await this.onCallback(event);
|
|
146
|
-
}
|
|
147
|
-
async handleIncoming(type, data) {
|
|
148
|
-
if (type === "init") {
|
|
149
|
-
await this.onInit(parseInitEvent(data));
|
|
150
|
-
await this.scheduleRender();
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (type === "event") {
|
|
154
|
-
const event = parseCallbackEvent(data);
|
|
155
|
-
if (isPopoverEvent(event)) {
|
|
156
|
-
this.popoverOpen = event.open;
|
|
157
|
-
}
|
|
158
|
-
await this.dispatchCallback(event);
|
|
159
|
-
await this.scheduleRender();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async scheduleRender() {
|
|
163
|
-
this.renderQueued = true;
|
|
164
|
-
if (this.flushPromise === null) {
|
|
165
|
-
this.flushPromise = Promise.resolve().then(async () => {
|
|
166
|
-
try {
|
|
167
|
-
while (this.renderQueued) {
|
|
168
|
-
this.renderQueued = false;
|
|
169
|
-
await this.flushRender();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
finally {
|
|
173
|
-
this.flushPromise = null;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
await this.flushPromise;
|
|
178
|
-
}
|
|
179
|
-
async flushRender() {
|
|
180
|
-
const statusItems = await this.status(this.state);
|
|
181
|
-
const status = statusItems.map((item) => item.toProtocol());
|
|
182
|
-
if (!deepEqual(status, this.lastStatus)) {
|
|
183
|
-
this.lastStatus = status;
|
|
184
|
-
this.emit("status", { items: status });
|
|
185
|
-
}
|
|
186
|
-
const widget = await this.popover(this.state);
|
|
187
|
-
if (widget !== null) {
|
|
188
|
-
const registry = new InlineHandlerRegistry();
|
|
189
|
-
widget.bindHandlers?.(registry, []);
|
|
190
|
-
this.inlineHandlerMap = registry.handlers;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
this.inlineHandlerMap = new Map();
|
|
194
|
-
}
|
|
195
|
-
const tree = { root: widget?.toProtocol() ?? null };
|
|
196
|
-
if (!deepEqual(tree, this.lastTree)) {
|
|
197
|
-
this.lastTree = tree;
|
|
198
|
-
this.emit("popover", tree);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
emit(command, data) {
|
|
202
|
-
const line = `${command} ${JSON.stringify(data)}`;
|
|
203
|
-
this.outgoing.push({ command, data, line });
|
|
204
|
-
try {
|
|
205
|
-
process.stdout.write(`${line}\n`);
|
|
206
|
-
}
|
|
207
|
-
catch (err) {
|
|
208
|
-
const code = err?.code;
|
|
209
|
-
if (code !== "EPIPE") {
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
emitAction(type, args) {
|
|
215
|
-
this.emit("action", { type, arguments: args });
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
function parseLine(line) {
|
|
219
|
-
const trimmed = line.trim();
|
|
220
|
-
if (trimmed === "") {
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
const split = trimmed.search(/\s/);
|
|
224
|
-
if (split < 0) {
|
|
225
|
-
throw new Error("missing command payload");
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
command: trimmed.slice(0, split),
|
|
229
|
-
data: JSON.parse(trimmed.slice(split).trimStart()),
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function deepEqual(left, right) {
|
|
233
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
234
|
-
}
|
|
235
|
-
function isPopoverEvent(event) {
|
|
236
|
-
return event.event === "open" || event.event === "close";
|
|
237
|
-
}
|
|
238
|
-
export async function runCommand(command) {
|
|
239
|
-
return await runCommandWithInput(command);
|
|
240
|
-
}
|
|
241
|
-
async function runDesktopCommand(command, input) {
|
|
242
|
-
const result = await runCommandWithInput(command, input);
|
|
243
|
-
if (result.rc !== 0) {
|
|
244
|
-
throw new Error(`${command[0]} exited with status ${result.rc}`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
async function runCommandWithInput(command, input) {
|
|
248
|
-
if (command.length === 0) {
|
|
249
|
-
throw new Error("command must not be empty");
|
|
250
|
-
}
|
|
251
|
-
return await new Promise((resolve, reject) => {
|
|
252
|
-
const child = spawn(command[0], command.slice(1), { stdio: ["pipe", "pipe", "pipe"] });
|
|
253
|
-
const stdout = [];
|
|
254
|
-
const stderr = [];
|
|
255
|
-
child.on("error", reject);
|
|
256
|
-
child.stdout.on("data", (chunk) => stdout.push(chunk));
|
|
257
|
-
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
258
|
-
child.on("close", (code) => {
|
|
259
|
-
resolve({
|
|
260
|
-
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
261
|
-
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
262
|
-
rc: code ?? -1,
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
if (input !== undefined) {
|
|
266
|
-
child.stdin.end(input);
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
child.stdin.end();
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
package/dist/src/events.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export interface InitEvent {
|
|
2
|
-
instance: string;
|
|
3
|
-
options: Record<string, unknown>;
|
|
4
|
-
}
|
|
5
|
-
interface CallbackEventBase {
|
|
6
|
-
id: string;
|
|
7
|
-
event: string;
|
|
8
|
-
}
|
|
9
|
-
export interface ClickEvent extends CallbackEventBase {
|
|
10
|
-
event: "click";
|
|
11
|
-
button?: string | null;
|
|
12
|
-
}
|
|
13
|
-
export interface ScrollEvent extends CallbackEventBase {
|
|
14
|
-
event: "scroll";
|
|
15
|
-
delta_y?: number;
|
|
16
|
-
}
|
|
17
|
-
export interface InputEvent extends CallbackEventBase {
|
|
18
|
-
event: "input";
|
|
19
|
-
text: string;
|
|
20
|
-
}
|
|
21
|
-
export interface ChangeEvent extends CallbackEventBase {
|
|
22
|
-
event: "change";
|
|
23
|
-
value: unknown;
|
|
24
|
-
}
|
|
25
|
-
export interface ToggleEvent extends CallbackEventBase {
|
|
26
|
-
event: "toggle";
|
|
27
|
-
value: boolean;
|
|
28
|
-
}
|
|
29
|
-
export interface PopoverEvent extends CallbackEventBase {
|
|
30
|
-
event: "open" | "close";
|
|
31
|
-
open: boolean;
|
|
32
|
-
}
|
|
33
|
-
export type CallbackEvent = ClickEvent | ScrollEvent | InputEvent | ChangeEvent | ToggleEvent | PopoverEvent;
|
|
34
|
-
export declare function parseInitEvent(payload: Record<string, unknown>): InitEvent;
|
|
35
|
-
export declare function parseCallbackEvent(payload: Record<string, unknown>): CallbackEvent;
|
|
36
|
-
export {};
|
package/dist/src/events.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function parseInitEvent(payload) {
|
|
2
|
-
return {
|
|
3
|
-
instance: String(payload.instance ?? ""),
|
|
4
|
-
options: (payload.options ?? {}),
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
export function parseCallbackEvent(payload) {
|
|
8
|
-
const event = String(payload.type ?? payload.event ?? "");
|
|
9
|
-
const id = String(payload.id ?? "");
|
|
10
|
-
if (event === "click") {
|
|
11
|
-
return { id, event, button: payload.button === undefined ? null : String(payload.button) };
|
|
12
|
-
}
|
|
13
|
-
if (event === "scroll") {
|
|
14
|
-
return {
|
|
15
|
-
id,
|
|
16
|
-
event,
|
|
17
|
-
delta_y: typeof payload.delta_y === "number" ? payload.delta_y : undefined,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
if (event === "input") {
|
|
21
|
-
return { id, event, text: String(payload.text ?? "") };
|
|
22
|
-
}
|
|
23
|
-
if (event === "toggle") {
|
|
24
|
-
let value = false;
|
|
25
|
-
if (typeof payload.active === "boolean") {
|
|
26
|
-
value = payload.active;
|
|
27
|
-
}
|
|
28
|
-
else if (typeof payload.value === "boolean") {
|
|
29
|
-
value = payload.value;
|
|
30
|
-
}
|
|
31
|
-
return { id, event, value };
|
|
32
|
-
}
|
|
33
|
-
if (event === "open" || event === "close") {
|
|
34
|
-
return { id, event, open: event === "open" };
|
|
35
|
-
}
|
|
36
|
-
return { id, event: "change", value: payload.value };
|
|
37
|
-
}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { Applet, runCommand } from "./app.js";
|
|
2
|
-
export { type CallbackEvent, type ChangeEvent, type ClickEvent, type InitEvent, type InputEvent, type PopoverEvent, type ScrollEvent, type ToggleEvent, parseCallbackEvent, parseInitEvent, } from "./events.js";
|
|
3
|
-
export { ipc, IpcError, Subscriber } from "./ipc.js";
|
|
4
|
-
export { StatusItem } from "./protocol.js";
|
|
5
|
-
export { Badge, type BadgeKind, BatteryHero, BoxedList, ButtonRow, Calendar, CameraIndicator, Choice, ChoiceList, ChoiceTile, CircleBox, Column, Container, DateHero, EmptyState, EventItem, Events, ExpanderTile, Header, Hero, KeyValueGrid, Label, LocationIndicator, Meter, MicIndicator, MutedIndicator, type PagerAppearance, PagerItem, PagerStrip, PanelIndicator, PopoverShell, type PopoverSize, Row, ScreenCastIndicator, Scroll, SegmentedTile, Separator, SliderTile, Spinner, StatusDot, type StatusDotStatus, SwitchTile, Tile, type TreeNode, WeatherForecastItem, WeatherForecastList, WeatherHourlyItem, WeatherHourlyStrip, WidgetBase, WorldClock, WorldClockRow, } from "./widgets.js";
|
package/dist/src/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { Applet, runCommand } from "./app.js";
|
|
2
|
-
export { parseCallbackEvent, parseInitEvent, } from "./events.js";
|
|
3
|
-
export { ipc, IpcError, Subscriber } from "./ipc.js";
|
|
4
|
-
export { StatusItem } from "./protocol.js";
|
|
5
|
-
export { Badge, BatteryHero, BoxedList, ButtonRow, Calendar, CameraIndicator, Choice, ChoiceList, ChoiceTile, CircleBox, Column, Container, DateHero, EmptyState, EventItem, Events, ExpanderTile, Header, Hero, KeyValueGrid, Label, LocationIndicator, Meter, MicIndicator, MutedIndicator, PagerItem, PagerStrip, PanelIndicator, PopoverShell, Row, ScreenCastIndicator, Scroll, SegmentedTile, Separator, SliderTile, Spinner, StatusDot, SwitchTile, Tile, WeatherForecastItem, WeatherForecastList, WeatherHourlyItem, WeatherHourlyStrip, WidgetBase, WorldClock, WorldClockRow, } from "./widgets.js";
|
package/dist/src/ipc.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** One decoded event line; `fields` values are unescaped. */
|
|
2
|
-
export interface Event {
|
|
3
|
-
name: string;
|
|
4
|
-
ts: number;
|
|
5
|
-
fields: Record<string, string>;
|
|
6
|
-
}
|
|
7
|
-
/** Thrown on connection failure or a rejected dispatch (`ok=false`). */
|
|
8
|
-
export declare class IpcError extends Error {
|
|
9
|
-
}
|
|
10
|
-
/** A resolved IPC endpoint. Cheap to create; holds only the socket path. */
|
|
11
|
-
export declare class Subscriber {
|
|
12
|
-
private readonly socketPath;
|
|
13
|
-
constructor(socketPath: string);
|
|
14
|
-
/** Subscribe to `channel` (an exact name, `prefix.*`, or `*`) and yield
|
|
15
|
-
* events until the server closes the connection. */
|
|
16
|
-
listen(channel: string): AsyncGenerator<Event>;
|
|
17
|
-
/** Dispatch `action` with `params` on a fresh connection and await the
|
|
18
|
-
* ack. Resolves with the extra ack fields; rejects with `IpcError` if the
|
|
19
|
-
* server replies `ok=false`. */
|
|
20
|
-
dispatch(action: string, params?: Record<string, string>): Promise<Record<string, string>>;
|
|
21
|
-
private connect;
|
|
22
|
-
}
|
|
23
|
-
/** Resolve the {@link Subscriber} for `service` (`"shell"` for the panel).
|
|
24
|
-
*
|
|
25
|
-
* The socket is `<dir>/<service>.sock` (`shell` maps to `ipc.sock`) where
|
|
26
|
-
* `<dir>` is `$GLIMPSE_IPC_DIR`, else `$XDG_RUNTIME_DIR/glimpse`. No
|
|
27
|
-
* connection is made here. */
|
|
28
|
-
export declare function ipc(service?: string): Subscriber;
|
package/dist/src/ipc.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
// Minimal client for the Glimpse IPC socket.
|
|
2
|
-
//
|
|
3
|
-
// `ipc(service)` resolves a `Subscriber` (no I/O — the connection is opened
|
|
4
|
-
// lazily). `Subscriber.listen` subscribes to an event channel and yields
|
|
5
|
-
// decoded `Event`s; `Subscriber.dispatch` sends an action and awaits the
|
|
6
|
-
// server ack on a one-shot connection. The wire protocol matches the
|
|
7
|
-
// `glimpse-shell watch` / `dispatch` CLIs.
|
|
8
|
-
import { createConnection } from "node:net";
|
|
9
|
-
import { createInterface } from "node:readline";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
/** Thrown on connection failure or a rejected dispatch (`ok=false`). */
|
|
12
|
-
export class IpcError extends Error {
|
|
13
|
-
}
|
|
14
|
-
/** A resolved IPC endpoint. Cheap to create; holds only the socket path. */
|
|
15
|
-
export class Subscriber {
|
|
16
|
-
socketPath;
|
|
17
|
-
constructor(socketPath) {
|
|
18
|
-
this.socketPath = socketPath;
|
|
19
|
-
}
|
|
20
|
-
/** Subscribe to `channel` (an exact name, `prefix.*`, or `*`) and yield
|
|
21
|
-
* events until the server closes the connection. */
|
|
22
|
-
async *listen(channel) {
|
|
23
|
-
const conn = await this.connect();
|
|
24
|
-
try {
|
|
25
|
-
conn.socket.write(`subscribe ${channel}\n`);
|
|
26
|
-
for (;;) {
|
|
27
|
-
const next = await conn.lines.next();
|
|
28
|
-
if (next.done)
|
|
29
|
-
return;
|
|
30
|
-
const line = next.value.trim();
|
|
31
|
-
if (line)
|
|
32
|
-
yield parseEvent(line);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
close(conn);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/** Dispatch `action` with `params` on a fresh connection and await the
|
|
40
|
-
* ack. Resolves with the extra ack fields; rejects with `IpcError` if the
|
|
41
|
-
* server replies `ok=false`. */
|
|
42
|
-
async dispatch(action, params = {}) {
|
|
43
|
-
validateToken("action", action, false);
|
|
44
|
-
const entries = Object.entries(params);
|
|
45
|
-
for (const [k] of entries)
|
|
46
|
-
validateToken("param key", k, true);
|
|
47
|
-
const conn = await this.connect();
|
|
48
|
-
try {
|
|
49
|
-
let line = action;
|
|
50
|
-
for (const [k, v] of entries) {
|
|
51
|
-
line += ` ${k}=${escape(v)}`;
|
|
52
|
-
}
|
|
53
|
-
conn.socket.write(line + "\n");
|
|
54
|
-
const next = await conn.lines.next();
|
|
55
|
-
if (next.done) {
|
|
56
|
-
throw new IpcError("IPC server closed connection without ack");
|
|
57
|
-
}
|
|
58
|
-
return parseAck(next.value.trim());
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
close(conn);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
connect() {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
const socket = createConnection({ path: this.socketPath });
|
|
67
|
-
let connected = false;
|
|
68
|
-
// This handler stays attached for the socket's whole lifetime. Never
|
|
69
|
-
// remove it: an unhandled 'error' event on a Socket throws and crashes
|
|
70
|
-
// the process. `close()` only destroys the socket, it does not detach.
|
|
71
|
-
socket.on("error", (err) => {
|
|
72
|
-
if (connected) {
|
|
73
|
-
// Post-connect transport error: end the stream cleanly so the
|
|
74
|
-
// line iterator completes instead of crashing the process.
|
|
75
|
-
socket.destroy();
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
reject(new IpcError(`cannot connect to IPC socket at ${this.socketPath}: ${err.message}`));
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
socket.once("connect", () => {
|
|
82
|
-
connected = true;
|
|
83
|
-
const rl = createInterface({ input: socket, crlfDelay: Infinity });
|
|
84
|
-
const lines = rl[Symbol.asyncIterator]();
|
|
85
|
-
void (async () => {
|
|
86
|
-
const hello = await lines.next();
|
|
87
|
-
if (hello.done || !hello.value.startsWith("hello")) {
|
|
88
|
-
rl.close();
|
|
89
|
-
socket.destroy();
|
|
90
|
-
reject(new IpcError(hello.done
|
|
91
|
-
? "IPC server closed connection before hello"
|
|
92
|
-
: `unexpected IPC greeting: ${hello.value}`));
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
resolve({ socket, rl, lines });
|
|
96
|
-
})();
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/** Resolve the {@link Subscriber} for `service` (`"shell"` for the panel).
|
|
102
|
-
*
|
|
103
|
-
* The socket is `<dir>/<service>.sock` (`shell` maps to `ipc.sock`) where
|
|
104
|
-
* `<dir>` is `$GLIMPSE_IPC_DIR`, else `$XDG_RUNTIME_DIR/glimpse`. No
|
|
105
|
-
* connection is made here. */
|
|
106
|
-
export function ipc(service = "shell") {
|
|
107
|
-
return new Subscriber(socketPath(service));
|
|
108
|
-
}
|
|
109
|
-
function socketPath(service) {
|
|
110
|
-
const override = process.env.GLIMPSE_IPC_DIR;
|
|
111
|
-
let dir;
|
|
112
|
-
if (override) {
|
|
113
|
-
dir = override;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
const runtime = process.env.XDG_RUNTIME_DIR;
|
|
117
|
-
if (!runtime) {
|
|
118
|
-
throw new IpcError("neither GLIMPSE_IPC_DIR nor XDG_RUNTIME_DIR is set; " +
|
|
119
|
-
"cannot locate the Glimpse IPC socket");
|
|
120
|
-
}
|
|
121
|
-
dir = join(runtime, "glimpse");
|
|
122
|
-
}
|
|
123
|
-
return join(dir, service === "shell" ? "ipc.sock" : `${service}.sock`);
|
|
124
|
-
}
|
|
125
|
-
function close(conn) {
|
|
126
|
-
conn.rl.close();
|
|
127
|
-
conn.socket.destroy();
|
|
128
|
-
}
|
|
129
|
-
// The wire protocol splits client lines on whitespace and never unescapes
|
|
130
|
-
// the command name or a field key, so an `action`/key with whitespace would
|
|
131
|
-
// forge extra tokens or whole client lines. Values are safe (escaped).
|
|
132
|
-
function validateToken(label, token, forbidEq) {
|
|
133
|
-
if (token.length === 0) {
|
|
134
|
-
throw new IpcError(`IPC ${label} must not be empty`);
|
|
135
|
-
}
|
|
136
|
-
if (/\s/.test(token)) {
|
|
137
|
-
throw new IpcError(`IPC ${label} "${token}" must not contain whitespace`);
|
|
138
|
-
}
|
|
139
|
-
if (forbidEq && token.includes("=")) {
|
|
140
|
-
throw new IpcError(`IPC param key "${token}" must not contain '='`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function escape(s) {
|
|
144
|
-
return s
|
|
145
|
-
.replaceAll("\\", "\\\\")
|
|
146
|
-
.replaceAll("\n", "\\n")
|
|
147
|
-
.replaceAll("\t", "\\t")
|
|
148
|
-
.replaceAll(" ", "\\s");
|
|
149
|
-
}
|
|
150
|
-
function unescape(s) {
|
|
151
|
-
let out = "";
|
|
152
|
-
for (let i = 0; i < s.length; i++) {
|
|
153
|
-
if (s[i] !== "\\") {
|
|
154
|
-
out += s[i];
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const next = s[++i];
|
|
158
|
-
if (next === "s")
|
|
159
|
-
out += " ";
|
|
160
|
-
else if (next === "n")
|
|
161
|
-
out += "\n";
|
|
162
|
-
else if (next === "t")
|
|
163
|
-
out += "\t";
|
|
164
|
-
else if (next === "\\")
|
|
165
|
-
out += "\\";
|
|
166
|
-
else if (next === undefined)
|
|
167
|
-
out += "\\";
|
|
168
|
-
else
|
|
169
|
-
out += "\\" + next;
|
|
170
|
-
}
|
|
171
|
-
return out;
|
|
172
|
-
}
|
|
173
|
-
function parseEvent(line) {
|
|
174
|
-
const tokens = line.split(/\s+/);
|
|
175
|
-
const name = tokens[0] ?? "";
|
|
176
|
-
let ts = 0;
|
|
177
|
-
const fields = {};
|
|
178
|
-
for (const token of tokens.slice(1)) {
|
|
179
|
-
const eq = token.indexOf("=");
|
|
180
|
-
if (eq < 0)
|
|
181
|
-
continue;
|
|
182
|
-
const key = token.slice(0, eq);
|
|
183
|
-
const value = unescape(token.slice(eq + 1));
|
|
184
|
-
if (key === "ts" && /^\d+$/.test(value)) {
|
|
185
|
-
ts = Number(value);
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
fields[key] = value;
|
|
189
|
-
}
|
|
190
|
-
return { name, ts, fields };
|
|
191
|
-
}
|
|
192
|
-
function parseAck(line) {
|
|
193
|
-
const tokens = line.split(/\s+/);
|
|
194
|
-
if (tokens[0] !== "ack") {
|
|
195
|
-
throw new IpcError(`expected an ack, got: ${line}`);
|
|
196
|
-
}
|
|
197
|
-
let ok = false;
|
|
198
|
-
const fields = {};
|
|
199
|
-
for (const token of tokens.slice(1)) {
|
|
200
|
-
const eq = token.indexOf("=");
|
|
201
|
-
if (eq < 0)
|
|
202
|
-
continue;
|
|
203
|
-
const key = token.slice(0, eq);
|
|
204
|
-
const value = unescape(token.slice(eq + 1));
|
|
205
|
-
if (key === "ok")
|
|
206
|
-
ok = value === "true";
|
|
207
|
-
else
|
|
208
|
-
fields[key] = value;
|
|
209
|
-
}
|
|
210
|
-
if (!ok) {
|
|
211
|
-
throw new IpcError(fields.error ?? "command failed");
|
|
212
|
-
}
|
|
213
|
-
return fields;
|
|
214
|
-
}
|
package/dist/src/protocol.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare class StatusItem {
|
|
2
|
-
readonly options: {
|
|
3
|
-
id?: string;
|
|
4
|
-
icon?: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
tooltip?: string;
|
|
7
|
-
};
|
|
8
|
-
constructor(options?: {
|
|
9
|
-
id?: string;
|
|
10
|
-
icon?: string;
|
|
11
|
-
label?: string;
|
|
12
|
-
tooltip?: string;
|
|
13
|
-
});
|
|
14
|
-
toProtocol(): Record<string, unknown>;
|
|
15
|
-
}
|