var __importMetaUrl = require("url").pathToFileURL(__filename).href;
"use strict";

// src/service/tunnel.ts
var import_node_child_process = require("node:child_process");
var import_node_path = require("node:path");
var import_node_path2 = require("node:path");
var import_node_url = require("node:url");
function startTunnel() {
  const defaultPath = process.platform === "win32" ? "pymobiledevice3\\pymobiledevice3.exe" : "pymobiledevice3/pymobiledevice3";
  const cliPath = (0, import_node_path.resolve)(
    (0, import_node_path2.dirname)((0, import_node_url.fileURLToPath)(__importMetaUrl)),
    process.env.PMD_CLI_PATH ?? defaultPath
  );
  console.log(`Starting tunnel with: ${cliPath} remote tunneld`);
  const child = (0, import_node_child_process.spawn)(cliPath, ["remote", "tunneld"], {
    stdio: "inherit"
  });
  child.on("error", (error) => {
    console.error("Failed to start tunnel:", error);
    process.exit(1);
  });
  child.on("exit", (code, signal) => {
    console.log(`Tunnel process exited with code ${code} and signal ${signal}`);
    process.exit(code ?? 1);
  });
  process.on("SIGTERM", () => {
    console.log("Received SIGTERM, stopping tunnel...");
    child.kill();
  });
  process.on("SIGINT", () => {
    console.log("Received SIGINT, stopping tunnel...");
    child.kill();
  });
}
startTunnel();
//# sourceMappingURL=tunnel.js.map
