| 1 | import { |
| 2 | readAccessibleWindowContextWithApp, |
| 3 | type SnapShotAccessibilityRequest, |
| 4 | } from "./SnapShotAccessibility.ts"; |
| 5 | |
| 6 | process.once("disconnect", () => process.exit(0)); |
| 7 | |
| 8 | async function readAccessibility() { |
| 9 | const { App } = await import("@crowecawcaw/xa11y"); |
| 10 | process.send?.("ready"); |
| 11 | const request = await new Promise<SnapShotAccessibilityRequest>((resolve) => { |
| 12 | process.once("message", resolve); |
| 13 | }); |
| 14 | let started = false; |
| 15 | const markStarted = () => { |
| 16 | if (started) return; |
| 17 | started = true; |
| 18 | process.send?.("started"); |
| 19 | }; |
| 20 | const context = await readAccessibleWindowContextWithApp(App, request, markStarted).catch( |
| 21 | () => undefined, |
| 22 | ); |
| 23 | markStarted(); |
| 24 | process.send?.({ type: "result", context }); |
| 25 | } |
| 26 | |
| 27 | if (process.argv[2] === "read") { |
| 28 | void readAccessibility().catch(() => process.send?.({ type: "result" })); |
| 29 | } |