import{r as t}from"./p-823ca21f.js";import{connectionManager as e}from"../gc-target-connection-manager/lib/ConnectionManager";import{GcPromise as i}from"../gc-core-assets/lib/GcPromise";import{GcUtils as r}from"../gc-core-assets/lib/GcUtils";import{ActionRegistry as o}from"../gc-widget-menu/lib/ActionRegistry";import{codecRegistry as a}from"../gc-target-configuration/lib/TargetConfiguration";import{ServicesRegistry as c}from"../gc-core-services/lib/ServicesRegistry";import{dsServiceType as n,ccsDebugSessionChangedEventType as s}from"../gc-service-ds/lib/DSService";async function g(t){try{const r=document.querySelectorAll("gc-target-configuration");const o=[];for(let t=0;t<r.length;t++){o.push(e.whenConfigurationReady(r[t].id||"default"))}if(t){o.push(e.whenConfigurationReady(t))}await i.timeout(Promise.all(o),5e3,"")}catch(t){}if(r.isCCS){const t=c.getService(n);t.addEventListener(s,(({data:t})=>{const i=e.getActiveTransports().filter((t=>t.isXdsTransport));if(i.length>0||this.autoConnect){if(t.status==="started"){e.connectToCCS()}else if(t.status==="terminated"){e.disconnect()}}}));e.connectToCCS().catch((()=>{}))}else{e.connect().catch((()=>{}))}e.allowAutoConnectOnDeviceDetection=true}let f=class{constructor(e){t(this,e);this.autoConnect=false}activeConfigurationChanged(){const t=this.activeConfiguration||"default";i.timeout(e.whenConfigurationReady(t),5e3,"").finally((()=>{e.setActiveConfiguration(t)}))}async getCodec(t,e=5e3){if(e>0){await i.timeout(a.whenConfigurationReady(t),e,`Codec id=${t} was not found.`)}return a.getInstance(t)}componentDidLoad(){this.activeConfigurationChanged();o.registerAction("cmd_open_program_loader_dialog",new class{run(){const t=document.querySelector("gc-target-program-loader");if(t){t.loadProgram()}}isVisible(){const t=document.querySelector("gc-target-program-loader");return!!t}isEnabled(){return!r.isInDesigner}});if(!r.isInDesigner&&(this.autoConnect||r.isCCS)){if(this.activeConfiguration){g(this.activeConfiguration)}}}static get watchers(){return{activeConfiguration:["activeConfigurationChanged"]}}};export{f as gc_target_connection_manager};
//# sourceMappingURL=p-4c9e1270.entry.js.map