@mcesystems/apple-kit 1.0.23 → 1.0.25

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 (116) hide show
  1. package/README.md +284 -250
  2. package/dist/index.js +304 -174
  3. package/dist/index.js.map +4 -4
  4. package/dist/index.mjs +303 -173
  5. package/dist/index.mjs.map +4 -4
  6. package/dist/resources/bin/darwin/idevice_id +0 -0
  7. package/dist/resources/bin/darwin/idevicedebug +0 -0
  8. package/dist/resources/bin/darwin/idevicediagnostics +0 -0
  9. package/dist/resources/bin/darwin/ideviceinfo +0 -0
  10. package/dist/resources/bin/darwin/ideviceinstaller +0 -0
  11. package/dist/resources/bin/darwin/idevicename +0 -0
  12. package/dist/resources/bin/darwin/idevicepair +0 -0
  13. package/dist/resources/bin/darwin/idevicescreenshot +0 -0
  14. package/dist/resources/bin/darwin/idevicesyslog +0 -0
  15. package/dist/resources/bin/darwin/iproxy +0 -0
  16. package/dist/resources/bin/darwin/libcrypto.3.dylib +0 -0
  17. package/dist/resources/bin/darwin/libimobiledevice-1.0.6.dylib +0 -0
  18. package/dist/resources/bin/darwin/libimobiledevice-glue-1.0.0.dylib +0 -0
  19. package/dist/resources/bin/darwin/liblzma.5.dylib +0 -0
  20. package/dist/resources/bin/darwin/libplist-2.0.4.dylib +0 -0
  21. package/dist/resources/bin/darwin/libssl.3.dylib +0 -0
  22. package/dist/resources/bin/darwin/libusbmuxd-2.0.7.dylib +0 -0
  23. package/dist/resources/bin/darwin/libzip.5.dylib +0 -0
  24. package/dist/resources/bin/darwin/libzstd.1.dylib +0 -0
  25. package/{resources → dist/resources}/licenses/LGPL-2.1.txt +33 -33
  26. package/dist/types/index.d.ts +0 -2
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/logic/actions/device.d.ts.map +1 -1
  29. package/dist/types/logic/actions/proxy.d.ts.map +1 -1
  30. package/dist/types/logic/appleDeviceKit.d.ts +2 -7
  31. package/dist/types/logic/appleDeviceKit.d.ts.map +1 -1
  32. package/package.json +7 -4
  33. package/scripts/README.md +209 -0
  34. package/scripts/build-windows.sh.template +134 -0
  35. package/scripts/export-resources.ts +444 -0
  36. package/dist/types/utils/portManager.d.ts +0 -68
  37. package/dist/types/utils/portManager.d.ts.map +0 -1
  38. package/resources/bin/windows/bz2.dll +0 -0
  39. package/resources/bin/windows/getopt.dll +0 -0
  40. package/resources/bin/windows/iconv-2.dll +0 -0
  41. package/resources/bin/windows/idevice_id.exe +0 -0
  42. package/resources/bin/windows/ideviceactivation.exe +0 -0
  43. package/resources/bin/windows/idevicedebug.exe +0 -0
  44. package/resources/bin/windows/ideviceinfo.exe +0 -0
  45. package/resources/bin/windows/ideviceinstaller.exe +0 -0
  46. package/resources/bin/windows/idevicepair.exe +0 -0
  47. package/resources/bin/windows/imobiledevice.dll +0 -0
  48. package/resources/bin/windows/iproxy.exe +0 -0
  49. package/resources/bin/windows/libcrypto-1_1-x64.dll +0 -0
  50. package/resources/bin/windows/libcurl.dll +0 -0
  51. package/resources/bin/windows/libideviceactivation-1.0.dll +0 -0
  52. package/resources/bin/windows/libimobiledevice-1.0.dll +0 -0
  53. package/resources/bin/windows/libimobiledevice-glue-1.0.dll +0 -0
  54. package/resources/bin/windows/libplist-2.0.dll +0 -0
  55. package/resources/bin/windows/libssl-1_1-x64.dll +0 -0
  56. package/resources/bin/windows/libusb-1.0.dll +0 -0
  57. package/resources/bin/windows/libusb0.dll +0 -0
  58. package/resources/bin/windows/libusbmuxd-2.0.dll +0 -0
  59. package/resources/bin/windows/libxml2.dll +0 -0
  60. package/resources/bin/windows/lzma.dll +0 -0
  61. package/resources/bin/windows/pcre.dll +0 -0
  62. package/resources/bin/windows/pcreposix.dll +0 -0
  63. package/resources/bin/windows/plist.dll +0 -0
  64. package/resources/bin/windows/pthreadVC3.dll +0 -0
  65. package/resources/bin/windows/readline.dll +0 -0
  66. package/resources/bin/windows/usbmuxd.dll +0 -0
  67. package/resources/bin/windows/usbmuxd.exe +0 -0
  68. package/resources/bin/windows/vcruntime140.dll +0 -0
  69. package/resources/bin/windows/zip.dll +0 -0
  70. package/resources/bin/windows/zlib1.dll +0 -0
  71. package/resources/lib/include/libimobiledevice/afc.h +0 -413
  72. package/resources/lib/include/libimobiledevice/bt_packet_logger.h +0 -156
  73. package/resources/lib/include/libimobiledevice/companion_proxy.h +0 -212
  74. package/resources/lib/include/libimobiledevice/debugserver.h +0 -272
  75. package/resources/lib/include/libimobiledevice/diagnostics_relay.h +0 -228
  76. package/resources/lib/include/libimobiledevice/file_relay.h +0 -166
  77. package/resources/lib/include/libimobiledevice/heartbeat.h +0 -137
  78. package/resources/lib/include/libimobiledevice/house_arrest.h +0 -180
  79. package/resources/lib/include/libimobiledevice/installation_proxy.h +0 -505
  80. package/resources/lib/include/libimobiledevice/libimobiledevice.h +0 -444
  81. package/resources/lib/include/libimobiledevice/lockdown.h +0 -577
  82. package/resources/lib/include/libimobiledevice/misagent.h +0 -168
  83. package/resources/lib/include/libimobiledevice/mobile_image_mounter.h +0 -275
  84. package/resources/lib/include/libimobiledevice/mobileactivation.h +0 -192
  85. package/resources/lib/include/libimobiledevice/mobilebackup.h +0 -246
  86. package/resources/lib/include/libimobiledevice/mobilebackup2.h +0 -214
  87. package/resources/lib/include/libimobiledevice/mobilesync.h +0 -359
  88. package/resources/lib/include/libimobiledevice/notification_proxy.h +0 -202
  89. package/resources/lib/include/libimobiledevice/ostrace.h +0 -198
  90. package/resources/lib/include/libimobiledevice/preboard.h +0 -187
  91. package/resources/lib/include/libimobiledevice/property_list_service.h +0 -184
  92. package/resources/lib/include/libimobiledevice/restore.h +0 -179
  93. package/resources/lib/include/libimobiledevice/reverse_proxy.h +0 -213
  94. package/resources/lib/include/libimobiledevice/sbservices.h +0 -175
  95. package/resources/lib/include/libimobiledevice/screenshotr.h +0 -118
  96. package/resources/lib/include/libimobiledevice/service.h +0 -202
  97. package/resources/lib/include/libimobiledevice/syslog_relay.h +0 -184
  98. package/resources/lib/include/libimobiledevice/webinspector.h +0 -137
  99. package/resources/lib/include/plist/Array.h +0 -80
  100. package/resources/lib/include/plist/Boolean.h +0 -48
  101. package/resources/lib/include/plist/Data.h +0 -50
  102. package/resources/lib/include/plist/Date.h +0 -54
  103. package/resources/lib/include/plist/Dictionary.h +0 -73
  104. package/resources/lib/include/plist/Integer.h +0 -54
  105. package/resources/lib/include/plist/Key.h +0 -49
  106. package/resources/lib/include/plist/Node.h +0 -57
  107. package/resources/lib/include/plist/Real.h +0 -48
  108. package/resources/lib/include/plist/String.h +0 -52
  109. package/resources/lib/include/plist/Structure.h +0 -62
  110. package/resources/lib/include/plist/Uid.h +0 -48
  111. package/resources/lib/include/plist/plist++.h +0 -39
  112. package/resources/lib/include/plist/plist.h +0 -1448
  113. package/resources/lib/libimobiledevice-1.0.dll +0 -0
  114. package/resources/lib/libimobiledevice-1.0.dll.a +0 -0
  115. package/resources/lib/libplist-2.0.dll +0 -0
  116. package/resources/lib/libplist-2.0.dll.a +0 -0
package/dist/index.mjs CHANGED
@@ -510,7 +510,7 @@ var require_has_flag = __commonJS({
510
510
  var require_supports_color = __commonJS({
511
511
  "../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js"(exports, module) {
512
512
  "use strict";
513
- var os = __require("os");
513
+ var os2 = __require("os");
514
514
  var tty = __require("tty");
515
515
  var hasFlag = require_has_flag();
516
516
  var { env } = process;
@@ -558,7 +558,7 @@ var require_supports_color = __commonJS({
558
558
  return min;
559
559
  }
560
560
  if (process.platform === "win32") {
561
- const osRelease = os.release().split(".");
561
+ const osRelease = os2.release().split(".");
562
562
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
563
563
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
564
564
  }
@@ -793,151 +793,158 @@ var require_src = __commonJS({
793
793
  }
794
794
  });
795
795
 
796
- // src/utils/debug.ts
797
- var import_debug = __toESM(require_src());
798
- var debug = (0, import_debug.default)("apple-kit");
799
- var debugTask = (0, import_debug.default)("apple-kit:task");
800
- var debugWarning = (0, import_debug.default)("apple-kit:warning");
801
- var debugError = (0, import_debug.default)("apple-kit:error");
802
- function logInfo(message) {
803
- debug(message);
804
- }
805
- function logTask(message) {
806
- debugTask(message);
807
- }
808
-
809
- // src/utils/portManager.ts
810
- import { createServer } from "node:net";
811
- var PortManager = class {
812
- allocations = /* @__PURE__ */ new Map();
813
- basePort;
814
- maxPortRange;
815
- /**
816
- * Create a new PortManager
817
- *
818
- * @param basePort Starting port number for allocation (default: 30000)
819
- * @param maxPortRange Maximum range of ports to search (default: 1000)
820
- */
821
- constructor(basePort = 3e4, maxPortRange = 1e3) {
822
- this.basePort = basePort;
823
- this.maxPortRange = maxPortRange;
796
+ // ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
797
+ import net from "node:net";
798
+ import os from "node:os";
799
+ var Locked = class extends Error {
800
+ constructor(port) {
801
+ super(`${port} is locked`);
824
802
  }
825
- /**
826
- * Find an available port starting from the given port number
827
- */
828
- async findAvailablePort(startPort) {
829
- const maxPort = this.basePort + this.maxPortRange;
830
- for (let port = startPort; port < maxPort; port++) {
831
- const isAllocated = Array.from(this.allocations.values()).some(
832
- (a) => a.localPort === port
833
- );
834
- if (isAllocated) {
835
- continue;
836
- }
837
- const isAvailable = await this.isPortAvailable(port);
838
- if (isAvailable) {
839
- return port;
840
- }
803
+ };
804
+ var lockedPorts = {
805
+ old: /* @__PURE__ */ new Set(),
806
+ young: /* @__PURE__ */ new Set()
807
+ };
808
+ var releaseOldLockedPortsIntervalMs = 1e3 * 15;
809
+ var minPort = 1024;
810
+ var maxPort = 65535;
811
+ var timeout;
812
+ var getLocalHosts = () => {
813
+ const interfaces = os.networkInterfaces();
814
+ const results = /* @__PURE__ */ new Set([void 0, "0.0.0.0"]);
815
+ for (const _interface of Object.values(interfaces)) {
816
+ for (const config of _interface) {
817
+ results.add(config.address);
841
818
  }
842
- throw new Error(
843
- `No available ports found in range ${startPort}-${maxPort}`
844
- );
845
819
  }
846
- /**
847
- * Check if a port is available for binding
848
- */
849
- isPortAvailable(port) {
850
- return new Promise((resolve) => {
851
- const server = createServer();
852
- server.once("error", () => {
853
- resolve(false);
854
- });
855
- server.once("listening", () => {
856
- server.close(() => {
857
- resolve(true);
858
- });
859
- });
860
- server.listen(port, "127.0.0.1");
820
+ return results;
821
+ };
822
+ var checkAvailablePort = (options) => new Promise((resolve, reject) => {
823
+ const server = net.createServer();
824
+ server.unref();
825
+ server.on("error", reject);
826
+ server.listen(options, () => {
827
+ const { port } = server.address();
828
+ server.close(() => {
829
+ resolve(port);
861
830
  });
831
+ });
832
+ });
833
+ var getAvailablePort = async (options, hosts) => {
834
+ if (options.host || options.port === 0) {
835
+ return checkAvailablePort(options);
862
836
  }
863
- /**
864
- * Allocate a local port for a logical port
865
- *
866
- * @param logicalPort The logical port number (USB hub position)
867
- * @param devicePort The device port to forward to
868
- * @returns The allocated port info
869
- */
870
- async allocate(logicalPort, devicePort) {
871
- const existing = this.allocations.get(logicalPort);
872
- if (existing) {
873
- logTask(`Reusing existing port allocation for logical port ${logicalPort}: ${existing.localPort}`);
874
- return existing;
837
+ for (const host of hosts) {
838
+ try {
839
+ await checkAvailablePort({ port: options.port, host });
840
+ } catch (error) {
841
+ if (!["EADDRNOTAVAIL", "EINVAL"].includes(error.code)) {
842
+ throw error;
843
+ }
875
844
  }
876
- const preferredPort = this.basePort + logicalPort;
877
- let localPort;
878
- const preferredAvailable = await this.isPortAvailable(preferredPort);
879
- if (preferredAvailable) {
880
- localPort = preferredPort;
881
- } else {
882
- localPort = await this.findAvailablePort(this.basePort);
845
+ }
846
+ return options.port;
847
+ };
848
+ var portCheckSequence = function* (ports) {
849
+ if (ports) {
850
+ yield* ports;
851
+ }
852
+ yield 0;
853
+ };
854
+ async function getPorts(options) {
855
+ let ports;
856
+ let exclude = /* @__PURE__ */ new Set();
857
+ if (options) {
858
+ if (options.port) {
859
+ ports = typeof options.port === "number" ? [options.port] : options.port;
860
+ }
861
+ if (options.exclude) {
862
+ const excludeIterable = options.exclude;
863
+ if (typeof excludeIterable[Symbol.iterator] !== "function") {
864
+ throw new TypeError("The `exclude` option must be an iterable.");
865
+ }
866
+ for (const element of excludeIterable) {
867
+ if (typeof element !== "number") {
868
+ throw new TypeError("Each item in the `exclude` option must be a number corresponding to the port you want excluded.");
869
+ }
870
+ if (!Number.isSafeInteger(element)) {
871
+ throw new TypeError(`Number ${element} in the exclude option is not a safe integer and can't be used`);
872
+ }
873
+ }
874
+ exclude = new Set(excludeIterable);
883
875
  }
884
- const allocation = {
885
- logicalPort,
886
- localPort,
887
- devicePort
888
- };
889
- this.allocations.set(logicalPort, allocation);
890
- logTask(`Allocated port ${localPort} for logical port ${logicalPort} -> device port ${devicePort}`);
891
- return allocation;
892
876
  }
893
- /**
894
- * Release the port allocation for a logical port
895
- */
896
- release(logicalPort) {
897
- const allocation = this.allocations.get(logicalPort);
898
- if (allocation) {
899
- logTask(`Released port ${allocation.localPort} for logical port ${logicalPort}`);
900
- this.allocations.delete(logicalPort);
877
+ if (timeout === void 0) {
878
+ timeout = setTimeout(() => {
879
+ timeout = void 0;
880
+ lockedPorts.old = lockedPorts.young;
881
+ lockedPorts.young = /* @__PURE__ */ new Set();
882
+ }, releaseOldLockedPortsIntervalMs);
883
+ if (timeout.unref) {
884
+ timeout.unref();
901
885
  }
902
886
  }
903
- /**
904
- * Get the current allocation for a logical port
905
- */
906
- getAllocation(logicalPort) {
907
- return this.allocations.get(logicalPort);
887
+ const hosts = getLocalHosts();
888
+ for (const port of portCheckSequence(ports)) {
889
+ try {
890
+ if (exclude.has(port)) {
891
+ continue;
892
+ }
893
+ let availablePort = await getAvailablePort({ ...options, port }, hosts);
894
+ while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
895
+ if (port !== 0) {
896
+ throw new Locked(port);
897
+ }
898
+ availablePort = await getAvailablePort({ ...options, port }, hosts);
899
+ }
900
+ lockedPorts.young.add(availablePort);
901
+ return availablePort;
902
+ } catch (error) {
903
+ if (!["EADDRINUSE", "EACCES"].includes(error.code) && !(error instanceof Locked)) {
904
+ throw error;
905
+ }
906
+ }
908
907
  }
909
- /**
910
- * Get all current allocations
911
- */
912
- getAllAllocations() {
913
- return Array.from(this.allocations.values());
908
+ throw new Error("No available ports found");
909
+ }
910
+ function portNumbers(from, to) {
911
+ if (!Number.isInteger(from) || !Number.isInteger(to)) {
912
+ throw new TypeError("`from` and `to` must be integer numbers");
914
913
  }
915
- /**
916
- * Release all allocations
917
- */
918
- releaseAll() {
919
- logTask(`Releasing all port allocations (${this.allocations.size} ports)`);
920
- this.allocations.clear();
914
+ if (from < minPort || from > maxPort) {
915
+ throw new RangeError(`'from' must be between ${minPort} and ${maxPort}`);
921
916
  }
922
- /**
923
- * Check if a logical port has an allocation
924
- */
925
- hasAllocation(logicalPort) {
926
- return this.allocations.has(logicalPort);
917
+ if (to < minPort || to > maxPort) {
918
+ throw new RangeError(`'to' must be between ${minPort} and ${maxPort}`);
927
919
  }
928
- };
929
- var sharedPortManager = null;
930
- function getSharedPortManager() {
931
- if (!sharedPortManager) {
932
- sharedPortManager = new PortManager();
920
+ if (from > to) {
921
+ throw new RangeError("`to` must be greater than or equal to `from`");
933
922
  }
934
- return sharedPortManager;
923
+ const generator = function* (from2, to2) {
924
+ for (let port = from2; port <= to2; port++) {
925
+ yield port;
926
+ }
927
+ };
928
+ return generator(from, to);
929
+ }
930
+
931
+ // src/utils/debug.ts
932
+ var import_debug = __toESM(require_src());
933
+ var debug = (0, import_debug.default)("apple-kit");
934
+ var debugTask = (0, import_debug.default)("apple-kit:task");
935
+ var debugWarning = (0, import_debug.default)("apple-kit:warning");
936
+ var debugError = (0, import_debug.default)("apple-kit:error");
937
+ function logInfo(message) {
938
+ debug(message);
939
+ }
940
+ function logTask(message) {
941
+ debugTask(message);
935
942
  }
936
943
 
937
944
  // src/logic/actions/device.ts
938
945
  import { exec as execCallback } from "node:child_process";
939
946
  import { existsSync } from "node:fs";
940
- import { join } from "node:path";
947
+ import { dirname, join } from "node:path";
941
948
  import { promisify } from "node:util";
942
949
 
943
950
  // src/logic/dataParser.ts
@@ -973,6 +980,13 @@ function parseAppList(output) {
973
980
 
974
981
  // src/logic/actions/device.ts
975
982
  var execAsync = promisify(execCallback);
983
+ function getModuleDir() {
984
+ if (typeof import.meta !== "undefined" && import.meta.url) {
985
+ const { fileURLToPath } = __require("node:url");
986
+ return dirname(fileURLToPath(import.meta.url));
987
+ }
988
+ return __dirname;
989
+ }
976
990
  async function getDeviceInfo(udid) {
977
991
  logTask(`Getting device info for ${udid}`);
978
992
  const result = await runIDeviceTool("ideviceinfo", ["-u", udid]);
@@ -1001,12 +1015,17 @@ async function getDeviceInfo(udid) {
1001
1015
  };
1002
1016
  }
1003
1017
  async function runIDeviceTool(toolName, args = [], options = {}) {
1004
- const command = `"${toolName}${process.platform === "win32" ? ".exe" : ""}" ${args.map((a) => `"${a}"`).join(" ")}`;
1018
+ const binPath = getIDeviceBinPath();
1019
+ const ext = process.platform === "win32" ? ".exe" : "";
1020
+ const toolPath = binPath ? join(binPath, `${toolName}${ext}`) : `${toolName}${ext}`;
1021
+ const command = `"${toolPath}" ${args.map((a) => `"${a}"`).join(" ")}`;
1005
1022
  return execIDevice(command, options);
1006
1023
  }
1007
1024
  async function execIDevice(command, options = {}) {
1008
1025
  const binPath = getIDeviceBinPath();
1009
- options.cwd = binPath;
1026
+ if (binPath) {
1027
+ options.cwd = binPath;
1028
+ }
1010
1029
  const result = await execAsync(command, {
1011
1030
  ...options,
1012
1031
  env: process.env,
@@ -1018,12 +1037,66 @@ async function execIDevice(command, options = {}) {
1018
1037
  stderr: result.stderr.toString()
1019
1038
  };
1020
1039
  }
1040
+ function getPlatformDir() {
1041
+ const platform = process.platform;
1042
+ if (platform === "win32") {
1043
+ return "windows";
1044
+ }
1045
+ if (platform === "darwin") {
1046
+ return "darwin";
1047
+ }
1048
+ if (platform === "linux") {
1049
+ return "linux";
1050
+ }
1051
+ return platform;
1052
+ }
1053
+ function getBundledResourcesPath() {
1054
+ const moduleDir = getModuleDir();
1055
+ let packageRoot;
1056
+ if (moduleDir.includes("dist")) {
1057
+ packageRoot = join(moduleDir, "..", "..");
1058
+ } else {
1059
+ packageRoot = join(moduleDir, "..", "..", "..", "..");
1060
+ }
1061
+ const platformDir = getPlatformDir();
1062
+ const distPath = join(packageRoot, "dist", "resources", "bin", platformDir);
1063
+ if (existsSync(join(distPath, "idevice_id")) || existsSync(join(distPath, "idevice_id.exe"))) {
1064
+ return distPath;
1065
+ }
1066
+ const devPath = join(packageRoot, "resources", "bin", platformDir);
1067
+ if (existsSync(join(devPath, "idevice_id")) || existsSync(join(devPath, "idevice_id.exe"))) {
1068
+ return devPath;
1069
+ }
1070
+ return null;
1071
+ }
1021
1072
  function getResourcesBinPath() {
1022
- const binPath = process.env.IDeviceBinPath;
1023
- if (!binPath) {
1024
- throw new Error("IDeviceBinPath is not set");
1073
+ const envBinPath = process.env.IDeviceBinPath;
1074
+ if (envBinPath) {
1075
+ return envBinPath;
1076
+ }
1077
+ const bundledPath = getBundledResourcesPath();
1078
+ if (bundledPath) {
1079
+ return bundledPath;
1080
+ }
1081
+ if (process.platform === "darwin") {
1082
+ const homebrewArmPath = "/opt/homebrew/bin";
1083
+ if (existsSync(join(homebrewArmPath, "idevice_id"))) {
1084
+ return homebrewArmPath;
1085
+ }
1086
+ const homebrewIntelPath = "/usr/local/bin";
1087
+ if (existsSync(join(homebrewIntelPath, "idevice_id"))) {
1088
+ return homebrewIntelPath;
1089
+ }
1025
1090
  }
1026
- return binPath;
1091
+ if (process.platform === "linux") {
1092
+ const linuxPaths = ["/usr/bin", "/usr/local/bin"];
1093
+ for (const linuxPath of linuxPaths) {
1094
+ if (existsSync(join(linuxPath, "idevice_id"))) {
1095
+ return linuxPath;
1096
+ }
1097
+ }
1098
+ }
1099
+ return "";
1027
1100
  }
1028
1101
  function getIDeviceBinPath() {
1029
1102
  return getResourcesBinPath();
@@ -1080,7 +1153,7 @@ async function isPaired(udid) {
1080
1153
  return false;
1081
1154
  }
1082
1155
  }
1083
- async function trustDevice(udid, timeout = 6e4, onWaitingForTrust) {
1156
+ async function trustDevice(udid, timeout2 = 6e4, onWaitingForTrust) {
1084
1157
  logTask(`Trusting device ${udid}`);
1085
1158
  if (await isPaired(udid)) {
1086
1159
  logInfo(`Device ${udid} is already trusted`);
@@ -1095,7 +1168,7 @@ async function trustDevice(udid, timeout = 6e4, onWaitingForTrust) {
1095
1168
  logInfo("Please accept the trust dialog on the device...");
1096
1169
  onWaitingForTrust?.();
1097
1170
  try {
1098
- await waitForPairing(udid, timeout, 1e3);
1171
+ await waitForPairing(udid, timeout2, 1e3);
1099
1172
  logInfo(`Device ${udid} is now trusted`);
1100
1173
  return true;
1101
1174
  } catch {
@@ -1103,17 +1176,17 @@ async function trustDevice(udid, timeout = 6e4, onWaitingForTrust) {
1103
1176
  return false;
1104
1177
  }
1105
1178
  }
1106
- async function waitForPairing(udid, timeout = 12e4, pollInterval = 1e3) {
1179
+ async function waitForPairing(udid, timeout2 = 12e4, pollInterval = 1e3) {
1107
1180
  logTask(`Waiting for pairing on device ${udid}`);
1108
1181
  const startTime = Date.now();
1109
- while (Date.now() - startTime < timeout) {
1182
+ while (Date.now() - startTime < timeout2) {
1110
1183
  if (await isPaired(udid)) {
1111
1184
  logInfo(`Device ${udid} is now paired`);
1112
1185
  return true;
1113
1186
  }
1114
1187
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
1115
1188
  }
1116
- throw new Error(`Timeout waiting for device pairing after ${timeout}ms`);
1189
+ throw new Error(`Timeout waiting for device pairing after ${timeout2}ms`);
1117
1190
  }
1118
1191
  async function pair(udid) {
1119
1192
  logTask(`Initiating pairing for device ${udid}`);
@@ -1332,27 +1405,93 @@ async function launchAppWithPymobiledevice3(bundleId, args, udid) {
1332
1405
 
1333
1406
  // src/logic/actions/proxy.ts
1334
1407
  import { spawn } from "node:child_process";
1335
- import { join as join2 } from "node:path";
1408
+ import { existsSync as existsSync2 } from "node:fs";
1409
+ import { dirname as dirname2, join as join2 } from "node:path";
1410
+ function getModuleDir2() {
1411
+ if (typeof import.meta !== "undefined" && import.meta.url) {
1412
+ const { fileURLToPath } = __require("node:url");
1413
+ return dirname2(fileURLToPath(import.meta.url));
1414
+ }
1415
+ return __dirname;
1416
+ }
1417
+ function getPlatformDir2() {
1418
+ const platform = process.platform;
1419
+ if (platform === "win32") {
1420
+ return "windows";
1421
+ }
1422
+ if (platform === "darwin") {
1423
+ return "darwin";
1424
+ }
1425
+ if (platform === "linux") {
1426
+ return "linux";
1427
+ }
1428
+ return platform;
1429
+ }
1430
+ function getBundledResourcesPath2() {
1431
+ const moduleDir = getModuleDir2();
1432
+ let packageRoot;
1433
+ if (moduleDir.includes("dist")) {
1434
+ packageRoot = join2(moduleDir, "..", "..");
1435
+ } else {
1436
+ packageRoot = join2(moduleDir, "..", "..", "..", "..");
1437
+ }
1438
+ const platformDir = getPlatformDir2();
1439
+ const distPath = join2(packageRoot, "dist", "resources", "bin", platformDir);
1440
+ if (existsSync2(join2(distPath, "iproxy")) || existsSync2(join2(distPath, "iproxy.exe"))) {
1441
+ return distPath;
1442
+ }
1443
+ const devPath = join2(packageRoot, "resources", "bin", platformDir);
1444
+ if (existsSync2(join2(devPath, "iproxy")) || existsSync2(join2(devPath, "iproxy.exe"))) {
1445
+ return devPath;
1446
+ }
1447
+ return null;
1448
+ }
1336
1449
  function getResourcesBinPath2() {
1337
- const binPath = process.env.IDeviceBinPath;
1338
- if (!binPath) {
1339
- throw new Error("IDeviceBinPath is not set");
1450
+ const envBinPath = process.env.IDeviceBinPath;
1451
+ if (envBinPath) {
1452
+ return envBinPath;
1453
+ }
1454
+ const bundledPath = getBundledResourcesPath2();
1455
+ if (bundledPath) {
1456
+ return bundledPath;
1457
+ }
1458
+ if (process.platform === "darwin") {
1459
+ const homebrewArmPath = "/opt/homebrew/bin";
1460
+ if (existsSync2(join2(homebrewArmPath, "iproxy"))) {
1461
+ return homebrewArmPath;
1462
+ }
1463
+ const homebrewIntelPath = "/usr/local/bin";
1464
+ if (existsSync2(join2(homebrewIntelPath, "iproxy"))) {
1465
+ return homebrewIntelPath;
1466
+ }
1340
1467
  }
1341
- return binPath;
1468
+ if (process.platform === "linux") {
1469
+ const linuxPaths = ["/usr/bin", "/usr/local/bin"];
1470
+ for (const linuxPath of linuxPaths) {
1471
+ if (existsSync2(join2(linuxPath, "iproxy"))) {
1472
+ return linuxPath;
1473
+ }
1474
+ }
1475
+ }
1476
+ return "";
1342
1477
  }
1343
1478
  function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
1344
1479
  return new Promise((resolve, reject) => {
1345
1480
  logTask(`Starting port forward ${localPort} -> ${devicePort} for device ${udid}`);
1346
1481
  const binPath = getResourcesBinPath2();
1347
- const toolPath = join2(binPath, `iproxy${process.platform === "win32" ? ".exe" : ""}`);
1482
+ const ext = process.platform === "win32" ? ".exe" : "";
1483
+ const toolPath = binPath ? join2(binPath, `iproxy${ext}`) : `iproxy${ext}`;
1484
+ const spawnOptions = {
1485
+ windowsHide: true,
1486
+ stdio: ["ignore", "pipe", "pipe"]
1487
+ };
1488
+ if (binPath) {
1489
+ spawnOptions.cwd = binPath;
1490
+ }
1348
1491
  const child = spawn(
1349
1492
  toolPath,
1350
1493
  [localPort.toString(), devicePort.toString(), "-u", udid],
1351
- {
1352
- cwd: binPath,
1353
- windowsHide: true,
1354
- stdio: ["ignore", "pipe", "pipe"]
1355
- }
1494
+ spawnOptions
1356
1495
  );
1357
1496
  let hasResolved = false;
1358
1497
  let stderrOutput = "";
@@ -1406,11 +1545,13 @@ var AppleDeviceKit = class {
1406
1545
  constructor(udid, logicalPort) {
1407
1546
  this.logicalPort = logicalPort;
1408
1547
  this.deviceId = udid;
1409
- logInfo(`AppleDeviceKit initialized for device: ${this.deviceId}, logical port: ${this.logicalPort}`);
1548
+ logInfo(
1549
+ `AppleDeviceKit initialized for device: ${this.deviceId}, logical port: ${this.logicalPort}`
1550
+ );
1410
1551
  }
1411
1552
  deviceId;
1412
1553
  proxyProcess = null;
1413
- portAllocation = null;
1554
+ localDevicePort = null;
1414
1555
  isDisposed = false;
1415
1556
  /**
1416
1557
  * Throws if the kit has been disposed
@@ -1441,9 +1582,9 @@ var AppleDeviceKit = class {
1441
1582
  * @param timeout Timeout in milliseconds (default: 120000)
1442
1583
  * @param pollInterval Poll interval in milliseconds (default: 1000)
1443
1584
  */
1444
- async waitForPairing(timeout = 12e4, pollInterval = 1e3) {
1585
+ async waitForPairing(timeout2 = 12e4, pollInterval = 1e3) {
1445
1586
  this.ensureNotDisposed();
1446
- return waitForPairing(this.deviceId, timeout, pollInterval);
1587
+ return waitForPairing(this.deviceId, timeout2, pollInterval);
1447
1588
  }
1448
1589
  /**
1449
1590
  * Attempt to pair/trust the device
@@ -1466,9 +1607,9 @@ var AppleDeviceKit = class {
1466
1607
  * @param onWaitingForTrust Callback when waiting for user to accept trust dialog
1467
1608
  * @returns true if device is now trusted
1468
1609
  */
1469
- async trustDevice(timeout = 6e4, onWaitingForTrust) {
1610
+ async trustDevice(timeout2 = 6e4, onWaitingForTrust) {
1470
1611
  this.ensureNotDisposed();
1471
- return trustDevice(this.deviceId, timeout, onWaitingForTrust);
1612
+ return trustDevice(this.deviceId, timeout2, onWaitingForTrust);
1472
1613
  }
1473
1614
  /**
1474
1615
  * Unpair/untrust the device
@@ -1538,10 +1679,9 @@ var AppleDeviceKit = class {
1538
1679
  async startPortForwardAsync(devicePort, startupTimeout = 500) {
1539
1680
  this.ensureNotDisposed();
1540
1681
  this.killProxyProcess();
1541
- const portManager = getSharedPortManager();
1542
- this.portAllocation = await portManager.allocate(this.logicalPort, devicePort);
1682
+ this.localDevicePort = await getPorts({ port: portNumbers(3e4, 31e3) });
1543
1683
  const { result, process: process2 } = await startPortForward(
1544
- this.portAllocation.localPort,
1684
+ this.localDevicePort,
1545
1685
  devicePort,
1546
1686
  this.deviceId,
1547
1687
  startupTimeout
@@ -1563,10 +1703,8 @@ var AppleDeviceKit = class {
1563
1703
  */
1564
1704
  closePortForward() {
1565
1705
  this.killProxyProcess();
1566
- if (this.portAllocation) {
1567
- const portManager = getSharedPortManager();
1568
- portManager.release(this.logicalPort);
1569
- this.portAllocation = null;
1706
+ if (this.localDevicePort) {
1707
+ this.localDevicePort = null;
1570
1708
  }
1571
1709
  }
1572
1710
  /**
@@ -1606,14 +1744,8 @@ var AppleDeviceKit = class {
1606
1744
  * Get the currently allocated local port for forwarding
1607
1745
  * Returns undefined if no port forward is active
1608
1746
  */
1609
- getAllocatedPort() {
1610
- return this.portAllocation?.localPort;
1611
- }
1612
- /**
1613
- * Get the current port allocation info
1614
- */
1615
- getPortAllocation() {
1616
- return this.portAllocation;
1747
+ getDevicePort() {
1748
+ return this.localDevicePort;
1617
1749
  }
1618
1750
  /**
1619
1751
  * Check if this kit has been disposed
@@ -1649,8 +1781,6 @@ var AppleDeviceKit = class {
1649
1781
  }
1650
1782
  };
1651
1783
  export {
1652
- AppleDeviceKit,
1653
- PortManager,
1654
- getSharedPortManager
1784
+ AppleDeviceKit
1655
1785
  };
1656
1786
  //# sourceMappingURL=index.mjs.map