antos-frontend/src/core/gui/gui.coffee

109 lines
4.0 KiB
CoffeeScript
Raw Normal View History

2017-08-07 00:49:24 +02:00
self.OS.GUI =
init: () ->
query =
path: 'VFS/get'
data: "#{_GUI.tagPath}/tags.json"
self.OS.API.request query, ()->
2017-08-14 00:20:19 +02:00
loadScheme: (path,app) ->
_API.get path,
(x) ->
2017-08-11 01:58:46 +02:00
return null unless x
2017-08-14 00:20:19 +02:00
scheme = $.parseHTML x
2017-08-11 01:58:46 +02:00
($ "#desktop").append scheme
2017-08-14 00:20:19 +02:00
riot.mount ($ scheme), {observable:app.observable}
app.scheme = scheme[0]
app.show()
app.main()
, (f) ->
alert "cannot load scheme"
2017-08-07 00:49:24 +02:00
loadTheme: (name) ->
path = "resources/themes/#{name}/#{name}.css"
2017-08-11 01:58:46 +02:00
$ "head link#ostheme"
.attr "href", path
2017-08-14 00:20:19 +02:00
2017-08-11 01:58:46 +02:00
launch: (app) ->
if not _APP[app]
# first load it
2017-08-14 00:20:19 +02:00
path = "packages/#{app}/"
$.getScript path + "main.js"
2017-08-11 01:58:46 +02:00
.done (e,s) ->
2017-08-14 00:20:19 +02:00
#load css file
$.get "#{path}main.css", () ->
$ '<link>', {rel:'stylesheet', type:'text/css', 'href':"#{path}main.css"}
.appendTo 'head'
2017-08-11 01:58:46 +02:00
#launch
2017-08-14 00:20:19 +02:00
if _APP[app]
# load app meta data
_API.get "#{path}package.json",
(data) ->
_APP[app].meta = data
_PM.createProcess app, _APP[app]
console.log "Fist time loading "+app
,(e,s)->
alert "cannot read application, meta-data"
2017-08-11 01:58:46 +02:00
.fail (e,s) ->
#BUG report here
console.log "bug report"
else
2017-08-14 00:20:19 +02:00
# now launch it
if _APP[app]
_PM.createProcess app, _APP[app]
dock: (app,meta) ->
# dock an application to a dock
# create a data object
data =
icon:null
iconclass:meta.iconclass||""
app:app
onbtclick:() ->
app.toggle()
data.icon = "packages/#{meta.app}/#{meta.icon}" if meta.icon
data.iconclass = "fa fa-cogs" if (not meta.icon) and (not meta.iconclass)
dock = $ "#sysdock"
dock.get(0).newapp data
app.sysdock = dock.get(0)
app.appmenu = ($ "[data-id = 'appmenu']","#syspanel")[0]
app.init()
#app.show() -- notwork, sice the scheme is not loaded yet
undock: (app) ->
($ "#sysdock").get(0).removeapp app
2017-08-11 01:58:46 +02:00
initDM: ->
_API.resource "schemes/dm.html", (x) ->
return null unless x
scheme = $.parseHTML x
($ "#wrapper").append scheme
2017-08-14 00:20:19 +02:00
($ "#desktop").on "click", (e)->
return if e.target isnt ($ "#desktop").get(0)
($ "#sysdock").get(0).set "selectedApp",null
2017-08-11 01:58:46 +02:00
osmenu = {child:[
2017-08-14 00:20:19 +02:00
{text:"",iconclass:"fa fa-eercast", child:[
2017-08-11 01:58:46 +02:00
{text:"About"},
2017-08-14 00:20:19 +02:00
{text:"System Preferences", iconclass:"fa fa-commenting"},
{text:"Applications",child:[
{text:"Terminal",type:"app"},
{text:"NotePad",type:"app", icon:"packages/NotePad/icon.png"},
{text:"ActivityMonitor",type:"app"}
]},
2017-08-11 01:58:46 +02:00
{text:"Logout"}
]}
2017-08-14 00:20:19 +02:00
],onmenuselect: (item)->
switch item.data.type
when "app" then _GUI.launch item.data.text
2017-08-11 01:58:46 +02:00
}
2017-08-14 00:20:19 +02:00
appmenu = {child:[]}
2017-08-11 01:58:46 +02:00
systray = {child:[
{text:"Sun 22:57 6 August 2017"},
2017-08-14 00:20:19 +02:00
{text:"",iconclass:"fa fa-search"},
{text:"",iconclass:"fa fa-commenting"}
2017-08-11 01:58:46 +02:00
2017-08-14 00:20:19 +02:00
],onmenuselect: (item)->
console.log item
2017-08-11 01:58:46 +02:00
}
riot.mount ($ "#syspanel", $ "#wrapper"),{osmenu:osmenu,appmenu:appmenu,systray:systray}
2017-08-14 00:20:19 +02:00
riot.mount ($ "#sysdock", $ "#wrapper"), {items:[]}