mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-13 14:14:27 +02:00
rename JarvisControl to SystemControl
This commit is contained in:
77
SystemControl/coffees/SysmondService.coffee
Normal file
77
SystemControl/coffees/SysmondService.coffee
Normal file
@ -0,0 +1,77 @@
|
||||
class SysmondService extends OS.application.BaseService
|
||||
constructor: (args) ->
|
||||
super "SysmondService", args
|
||||
@text = __("{0}%", 0.toString())
|
||||
@iconclass = "fa fa-android"
|
||||
@app = undefined
|
||||
#@nodes = [
|
||||
# {text: __("Status"), id: 1},
|
||||
# {text: __("Shutdown"), id: 3},
|
||||
# {text: __("Reboot"), id: 4},
|
||||
# {text: __("Exit service"), id: 2}
|
||||
#]
|
||||
@onmenuselect = (e) => @openApp()
|
||||
|
||||
init: () ->
|
||||
checklib = () =>
|
||||
if not Antunnel.tunnel
|
||||
@error __("The Antunnel service is not started, please start it first")
|
||||
@_gui.pushService("Antunnel/AntunnelService")
|
||||
.catch (e) =>
|
||||
@error e.toString(), e
|
||||
@quit()
|
||||
else
|
||||
@tunnel = Antunnel.tunnel
|
||||
@sub = new Antunnel.Subscriber("fbf070ddea3ea90d07f456540b405d302554ec82")
|
||||
@sub.onopen = () =>
|
||||
#@sub.send Antunnel.Msg.DATA, new TextEncoder("utf-8").encode("Hello")
|
||||
console.log("Subscribed to notification channel")
|
||||
|
||||
@sub.onerror = (e) =>
|
||||
@error __("Error: {0}", new TextDecoder("utf-8").decode(e.data)), e
|
||||
#@sub = undefined
|
||||
|
||||
@sub.onmessage = (e) =>
|
||||
obj = JSON.parse(new TextDecoder("utf-8").decode(e.data)) if e.data
|
||||
# update the battery
|
||||
@text = __("{0}%", Math.round(obj.battery_percent).toString())
|
||||
@app.feed obj if @app
|
||||
@update()
|
||||
|
||||
@sub.onclose = () =>
|
||||
@sub = undefined
|
||||
@notify __("Unsubscribed to the notification service")
|
||||
@quit()
|
||||
Antunnel.tunnel.subscribe @sub
|
||||
|
||||
checklib()
|
||||
|
||||
|
||||
openApp: () ->
|
||||
return if @app
|
||||
@_gui.launch "SystemControl", []
|
||||
|
||||
|
||||
execute: (cmd) ->
|
||||
#return unless @tunnel
|
||||
#sub = new Antunnel.Subscriber("jarvis_control")
|
||||
#sub.onopen = () =>
|
||||
# console.log("Subscribed to jarvis_control channel. Send the command")
|
||||
# sub.send Antunnel.Msg.DATA, new TextEncoder("utf-8").encode(cmd)
|
||||
# sub.close()
|
||||
|
||||
#sub.onerror = (e) =>
|
||||
# @error __("Error: {0}", new TextDecoder("utf-8").decode(e.data)), e
|
||||
#@sub = undefined
|
||||
|
||||
#sub.onclose = () =>
|
||||
# @notify __("Unsubscribed to the jarvis_control service")
|
||||
#@tunnel.subscribe sub
|
||||
|
||||
awake: () ->
|
||||
|
||||
cleanup: () ->
|
||||
@sub.close() if @sub
|
||||
|
||||
|
||||
this.OS.register "SysmondService", SysmondService
|
146
SystemControl/coffees/main.coffee
Normal file
146
SystemControl/coffees/main.coffee
Normal file
@ -0,0 +1,146 @@
|
||||
|
||||
|
||||
class SystemControl extends this.OS.application.BaseApplication
|
||||
constructor: ( args ) ->
|
||||
super "SystemControl", args
|
||||
|
||||
main: () ->
|
||||
@diskchart = $(@find("disk-area")).epoch({
|
||||
type: 'time.gauge',
|
||||
value: 0
|
||||
});
|
||||
@on "resize", () =>
|
||||
el = @find("cpu-area")
|
||||
if @cpu
|
||||
$(el).children().hide()
|
||||
@cpu.option("width", $(el).width())
|
||||
@cpu.option("height", $(el).height())
|
||||
$(el).children().show()
|
||||
el = @find("battery-area")
|
||||
|
||||
el = @find("memory-area")
|
||||
if @memory
|
||||
$(el).children().hide()
|
||||
@memory.option("width", $(el).width())
|
||||
@memory.option("height", $(el).height())
|
||||
$(el).children().show()
|
||||
|
||||
el = @find("network-area")
|
||||
if @network
|
||||
$(el).children().hide()
|
||||
@network.option("width", $(el).width())
|
||||
@network.option("height", $(el).height())
|
||||
$(el).children().show()
|
||||
|
||||
el = @find("temp-area")
|
||||
if @temp
|
||||
$(el).children().hide()
|
||||
@temp.option("width", $(el).width())
|
||||
@temp.option("height", $(el).height())
|
||||
$(el).children().show()
|
||||
|
||||
el = @find("battery-area")
|
||||
if @battery
|
||||
$(el).children().hide()
|
||||
@battery.option("width", $(el).width())
|
||||
@battery.option("height", $(el).height())
|
||||
$(el).children().show()
|
||||
|
||||
@_gui.pushService("SystemControl/SysmondService", [])
|
||||
.then (p) =>
|
||||
@service = p
|
||||
p.app = @
|
||||
.catch (e) =>
|
||||
@error __("Unable to start sysmond service"), e
|
||||
|
||||
streamline: (name, data, range, labels) ->
|
||||
i = 0
|
||||
legend = $(@find("#{name}-text"))
|
||||
if not @[name]
|
||||
options = {
|
||||
type: 'time.line',
|
||||
axes: ['bottom', 'left', "right"]
|
||||
}
|
||||
options.range = range if range
|
||||
dobj = []
|
||||
for item in data
|
||||
dobj.push { label: "label-#{i}", values: [] }
|
||||
$("<div>")
|
||||
.addClass('legend-color')
|
||||
.addClass('ref')
|
||||
.addClass('category' + (i+1))
|
||||
.appendTo(legend)
|
||||
$("<div>")
|
||||
.addClass('legend-label')
|
||||
.appendTo(legend)
|
||||
.text(if labels then labels[i] else "#{name}-#{i}")
|
||||
$("<div>")
|
||||
.addClass('legend-value')
|
||||
.appendTo(legend)
|
||||
i = i + 1
|
||||
options.data =dobj
|
||||
@[name] = $(@find("#{name}-area")).epoch(options)
|
||||
|
||||
for item in data
|
||||
$(legend.children()[i*3 + 2]).text( item.y.toString() )
|
||||
i = i + 1
|
||||
@[name].push data
|
||||
|
||||
feed: (data) ->
|
||||
#mem_percent = parseFloat(data.mem.match(/([0-9\.]+)%/)[1])
|
||||
#@memchart.push mem_percent / 100.0
|
||||
#@find("mem-text").text = data.mem
|
||||
|
||||
disk_used = data.disk_total - data.disk_free
|
||||
@diskchart.push(disk_used / data.disk_total)
|
||||
@find("disk-text").text = "Disk: " + (Math.round(disk_used / 1024 / 1024 / 1024)) + "/" + (Math.round(data.disk_total / 1024 / 1024 / 1024)) + " GB"
|
||||
|
||||
now = data.stamp_sec
|
||||
|
||||
data.cpu_usages.shift()
|
||||
cpu_data = ({ time: now, y: v.toFixed(2) } for v in data.cpu_usages)
|
||||
@streamline "cpu", cpu_data, [0, 100]
|
||||
|
||||
total_mem = data.mem_total / 1024.0 / 1024.0
|
||||
used_mem = data.mem_used / 1024.0 / 1024.0
|
||||
total_swap = data.mem_swap_total / 1024.0 / 1024.0
|
||||
used_swap = (data.mem_swap_total - data.mem_swap_free) / 1024.0 / 1024.0
|
||||
mem_data = [
|
||||
{ time: now, y: used_mem.toFixed(3)},
|
||||
{ time: now, y: used_swap.toFixed(3)}
|
||||
]
|
||||
mem_range = [0, if total_mem > total_swap then total_mem else total_swap]
|
||||
@streamline "memory", mem_data, mem_range, ["RAM (GB)", "SWAP (GB)"]
|
||||
|
||||
net_rx = 0
|
||||
net_tx = 0
|
||||
|
||||
net_rx = net_rx + v.rx_rate for v in data.net
|
||||
net_tx = net_tx + v.tx_rate for v in data.net
|
||||
net_data = [
|
||||
{ time: now, y: (net_rx / 1024.0).toFixed(3)},
|
||||
{ time: now, y: (net_tx / 1024.0).toFixed(3)}
|
||||
]
|
||||
@streamline "network", net_data, undefined, ["RX (Kb/s)", "TX (Kb/s)"]
|
||||
|
||||
|
||||
temp_data = [
|
||||
{ time: now, y: (data.cpu_temp / 1000.0).toFixed(2)},
|
||||
{ time: now, y: (data.gpu_temp / 1000.0).toFixed(2)}
|
||||
]
|
||||
@streamline "temp", temp_data, undefined, ["CPU temp (C)", "GPU temp (C)"]
|
||||
|
||||
battery_range = [
|
||||
(data.battery_min_voltage / 1000.0).toFixed(2),
|
||||
(data.battery_max_voltage / 1000.0).toFixed(2)]
|
||||
@streamline "battery", [ { time: now, y: (data.battery/ 1000.0).toFixed(2)} ], battery_range, ["Baterry (v)"]
|
||||
cleanup: () ->
|
||||
return unless @service
|
||||
@service.app = undefined
|
||||
@service = undefined
|
||||
|
||||
SystemControl.singleton = true
|
||||
SystemControl.dependencies = [
|
||||
"pkg://Antunnel/main.js"
|
||||
]
|
||||
this.OS.register "SystemControl", SystemControl
|
Reference in New Issue
Block a user