"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.startUSBManagerProcess=startUSBManagerProcess;const tslib_1=require("tslib"),child_process=tslib_1.__importStar(require("child_process")),miniapp_builder_1=require("./miniapp-builder"),fse=require("fs-extra");class USBProcess{constructor(e,s){this.isAlive=!1,this.child=null,this.child=child_process.exec(`"${e}"`,{},(e,r,i)=>{if(e)throw s.progress("USBProcess exec error: "+e),this.isAlive=!1,new Error("exec USBProcess failed");s.progress("USBProcess stdout: "+r),s.progress("USBProcess stderr: "+i)}),this.isAlive=!0}kill(){var e;null===(e=this.child)||void 0===e||e.kill()}}let USBProcessShareInstance=null;async function startUSBManagerProcess(e,s){const{builderPath:r}=await(0,miniapp_builder_1.getMiniAppBuilderFromRemoteCore)(e,"PTWin.exe","PTMac");if(!fse.existsSync(r))throw new Error("exec USBProcess failed （cant find target path）");try{return USBProcessShareInstance&&USBProcessShareInstance.isAlive?s.progress("USBProcessShareInstance is isAlive"):(s.progress("new USBProcess"),USBProcessShareInstance=new USBProcess(r,s)),!0}catch(e){throw new Error(`exec USBProcess failed (execSync failed! ${r}）`)}}