2017-08-07 00:49:24 +02:00
|
|
|
self.OS.GUI =
|
2017-08-24 01:53:13 +02:00
|
|
|
dialog: new Object()
|
|
|
|
htmlToScheme: (html, app, parent) ->
|
|
|
|
scheme = $.parseHTML html
|
|
|
|
($ parent).append scheme
|
|
|
|
riot.mount ($ scheme), { observable: app.observable }
|
|
|
|
app.scheme = scheme[0]
|
|
|
|
app.main()
|
|
|
|
app.show()
|
2017-08-16 00:27:32 +02:00
|
|
|
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) ->
|
2017-08-27 23:40:02 +02:00
|
|
|
_courrier.osfail "Cannot load scheme file: #{path} for #{app.name} (#{app.pid})",e,s
|
|
|
|
|
|
|
|
clearTheme: () ->
|
|
|
|
$ "head link#ostheme"
|
|
|
|
.attr "href", ""
|
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
|
|
|
|
2017-08-16 00:27:32 +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
|
|
|
|
|
2018-01-22 19:59:08 +01:00
|
|
|
pushService: (ph) ->
|
|
|
|
arr = ph.split "/"
|
|
|
|
srv = arr[1]
|
|
|
|
app = arr[0]
|
2017-08-27 23:40:02 +02:00
|
|
|
return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv]
|
2018-01-22 19:59:08 +01:00
|
|
|
_GUI.loadApp app,
|
|
|
|
(a)->
|
|
|
|
return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv]
|
|
|
|
(e, s) ->
|
2017-08-16 00:27:32 +02:00
|
|
|
_courrier.trigger "srvroutineready", srv
|
2017-08-27 23:40:02 +02:00
|
|
|
_courrier.osfail "Cannot read service script: #{srv} ", e, s
|
2018-01-22 19:59:08 +01:00
|
|
|
|
2017-08-27 23:40:02 +02:00
|
|
|
forceLaunch: (app, args) ->
|
|
|
|
console.log "This method is used for developing only, please use the launch method instead"
|
|
|
|
_PM.killAll app
|
|
|
|
_OS.APP[app] = undefined
|
|
|
|
_GUI.launch app, args
|
|
|
|
|
2018-01-22 19:59:08 +01:00
|
|
|
loadApp:(app, ok, err) ->
|
|
|
|
path = "packages/#{app}/"
|
|
|
|
_API.script path + "main.js",
|
|
|
|
(d) ->
|
|
|
|
#load css file
|
|
|
|
_API.get "#{path}main.css",
|
|
|
|
() ->
|
|
|
|
$ '<link>', { rel: 'stylesheet', type: 'text/css', 'href': "#{path}main.css" }
|
|
|
|
.appendTo 'head'
|
|
|
|
, () ->
|
|
|
|
#launch
|
|
|
|
if _OS.APP[app]
|
|
|
|
# load app meta data
|
|
|
|
_API.get "#{path}package.json",
|
|
|
|
(data) ->
|
|
|
|
_OS.APP[app].meta = data
|
|
|
|
ok app
|
|
|
|
, (e, s) ->
|
|
|
|
_courrier.osfail "Cannot read application metadata: #{app}", e, s
|
|
|
|
err e, s
|
|
|
|
else
|
|
|
|
ok app
|
|
|
|
, (e, s) ->
|
|
|
|
#BUG report here
|
|
|
|
_courrier.osfail "Cannot load application script: #{app}", e, s
|
|
|
|
console.log "bug report", e, s, path
|
|
|
|
err e,s
|
2017-08-27 23:40:02 +02:00
|
|
|
launch: (app, args) ->
|
|
|
|
if not _OS.APP[app]
|
2017-08-11 01:58:46 +02:00
|
|
|
# first load it
|
2018-01-22 19:59:08 +01:00
|
|
|
_GUI.loadApp app,
|
|
|
|
(a)->
|
|
|
|
_PM.createProcess a, _OS.APP[a], args
|
2017-08-26 16:50:13 +02:00
|
|
|
, (e, s) ->
|
2017-08-11 01:58:46 +02:00
|
|
|
else
|
2017-08-14 00:20:19 +02:00
|
|
|
# now launch it
|
2017-08-27 23:40:02 +02:00
|
|
|
if _OS.APP[app]
|
|
|
|
_PM.createProcess app, _OS.APP[app], args
|
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: ->
|
2017-08-27 23:40:02 +02:00
|
|
|
# check login first
|
2017-08-11 01:58:46 +02:00
|
|
|
_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")
|
2017-08-27 23:40:02 +02:00
|
|
|
riot.mount ($ "#sysdock", $ "#wrapper"), { items: [] }
|
|
|
|
, (e, s) ->
|
|
|
|
alert "System fall: Cannot init desktop manager"
|
|
|
|
|
|
|
|
login: () ->
|
2018-01-04 11:51:12 +01:00
|
|
|
_OS.cleanup()
|
2017-08-27 23:40:02 +02:00
|
|
|
_API.resource "schemes/login.html", (x) ->
|
|
|
|
return null unless x
|
|
|
|
scheme = $.parseHTML x
|
|
|
|
($ "#wrapper").append scheme
|
|
|
|
($ "#btlogin").click () ->
|
|
|
|
data =
|
|
|
|
username: ($ "#txtuser").val(),
|
|
|
|
password: ($ "#txtpass").val()
|
|
|
|
_API.handler.login data, (d) ->
|
|
|
|
console.log d
|
|
|
|
if d.error then ($ "#login_error").html d.error else _GUI.startAntOS d.result
|
|
|
|
, (e, s) ->
|
|
|
|
alert "System fall: Cannot init login screen"
|
|
|
|
|
|
|
|
startAntOS: (conf) ->
|
2018-01-04 11:51:12 +01:00
|
|
|
_OS.cleanup()
|
2017-08-27 23:40:02 +02:00
|
|
|
_OS.setting.applications = conf.applications if conf.applications
|
|
|
|
_OS.setting.appearance = conf.appearance if conf.appearance
|
|
|
|
_OS.setting.user = conf.user
|
|
|
|
# get setting from conf
|
|
|
|
# load packages list
|
|
|
|
# load theme
|
|
|
|
# initDM
|
|
|
|
_GUI.loadTheme "antos"
|
|
|
|
_GUI.initDM()
|
|
|
|
_courrier.observable.one "syspanelloaded", () ->
|
2018-01-22 19:59:08 +01:00
|
|
|
#_GUI.loadApp "CoreServices", (a) ->
|
|
|
|
_GUI.pushServices ["CoreServices/PushNotification", "CoreServices/Spotlight", "CoreServices/Calendar"]
|