refactory code

This commit is contained in:
lxsang
2020-05-11 19:52:31 +02:00
parent f5e5d8501b
commit c53fd8bd88
32 changed files with 554 additions and 655 deletions

View File

@ -24,18 +24,34 @@ class ActivityMonitor extends this.OS.GUI.BaseApplication
me = @
@scheme.set "apptitle", "Activity Monitor"
@grid = @find "mygrid"
@on "btclick", (e)->
@on "btclick", (e) ->
return unless e.id == "btkill"
item = me.grid.get "selected"
return unless item
app = _PM.appByPid item[0].value
app.quit(true) if app
header = [{width:50,value: "__(Pid)"},{value:"__(Name)"}, {value:"__(Type)", width:80},{width:75,value: "__(Alive (ms))"}]
@gdata =
processes:{}
alive:[]
@grid.set "header",header
header = [
{
width: 50,
text: "__(Pid)"
},
{
text: "__(Name)"
},
{
text: "__(Type)",
width: 80
},
{
width: 75,
text: "__(Alive (ms))"
}
]
@gdata =
processes: {}
alive: []
@grid.set "header", header
@monitor()
monitor: () ->
@ -43,34 +59,40 @@ class ActivityMonitor extends this.OS.GUI.BaseApplication
#get all current running process
me.gdata.alive = []
now = (new Date).getTime()
$.each _PM.processes, (i,d)->
$.each d , (j,a)->
$.each _PM.processes, (i, d) ->
$.each d , (j, a) ->
if me.gdata.processes[a.pid] #update it
me.gdata.processes[a.pid][3].value = now - a.birth
else #add it
me.gdata.processes[a.pid] = [
{value:a.pid},
{icon:if _APP[a.name].type == 1 then _APP[a.name].meta.icon else a.icon,
iconclass:if _APP[a.name].type == 1 then _APP[a.name].meta.iconclass else a.iconclass,
value:a.name},
{value: if _APP[a.name].type == 1 then "__(Application)" else "__(Service)"}
{value: now - a.birth}
{ text: a.pid },
{
icon: if _APP[a.name].type == 1 then _APP[a.name].meta.icon else a.icon,
iconclass: if _APP[a.name].type == 1 then _APP[a.name].meta.iconclass else a.iconclass,
text: a.name
},
{
text: if _APP[a.name].type == 1 then "__(Application)" else "__(Service)"
}
{
text: now - a.birth
}
]
me.gdata.alive.push a.pid
me.gdata.alive.push a.pid
@refreshGrid()
@timer = setTimeout (()-> me.monitor()),500#one second
@timer = setTimeout (() -> me.monitor()), 500
refreshGrid: ()->
refreshGrid: () ->
activeList = []
me = @
$.each @gdata.processes, (i,e) ->
if ($.inArray (Number i),me.gdata.alive) >= 0
$.each @gdata.processes, (i, e) ->
if ($.inArray (Number i), me.gdata.alive) >= 0
activeList.push e
else
else
me.gdata.processes[i] = undefined
@grid.set "rows",activeList
@grid.set "rows", activeList
cleanup: (e) ->
clearTimeout @timer if @timer
ActivityMonitor.singleton = true
this.OS.register "ActivityMonitor",ActivityMonitor
this.OS.register "ActivityMonitor", ActivityMonitor

View File

@ -1,4 +1,4 @@
coffee_files = Calendar.coffee PushNotification.coffee Spotlight.coffee UserService.coffee
coffee_files = Calendar.coffee PushNotification.coffee
jsfiles =

View File

@ -25,8 +25,6 @@ class PushNotification extends this.OS.GUI.BaseService
init: ->
@view = false
@_gui.htmlToScheme PushNotification.scheme, @, @host
#path = path = "#{@meta().path}/notifications.html"
#@render path
spin: (b) ->
if b and @iconclass is "fa fa-bars"
@ -60,24 +58,19 @@ class PushNotification extends this.OS.GUI.BaseService
i = me.pending.indexOf o.id
me.pending.splice i, 1 if i >= 0
me.spin false if me.pending.length is 0
@nzone.set "height", "100%"
@fzone.set "height", "100%"
($ @nzone).css "right", 0
.css "top", "-3px"
.css "height", "100%"
.css "bottom", "0"
.css "z-index", 1000000
.css "display", "flex"
.css "flex-direction", "column"
.hide()
($ @mlist).css "flex", "1"
($ @fzone)
#.css("z-index", 99999)
.css("bottom", "0")
.css("height", "100%")
.css "display", "flex"
.css "flex-direction", "column"
.css "bottom", "0"
.hide()
($ @mfeed).css "flex", "1"
pushout: (s, o, mfeed) ->
d = {
@ -96,6 +89,7 @@ class PushNotification extends this.OS.GUI.BaseService
($ @fzone).show()
timer = setTimeout () ->
me.mfeed.remove d.domel
($ me.fzone).hide() if me.mfeed.get("data").length is 0
clearTimeout timer
, 3000
@ -117,9 +111,9 @@ class PushNotification extends this.OS.GUI.BaseService
cleanup: (evt) ->
# do nothing
PushNotification.scheme = """
<divs>
<afx-overlay data-id = "notifyzone" width = "250">
<afx-button text = "__(Clear all)" data-id = "btclear" ></afx-button>
<div>
<afx-overlay data-id = "notifyzone" width = "250px">
<afx-button text = "__(Clear all)" data-id = "btclear" data-height="30"></afx-button>
<afx-list-view data-id="notifylist"></afx-list-view>
</afx-overlay>
<afx-overlay data-id = "feedzone" width = "250">

View File

@ -1,134 +0,0 @@
# 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/.
class SpotlightDialog extends this.OS.GUI.BaseDialog
constructor: () ->
super "SpotlightDialog"
init: () ->
#@render "#{@path()}/spotlight.html"
@_gui.htmlToScheme SpotlightDialog.scheme, @, @host
main: () ->
me = @
@height = ($ @scheme).css("height")
@container = @find "container"
($ @scheme).css("height", "45px")
@fn = (e) ->
if e.which is 27
($ document).unbind "click", me.fn1
($ document).unbind "keyup", me.fn
me.handler(e) if me.handler
me.quit()
($ document).keyup @fn
@fn1 = (e) ->
return if $(e.target).closest(me.parent.holder).length
if not $(e.target).closest(me.scheme).length
($ document).unbind "click", me.fn1
($ document).unbind "keyup", me.fn
me.handler(e) if me.handler
me.quit()
($ document).click @fn1
@searchbox = @find "searchbox"
($ @searchbox).focus()
($ @searchbox).keyup (e) ->
me.search e
@container.set "onlistdbclick", (e) ->
return if e.data.dataid and e.data.dataid is "header"
me.handler(e) if me.handler
me._gui.openWith e.data
($ document).unbind "click", me.fn1
($ document).unbind "keyup", me.fn
me.quit()
search: (e) ->
switch e.which
when 37
e.preventDefault()
when 38
@container.selectPrev()
e.preventDefault()
when 39
e.preventDefault()
when 40
@container.selectNext()
e.preventDefault()
when 13
e.preventDefault()
sel = @container.get "selected"
return unless sel
return if sel.dataid and sel.dataid is "header"
@.handler(e) if @.handler
@._gui.openWith sel
($ document).unbind "click", @fn1
($ document).unbind "keyup", @fn
@.quit()
else
text = @searchbox.value
($ @scheme).css("height", "45px")
return unless text.length >= 3
result = @_api.search text
return if result.length is 0
@container.set "data", result
console.log result
($ @scheme).css("height", @height)
SpotlightDialog.scheme = """
<afx-app-window data-id = "spotlight-win"
apptitle="" minimizable="false"
resizable = "false" width="500" height="300">
<afx-vbox>
<afx-hbox data-height="45">
<div data-id = "searchicon" data-width="45"></div>
<input type = "text" data-id="searchbox"/>
</afx-hbox>
<afx-list-view data-id="container"></afx-list-view>
</afx-vbox>
</afx-app-window>
"""
this.OS.register "SpotlightDialog", SpotlightDialog
class Spotlight extends this.OS.GUI.BaseService
constructor: (args) ->
super "Spotlight", args
@iconclass = "fa fa-search"
@show = false
init: ->
me = @
@_gui.bindKey "CTRL- ", (e) ->
me.awake(e)
main: ->
awake: (e) ->
me = @
if not @show
me.show = true
@openDialog "SpotlightDialog", (d) ->
me.show = false
me.dialog = undefined
else
me.show = false
@dialog.quit() if @dialog
cleanup: (evt) ->
# do nothing
this.OS.register "Spotlight", Spotlight

View File

@ -1,45 +0,0 @@
# 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/.
class UserService extends this.OS.GUI.BaseService
constructor: (args) ->
super "UserService", args
@text = @systemsetting.user.username
@iconclass = undefined
me = @
@children = [
{
text: "__(About)", dataid: "user-about",
iconclass: "fa fa-user-circle-o"
},
{
text: "__(Logout)", dataid: "sys-logout",
iconclass: "fa fa-user-times",
onmenuselect: (d) ->
me.notify __("This feature is not implemented yet")
}
]
init: ->
awake: (e) ->
cleanup: (evt) ->
this.OS.register "UserService", UserService

View File

@ -48,53 +48,4 @@ afx-list-view[data-id = "notifeed"] li{
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
}
afx-app-window[data-id = "spotlight-win"] .afx-window-wrapper{
background-color: white;
border-radius: 0px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
afx-app-window[data-id = "spotlight-win"] .afx-window-top{
height: 0;
border:0;
}
afx-app-window[data-id = "spotlight-win"] input{
border:0;
font-size: 25px;
color:#afafaf;
height: 45px;
}
afx-app-window[data-id = "spotlight-win"] div[data-id="searchicon"]:before{
content: "\f002";
padding-top:5px;
padding-left: 10px;
display: block;
background-color: #F6F6F6;
color:#afafaf;
width:40px;
height: 40px;
font-family: "FontAwesome";
font-size: 30px;
}
afx-app-window[data-id = "spotlight-win"] .afx-window-content{
border-radius: 10px;
}
afx-app-window[data-id = "spotlight-win"] afx-list-view[data-id="container"]{
border-top:1px solid #cacaca;
}
afx-app-window[data-id = "spotlight-win"] afx-list-view[data-id="container"] afx-label.search-header{
font-weight: bold;
}
afx-app-window[data-id = "spotlight-win"] afx-resizer{
background-color: transparent;
border-left: 1px solid #cacaca;
}
afx-app-window[data-id = "spotlight-win"] afx-list-view[data-id="container"] ul.complex-content li{
/*padding-left: 20px;*/
font-style: italic;
color: #b1b1b1;
font-size: 11px;
}

View File

@ -1,6 +1,6 @@
{
"app":null,
"services": [ "Calendar", "PushNotification", "Spotlight", "UserService" ],
"services": [ "Calendar", "PushNotification" ],
"name":"CoreServices",
"description":"This is the core services",
"info":{

View File

@ -27,18 +27,13 @@
</afx-hbox>
</afx-vbox>
</afx-hbox>
<afx-hbox tabname="Virtual desktop">
<afx-float-list data-id = "flist"/>
</afx-hbox>
<afx-hbox tabname="Calendar">
<afx-hbox tabname="Calendar & color picker">
<afx-calendar-view data-id = "cal"/>
</afx-hbox>
<afx-hbox tabname="Color picker">
<afx-color-picker data-id = "cpk"/>
</afx-hbox>
<afx-hbox tabname="File view">
<afx-vbox>
<afx-file-view data-id = "fileview"/>
<afx-file-view data-id = "fileview" view="icon" />
<afx-list-view data-id = "viewoption" data-height="30" dropdown="true" />
</afx-vbox>
</afx-hbox>

View File

@ -114,14 +114,6 @@ class ShowCase extends this.OS.GUI.BaseApplication
slider.set "onchanging", (v) ->
console.log v
flist = @find 'flist'
flist.set "data", [
{ text: "File.txt" },
{ text: "FileB.doc" },
{ text: "Data.doc", iconclass: "fa fa-camera-retro fa-lg" }
]
cal = @find 'cal'
cal.set "ondateselect", (e) ->
console.log e
@ -220,6 +212,15 @@ class ShowCase extends this.OS.GUI.BaseApplication
when "about"
me.openDialog("AboutDialog" )
.then (d) ->
when "file"
me.openDialog("FileDialog", {
title: "Select file ?",
#root: "home:///",
mimes: ["text/*", "dir"],
file: "Untitled".asFileHandle()
})
.then (f, name) ->
console.log f, name
else return

View File

@ -1,14 +0,0 @@
afx-app-window[data-id="example-show-case"] afx-grid-view div.afx-grid-row:nth-child(even) .afx-grid-cell
{
background-color: #f5F5F5;
}
afx-app-window[data-id="example-show-case"] afx-grid-view div.afx-grid-row-selected .afx-grid-cell
{
background-color: #116cd6;
color:white;
}
afx-app-window[data-id="example-show-case"] afx-grid-view div.afx-grid-row-selected .afx-grid-cell-selected
{
font-weight: bold;
}