antosdk-apps/SystemControl/build/debug/main.js

1 line
220 KiB
JavaScript
Raw Normal View History

2021-03-22 20:30:30 +01:00
var t,n,e;(function(){var t,n;t=class extends OS.application.BaseService{constructor(t){super("SysmondService",t),this.text=__("{0}%",(0).toString()),this.iconclass="fa fa-android",this.app=void 0,this.onmenuselect=t=>this.openApp()}setting(){return this.systemsetting.applications.SystemControl}init(){var t;return t=()=>{if(Antunnel.tunnel){if(!this.setting().topic)return;return this.tunnel=Antunnel.tunnel,this.sub=new Antunnel.Subscriber(this.setting().topic),this.sub.onopen=()=>console.log("Subscribed to notification channel"),this.sub.onerror=t=>this.error(__("Error: {0}",new TextDecoder("utf-8").decode(t.data)),t),this.sub.onmessage=t=>{var n;return t.data&&(n=JSON.parse(new TextDecoder("utf-8").decode(t.data))),this.text=__("{0}%",Math.round(n.battery_percent).toString()),this.app&&this.app.feed(n),this.update()},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Unsubscribed to the notification service")),this.quit()),Antunnel.tunnel.subscribe(this.sub)}return this.error(__("The Antunnel service is not started, please start it first")),this._gui.pushService("Antunnel/AntunnelService").catch(t=>this.error(t.toString(),t)),this.quit()},this.setting().topic?t():(console.log("Open dialog"),this._gui.openDialog("PromptDialog",{title:__("Enter topic name"),label:__("Please enter topic name")}).then(n=>(this.setting().topic=n,t())))}openApp(){if(!this.app)return this._gui.launch("SystemControl",[])}execute(t){}awake(){}cleanup(){if(this.app&&this.app.quit(),this.sub)return this.sub.close()}},this.OS.register("SysmondService",t),(n=class extends this.OS.application.BaseApplication{constructor(t){super("SystemControl",t)}main(){return this.max_net_range=2048,this.diskchart=$(this.find("disk-area")).epoch({type:"time.gauge",value:0}),this.on("resize",()=>{var t;if(t=this.find("cpu-area"),this.cpu&&($(t).children().hide(),this.cpu.option("width",$(t).width()),this.cpu.option("height",$(t).height()),$(t).children().show()),t=this.find("battery-area"),t=this.find("memory-area"),this.memory&&($(t).children().hide(),this.memory.option("width",$(t).width()),this.memory.option("height",$(t).height()),$(t).children().show()),t=this.find("network-area"),this.network&&($(t).children().hide(),this.network.option("width",$(t).width()),this.network.option("height",$(t).height()),$(t).children().show()),t=this.find("temp-area"),this.temp&&($(t).children().hide(),this.temp.option("width",$(t).width()),this.temp.option("height",$(t).height()),$(t).children().show()),t=this.find("battery-area"),this.battery)return $(t).children().hide(),this.battery.option("width",$(t).width()),this.battery.option("height",$(t).height()),$(t).children().show()}),this._gui.pushService("SystemControl/SysmondService",[]).then(t=>(this.service=t,t.app=this)).catch(t=>this.error(__("Unable to start sysmond service"),t))}streamline(t,n,e,r){var i,o,a,u,s,l,c,h,f;if(o=0,l=$(this.find(t+"-text")),!this[t]){for(f={type:"time.line",axes:["bottom","left","right"]},e&&(f.range=e),i=[],u=0,c=n.length;u<c;u++)a=n[u],i.push({label:"label-"+o,values:[]}),$("<div>").addClass("legend-color").addClass("ref").addClass("category"+(o+1)).appendTo(l),$("<div>").addClass("legend-label").appendTo(l).text(r?r[o]:`${t}-${o}`),$("<div>").addClass("legend-value").appendTo(l),o+=1;f.data=i,this[t]=$(this.find(t+"-area")).epoch(f)}for(s=0,h=n.length;s<h;s++)a=n[s],$(l.children()[3*o+2]).text(a.y.toString()),o+=1;return this[t].push(n)}feed(t){var n,e,r,i,o,a,u,s,l,c,h,f,p,g,d,y,v,m,x,_,w;for(r=t.disk_total-t.disk_free,this.diskchart.push(r/t.disk_total),this.find("disk-text").text="Disk: "+Math.round(r/1024/1024/1024)+"/"+Math.round(t.disk_total/1024/1024/1024)+" GB",p=t.stamp_sec,t.cpu_usages.shift(),e=function(){var n,e,r,i;for(i=[],n=0,e=(r=t.cpu_usages).length;n<e;n++)w=r[n],i.push({time:p,y:w.toFixed(2)});return i}(),this.streamline("cpu",e,[0,100]),v=t.mem_total/1024/1024,x=t.mem_used/1024/1024,m=t.mem_swap_total/1024/1024,_=(t.mem_swap_total-t.mem_swap_free)/1024/1024,s=[{time:p,y:x.toFixed(3)},{time:p,y:_.toFixed(3)}],l=[0,v>m?v:m],this.streamline("memory",s,l,["RAM (GB)","SWA