antosdk-apps/ActivityMonitor/main.coffee

98 lines
3.4 KiB
CoffeeScript
Raw Permalink Normal View History

# Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
# AnTOS Web desktop is is licensed under the GNU General Public
# License v3.0, see the LICENCE file for more information
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
_PM = this.OS.PM
2020-06-05 17:45:07 +02:00
_APP = this.OS.application
class ActivityMonitor extends this.OS.application.BaseApplication
constructor: (args) ->
super "ActivityMonitor", args
main: () ->
2020-06-05 17:45:07 +02:00
@scheme.apptitle = "Activity Monitor"
@grid = @find "mygrid"
@on "btclick", (e) =>
return unless e.id == "btkill"
2020-06-05 17:45:07 +02:00
item = @grid.selectedRow
return unless item
2020-06-05 17:45:07 +02:00
data = item.data[0]
app = _PM.appByPid data.text
app.quit(true) if app
header = [
{
width: 50,
text: "__(Pid)"
},
{
text: "__(Name)"
},
{
text: "__(Type)",
width: 80
},
{
width: 80,
text: "__(Alive (ms))"
}
]
@gdata = {
processes: {}
alive: []
}
2020-06-05 17:45:07 +02:00
@grid.header = header
@monitor()
monitor: () ->
#get all current running process
@gdata.alive = []
now = (new Date).getTime()
$.each _PM.processes, (i, d) =>
$.each d , (j, a) =>
if @gdata.processes[a.pid] #update it
@gdata.processes[a.pid][3].text = now - a.birth
2022-06-03 19:30:11 +02:00
# @gdata.processes[a.pid][3].domel.update()
@grid.update()
else #add it
@gdata.processes[a.pid] = [
{ text: a.pid },
{
2020-06-05 20:31:39 +02:00
icon: if _APP[a.name].type == 0 then _APP[a.name].meta.icon else a.icon,
iconclass: if _APP[a.name].type == 0 then _APP[a.name].meta.iconclass else a.iconclass,
text: a.name
},
{
2020-06-05 20:28:35 +02:00
text: if _APP[a.name].type == 0 then "__(Application)" else "__(Service)"
},
{
text: now - a.birth
}
]
@grid.push @gdata.processes[a.pid]
@gdata.alive.push a.pid
$.each @gdata.processes, (i, e) =>
if ($.inArray (Number i), @gdata.alive) < 0
2020-06-05 17:45:07 +02:00
@grid.delete @gdata.processes[i].domel
@gdata.processes[i] = undefined
delete @gdata.processes[i]
@timer = setTimeout (() => @monitor()), 500
cleanup: (e) ->
clearTimeout @timer if @timer
ActivityMonitor.singleton = true
this.OS.register "ActivityMonitor", ActivityMonitor