VFS(cont)

This commit is contained in:
Xuan Sang LE 2018-01-24 01:03:14 +01:00
parent a70f52f965
commit dfbeb16601
6 changed files with 34 additions and 19 deletions

View File

@ -9,12 +9,12 @@ class BaseModel
@setting = _OS.setting.applications[@name] @setting = _OS.setting.applications[@name]
@dialog = undefined @dialog = undefined
@subscribe "appregistry" @subscribe "appregistry"
,(m)-> , ( m ) ->
me.applySetting m.data.m if (m.name is me.name) me.applySetting m.data.m if (m.name is me.name)
registry: (k,v) -> registry: (k, v) ->
@setting[k] = v @setting[k] = v
@publish "appregistry",k @publish "appregistry", k
render: (p) -> render: (p) ->
_GUI.loadScheme p, @, @host _GUI.loadScheme p, @, @host
@ -70,6 +70,8 @@ class BaseModel
fail: (m) -> fail: (m) ->
@publish "fail", m @publish "fail", m
throwe: () ->
@_api.throwe @name
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme

View File

@ -55,3 +55,12 @@ self.OS.API =
path = "resources/#{r}" path = "resources/#{r}"
_API.get path, c, f _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

View File

@ -37,7 +37,7 @@ self.OS.GUI =
app = arr[0] app = arr[0]
return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv] return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv]
_GUI.loadApp app, _GUI.loadApp app,
(a)-> (a) ->
return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv] return _PM.createProcess srv, _OS.APP[srv] if _OS.APP[srv]
(e, s) -> (e, s) ->
_courrier.trigger "srvroutineready", srv _courrier.trigger "srvroutineready", srv
@ -49,7 +49,7 @@ self.OS.GUI =
_OS.APP[app] = undefined _OS.APP[app] = undefined
_GUI.launch app, args _GUI.launch app, args
loadApp:(app, ok, err) -> loadApp: (app, ok, err) ->
path = "packages/#{app}/" path = "packages/#{app}/"
_API.script path + "main.js", _API.script path + "main.js",
(d) -> (d) ->

View File

@ -2,12 +2,17 @@ self.OS.API.handler =
scandir: (p, c ) -> scandir: (p, c ) ->
path = "lua-api/fs/scandir" path = "lua-api/fs/scandir"
_API.post path, { path: p }, c, (e, s) -> _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) -> fileinfo: (p, c) ->
path = "lua-api/fs/fileinfo" path = "lua-api/fs/fileinfo"
_API.post path, { path: p }, c, (e, s) -> _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 ) -> scanapp: (p, c ) ->
path = "lua-api/system/application" path = "lua-api/system/application"

View File

@ -39,21 +39,21 @@ class BasicFileHandler
return @ if @isRoot() return @ if @isRoot()
(@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler() (@protocol + ":///" + (@genealogy.slice 0 , @genealogy.length - 1).join "/").asFileHandler()
onready: (f, e) -> onready: (f) ->
# read meta data # read meta data
return f() if @ready return f() if @ready
me = @ me = @
me.meta (d) -> 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.meta = d.result
me.ready = true me.ready = true
f() f()
#public interface for all action on file #public interface for all action on file
do: (a, f, e) -> do: (a, f) ->
return e "Action #{a} not found" if not @[a] return _courrier.osfail "VFS unknown action: #{a}", (_API.throwe "OS.VFS"), a if not @[a]
me = @ me = @
@onready (() -> me[a] f), e @onready (() -> me[a] f)
# methods implemented by subclasses used as private methods # methods implemented by subclasses used as private methods
@ -67,8 +67,6 @@ class BasicFileHandler
execute: (f) -> execute: (f) ->
ls: (f) ->
mk: (f) -> mk: (f) ->
# now export the class # now export the class
@ -82,9 +80,10 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler
meta: (f) -> meta: (f) ->
_API.handler.fileinfo @path, f _API.handler.fileinfo @path, f
ls: (f) -> read: (f) ->
return f(@) if @meta.type is "file" return _API.handler.scandir @path, f if @meta.type is "dir"
_API.handler.scandir @path, f #read the file
_API.handler.readfile @path, f
self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler self.OS.API.VFS.RemoteFileHandler = RemoteFileHandler

View File

@ -55,7 +55,7 @@ class PushNotification extends this.OS.GUI.BaseService
pushout: (s, o, mfeed) -> pushout: (s, o, mfeed) ->
d = { 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, icon: o.data.icon,
iconclass: o.data.iconclass, iconclass: o.data.iconclass,
closable: true } closable: true }