2017-08-07 00:49:24 +02:00
|
|
|
self.OS.GUI =
|
|
|
|
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-15 02:56:04 +02:00
|
|
|
loadScheme: (path, app) ->
|
|
|
|
_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-14 00:20:19 +02:00
|
|
|
scheme = $.parseHTML x
|
2017-08-11 01:58:46 +02:00
|
|
|
($ "#desktop").append scheme
|
2017-08-15 02:56:04 +02:00
|
|
|
riot.mount ($ scheme), { observable: app.observable }
|
2017-08-14 00:20:19 +02:00
|
|
|
app.scheme = scheme[0]
|
|
|
|
app.main()
|
2017-08-15 02:56:04 +02:00
|
|
|
app.show()
|
2017-08-14 00:20:19 +02:00
|
|
|
, (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-15 02:56:04 +02:00
|
|
|
pushService: (srv) ->
|
|
|
|
return _PM.createProcess srv, _APP[srv] if _APP[srv]
|
|
|
|
path = "services/#{srv}.js"
|
|
|
|
$.getScript path
|
|
|
|
.done (e, s) ->
|
|
|
|
_PM.createProcess srv, _APP[srv]
|
|
|
|
.fail (e, s) ->
|
|
|
|
_courrier.trigger "fail",
|
|
|
|
{ m: "Cannot read service script: #{srv} ",
|
|
|
|
e: e, s: s }
|
|
|
|
|
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-15 02:56:04 +02:00
|
|
|
.done (e, s) ->
|
2017-08-14 00:20:19 +02:00
|
|
|
#load css file
|
|
|
|
$.get "#{path}main.css", () ->
|
2017-08-15 02:56:04 +02:00
|
|
|
$ '<link>', { rel: 'stylesheet', type: 'text/css', 'href': "#{path}main.css" }
|
2017-08-14 00:20:19 +02:00
|
|
|
.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
|
|
|
console.log "Fist time loading " + app
|
|
|
|
, (e, s) ->
|
|
|
|
_courrier.trigger "fail",
|
|
|
|
{ m: "Cannot read application metadata: #{app} ",
|
|
|
|
e: e, s: s }
|
|
|
|
alert "cannot read application, meta-data"
|
2017-08-11 01:58:46 +02:00
|
|
|
.fail (e,s) ->
|
|
|
|
#BUG report here
|
2017-08-15 02:56:04 +02:00
|
|
|
_courrier.trigger "fail",
|
|
|
|
{ m: "Cannot load application script: #{app}",
|
|
|
|
e: e, s:s }
|
|
|
|
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]
|
|
|
|
dock: (app,meta) ->
|
|
|
|
# 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-14 00:20:19 +02:00
|
|
|
app:app
|
2017-08-15 02:56:04 +02:00
|
|
|
onbtclick: () ->
|
2017-08-14 00:20:19 +02:00
|
|
|
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)
|
2017-08-15 02:56:04 +02:00
|
|
|
app.appmenu = ($ "[data-id = 'appmenu']", "#syspanel")[0]
|
2017-08-14 00:20:19 +02:00
|
|
|
app.init()
|
|
|
|
#app.show() -- notwork, sice the scheme is not loaded yet
|
|
|
|
|
|
|
|
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
|
|
|
|
#console.log ($ "#workspace").get(0), ($ e).parent().get(0)
|
|
|
|
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: [] }
|