index.js 1.1 KB

1234567891011121314151617181920212223
  1. const path = require("path");
  2. if (process.platform !== "darwin") {
  3. throw new Error("@ant/computer-use-swift is only available on macOS");
  4. }
  5. // COMPUTER_USE_SWIFT_NODE_PATH: escape hatch for bundlers. Bun's --compile
  6. // embeds the .node as an asset, not in a node_modules tree — __dirname is the
  7. // exe dir and ../prebuilds/ doesn't exist. The consuming build bakes this var
  8. // to the embedded asset's path. Unset → normal node_modules layout.
  9. //
  10. // Four methods use `Task { @MainActor in ... }` (captureExcluding,
  11. // captureRegion, apps.listInstalled, resolvePrepareCapture) which enqueue
  12. // onto DispatchQueue.main. Electron drains that queue via CFRunLoop; libuv
  13. // (Node/bun) does not — the promises hang. Consumers running under libuv
  14. // must pump `_drainMainRunLoop` via setInterval while those promises are
  15. // pending. Consumers under Electron don't need to (CFRunLoop drains
  16. // automatically).
  17. const native = require(
  18. process.env.COMPUTER_USE_SWIFT_NODE_PATH ??
  19. path.resolve(__dirname, "../prebuilds/computer_use.node"),
  20. );
  21. module.exports = native.computerUse;