UNPKG

homebridge-config-ui-x

Version:

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

15 lines (14 loc) 5.69 kB
import{a as k,b as B,c as j}from"./chunk-YEMALHZS.js";import{a as R}from"./chunk-M5NPMQ5Y.js";import{a as w}from"./chunk-XTCYYJPD.js";import{a as b}from"./chunk-SMGTZ45N.js";import{a as _}from"./chunk-GAHGBZ7U.js";import{b as g,d as z}from"./chunk-NAG4LCT2.js";import{t as S}from"./chunk-2QHNXSQY.js";import{$c as L,G as u,Qa as p,R as f,X as x,Yc as v,aa as l,d as m,da as F,dd as T}from"./chunk-LTGI3NYM.js";import{a as y,b as A,g as I,h as d}from"./chunk-B4AJQJMI.js";var $=I(R(),1);function E(o){let c=()=>{let r=o.querySelector(".xterm-helper-textarea");r&&(r.setAttribute("aria-hidden","true"),r.setAttribute("tabindex","-1"),r.setAttribute("readonly","true"))};c(),setTimeout(c,0),setTimeout(c,50),setTimeout(c,250);let e=new MutationObserver(c);return e.observe(o,{childList:!0,subtree:!0}),()=>e.disconnect()}var Z=(()=>{class o{injector=l(F);$api=l(T);$modal=l(S);$toastr=l(L);$translate=l(v);$ws=l(_);io;fitAddon;webLinksAddon;resize;elementResize;pluginName;searchFilter=null;logBuffer=[];maxBufferSize=1e3;destroy$=new m;xtermA11yDisposer=null;term;startTerminal(e,r={},t,n){this.pluginName=n,this.elementResize=t,this.io=this.$ws.connectToNamespace("log"),this.fitAddon=new k,this.webLinksAddon=new B,this.term=new j(A(y({},r),{disableStdin:!0})),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new m,this.term.open(e.nativeElement),this.xtermA11yDisposer?.(),this.xtermA11yDisposer=E(e.nativeElement),setTimeout(()=>{this.fitAddon.fit()}),this.io.connected.pipe(f(this.destroy$)).subscribe(()=>{this.term.reset(),this.logBuffer=[],this.io.socket.emit("tail-log",{cols:this.term.cols,rows:this.term.rows})}),this.io.socket.on("disconnect",()=>{this.term.write(` \r \rWebsocket failed to connect. Is the server running? \r \r`)}),this.resize.pipe(u(500),f(this.destroy$)).subscribe(i=>{this.io.socket.emit("resize",i)}),this.io.socket.on("stdout",i=>{if(this.pluginName){let h=i.split(` \r`),s=!1;h.forEach(a=>{if(a){if(s)if(z.test(a))s=!1;else{this.term.write(`${a} \r`);return}a.includes(`36m[${this.pluginName}]`)&&(this.term.write(`${a} \r`),s=!0)}})}else this.logBuffer.push(i),this.logBuffer.length>this.maxBufferSize&&this.logBuffer.shift(),this.searchFilter?i.split(` \r`).forEach(s=>{s&&this.lineMatchesFilter(s)&&this.term.write(`${s} \r`)}):this.term.write(i)}),this.term.onResize(i=>{this.resize.next(i)}),this.elementResize&&this.elementResize.pipe(u(100),f(this.destroy$)).subscribe({next:()=>{this.fitAddon.fit()}})}setSearchFilter(e){this.searchFilter=e.toLowerCase(),this.redrawTerminalWithFilter()}clearSearchFilter(){this.searchFilter=null,this.redrawTerminalWithFilter()}getSearchFilter(){return this.searchFilter}scrollToBottom(){this.term&&setTimeout(()=>this.term.scrollToLine(this.term.buffer.active.length),10)}lineMatchesFilter(e){return this.searchFilter?e.replace(g,"").toLowerCase().includes(this.searchFilter):!0}redrawTerminalWithFilter(){this.term&&(this.term.clear(),this.logBuffer.forEach(e=>{this.searchFilter?e.split(` \r`).forEach(t=>{t&&this.lineMatchesFilter(t)&&this.term.write(`${t} \r`)}):this.term.write(e)}))}downloadLogFile(){return d(this,null,function*(){let e=p([{provide:b,useValue:{title:this.$translate.instant("logs.title_download_log_file"),message:this.$translate.instant("logs.download_warning"),confirmButtonLabel:this.$translate.instant("form.button_download"),faIconClass:"fas fa-user-secret primary-text"}}],this.injector),r=this.$modal.open(w,{size:"lg",backdrop:"static",injector:e});try{yield r.result;try{let t=yield this.$api.get("/platform-tools/hb-service/log/download",{observe:"response",responseType:"blob"});if(this.searchFilter){let n=yield t.body.text(),i=this.searchFilter,h=n.split(` `).filter(a=>a.replace(g,"").toLowerCase().includes(i)),s=new Blob([h.join(` `)],{type:"text/plain"});(0,$.saveAs)(s,"homebridge.log.txt")}else(0,$.saveAs)(t.body,"homebridge.log.txt")}catch(t){let n;try{if(t&&typeof t=="object"&&"error"in t){let i=yield t.error.text();n=JSON.parse(i).message}}catch(i){console.error(i)}this.$toastr.error(n||this.$translate.instant("logs.download.error"),this.$translate.instant("toast.title_error"))}}catch(t){}})}truncateLogFile(){return d(this,null,function*(){let e=p([{provide:b,useValue:{title:this.$translate.instant("logs.title_truncate_log_file"),message:this.$translate.instant("logs.truncate_log_warning"),confirmButtonLabel:this.$translate.instant("form.button_delete"),confirmButtonClass:"btn-danger",faIconClass:"fas fa-circle-exclamation primary-text"}}],this.injector),r=this.$modal.open(w,{size:"lg",backdrop:"static",injector:e});try{yield r.result;try{yield this.$api.put("/platform-tools/hb-service/log/truncate",{}),this.$toastr.success(this.$translate.instant("logs.log_file_truncated"),this.$translate.instant("toast.title_success")),this.term?.clear()}catch(t){console.error(t);let n=t&&typeof t=="object"&&"error"in t&&t.error&&typeof t.error=="object"&&"message"in t.error?String(t.error.message):this.$translate.instant("logs.truncate.error");this.$toastr.error(n,this.$translate.instant("toast.title_error"))}}catch(t){}})}destroyTerminal(){this.destroy$.next(),this.destroy$.complete(),this.io&&this.io.socket&&(this.io.socket.removeAllListeners("stdout"),this.io.socket.removeAllListeners("disconnect")),this.io&&this.io.end(),this.term&&this.term.dispose(),this.xtermA11yDisposer?.(),this.xtermA11yDisposer=null,this.resize&&this.resize.complete(),this.elementResize&&this.elementResize.complete(),this.destroy$=new m,this.logBuffer=[],this.searchFilter=null}static \u0275fac=function(r){return new(r||o)};static \u0275prov=x({token:o,factory:o.\u0275fac,providedIn:"root"})}return o})();export{E as a,Z as b};