UNPKG

homebridge-config-ui-x

Version:

A web based management, configuration and control platform for Homebridge.

5 lines 4.77 kB
import {b as bn,k as kn,M as Mn}from'./chunk-CCTcrEQI.js';import {d as dr}from'./chunk-KTYlT6lA.js';import {g,X as I3,aF as $$1,E,H as Hf,aP as Is,ae as C}from'./main-ONDCASUV.js';var L=(()=>{class n{$ws=g(dr);$api=g(I3);io;fitAddon;webLinksAddon;resize;elementResize;dataDisposable=null;isInitializing=false;hasUserTyped=false;autoFocusOnStart=true;destroy$=new $$1;term;destroyTerminal(){this.destroy$.next(),this.destroy$.complete(),this.dataDisposable&&(this.dataDisposable.dispose(),this.dataDisposable=null),this.io&&this.io.socket&&(this.io.socket.removeAllListeners("disconnect"),this.io.socket.removeAllListeners("stdout"),this.io.socket.removeAllListeners("process-exit")),this.io&&this.io.end(),this.term&&(this.term.dispose(),this.term=null),this.resize&&this.resize.complete(),this.elementResize&&this.elementResize.complete(),this.destroy$=new $$1,this.isInitializing=false,this.hasUserTyped=false;}destroyPersistentSession(){return E(this,null,function*(){this.destroyTerminal();try{yield this.$api.post("/platform-tools/terminal/destroy-persistent-session",{});}catch(s){console.error("Failed to destroy persistent session:",s);}})}detachTerminal(){this.destroy$.next(),this.destroy$.complete(),this.dataDisposable&&(this.dataDisposable.dispose(),this.dataDisposable=null),this.term&&this.term.dispose(),this.resize&&this.resize.complete(),this.elementResize&&this.elementResize.complete(),this.destroy$=new $$1,this.isInitializing=false;}hasActiveSession(){return this.io&&this.io.socket&&this.io.socket.connected}hasUserTypedInSession(){return this.hasUserTyped}isTerminalReady(){return this.term&&!this.isInitializing}activateTerminal(){this.isTerminalReady()&&this.term&&this.term.focus();}touchStartY=null;onTouchStart(s){this.touchStartY=s.touches[0].clientY;}onTouchEnd(s){if(this.touchStartY===null)return;let i=Math.abs(s.changedTouches[0].clientY-this.touchStartY);this.touchStartY=null,i<10&&this.activateTerminal();}reconnectTerminal(s,i={},h,a=true){return this.isInitializing?false:(this.isInitializing=true,this.autoFocusOnStart=a,this.elementResize=h,this.io&&this.io.socket&&this.io.socket.connected?(this.fitAddon=new bn,this.webLinksAddon=new kn,this.term=new Mn(i),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new $$1,this.term.open(s.nativeElement),setTimeout(()=>{this.fitAddon.fit();}),this.io.socket.removeAllListeners("stdout"),this.io.socket.removeAllListeners("process-exit"),this.io.socket.on("stdout",t=>{this.term.write(t);}),this.io.socket.on("process-exit",()=>{this.startSession();}),this.dataDisposable&&this.dataDisposable.dispose(),this.dataDisposable=this.term.onData(t=>{this.hasUserTyped=true,this.io.socket.emit("stdin",t);}),this.term.onResize(t=>{this.resize.next(t);}),this.resize.pipe(Hf(500),Is(this.destroy$)).subscribe(t=>{this.io.socket.emit("resize",t);}),this.elementResize&&this.elementResize.pipe(Hf(100),Is(this.destroy$)).subscribe({next:()=>{this.fitAddon.fit();}}),this.io.socket.emit("start-session",{cols:this.term.cols,rows:this.term.rows}),this.isInitializing=false,true):this.startTerminal(s,i,h,a))}startTerminal(s,i={},h,a=true){return this.isInitializing?false:(this.isInitializing=true,this.autoFocusOnStart=a,this.elementResize=h,this.io=this.$ws.connectToNamespace("platform-tools/terminal"),this.fitAddon=new bn,this.webLinksAddon=new kn,this.term=new Mn(i),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new $$1,this.term.open(s.nativeElement),setTimeout(()=>{this.fitAddon.fit();}),this.io.connected.pipe(Hf(200),Is(this.destroy$)).subscribe(()=>{this.startSession();}),this.io.socket.removeAllListeners("disconnect"),this.io.socket.removeAllListeners("process-exit"),this.io.socket.removeAllListeners("stdout"),this.io.socket.on("disconnect",()=>{this.term?.write(` \r \rTerminal disconnected. Is the server running? \r \r`);}),this.io.socket.on("process-exit",()=>{this.startSession();}),this.resize.pipe(Hf(500),Is(this.destroy$)).subscribe(t=>{this.io.socket.emit("resize",t);}),this.io.socket.on("stdout",t=>{this.term.write(t);}),this.dataDisposable=this.term.onData(t=>{this.hasUserTyped=true,this.io.socket.emit("stdin",t);}),this.term.onResize(t=>{this.resize.next(t);}),this.elementResize&&this.elementResize.pipe(Hf(100),Is(this.destroy$)).subscribe({next:()=>{this.fitAddon.fit();}}),true)}startSession(){this.term.reset(),this.hasUserTyped=false,this.io.socket.emit("start-session",{cols:this.term.cols,rows:this.term.rows}),this.resize.next({cols:this.term.cols,rows:this.term.rows}),this.isInitializing=false,this.autoFocusOnStart&&this.term.focus();}static \u0275fac=function(i){return new(i||n)};static \u0275prov=C({token:n,factory:n.\u0275fac,providedIn:"root"})}return n})();export{L};