UNPKG

homebridge-config-ui-x

Version:

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

6 lines (5 loc) 4.54 kB
import{a as d,b as c,c as m}from"./chunk-YEMALHZS.js";import{a as z}from"./chunk-GAHGBZ7U.js";import{G as o,R as r,X as f,aa as l,d as e,dd as u}from"./chunk-LTGI3NYM.js";import{h as p}from"./chunk-B4AJQJMI.js";var R=(()=>{class n{$ws=l(z);$api=l(u);io;fitAddon;webLinksAddon;resize;elementResize;dataDisposable=null;isInitializing=!1;hasUserTyped=!1;autoFocusOnStart=!0;destroy$=new e;term;destroyTerminal(){this.destroy$.next(),this.destroy$.complete(),this.dataDisposable&&(this.dataDisposable.dispose(),this.dataDisposable=null),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 e,this.isInitializing=!1,this.hasUserTyped=!1}destroyPersistentSession(){return p(this,null,function*(){this.destroyTerminal();try{yield this.$api.post("/platform-tools/terminal/destroy-persistent-session",{})}catch(i){console.error("Failed to destroy persistent session:",i)}})}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 e,this.isInitializing=!1}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(i){this.touchStartY=i.touches[0].clientY}onTouchEnd(i){if(this.touchStartY===null)return;let s=Math.abs(i.changedTouches[0].clientY-this.touchStartY);this.touchStartY=null,s<10&&this.activateTerminal()}reconnectTerminal(i,s={},h,a=!0){return this.isInitializing?!1:(this.isInitializing=!0,this.autoFocusOnStart=a,this.elementResize=h,this.io&&this.io.socket&&this.io.socket.connected?(this.fitAddon=new d,this.webLinksAddon=new c,this.term=new m(s),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new e,this.term.open(i.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=!0,this.io.socket.emit("stdin",t)}),this.term.onResize(t=>{this.resize.next(t)}),this.resize.pipe(o(500),r(this.destroy$)).subscribe(t=>{this.io.socket.emit("resize",t)}),this.elementResize&&this.elementResize.pipe(o(100),r(this.destroy$)).subscribe({next:()=>{this.fitAddon.fit()}}),this.io.socket.emit("start-session",{cols:this.term.cols,rows:this.term.rows}),this.isInitializing=!1,!0):this.startTerminal(i,s,h,a))}startTerminal(i,s={},h,a=!0){return this.isInitializing?!1:(this.isInitializing=!0,this.autoFocusOnStart=a,this.elementResize=h,this.io=this.$ws.connectToNamespace("platform-tools/terminal"),this.fitAddon=new d,this.webLinksAddon=new c,this.term=new m(s),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new e,this.term.open(i.nativeElement),setTimeout(()=>{this.fitAddon.fit()}),this.io.connected.pipe(o(200),r(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(o(500),r(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=!0,this.io.socket.emit("stdin",t)}),this.term.onResize(t=>{this.resize.next(t)}),this.elementResize&&this.elementResize.pipe(o(100),r(this.destroy$)).subscribe({next:()=>{this.fitAddon.fit()}}),!0)}startSession(){this.term.reset(),this.hasUserTyped=!1,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=!1,this.autoFocusOnStart&&this.term.focus()}static \u0275fac=function(s){return new(s||n)};static \u0275prov=f({token:n,factory:n.\u0275fac,providedIn:"root"})}return n})();export{R as a};