gestament 0.2.0 → 0.3.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.
Files changed (86) hide show
  1. package/README.md +4 -6
  2. package/dist/displaySession.d.ts +18 -0
  3. package/dist/displaySession.d.ts.map +1 -0
  4. package/dist/element.d.ts +2 -2
  5. package/dist/errors-6gj5YuLw.cjs +36 -0
  6. package/dist/errors-6gj5YuLw.cjs.map +1 -0
  7. package/dist/errors-CCW4ATME.js +37 -0
  8. package/dist/errors-CCW4ATME.js.map +1 -0
  9. package/dist/errors.d.ts +2 -2
  10. package/dist/errors.d.ts.map +1 -1
  11. package/dist/generated/packageMetadata.d.ts +4 -4
  12. package/dist/gestament-config.d.ts +2 -2
  13. package/dist/gestament-launcher-driver.cjs +656 -0
  14. package/dist/gestament-launcher-driver.cjs.map +1 -0
  15. package/dist/gestament-launcher-driver.d.ts +13 -0
  16. package/dist/gestament-launcher-driver.d.ts.map +1 -0
  17. package/dist/gestament-launcher-driver.mjs +655 -0
  18. package/dist/gestament-launcher-driver.mjs.map +1 -0
  19. package/dist/gestament-tray-host.cjs +1 -1
  20. package/dist/gestament-tray-host.d.ts +2 -2
  21. package/dist/gestament-tray-host.mjs +1 -1
  22. package/dist/gestament-xvfb-pool-probe.cjs +29 -0
  23. package/dist/gestament-xvfb-pool-probe.cjs.map +1 -0
  24. package/dist/gestament-xvfb-pool-probe.d.ts +13 -0
  25. package/dist/gestament-xvfb-pool-probe.d.ts.map +1 -0
  26. package/dist/gestament-xvfb-pool-probe.mjs +28 -0
  27. package/dist/gestament-xvfb-pool-probe.mjs.map +1 -0
  28. package/dist/gestament-xvfb-worker.d.ts +2 -2
  29. package/dist/gestament-xvfb.cjs +8 -2
  30. package/dist/gestament-xvfb.cjs.map +1 -1
  31. package/dist/gestament-xvfb.d.ts +2 -2
  32. package/dist/gestament-xvfb.mjs +8 -2
  33. package/dist/gestament-xvfb.mjs.map +1 -1
  34. package/dist/index.cjs +4 -1147
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.mjs +4 -1147
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/launchGtkApp-BIO_5Xjn.cjs +2479 -0
  40. package/dist/launchGtkApp-BIO_5Xjn.cjs.map +1 -0
  41. package/dist/launchGtkApp-qi1qm5G4.js +2479 -0
  42. package/dist/launchGtkApp-qi1qm5G4.js.map +1 -0
  43. package/dist/launchGtkApp.d.ts +2 -2
  44. package/dist/launchGtkApp.d.ts.map +1 -1
  45. package/dist/launcherDriverProtocol.d.ts +107 -0
  46. package/dist/launcherDriverProtocol.d.ts.map +1 -0
  47. package/dist/{native-ie_XIt1J.cjs → native-CBXaFWP-.cjs} +14 -40
  48. package/dist/native-CBXaFWP-.cjs.map +1 -0
  49. package/dist/{native-DUeVYIBs.js → native-CWdUmdty.js} +48 -74
  50. package/dist/native-CWdUmdty.js.map +1 -0
  51. package/dist/native.d.ts +4 -2
  52. package/dist/native.d.ts.map +1 -1
  53. package/dist/prerequisites-BuZST2Dy.cjs +15 -0
  54. package/dist/prerequisites-BuZST2Dy.cjs.map +1 -0
  55. package/dist/prerequisites-JB0SKPVd.js +16 -0
  56. package/dist/prerequisites-JB0SKPVd.js.map +1 -0
  57. package/dist/prerequisites.d.ts +23 -0
  58. package/dist/prerequisites.d.ts.map +1 -0
  59. package/dist/testing.cjs +3 -0
  60. package/dist/testing.cjs.map +1 -1
  61. package/dist/testing.d.ts +4 -2
  62. package/dist/testing.d.ts.map +1 -1
  63. package/dist/testing.mjs +4 -1
  64. package/dist/testing.mjs.map +1 -1
  65. package/dist/tray.d.ts +2 -2
  66. package/dist/types.d.ts +64 -2
  67. package/dist/types.d.ts.map +1 -1
  68. package/dist/wait-DV5gkXs8.js +113 -0
  69. package/dist/wait-DV5gkXs8.js.map +1 -0
  70. package/dist/wait-eOIz4nZm.cjs +112 -0
  71. package/dist/wait-eOIz4nZm.cjs.map +1 -0
  72. package/dist/wait.d.ts +67 -0
  73. package/dist/wait.d.ts.map +1 -0
  74. package/package.json +7 -7
  75. package/prebuilds/linux-arm/gtk3/node.napi.armv7.glibc.node +0 -0
  76. package/prebuilds/linux-arm/gtk4/node.napi.armv7.glibc.node +0 -0
  77. package/prebuilds/linux-arm64/gtk3/node.napi.glibc.node +0 -0
  78. package/prebuilds/linux-arm64/gtk4/node.napi.glibc.node +0 -0
  79. package/prebuilds/linux-ia32/gtk3/node.napi.glibc.node +0 -0
  80. package/prebuilds/linux-ia32/gtk4/node.napi.glibc.node +0 -0
  81. package/prebuilds/linux-riscv64/gtk3/node.napi.glibc.node +0 -0
  82. package/prebuilds/linux-riscv64/gtk4/node.napi.glibc.node +0 -0
  83. package/prebuilds/linux-x64/gtk3/node.napi.glibc.node +0 -0
  84. package/prebuilds/linux-x64/gtk4/node.napi.glibc.node +0 -0
  85. package/dist/native-DUeVYIBs.js.map +0 -1
  86. package/dist/native-ie_XIt1J.cjs.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,1150 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_child_process = require("node:child_process");
4
- const native = require("./native-ie_XIt1J.cjs");
5
- /*!
6
- * name: async-primitives
7
- * version: 1.7.0
8
- * description: A collection of primitive functions for asynchronous operations
9
- * author: Kouji Matsui (@kekyo@mi.kekyo.net)
10
- * license: MIT
11
- * repository.url: https://github.com/kekyo/async-primitives.git
12
- * git.commit.hash: 9472fbd5310b92690d84aaafb897429a04c013c5
13
- */
14
- var delay = (msec, signal) => {
15
- return new Promise((resolve) => {
16
- setTimeout(resolve, msec);
17
- });
18
- };
19
- const assertNonNegativeIndex$1 = (name, index) => {
20
- if (!Number.isInteger(index) || index < 0) {
21
- throw native.createGtkInvalidArgumentError(
22
- `${name} must be a non-negative integer.`
23
- );
24
- }
25
- };
26
- const assertFiniteNumber = (name, value) => {
27
- if (!Number.isFinite(value)) {
28
- throw native.createGtkInvalidArgumentError(`${name} must be a finite number.`);
29
- }
30
- };
31
- const normalizeRoleName = (roleName) => roleName.trim().toLowerCase().replace(/[_-]+/g, " ").replace(/\s+/g, " ");
32
- const hasInterface = (info, name) => info.interfaces.some(
33
- (interfaceName) => interfaceName.toLowerCase() === name.toLowerCase()
34
- );
35
- const hasState = (info, name) => info.states.some((state) => state.toLowerCase() === name.toLowerCase());
36
- const elementInfoOverrides = /* @__PURE__ */ new WeakMap();
37
- const overrideElementInfo = (handle, override) => {
38
- elementInfoOverrides.set(handle, override);
39
- return handle;
40
- };
41
- const nativeInfoKind = (handle) => elementInfoOverrides.get(handle)?.kind ?? widgetKindFromInfo(native.nativeElementInfo(handle));
42
- const widgetKindFromInfo = (info) => {
43
- const roleName = normalizeRoleName(info.roleName);
44
- if (hasInterface(info, "TableCell")) {
45
- return "tableCell";
46
- }
47
- switch (roleName) {
48
- case "frame":
49
- case "dialog":
50
- case "window":
51
- return "window";
52
- case "filler":
53
- case "panel":
54
- case "scroll pane":
55
- case "layered pane":
56
- case "split pane":
57
- case "viewport":
58
- return "container";
59
- case "button":
60
- case "push button":
61
- case "push button menu":
62
- return "button";
63
- case "label":
64
- case "static":
65
- return "label";
66
- case "entry":
67
- case "password text":
68
- case "search box":
69
- return "entry";
70
- case "text":
71
- return hasInterface(info, "EditableText") || hasState(info, "editable") || hasState(info, "singleLine") ? "entry" : "text";
72
- case "paragraph":
73
- return "text";
74
- case "check box":
75
- return "checkbox";
76
- case "switch":
77
- return "switch";
78
- case "radio button":
79
- return "radio";
80
- case "toggle button":
81
- return hasInterface(info, "Image") || info.name.length > 0 ? "toggleButton" : "switch";
82
- case "slider":
83
- return "slider";
84
- case "spin button":
85
- return "spinButton";
86
- case "progress bar":
87
- case "level bar":
88
- return "progressBar";
89
- case "combo box":
90
- return "comboBox";
91
- case "list":
92
- case "list box":
93
- return "list";
94
- case "tree":
95
- return hasInterface(info, "Table") ? "table" : "list";
96
- case "list item":
97
- case "tree item":
98
- return "listItem";
99
- case "table":
100
- case "tree table":
101
- return "table";
102
- case "table cell":
103
- return "tableCell";
104
- case "image":
105
- case "icon":
106
- return "image";
107
- case "menu":
108
- case "menu bar":
109
- case "popup menu":
110
- return "menu";
111
- case "menu item":
112
- case "check menu item":
113
- case "radio menu item":
114
- case "tearoff menu item":
115
- return "menuItem";
116
- default:
117
- return "unknown";
118
- }
119
- };
120
- const toGtkElementInfo = (info) => ({
121
- ...info,
122
- kind: widgetKindFromInfo(info)
123
- });
124
- const toGtkElementInfoForHandle = (handle) => {
125
- const info = toGtkElementInfo(native.nativeElementInfo(handle));
126
- const override = elementInfoOverrides.get(handle);
127
- return override === void 0 ? info : { ...info, ...override };
128
- };
129
- const createCommonElement = (handle) => ({
130
- info: async () => toGtkElementInfoForHandle(handle),
131
- capture: async () => native.nativeCapture(handle)
132
- });
133
- const expectedKindLabel = (expectedKinds) => expectedKinds.join(", ");
134
- const assertExpectedKind = (element, expectedKinds, operation) => {
135
- if (!expectedKinds.includes(element.kind)) {
136
- throw native.createGtkUnsupportedInterfaceError(
137
- `${operation} returned ${element.kind}, expected ${expectedKindLabel(
138
- expectedKinds
139
- )}.`
140
- );
141
- }
142
- return element;
143
- };
144
- const createGetChildCountOperation = (handle) => async () => native.nativeChildCount(handle);
145
- const createChildAtOperation = (handle, expectedKinds) => async (index) => {
146
- assertNonNegativeIndex$1("index", index);
147
- const childHandle = native.nativeChildAt(handle, index);
148
- if (childHandle === void 0) {
149
- return void 0;
150
- }
151
- const child = createGtkElement(childHandle);
152
- return expectedKinds === void 0 ? child : assertExpectedKind(child, expectedKinds, "childAt()");
153
- };
154
- const createChildContainerOperations = (handle, expectedKinds) => ({
155
- childAt: createChildAtOperation(handle, expectedKinds),
156
- getChildCount: createGetChildCountOperation(handle)
157
- });
158
- const createSelectableChildContainerOperations = (handle, expectedKinds) => ({
159
- ...createChildContainerOperations(handle, expectedKinds),
160
- getSelectedChildCount: async () => native.nativeSelectedChildCount(handle),
161
- selectedChildAt: async (selectedIndex) => {
162
- assertNonNegativeIndex$1("selectedIndex", selectedIndex);
163
- const childHandle = native.nativeSelectedChildAt(handle, selectedIndex);
164
- if (childHandle === void 0) {
165
- return void 0;
166
- }
167
- const child = createGtkElement(childHandle);
168
- return assertExpectedKind(child, expectedKinds, "selectedChildAt()");
169
- },
170
- isChildSelected: async (index) => {
171
- assertNonNegativeIndex$1("index", index);
172
- return native.nativeIsChildSelected(handle, index);
173
- },
174
- selectChildAt: async (index) => {
175
- assertNonNegativeIndex$1("index", index);
176
- native.nativeSelectChildAt(handle, index);
177
- },
178
- deselectChildAt: async (index) => {
179
- assertNonNegativeIndex$1("index", index);
180
- native.nativeDeselectChildAt(handle, index);
181
- },
182
- selectAllChildren: async () => {
183
- native.nativeSelectAllChildren(handle);
184
- },
185
- clearSelection: async () => {
186
- native.nativeClearSelection(handle);
187
- }
188
- });
189
- const createOperationFailedForOutOfRangeIndex = (index) => native.createGtkOperationFailedError(`Child index is out of range: ${index}`);
190
- const isUnsupportedInterfaceError = (error) => error.code === "UNSUPPORTED_INTERFACE";
191
- const visitNativeDescendants = (handle, visitor, maxNodes) => {
192
- const queue = [];
193
- const childCount = native.nativeChildCount(handle);
194
- for (let index = 0; index < childCount; index += 1) {
195
- const childHandle = native.nativeChildAt(handle, index);
196
- if (childHandle !== void 0) {
197
- queue.push(childHandle);
198
- }
199
- }
200
- let visitedNodes = 0;
201
- while (queue.length > 0 && visitedNodes < maxNodes) {
202
- const currentHandle = queue.shift();
203
- visitedNodes += 1;
204
- if (visitor(currentHandle)) {
205
- return;
206
- }
207
- const currentChildCount = native.nativeChildCount(currentHandle);
208
- for (let index = 0; index < currentChildCount; index += 1) {
209
- const childHandle = native.nativeChildAt(currentHandle, index);
210
- if (childHandle !== void 0) {
211
- queue.push(childHandle);
212
- }
213
- }
214
- }
215
- };
216
- const findFirstDescendantName = (handle) => {
217
- let foundName;
218
- visitNativeDescendants(
219
- handle,
220
- (descendantHandle) => {
221
- const name = native.nativeElementInfo(descendantHandle).name;
222
- if (name.length === 0) {
223
- return false;
224
- }
225
- foundName = name;
226
- return true;
227
- },
228
- 64
229
- );
230
- return foundName;
231
- };
232
- const directChildKindAt = (handle, index) => {
233
- const childHandle = native.nativeChildAt(handle, index);
234
- return childHandle === void 0 ? void 0 : nativeInfoKind(childHandle);
235
- };
236
- const handleContainsComboItems = (handle) => {
237
- const childCount = native.nativeChildCount(handle);
238
- if (childCount === 0) {
239
- return false;
240
- }
241
- const firstChildKind = directChildKindAt(handle, 0);
242
- return firstChildKind === "listItem" || firstChildKind === "menuItem";
243
- };
244
- const findComboBoxItemContainerHandle = (handle) => {
245
- if (handleContainsComboItems(handle)) {
246
- return handle;
247
- }
248
- let foundHandle;
249
- visitNativeDescendants(
250
- handle,
251
- (descendantHandle) => {
252
- const kind = nativeInfoKind(descendantHandle);
253
- if ((kind === "list" || kind === "menu") && handleContainsComboItems(descendantHandle)) {
254
- foundHandle = descendantHandle;
255
- return true;
256
- }
257
- return false;
258
- },
259
- 128
260
- );
261
- return foundHandle;
262
- };
263
- const resolveComboBoxItemContainerHandle = (handle) => {
264
- const descendantItemContainer = findComboBoxItemContainerHandle(handle);
265
- if (descendantItemContainer !== void 0) {
266
- return descendantItemContainer;
267
- }
268
- const childCount = native.nativeChildCount(handle);
269
- if (childCount !== 1) {
270
- return handle;
271
- }
272
- const childHandle = native.nativeChildAt(handle, 0);
273
- if (childHandle === void 0) {
274
- return handle;
275
- }
276
- const childKind = nativeInfoKind(childHandle);
277
- return childKind === "menu" || childKind === "list" ? childHandle : handle;
278
- };
279
- const comboBoxClickTargetHandle = (handle) => {
280
- const childHandle = native.nativeChildAt(handle, 0);
281
- if (childHandle === void 0) {
282
- return handle;
283
- }
284
- const childKind = nativeInfoKind(childHandle);
285
- return childKind === "button" || childKind === "toggleButton" ? childHandle : handle;
286
- };
287
- const overrideComboBoxItemInfo = (handle) => {
288
- const info = native.nativeElementInfo(handle);
289
- if (info.name.length > 0) {
290
- return handle;
291
- }
292
- const descendantName = findFirstDescendantName(handle);
293
- return descendantName === void 0 ? handle : overrideElementInfo(handle, { name: descendantName });
294
- };
295
- const itemIdentityMatches = (candidate, selected) => {
296
- if (candidate.accessibleId.length > 0 && selected.accessibleId.length > 0) {
297
- return candidate.accessibleId === selected.accessibleId;
298
- }
299
- return candidate.kind === selected.kind && candidate.roleName === selected.roleName && candidate.name === selected.name && candidate.description === selected.description;
300
- };
301
- const comboBoxItemLookupAt = (handle, index) => {
302
- const itemContainerHandle = resolveComboBoxItemContainerHandle(handle);
303
- const itemHandle = native.nativeChildAt(itemContainerHandle, index);
304
- if (itemHandle === void 0) {
305
- throw createOperationFailedForOutOfRangeIndex(index);
306
- }
307
- const itemKind = nativeInfoKind(itemHandle);
308
- if (itemKind !== "listItem" && itemKind !== "menuItem") {
309
- throw native.createGtkUnsupportedInterfaceError(
310
- `ComboBox childAt() returned ${itemKind}, expected listItem, menuItem.`
311
- );
312
- }
313
- return {
314
- itemContainerHandle,
315
- itemHandle: overrideComboBoxItemInfo(itemHandle)
316
- };
317
- };
318
- const comboBoxItemHandleAt = (handle, index) => comboBoxItemLookupAt(handle, index).itemHandle;
319
- const createComboBoxOperations = (handle) => ({
320
- childAt: async (index) => {
321
- assertNonNegativeIndex$1("index", index);
322
- const itemContainerHandle = resolveComboBoxItemContainerHandle(handle);
323
- const itemHandle = native.nativeChildAt(itemContainerHandle, index);
324
- if (itemHandle === void 0) {
325
- return void 0;
326
- }
327
- overrideComboBoxItemInfo(itemHandle);
328
- return assertExpectedKind(
329
- createGtkElement(itemHandle),
330
- ["listItem", "menuItem"],
331
- "childAt()"
332
- );
333
- },
334
- getChildCount: async () => native.nativeChildCount(resolveComboBoxItemContainerHandle(handle)),
335
- getSelectedChildCount: async () => native.nativeSelectedChildCount(handle),
336
- selectedChildAt: async (selectedIndex) => {
337
- assertNonNegativeIndex$1("selectedIndex", selectedIndex);
338
- const childHandle = native.nativeSelectedChildAt(handle, selectedIndex);
339
- if (childHandle === void 0) {
340
- return void 0;
341
- }
342
- return assertExpectedKind(
343
- createGtkElement(childHandle),
344
- ["listItem", "menuItem"],
345
- "selectedChildAt()"
346
- );
347
- },
348
- isChildSelected: async (index) => {
349
- assertNonNegativeIndex$1("index", index);
350
- const itemHandle = comboBoxItemHandleAt(handle, index);
351
- const itemInfo = toGtkElementInfoForHandle(itemHandle);
352
- const selectedCount = native.nativeSelectedChildCount(handle);
353
- for (let selectedIndex = 0; selectedIndex < selectedCount; selectedIndex += 1) {
354
- const selectedHandle = native.nativeSelectedChildAt(handle, selectedIndex);
355
- if (selectedHandle === void 0) {
356
- continue;
357
- }
358
- const selectedInfo = toGtkElementInfo(native.nativeElementInfo(selectedHandle));
359
- if (itemIdentityMatches(itemInfo, selectedInfo)) {
360
- return true;
361
- }
362
- }
363
- return false;
364
- },
365
- selectChildAt: async (index) => {
366
- assertNonNegativeIndex$1("index", index);
367
- const { itemContainerHandle, itemHandle } = comboBoxItemLookupAt(
368
- handle,
369
- index
370
- );
371
- const expectedName = toGtkElementInfoForHandle(itemHandle).name;
372
- native.nativeClick(itemHandle);
373
- if (itemContainerHandle !== handle && expectedName.length > 0 && native.nativeElementInfo(handle).name !== expectedName) {
374
- throw native.createGtkOperationFailedError(
375
- "ComboBox child selection did not change the selected item."
376
- );
377
- }
378
- },
379
- deselectChildAt: async (index) => {
380
- assertNonNegativeIndex$1("index", index);
381
- comboBoxItemHandleAt(handle, index);
382
- native.nativeDeselectChildAt(handle, 0);
383
- },
384
- selectAllChildren: async () => {
385
- native.nativeSelectAllChildren(handle);
386
- },
387
- clearSelection: async () => {
388
- const selectedBefore = native.nativeSelectedChildCount(handle);
389
- native.nativeClearSelection(handle);
390
- if (selectedBefore > 0 && native.nativeSelectedChildCount(handle) > 0) {
391
- throw native.createGtkOperationFailedError(
392
- "ComboBox selection could not be cleared."
393
- );
394
- }
395
- }
396
- });
397
- const createSetTextOperation = (handle) => async (text) => {
398
- native.nativeSetText(handle, text);
399
- };
400
- const createClickOperation = (handle) => async () => {
401
- native.nativeClick(handle);
402
- };
403
- const createComboBoxClickOperation = (handle) => async () => {
404
- native.nativeClick(comboBoxClickTargetHandle(handle));
405
- };
406
- const createTextOperation = (handle) => async () => native.nativeText(handle);
407
- const createIsCheckedOperation = (handle) => async () => {
408
- const info = native.nativeElementInfo(handle);
409
- return hasState(info, "checked") || hasState(info, "pressed");
410
- };
411
- const createToggleOperation = (handle) => async () => {
412
- native.nativeClick(handle);
413
- };
414
- const createValueInfoOperation = (handle) => async () => native.nativeValueInfo(handle);
415
- const createImageInfoOperation = (handle) => async () => {
416
- const info = native.nativeImageInfo(handle);
417
- return {
418
- ...info,
419
- capture: async () => native.nativeCaptureBounds(info.bounds)
420
- };
421
- };
422
- const createValueOperation = (handle) => async () => native.nativeValueInfo(handle).value;
423
- const createSetValueOperation = (handle) => async (value) => {
424
- assertFiniteNumber("value", value);
425
- native.nativeSetValue(handle, value);
426
- };
427
- const assertUsableValueMetadata = (info) => {
428
- if (!Number.isFinite(info.value) || !Number.isFinite(info.minimum) || !Number.isFinite(info.maximum) || !Number.isFinite(info.minimumIncrement)) {
429
- throw native.createGtkOperationFailedError(
430
- "Accessible value metadata does not contain usable numeric values."
431
- );
432
- }
433
- };
434
- const valueStep = (info) => {
435
- assertUsableValueMetadata(info);
436
- if (info.minimumIncrement > 0) {
437
- return info.minimumIncrement;
438
- }
439
- const range = info.maximum - info.minimum;
440
- if (!Number.isFinite(range) || range <= 0) {
441
- throw native.createGtkOperationFailedError(
442
- "Accessible value metadata does not contain a usable increment."
443
- );
444
- }
445
- return Math.min(1, range);
446
- };
447
- const clampedValue = (value, minimum, maximum) => Math.min(Math.max(value, minimum), maximum);
448
- const createIncrementOperation = (handle) => async () => {
449
- const info = native.nativeValueInfo(handle);
450
- const step = valueStep(info);
451
- native.nativeSetValue(
452
- handle,
453
- clampedValue(info.value + step, info.minimum, info.maximum)
454
- );
455
- };
456
- const createDecrementOperation = (handle) => async () => {
457
- const info = native.nativeValueInfo(handle);
458
- const step = valueStep(info);
459
- native.nativeSetValue(
460
- handle,
461
- clampedValue(info.value - step, info.minimum, info.maximum)
462
- );
463
- };
464
- const collectDirectTableCellChildren = (rowHandle) => {
465
- const cells = [];
466
- const childCount = native.nativeChildCount(rowHandle);
467
- for (let index = 0; index < childCount; index += 1) {
468
- const childHandle = native.nativeChildAt(rowHandle, index);
469
- if (childHandle !== void 0 && nativeInfoKind(childHandle) === "tableCell") {
470
- cells.push(childHandle);
471
- }
472
- }
473
- return cells;
474
- };
475
- const collectFallbackTableRows = (handle) => {
476
- const rows = [];
477
- visitNativeDescendants(
478
- handle,
479
- (descendantHandle) => {
480
- const roleName = normalizeRoleName(
481
- native.nativeElementInfo(descendantHandle).roleName
482
- );
483
- if (roleName !== "table row") {
484
- return false;
485
- }
486
- const cells = collectDirectTableCellChildren(descendantHandle);
487
- if (cells.length > 0) {
488
- rows.push(
489
- cells.map(
490
- (cellHandle) => overrideElementInfo(cellHandle, { kind: "tableCell" })
491
- )
492
- );
493
- }
494
- return false;
495
- },
496
- 512
497
- );
498
- return rows;
499
- };
500
- const fallbackTableRowCount = (handle) => collectFallbackTableRows(handle).length;
501
- const fallbackTableColumnCount = (handle) => {
502
- const rows = collectFallbackTableRows(handle);
503
- return rows.reduce((max, row) => Math.max(max, row.length), 0);
504
- };
505
- const fallbackTableCellAt = (handle, row, column) => {
506
- const rows = collectFallbackTableRows(handle);
507
- return rows[row]?.[column];
508
- };
509
- const createTableCellAtOperation = (handle) => async (row, column) => {
510
- assertNonNegativeIndex$1("row", row);
511
- assertNonNegativeIndex$1("column", column);
512
- let cellHandle;
513
- try {
514
- cellHandle = native.nativeTableCellAt(handle, row, column);
515
- } catch (error) {
516
- if (!isUnsupportedInterfaceError(error)) {
517
- throw error;
518
- }
519
- cellHandle = fallbackTableCellAt(handle, row, column);
520
- }
521
- if (cellHandle === void 0) {
522
- return void 0;
523
- }
524
- overrideElementInfo(cellHandle, { kind: "tableCell" });
525
- return assertExpectedKind(
526
- createGtkElement(cellHandle),
527
- ["tableCell"],
528
- "cellAt()"
529
- );
530
- };
531
- const createTableOperations = (handle) => ({
532
- getRowCount: async () => {
533
- try {
534
- return native.nativeTableRowCount(handle);
535
- } catch (error) {
536
- if (!isUnsupportedInterfaceError(error)) {
537
- throw error;
538
- }
539
- return fallbackTableRowCount(handle);
540
- }
541
- },
542
- getColumnCount: async () => {
543
- try {
544
- return native.nativeTableColumnCount(handle);
545
- } catch (error) {
546
- if (!isUnsupportedInterfaceError(error)) {
547
- throw error;
548
- }
549
- return fallbackTableColumnCount(handle);
550
- }
551
- },
552
- cellAt: createTableCellAtOperation(handle),
553
- selectedRows: async () => native.nativeTableSelectedRows(handle),
554
- selectedColumns: async () => native.nativeTableSelectedColumns(handle),
555
- isRowSelected: async (row) => {
556
- assertNonNegativeIndex$1("row", row);
557
- return native.nativeTableIsRowSelected(handle, row);
558
- },
559
- isColumnSelected: async (column) => {
560
- assertNonNegativeIndex$1("column", column);
561
- return native.nativeTableIsColumnSelected(handle, column);
562
- },
563
- isCellSelected: async (row, column) => {
564
- assertNonNegativeIndex$1("row", row);
565
- assertNonNegativeIndex$1("column", column);
566
- return native.nativeTableIsCellSelected(handle, row, column);
567
- },
568
- selectRow: async (row) => {
569
- assertNonNegativeIndex$1("row", row);
570
- native.nativeTableSelectRow(handle, row);
571
- },
572
- deselectRow: async (row) => {
573
- assertNonNegativeIndex$1("row", row);
574
- native.nativeTableDeselectRow(handle, row);
575
- },
576
- selectColumn: async (column) => {
577
- assertNonNegativeIndex$1("column", column);
578
- native.nativeTableSelectColumn(handle, column);
579
- },
580
- deselectColumn: async (column) => {
581
- assertNonNegativeIndex$1("column", column);
582
- native.nativeTableDeselectColumn(handle, column);
583
- }
584
- });
585
- const createGtkElement = (handle) => {
586
- const initialInfo = toGtkElementInfoForHandle(handle);
587
- const common = createCommonElement(handle);
588
- switch (initialInfo.kind) {
589
- case "window":
590
- return {
591
- ...common,
592
- kind: "window",
593
- ...createChildContainerOperations(handle, void 0)
594
- };
595
- case "button":
596
- return { ...common, kind: "button", click: createClickOperation(handle) };
597
- case "container":
598
- return {
599
- ...common,
600
- kind: "container",
601
- ...createChildContainerOperations(handle, void 0)
602
- };
603
- case "label":
604
- return { ...common, kind: "label", text: createTextOperation(handle) };
605
- case "entry":
606
- return {
607
- ...common,
608
- kind: "entry",
609
- setText: createSetTextOperation(handle),
610
- text: createTextOperation(handle)
611
- };
612
- case "text":
613
- return { ...common, kind: "text", text: createTextOperation(handle) };
614
- case "checkbox":
615
- return {
616
- ...common,
617
- kind: "checkbox",
618
- click: createClickOperation(handle),
619
- isChecked: createIsCheckedOperation(handle),
620
- toggle: createToggleOperation(handle)
621
- };
622
- case "switch":
623
- return {
624
- ...common,
625
- kind: "switch",
626
- click: createClickOperation(handle),
627
- isChecked: createIsCheckedOperation(handle),
628
- toggle: createToggleOperation(handle)
629
- };
630
- case "radio":
631
- return {
632
- ...common,
633
- kind: "radio",
634
- click: createClickOperation(handle),
635
- isChecked: createIsCheckedOperation(handle),
636
- toggle: createToggleOperation(handle)
637
- };
638
- case "toggleButton":
639
- return {
640
- ...common,
641
- kind: "toggleButton",
642
- click: createClickOperation(handle),
643
- isChecked: createIsCheckedOperation(handle),
644
- toggle: createToggleOperation(handle)
645
- };
646
- case "slider":
647
- return {
648
- ...common,
649
- kind: "slider",
650
- value: createValueOperation(handle),
651
- valueInfo: createValueInfoOperation(handle),
652
- setValue: createSetValueOperation(handle)
653
- };
654
- case "spinButton":
655
- return {
656
- ...common,
657
- kind: "spinButton",
658
- value: createValueOperation(handle),
659
- valueInfo: createValueInfoOperation(handle),
660
- setValue: createSetValueOperation(handle),
661
- increment: createIncrementOperation(handle),
662
- decrement: createDecrementOperation(handle)
663
- };
664
- case "progressBar":
665
- return {
666
- ...common,
667
- kind: "progressBar",
668
- value: createValueOperation(handle),
669
- valueInfo: createValueInfoOperation(handle)
670
- };
671
- case "comboBox":
672
- return {
673
- ...common,
674
- kind: "comboBox",
675
- click: createComboBoxClickOperation(handle),
676
- ...createComboBoxOperations(handle)
677
- };
678
- case "list":
679
- return {
680
- ...common,
681
- kind: "list",
682
- ...createSelectableChildContainerOperations(
683
- handle,
684
- ["listItem"]
685
- )
686
- };
687
- case "listItem":
688
- return {
689
- ...common,
690
- kind: "listItem",
691
- click: createClickOperation(handle)
692
- };
693
- case "table":
694
- return { ...common, kind: "table", ...createTableOperations(handle) };
695
- case "tableCell":
696
- return { ...common, kind: "tableCell" };
697
- case "image":
698
- return {
699
- ...common,
700
- kind: "image",
701
- imageInfo: createImageInfoOperation(handle)
702
- };
703
- case "menu":
704
- return {
705
- ...common,
706
- kind: "menu",
707
- ...createChildContainerOperations(handle, [
708
- "menuItem"
709
- ])
710
- };
711
- case "menuItem":
712
- return {
713
- ...common,
714
- kind: "menuItem",
715
- click: createClickOperation(handle)
716
- };
717
- case "unknown":
718
- return { ...common, kind: "unknown" };
719
- }
720
- };
721
- const optionalString = (value) => value.length === 0 ? void 0 : value;
722
- const toMetadata = (item) => {
723
- const iconName = optionalString(item.iconName);
724
- const id = optionalString(item.id);
725
- const status = optionalString(item.status);
726
- const title = optionalString(item.title);
727
- return {
728
- backend: "status-notifier",
729
- ...iconName === void 0 ? {} : { iconName },
730
- ...id === void 0 ? {} : { id },
731
- ...status === void 0 ? {} : { status },
732
- ...title === void 0 ? {} : { title }
733
- };
734
- };
735
- const sameTrayItem = (first, second) => first.busName === second.busName && first.objectPath === second.objectPath;
736
- const staleTrayItemError = () => native.createGtkStaleElementError("Tray item is no longer registered.");
737
- const resolveCurrentInfo = (handle) => {
738
- const item = native.nativeTrayItems(handle.processId).find(
739
- (candidate) => sameTrayItem(handle, candidate)
740
- );
741
- if (item === void 0) {
742
- throw staleTrayItemError();
743
- }
744
- return item;
745
- };
746
- const isClickableElement = (element) => {
747
- switch (element.kind) {
748
- case "button":
749
- case "checkbox":
750
- case "switch":
751
- case "radio":
752
- case "toggleButton":
753
- case "comboBox":
754
- case "listItem":
755
- case "menuItem":
756
- return true;
757
- default:
758
- return false;
759
- }
760
- };
761
- const nativeTrayItemMatchesSelector = (item, selector) => {
762
- if ("id" in selector) {
763
- return item.id === selector.id;
764
- }
765
- if ("title" in selector) {
766
- return item.title === selector.title;
767
- }
768
- if ("busName" in selector) {
769
- return item.busName === selector.busName && (selector.objectPath === void 0 || item.objectPath === selector.objectPath);
770
- }
771
- return false;
772
- };
773
- const createGtkTrayItem = (processId, item) => {
774
- const handle = {
775
- busName: item.busName,
776
- objectPath: item.objectPath,
777
- processId
778
- };
779
- const trayItem = {
780
- metadata: async () => toMetadata(resolveCurrentInfo(handle)),
781
- element: async () => {
782
- const current = resolveCurrentInfo(handle);
783
- const elementHandle = native.nativeFindAnyById(current.accessibleId);
784
- return elementHandle === void 0 ? void 0 : createGtkElement(elementHandle);
785
- },
786
- capture: async () => {
787
- const element = await trayItem.element();
788
- if (element === void 0) {
789
- throw native.createGtkElementNotFoundError(
790
- "Tray item is registered but not visible."
791
- );
792
- }
793
- return element.capture();
794
- },
795
- click: async () => {
796
- const element = await trayItem.element();
797
- if (element === void 0) {
798
- throw native.createGtkElementNotFoundError(
799
- "Tray item is registered but not visible."
800
- );
801
- }
802
- if (!isClickableElement(element)) {
803
- throw native.createGtkUnsupportedInterfaceError(
804
- `Tray item element does not support click: ${element.kind}.`
805
- );
806
- }
807
- await element.click();
808
- },
809
- openMenu: async () => {
810
- resolveCurrentInfo(handle);
811
- return void 0;
812
- }
813
- };
814
- return trayItem;
815
- };
816
- const appendOutput = (lines, chunk) => {
817
- lines.push(chunk.toString("utf8"));
818
- if (lines.length > 40) {
819
- lines.splice(0, lines.length - 40);
820
- }
821
- };
822
- const formatProcessOutput = (state) => {
823
- const stdout = state.stdout.join("").trim();
824
- const stderr = state.stderr.join("").trim();
825
- if (stdout.length === 0 && stderr.length === 0) {
826
- return "";
827
- }
828
- return `
829
- stdout:
830
- ${stdout}
831
- stderr:
832
- ${stderr}`;
833
- };
834
- const assertProcessRunning = (state, command) => {
835
- if (state.exitCode !== null || state.exitSignal !== null) {
836
- throw native.createGtkAppExitedError(
837
- `GTK application exited before the operation completed: ${command} (code=${String(state.exitCode)}, signal=${String(state.exitSignal)})` + formatProcessOutput(state)
838
- );
839
- }
840
- const processId = state.process.pid;
841
- if (processId === void 0) {
842
- throw native.createGtkAppExitedError(
843
- `GTK application did not expose a process id: ${command}`
844
- );
845
- }
846
- return processId;
847
- };
848
- const assertNonNegativeIndex = (name, index) => {
849
- if (!Number.isInteger(index) || index < 0) {
850
- throw native.createGtkInvalidArgumentError(
851
- `${name} must be a non-negative integer.`
852
- );
853
- }
854
- };
855
- const parseElementPath = (path) => {
856
- const segments = path.split(/[.:;,]/u);
857
- const id = segments[0];
858
- if (id === void 0 || id.length === 0) {
859
- throw native.createGtkInvalidArgumentError(
860
- "path must start with an accessible id."
861
- );
862
- }
863
- const childIndexes = [];
864
- for (let index = 1; index < segments.length; index += 1) {
865
- const segment = segments[index];
866
- if (segment === void 0 || !/^\d+$/u.test(segment)) {
867
- throw native.createGtkInvalidArgumentError(
868
- "path child indexes must be non-negative decimal integers."
869
- );
870
- }
871
- const childIndex = Number(segment);
872
- if (!Number.isSafeInteger(childIndex)) {
873
- throw native.createGtkInvalidArgumentError(
874
- "path child indexes must be safe non-negative integers."
875
- );
876
- }
877
- childIndexes.push(childIndex);
878
- }
879
- return { id, childIndexes };
880
- };
881
- const isPathChildContainer = (element) => "childAt" in element;
882
- const waitForAtspiReady = async (state, command, timeoutMs, startedAt) => {
883
- if (state.atspiReady) {
884
- return assertProcessRunning(state, command);
885
- }
886
- while (Date.now() - startedAt <= timeoutMs) {
887
- const processId = assertProcessRunning(state, command);
888
- state.atspiReadiness = native.nativeProcessAtspiReadiness(processId);
889
- if (state.atspiReadiness === "ready") {
890
- state.atspiReady = true;
891
- return processId;
892
- }
893
- await delay(50);
894
- }
895
- assertProcessRunning(state, command);
896
- throw native.createGtkOperationFailedError(
897
- `AT-SPI did not become ready for GTK application: ${command} (last readiness: ${state.atspiReadiness})` + formatProcessOutput(state)
898
- );
899
- };
900
- const createGtkAppEnvironment = (baseEnv, overrides) => {
901
- const env = {
902
- ...baseEnv,
903
- GDK_BACKEND: baseEnv.GDK_BACKEND ?? "x11",
904
- GSETTINGS_BACKEND: baseEnv.GSETTINGS_BACKEND ?? "memory",
905
- GTK_THEME: baseEnv.GTK_THEME ?? "Adwaita",
906
- ...overrides
907
- };
908
- delete env.NO_AT_BRIDGE;
909
- return env;
910
- };
911
- const launchGtkApp = (appPath, args, options) => {
912
- const _args = args ?? [];
913
- const _timeoutMs = options?.timeoutMs ?? 1e4;
914
- const child = node_child_process.spawn(appPath, [..._args], {
915
- env: createGtkAppEnvironment(process.env, options?.env),
916
- stdio: "pipe"
917
- });
918
- const state = {
919
- atspiReadiness: "missing-bus-name",
920
- atspiReady: false,
921
- exitCode: null,
922
- exitSignal: null,
923
- process: child,
924
- stderr: [],
925
- stdout: []
926
- };
927
- child.stdout.on("data", (chunk) => {
928
- appendOutput(state.stdout, chunk);
929
- });
930
- child.stderr.on("data", (chunk) => {
931
- appendOutput(state.stderr, chunk);
932
- });
933
- child.on("exit", (code, signal) => {
934
- state.exitCode = code;
935
- state.exitSignal = signal;
936
- });
937
- const release = async () => {
938
- if (state.exitCode !== null || state.exitSignal !== null) {
939
- return;
940
- }
941
- child.kill("SIGTERM");
942
- const startedAt = Date.now();
943
- while (state.exitCode === null && state.exitSignal === null) {
944
- if (Date.now() - startedAt > 2e3) {
945
- child.kill("SIGKILL");
946
- break;
947
- }
948
- await delay(25);
949
- }
950
- };
951
- const findById = async (id) => {
952
- const startedAt = Date.now();
953
- await waitForAtspiReady(state, appPath, _timeoutMs, startedAt);
954
- while (Date.now() - startedAt <= _timeoutMs) {
955
- const processId = assertProcessRunning(state, appPath);
956
- try {
957
- const handle = native.nativeFindById(processId, id);
958
- if (handle !== void 0) {
959
- return createGtkElement(handle);
960
- }
961
- } catch (error) {
962
- throw native.normalizeNativeError(error);
963
- }
964
- await delay(50);
965
- }
966
- assertProcessRunning(state, appPath);
967
- return void 0;
968
- };
969
- const getById = async (id) => {
970
- const element = await findById(id);
971
- if (element === void 0) {
972
- throw native.createGtkElementNotFoundError(`Accessible id was not found: ${id}`);
973
- }
974
- return element;
975
- };
976
- const findByPath = async (path) => {
977
- const parsedPath = parseElementPath(path);
978
- const startedAt = Date.now();
979
- await waitForAtspiReady(state, appPath, _timeoutMs, startedAt);
980
- while (Date.now() - startedAt <= _timeoutMs) {
981
- const processId = assertProcessRunning(state, appPath);
982
- try {
983
- const handle = native.nativeFindById(processId, parsedPath.id);
984
- if (handle !== void 0) {
985
- let element = createGtkElement(handle);
986
- let resolved = true;
987
- for (const childIndex of parsedPath.childIndexes) {
988
- if (!isPathChildContainer(element)) {
989
- resolved = false;
990
- break;
991
- }
992
- const child2 = await element.childAt(childIndex);
993
- if (child2 === void 0) {
994
- resolved = false;
995
- break;
996
- }
997
- element = child2;
998
- }
999
- if (resolved) {
1000
- return element;
1001
- }
1002
- }
1003
- } catch (error) {
1004
- throw native.normalizeNativeError(error);
1005
- }
1006
- await delay(50);
1007
- }
1008
- assertProcessRunning(state, appPath);
1009
- return void 0;
1010
- };
1011
- const getByPath = async (path) => {
1012
- const element = await findByPath(path);
1013
- if (element === void 0) {
1014
- throw native.createGtkElementNotFoundError(
1015
- `Element path was not found: ${path}`
1016
- );
1017
- }
1018
- return element;
1019
- };
1020
- const findTrayItem = async (selector) => {
1021
- const startedAt = Date.now();
1022
- while (Date.now() - startedAt <= _timeoutMs) {
1023
- const processId = assertProcessRunning(state, appPath);
1024
- try {
1025
- const item = native.nativeTrayItems(processId).find(
1026
- (candidate) => nativeTrayItemMatchesSelector(candidate, selector)
1027
- );
1028
- if (item !== void 0) {
1029
- return createGtkTrayItem(processId, item);
1030
- }
1031
- } catch (error) {
1032
- const normalizedError = native.normalizeNativeError(error);
1033
- if (normalizedError.code === "OPERATION_FAILED" && normalizedError.message.includes("Timeout was reached")) {
1034
- await delay(50);
1035
- continue;
1036
- }
1037
- throw normalizedError;
1038
- }
1039
- await delay(50);
1040
- }
1041
- assertProcessRunning(state, appPath);
1042
- return void 0;
1043
- };
1044
- const getTrayItem = async (selector) => {
1045
- const trayItem = await findTrayItem(selector);
1046
- if (trayItem === void 0) {
1047
- throw native.createGtkElementNotFoundError(
1048
- `StatusNotifier tray item was not found: ${JSON.stringify(selector)}`
1049
- );
1050
- }
1051
- return trayItem;
1052
- };
1053
- const app = {
1054
- capture: async () => {
1055
- assertProcessRunning(state, appPath);
1056
- try {
1057
- return native.nativeCaptureScreen();
1058
- } catch (error) {
1059
- throw native.normalizeNativeError(error);
1060
- }
1061
- },
1062
- findById,
1063
- findByPath,
1064
- getById,
1065
- getByPath,
1066
- windowAt: async (index) => {
1067
- assertNonNegativeIndex("index", index);
1068
- const processId = await waitForAtspiReady(
1069
- state,
1070
- appPath,
1071
- _timeoutMs,
1072
- Date.now()
1073
- );
1074
- try {
1075
- const handle = native.nativeWindowAt(processId, index);
1076
- return handle === void 0 ? void 0 : createGtkElement(handle);
1077
- } catch (error) {
1078
- throw native.normalizeNativeError(error);
1079
- }
1080
- },
1081
- getWindowCount: async () => {
1082
- const processId = await waitForAtspiReady(
1083
- state,
1084
- appPath,
1085
- _timeoutMs,
1086
- Date.now()
1087
- );
1088
- try {
1089
- return native.nativeWindowCount(processId);
1090
- } catch (error) {
1091
- throw native.normalizeNativeError(error);
1092
- }
1093
- },
1094
- findTrayItem,
1095
- getTrayItem,
1096
- trayItemAt: async (index) => {
1097
- assertNonNegativeIndex("index", index);
1098
- const processId = assertProcessRunning(state, appPath);
1099
- try {
1100
- const item = native.nativeTrayItems(processId)[index];
1101
- return item === void 0 ? void 0 : createGtkTrayItem(processId, item);
1102
- } catch (error) {
1103
- throw native.normalizeNativeError(error);
1104
- }
1105
- },
1106
- getTrayItemCount: async () => {
1107
- const processId = assertProcessRunning(state, appPath);
1108
- try {
1109
- return native.nativeTrayItems(processId).length;
1110
- } catch (error) {
1111
- throw native.normalizeNativeError(error);
1112
- }
1113
- },
1114
- release,
1115
- [Symbol.asyncDispose]: release
1116
- };
1117
- child.on("error", (error) => {
1118
- appendOutput(state.stderr, Buffer.from(error.message));
1119
- });
1120
- return Promise.resolve(app);
1121
- };
1122
- const createGtkAppLauncher = (options) => {
1123
- const launchedApps = [];
1124
- const launch = async (args) => {
1125
- const launchOptions = {
1126
- env: options.env,
1127
- timeoutMs: options.timeoutMs
1128
- };
1129
- const app = await launchGtkApp(
1130
- options.appPath,
1131
- [...options.args ?? [], ...args ?? []],
1132
- launchOptions
1133
- );
1134
- launchedApps.push(app);
1135
- return app;
1136
- };
1137
- const release = async () => {
1138
- const apps = launchedApps.splice(0);
1139
- await Promise.all(apps.map((app) => app.release()));
1140
- };
1141
- return {
1142
- launch,
1143
- release,
1144
- [Symbol.asyncDispose]: release
1145
- };
1146
- };
1147
- exports.createGtkAppEnvironment = createGtkAppEnvironment;
1148
- exports.createGtkAppLauncher = createGtkAppLauncher;
1149
- exports.launchGtkApp = launchGtkApp;
3
+ const launchGtkApp = require("./launchGtkApp-BIO_5Xjn.cjs");
4
+ exports.createGtkAppEnvironment = launchGtkApp.createGtkAppEnvironment;
5
+ exports.createGtkAppLauncher = launchGtkApp.createGtkAppLauncher;
6
+ exports.launchGtkApp = launchGtkApp.launchGtkApp;
1150
7
  //# sourceMappingURL=index.cjs.map