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

1 line
219 KiB
JavaScript
Raw Normal View History

2020-08-16 03:23:48 +02:00
var t,n,e;(function(){var t,n;n=class extends OS.application.BaseService{constructor(t){super("JarvisService",t),this.text=__("Jarvis({0}%)",(0).toString()),this.iconclass="fa fa-android",this.nodes=[{text:__("Status"),id:1},{text:__("Shutdown"),id:3},{text:__("Reboot"),id:4},{text:__("Exit service"),id:2}],this.onchildselect=t=>this.action(t)}init(){var t;return t=()=>Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.sub=new Antunnel.Subscriber("notification"),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=__("Jarvis({0}%)",Math.round(n.battery_percent).toString()),this.update()},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Unsubscribed to the notification service")),this.quit()),Antunnel.tunnel.subscribe(this.sub)):(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()),window.Antunnel?t():(console.log("require Antunnel"),this._api.requires("pkg://Antunnel/main.js").then(()=>t()).catch(t=>(this.error(__("Unable to load Antunnel: {0}",t.toString()),t),this.quit())))}action(t){switch(t.data.item.data.id){case 1:return this._gui.launch("JarvisControl",[]);case 2:return this.quit();case 3:return this.execute("poweroff");case 4:return this.execute("reboot")}}execute(t){var n;if(this.tunnel)return(n=new Antunnel.Subscriber("jarvis_control")).onopen=()=>(console.log("Subscribed to jarvis_control channel. Send the command"),n.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t)),n.close()),n.onerror=t=>this.error(__("Error: {0}",new TextDecoder("utf-8").decode(t.data)),t),n.onclose=()=>this.notify(__("Unsubscribed to the jarvis_control service")),this.tunnel.subscribe(n)}awake(){}cleanup(){if(this.sub)return this.sub.close()}},this.OS.register("JarvisService",n),(t=class extends this.OS.application.BaseApplication{constructor(t){super("JarvisControl",t)}main(){var t;return this.batterychart=$(this.find("battery-area")).epoch({type:"time.line",axes:["bottom","left","right"],range:[2500,4300],data:[{label:"Battery",values:[]}]}),this.tempchart=$(this.find("temp-area")).epoch({type:"time.line",axes:["bottom","left","right"],range:[0,100],data:[{label:"Temperature",values:[]}]}),this.memchart=$(this.find("mem-area")).epoch({type:"time.gauge",value:0}),this.diskchart=$(this.find("disk-area")).epoch({type:"time.gauge",value:0}),this.cpuchart=$(this.find("cpu-area")).epoch({type:"time.gauge",value:0}),t=()=>Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.sub=new Antunnel.Subscriber("notification"),this.sub.onopen=()=>(console.log("Subscribed to notification channel"),this._gui.pushService("JarvisControl/JarvisService")),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.display(n)},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Unsubscribed to the notification service")),this.quit()),Antunnel.tunnel.subscribe(this.sub)):(this.error(__("The Antunnel service is not started, please start it first")).catch(t=>this.error(t.toString(),t)),this.quit()),this.on("resize",()=>{var t;return t=this.find("battery-area"),this.batterychart.option("width",$(t).width()),this.batterychart.option("height",$(t).height()),t=this.find("temp-area"),this.tempchart.option("width",$(t).width()),this.tempchart.option("height",$(t).height())}),t()}display(t){var n,e,r;return r=parseFloat(t.mem.match(/([0-9\.]+)%/)[1]),this.memchart.push(r/100),this.find("mem-text").text=t.mem,e=parseFloat(t.disk.match(/([0-9\.]+)%/)[1]),this.diskchart.push(e/100),this.find("disk-text").text=t.disk,n=parseFloat(t.cpu.match(/([0-9\.]+)$/)[1]),this.cpuchart.push(n/100),this.find("cpu-text").text=t.cpu,this.batterychart.push([{time:(new Date).timestamp(),y:t.battery}]),this.fi