UNPKG

homebridge-config-ui-x

Version:

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

14 lines 5.69 kB
import {b as bn,k as kn,M as Mn}from'./chunk-CCTcrEQI.js';import {L}from'./chunk-DL7vVfE4.js';import {O}from'./chunk-BtxeAJ3m.js';import {A}from'./chunk-BWu8OGjA.js';import {d as dr}from'./chunk-KTYlT6lA.js';import {o as o$1,t}from'./chunk-WUyBXYN7.js';import {g,ag as we,X as I3,ah as si,a1 as M0,a2 as bf,aF as $$1,a5 as x,a4 as w,aP as Is,H as Hf,E as E$1,ai as ty,ae as C,aj as D}from'./main-ONDCASUV.js';var $=D(L());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:true,subtree:true}),()=>e.disconnect()}var Z=(()=>{class o{injector=g(we);$api=g(I3);$modal=g(si);$toastr=g(M0);$translate=g(bf);$ws=g(dr);io;fitAddon;webLinksAddon;resize;elementResize;pluginName;searchFilter=null;logBuffer=[];maxBufferSize=1e3;destroy$=new $$1;xtermA11yDisposer=null;term;startTerminal(e,r={},t$1,n){this.pluginName=n,this.elementResize=t$1,this.io=this.$ws.connectToNamespace("log"),this.fitAddon=new bn,this.webLinksAddon=new kn,this.term=new Mn(x(w({},r),{disableStdin:true})),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new $$1,this.term.open(e.nativeElement),this.xtermA11yDisposer?.(),this.xtermA11yDisposer=E(e.nativeElement),setTimeout(()=>{this.fitAddon.fit();}),this.io.connected.pipe(Is(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(Hf(500),Is(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=false;h.forEach(a=>{if(a){if(s)if(t.test(a))s=false;else {this.term.write(`${a} \r`);return}a.includes(`36m[${this.pluginName}]`)&&(this.term.write(`${a} \r`),s=true);}});}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(Hf(100),Is(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(o$1,"").toLowerCase().includes(this.searchFilter):true}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 E$1(this,null,function*(){let e=ty([{provide:A,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(O,{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(o$1,"").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 E$1(this,null,function*(){let e=ty([{provide:A,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(O,{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 $$1,this.logBuffer=[],this.searchFilter=null;}static \u0275fac=function(r){return new(r||o)};static \u0275prov=C({token:o,factory:o.\u0275fac,providedIn:"root"})}return o})();export{E,Z};