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AmB;QACzB,IAAI,YAAY,GAAG,IAAI,CAAC,YAAY,CAAA;QACpC,IAAI,YAAY,IAAI,IAAI,EAAE;YACxB,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;YAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;SACjC;QACD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,iHAAiH;QACjH,OAAO,yBAAyB,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;CACF;AAxED,gDAwEC;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAC3B,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AACtD,CAAC;AALD,8DAKC","sourcesContent":["import { exec, spawn, DebugLogger, ExtraSpawnOptions, log } from \"builder-util\"\nimport { SpawnOptions, execFileSync, ExecFileOptions } from \"child_process\"\nimport { VmManager } from \"./vm\"\n\n/** @internal */\nexport async function parseVmList(debugLogger: DebugLogger) {\n // do not log output if debug - it is huge, logged using debugLogger\n let rawList = await exec(\"prlctl\", [\"list\", \"-i\", \"-s\", \"name\"], undefined, false)\n debugLogger.add(\"parallels.list\", rawList)\n\n rawList = rawList.substring(rawList.indexOf(\"ID:\"))\n\n // let match: Array | null\n const result: Array = []\n for (const info of rawList\n .split(\"\\n\\n\")\n .map(it => it.trim())\n .filter(it => it.length > 0)) {\n const vm: any = {}\n for (const line of info.split(\"\\n\")) {\n const meta = /^([^:(\"]+): (.*)$/.exec(line)\n if (meta == null) {\n continue\n }\n\n const key = meta[1].toLowerCase()\n if (key === \"id\" || key === \"os\" || key === \"name\" || key === \"state\" || key === \"name\") {\n vm[key] = meta[2].trim()\n }\n }\n result.push(vm)\n }\n return result\n}\n\n/** @internal */\nexport class ParallelsVmManager extends VmManager {\n private startPromise: Promise\n\n private isExitHookAdded = false\n\n constructor(private readonly vm: ParallelsVm) {\n super()\n\n this.startPromise = this.doStartVm()\n }\n\n get pathSep(): string {\n return \"/\"\n }\n\n private handleExecuteError(error: Error): any {\n if (error.message.includes(\"Unable to open new session in this virtual machine\")) {\n throw new Error(`Please ensure that your are logged in \"${this.vm.name}\" parallels virtual machine. In the future please do not stop VM, but suspend.\\n\\n${error.message}`)\n }\n\n log.warn(\"ensure that 'Share folders' is set to 'All Disks', see https://goo.gl/E6XphP\")\n throw error\n }\n\n async exec(file: string, args: Array, options?: ExecFileOptions): Promise {\n await this.ensureThatVmStarted()\n // it is important to use \"--current-user\" to execute command under logged in user - to access certs.\n return await exec(\"prlctl\", [\"exec\", this.vm.id, \"--current-user\", file.startsWith(\"/\") ? macPathToParallelsWindows(file) : file].concat(args), options).catch(error =>\n this.handleExecuteError(error)\n )\n }\n\n async spawn(file: string, args: Array, options?: SpawnOptions, extraOptions?: ExtraSpawnOptions): Promise {\n await this.ensureThatVmStarted()\n return await spawn(\"prlctl\", [\"exec\", this.vm.id, file].concat(args), options, extraOptions).catch(error => this.handleExecuteError(error))\n }\n\n private async doStartVm() {\n const vmId = this.vm.id\n const state = this.vm.state\n if (state === \"running\") {\n return\n }\n\n if (!this.isExitHookAdded) {\n this.isExitHookAdded = true\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n require(\"async-exit-hook\")((callback: (() => void) | null) => {\n const stopArgs = [\"suspend\", vmId]\n if (callback == null) {\n execFileSync(\"prlctl\", stopArgs)\n } else {\n exec(\"prlctl\", stopArgs).then(callback).catch(callback)\n }\n })\n }\n await exec(\"prlctl\", [\"start\", vmId])\n }\n\n private ensureThatVmStarted() {\n let startPromise = this.startPromise\n if (startPromise == null) {\n startPromise = this.doStartVm()\n this.startPromise = startPromise\n }\n return startPromise\n }\n\n toVmFile(file: string): string {\n // https://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator\n return macPathToParallelsWindows(file)\n }\n}\n\nexport function macPathToParallelsWindows(file: string) {\n if (file.startsWith(\"C:\\\\\")) {\n return file\n }\n return \"\\\\\\\\Mac\\\\Host\\\\\" + file.replace(/\\//g, \"\\\\\")\n}\n\nexport interface ParallelsVm {\n id: string\n name: string\n os: \"win-10\" | \"win-11\" | \"ubuntu\" | \"elementary\"\n state: \"running\" | \"suspended\" | \"stopped\"\n}\n"]}