diff --git a/TODO b/TODO index 09c95db..9c048d3 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ VFS mountpoints object (selected) is changed between apps, which is not a good ideal -API handler readfile function return JSON object in reading JSON file, need to be text Some error in event handle using observable \ No newline at end of file diff --git a/src/core/api.coffee b/src/core/api.coffee index e6e835d..b96ddb7 100644 --- a/src/core/api.coffee +++ b/src/core/api.coffee @@ -13,7 +13,7 @@ self.OS.API = url: p, contentType: 'application/json', data: JSON.stringify d, - dataType: 'json', # data type need to be configurable + dataType: 'json', success: null } #$.getJSON p, d @@ -86,10 +86,15 @@ self.OS.API = _courrier.trigger "loading", { id: q, data: { m: "#{p}", s: true }, name: "OS" } loaded: (q, p, m ) -> _courrier.trigger "loaded", { id: q, data: { m: "#{m}: #{p}", s: false }, name: "OS" } - get: (p, c, f) -> + get: (p, c, f, t) -> + conf = + type: 'GET', + url: p, + conf.dataType = t if t + q = _courrier.getMID() _API.loading q, p - $.get p # TODO add return type setting support + $.ajax conf .done (data) -> _API.loaded q, p, "OK" c(data) @@ -109,6 +114,12 @@ self.OS.API = resource: (r, c, f) -> path = "resources/#{r}" _API.get path, c, f + + packages: + fetch: (f) -> + _API.handler.packages { + command: "list", args: { paths: _OS.setting.system.pkgpaths } + }, f throwe: (n) -> err = undefined diff --git a/src/core/core.coffee b/src/core/core.coffee index 80f4f41..56524e2 100644 --- a/src/core/core.coffee +++ b/src/core/core.coffee @@ -11,6 +11,7 @@ self.OS or= desktop: {} appearance: {} VFS: {} + system: {} courrier: observable: riot.observable() quota: 0 @@ -33,7 +34,7 @@ self.OS or= _courrier.observable.off i.e, i.f for i in _courrier.listeners[app.pid] delete _courrier.listeners[app.pid] _courrier.listeners[app.pid] = [] - getMID: () -> + getMID: () -> _courrier.quota += 1 _courrier.quota register: (name, x) -> diff --git a/src/core/gui.coffee b/src/core/gui.coffee index 75a5296..df00588 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -14,7 +14,7 @@ self.OS.GUI = return null unless x _GUI.htmlToScheme x, app, parent , (e, s) -> - _courrier.osfail "Cannot load scheme file: #{path} for #{app.name} (#{app.pid})",e,s + _courrier.osfail "Cannot load scheme file: #{path} for #{app.name} (#{app.pid})", e, s clearTheme: () -> $ "head link#ostheme" @@ -244,7 +244,44 @@ self.OS.GUI = riot.mount desktop , (e, s) -> alert "System fall: Cannot init desktop manager" - + console.log s, e + + + buildSystemMenu: () -> + + menu = + text: "" + iconclass: "fa fa-eercast" + dataid: "sys-menu-root" + child: [ + { + text: "Application", + child: [], + dataid: "sys-apps" + iconclass: "fa fa-adn", + onmenuselect: (d) -> + _GUI.launch d.item.data.app + } + ] + menu.child = menu.child.concat _OS.setting.system.menu + menu.child.push + text: "Log out", + dataid: "sys-logout", + iconclass: "fa fa-user-times" + menu.onmenuselect = (d) -> + console.log d + return _API.handler.logout() if d.item.data.dataid is "sys-logout" + _GUI.launch d.item.data.app unless d.item.data.dataid + + #now get app list + _API.packages.fetch (r) -> + if r.result + v.text = v.name for k, v of r.result + menu.child[0].child = r.result if r.result + ($ "[data-id = 'os_menu']", "#syspanel")[0].set "items", [menu] + #console.log menu + + login: () -> _OS.cleanup() _API.resource "schemes/login.html", (x) -> @@ -269,13 +306,20 @@ self.OS.GUI = _OS.setting.appearance = conf.appearance if conf.appearance _OS.setting.user = conf.user _OS.setting.VFS = conf.VFS if conf.VFS - _OS.setting.VFS.mountpoints = [ #TODO: multi app try to write to this object, it neet to be cloned + _OS.setting.VFS.mountpoints = [ + #TODO: multi app try to write to this object, it neet to be cloned { text: "Applications", path: 'app:///', iconclass: "fa fa-adn", type: "app" }, { text: "Home", path: 'home:///', iconclass: "fa fa-home", type: "fs" }, { text: "OS", path: 'os:///', iconclass: "fa fa-inbox", type: "fs" }, - { text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop", type: "fs"}, + { text: "Desktop", path: 'home:///.desktop', iconclass: "fa fa-desktop", type: "fs" }, ] if not _OS.setting.VFS.mountpoints + _OS.setting.system = conf.system if conf.system + _OS.setting.system.pkgpaths = [ + "home:///.packages", + "os:///packages" + ] unless _OS.setting.system.pkgpaths + _OS.setting.system.menu = [] unless _OS.setting.system.menu _OS.setting.desktop.path = "home:///.desktop" unless _OS.setting.desktop.path _OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme # load theme @@ -286,9 +330,14 @@ self.OS.GUI = # TODO load packages list then build system menu # push startup services # TODO: get services list from user setting - _GUI.pushServices ["CoreServices/PushNotification", "CoreServices/Spotlight", "CoreServices/Calendar"] + _GUI.buildSystemMenu() + _GUI.pushServices [ + "CoreServices/PushNotification", + "CoreServices/Spotlight", + "CoreServices/Calendar" + ] # startup application here _courrier.observable.one "desktoploaded", () -> #_GUI.launch "DummyApp" - _GUI.launch "NotePad" \ No newline at end of file + #_GUI.launch "NotePad" \ No newline at end of file diff --git a/src/core/handlers/RemoteHandler.coffee b/src/core/handlers/RemoteHandler.coffee index 1ac7d1f..4dafb8d 100644 --- a/src/core/handlers/RemoteHandler.coffee +++ b/src/core/handlers/RemoteHandler.coffee @@ -17,6 +17,7 @@ self.OS.API.handler = path = "lua-api/fs/get/" _API.get path + p, c, (e, s) -> _courrier.osfail "Fail to read file: #{p}", e, s + , "text" move: (s, d, c) -> path = "lua-api/fs/move" @@ -33,6 +34,11 @@ self.OS.API.handler = _API.blob path + p, c, (e, s) -> _courrier.osfail "Fail to read file: #{p}", e, s + packages: (d, c) -> + path = "lua-api/system/packages" + _API.post path, d, c, (e, s) -> + _courrier.osfail "Fail to #{d.command} package", e, s + upload: (d, c) -> path = "lua-api/fs/upload" _API.upload path, d, c, (e, s) -> diff --git a/src/core/tags/afx-sys-panel.js b/src/core/tags/afx-sys-panel.js index 49f58c9..6391aff 100644 --- a/src/core/tags/afx-sys-panel.js +++ b/src/core/tags/afx-sys-panel.js @@ -6,33 +6,7 @@