homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge.
14 lines • 5.73 kB
JavaScript
import{a as E$1,i as D,o as w,s as x}from"./chunk-D39XL-zh.js";import{Gr as uy,Rt as Te,Un as g,Vt as U3,dt as Nf,mt as P,rn as Wf,ui as z0,v as C,zt as Ts}from"./chunk-D96TCRAL.js";import{ut as si}from"./main-E3N63CH7.js";import{t as ds}from"./chunk-CiY-LsUw.js";import{n as bn,r as kn,t as Mn}from"./chunk-CLsCjV2Q.js";import{t as A}from"./chunk-nWnpef0a.js";import{t as O}from"./chunk-C-2fYS21.js";import{D as o,j as t}from"./chunk-BuXBmaui.js";import{t as L}from"./chunk-tTuB-TjV2.js";var $=D(L(),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$1{injector=g(Te);$api=g(U3);$modal=g(si);$toastr=g(z0);$translate=g(Nf);$ws=g(ds);io;fitAddon;webLinksAddon;resize;elementResize;pluginName;searchFilter=null;logBuffer=[];maxBufferSize=1e3;destroy$=new P;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:!0})),this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon),this.resize=new P,this.term.open(e.nativeElement),this.xtermA11yDisposer?.(),this.xtermA11yDisposer=E(e.nativeElement),setTimeout(()=>{this.fitAddon.fit()}),this.io.connected.pipe(Ts(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(Wf(500),Ts(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(t.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(Wf(100),Ts(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,``).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 E$1(this,null,function*(){let e=uy([{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,``).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=uy([{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 P,this.logBuffer=[],this.searchFilter=null}static ɵfac=function(r){return new(r||o$1)};static ɵprov=C({token:o$1,factory:o$1.ɵfac,providedIn:`root`})}return o$1})();export{Z as n,E as t};