antos-frontend/src/core/gui.coffee

137 lines
5.1 KiB
CoffeeScript
Raw Normal View History

2017-08-07 00:49:24 +02:00
self.OS.GUI =
2017-08-24 01:53:13 +02:00
dialog: new Object()
2017-08-07 00:49:24 +02:00
init: () ->
2017-08-15 02:56:04 +02:00
query =
2017-08-07 00:49:24 +02:00
path: 'VFS/get'
data: "#{_GUI.tagPath}/tags.json"
self.OS.API.request query, ()->
2017-08-24 01:53:13 +02:00
htmlToScheme: (html, app, parent) ->
scheme = $.parseHTML html
($ parent).append scheme
riot.mount ($ scheme), { observable: app.observable }
app.scheme = scheme[0]
app.main()
app.show()
loadScheme: (path, app, parent) ->
2017-08-15 02:56:04 +02:00
_API.get path,
2017-08-14 00:20:19 +02:00
(x) ->
2017-08-11 01:58:46 +02:00
return null unless x
2017-08-24 01:53:13 +02:00
_GUI.htmlToScheme x, app, parent
2017-08-26 16:50:13 +02:00
, (e, s) ->
_courrier.trigger "fail",
{id: 0, data: {
m: "Cannot load scheme file: #{path} for #{app.name} (#{app.pid})",e: e, s: s },
name:"OS"
}
2017-08-14 00:20:19 +02:00
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
pushServices: (srvs) ->
f = (v) ->
_courrier.observable.one "srvroutineready", () -> _GUI.pushService v
_GUI.pushService srvs[0]
srvs.splice 0, 1
f i for i in srvs
2017-08-15 02:56:04 +02:00
pushService: (srv) ->
return _PM.createProcess srv, _APP[srv] if _APP[srv]
path = "services/#{srv}.js"
2017-08-26 16:50:13 +02:00
_API.script path,
(d) ->
2017-08-15 02:56:04 +02:00
_PM.createProcess srv, _APP[srv]
2017-08-26 16:50:13 +02:00
, (e, s) ->
_courrier.trigger "srvroutineready", srv
2017-08-15 02:56:04 +02:00
_courrier.trigger "fail",
{ id:0,data:{m: "Cannot read service script: #{srv} ", e: e, s: s },
name:"0S"}
2017-08-15 02:56:04 +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}/"
2017-08-26 16:50:13 +02:00
_API.script path + "main.js",
(d) ->
2017-08-14 00:20:19 +02:00
#load css file
2017-08-26 16:50:13 +02:00
_API.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) ->
2017-08-15 02:56:04 +02:00
_APP[app].meta = data
2017-08-14 00:20:19 +02:00
_PM.createProcess app, _APP[app]
2017-08-15 02:56:04 +02:00
, (e, s) ->
_courrier.trigger "fail",
{id:0, data:{ m: "Cannot read application metadata: #{app} ",e: e, s: s }, name:"OS"}
2017-08-15 02:56:04 +02:00
alert "cannot read application, meta-data"
2017-08-26 16:50:13 +02:00
, (e, s) ->
2017-08-11 01:58:46 +02:00
#BUG report here
2017-08-15 02:56:04 +02:00
_courrier.trigger "fail",
{id :0, data:{m: "Cannot load application script: #{app}",
e: e, s:s }, name:"OS"}
2017-08-15 02:56:04 +02:00
console.log "bug report", e, s, path
2017-08-11 01:58:46 +02:00
else
2017-08-14 00:20:19 +02:00
# now launch it
if _APP[app]
_PM.createProcess app, _APP[app]
2017-08-26 16:50:13 +02:00
dock: (app, meta) ->
2017-08-14 00:20:19 +02:00
# dock an application to a dock
# create a data object
2017-08-15 02:56:04 +02:00
data =
icon: null
iconclass: meta.iconclass || ""
2017-08-26 16:50:13 +02:00
app: app
onbtclick: () -> app.toggle()
2017-08-14 00:20:19 +02:00
data.icon = "packages/#{meta.app}/#{meta.icon}" if meta.icon
2017-08-26 16:50:13 +02:00
# TODO: add default app icon class in system setting
# so that it can be themed
2017-08-14 00:20:19 +02:00
data.iconclass = "fa fa-cogs" if (not meta.icon) and (not meta.iconclass)
dock = $ "#sysdock"
2017-08-26 16:50:13 +02:00
app.one "rendered", () ->
dock.get(0).newapp data
app.sysdock = dock.get(0)
app.appmenu = ($ "[data-id = 'appmenu']", "#syspanel")[0]
2017-08-14 00:20:19 +02:00
app.init()
undock: (app) ->
($ "#sysdock").get(0).removeapp app
2017-08-15 02:56:04 +02:00
attachservice: (srv) ->
($ "#syspanel")[0].attachservice srv
srv.init()
detachservice: (srv) ->
($ "#syspanel")[0].detachservice srv
bindContextMenu: (event) ->
handler = (e) ->
if e.contextmenuHandler
e.contextmenuHandler event, ($ "#contextmenu")[0]
else
p = $(e).parent().get(0)
handler p if p isnt ($ "#workspace").get(0)
handler event.target
event.preventDefault()
2017-08-11 01:58:46 +02:00
initDM: ->
_API.resource "schemes/dm.html", (x) ->
return null unless x
2017-08-15 02:56:04 +02:00
scheme = $.parseHTML x
2017-08-11 01:58:46 +02:00
($ "#wrapper").append scheme
2017-08-15 02:56:04 +02:00
# context menu
riot.mount ($ "#contextmenu")
($ "#workspace").contextmenu (e) -> _GUI.bindContextMenu e
#desktop
desktop = ($ "#desktop")
desktop.on "click", (e) ->
return if e.target isnt desktop.get(0)
($ "#sysdock").get(0).set "selectedApp", null
desktop.get(0).contextmenuHandler = (e, m) ->
console.log "context menu handler for desktop"
# system menu
riot.mount ($ "#syspanel", $ "#wrapper")
riot.mount ($ "#sysdock", $ "#wrapper"), { items: [] }