From dfbeb1660174d258e366ce0fa2b9b647efaf97c6 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Wed, 24 Jan 2018 01:03:14 +0100 Subject: [PATCH] VFS(cont) --- src/core/BaseModel.coffee | 8 +++++--- src/core/api.coffee | 9 +++++++++ src/core/gui.coffee | 4 ++-- src/core/handlers/RemoteHandler.coffee | 11 ++++++++--- src/core/vfs.coffee | 19 +++++++++---------- .../CoreServices/PushNotification.coffee | 2 +- 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/core/BaseModel.coffee b/src/core/BaseModel.coffee index 9a01462..43db9b2 100644 --- a/src/core/BaseModel.coffee +++ b/src/core/BaseModel.coffee @@ -9,12 +9,12 @@ class BaseModel @setting = _OS.setting.applications[@name] @dialog = undefined @subscribe "appregistry" - ,(m)-> + , ( m ) -> me.applySetting m.data.m if (m.name is me.name) - registry: (k,v) -> + registry: (k, v) -> @setting[k] = v - @publish "appregistry",k + @publish "appregistry", k render: (p) -> _GUI.loadScheme p, @, @host @@ -70,6 +70,8 @@ class BaseModel fail: (m) -> @publish "fail", m + throwe: () -> + @_api.throwe @name find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme diff --git a/src/core/api.coffee b/src/core/api.coffee index c6df68a..b8f7bb0 100644 --- a/src/core/api.coffee +++ b/src/core/api.coffee @@ -54,4 +54,13 @@ self.OS.API = resource: (r, c, f) -> path = "resources/#{r}" _API.get path, c, f + + throwe: (n) -> + err = undefined + try + throw new Error(n) + catch e + err = e + return "" if not err + return err.stack diff --git a/src/core/gui.coffee b/src/core/gui.coffee index 333996d..b9af0ab 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -37,7 +37,7 @@ self.OS.GUI = app = arr[0] return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv] _GUI.loadApp app, - (a)-> + (a) -> return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv] (e, s) -> _courrier.trigger "srvroutineready", srv @@ -49,7 +49,7 @@ self.OS.GUI = _OS.APP[app] = undefined _GUI.launch app, args - loadApp:(app, ok, err) -> + loadApp: (app, ok, err) -> path = "packages/#{app}/" _API.script path + "main.js", (d) -> diff --git a/src/core/handlers/RemoteHandler.coffee b/src/core/handlers/RemoteHandler.coffee index b70613c..6433af6 100644 --- a/src/core/handlers/RemoteHandler.coffee +++ b/src/core/handlers/RemoteHandler.coffee @@ -2,13 +2,18 @@ self.OS.API.handler = scandir: (p, c ) -> path = "lua-api/fs/scandir" _API.post path, { path: p }, c, (e, s) -> - _courrier.osfail "Fail to scan directory: #{path}", e, s + _courrier.osfail "Fail to scan directory: #{p}", e, s fileinfo: (p, c) -> path = "lua-api/fs/fileinfo" _API.post path, { path: p }, c, (e, s) -> - _courrier.osfail "Fail to get file metadata: #{path}", e, s - + _courrier.osfail "Fail to get file metadata: #{p}", e, s + + readfile: (p, c) -> + path = "lua-api/fs/get/" + _API.get path + p, c, (e, s) -> + _courrier.osfail "Fail to read file: #{p}",e , s + scanapp: (p, c ) -> path = "lua-api/system/application" auth: (c) -> diff --git a/src/core/vfs.coffee b/src/core/vfs.coffee index bc12973..63bffe5 100644 --- a/src/core/vfs.coffee +++ b/src/core/vfs.coffee @@ -39,21 +39,21 @@ class BasicFileHandler return @ if @isRoot() (@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler() - onready: (f, e) -> + onready: (f) -> # read meta data return f() if @ready me = @ me.meta (d) -> - return e d.error if d.error + return _courrier.osfail d.error, (_API.throwe "OS.VFS"), d.error if d.error me.meta = d.result me.ready = true f() #public interface for all action on file - do: (a, f, e) -> - return e "Action #{a} not found" if not @[a] + do: (a, f) -> + return _courrier.osfail "VFS unknown action: #{a}", (_API.throwe "OS.VFS"), a if not @[a] me = @ - @onready (() -> me[a] f), e + @onready (() -> me[a] f) # methods implemented by subclasses used as private methods @@ -66,8 +66,6 @@ class BasicFileHandler remove: (f) -> execute: (f) -> - - ls: (f) -> mk: (f) -> @@ -82,9 +80,10 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler meta: (f) -> _API.handler.fileinfo @path, f - ls: (f) -> - return f(@) if @meta.type is "file" - _API.handler.scandir @path, f + read: (f) -> + return _API.handler.scandir @path, f if @meta.type is "dir" + #read the file + _API.handler.readfile @path, f self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler diff --git a/src/packages/CoreServices/PushNotification.coffee b/src/packages/CoreServices/PushNotification.coffee index 547b7bf..fc7fc04 100644 --- a/src/packages/CoreServices/PushNotification.coffee +++ b/src/packages/CoreServices/PushNotification.coffee @@ -55,7 +55,7 @@ class PushNotification extends this.OS.GUI.BaseService pushout: (s, o, mfeed) -> d = { - text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m}", + text: "[#{s}] #{o.name} (#{o.id}): #{o.data.m} : #{o.data.e}", icon: o.data.icon, iconclass: o.data.iconclass, closable: true }