From f5ff434152f40a6366f458f4ba9bca6bfece0e4e Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Wed, 31 Jan 2018 19:20:42 +0100 Subject: [PATCH] fix resource load --- src/core/gui.coffee | 42 +++++++++++-------------- src/core/handlers/RemoteHandler.coffee | 6 ++-- src/core/vfs.coffee | 6 ++-- src/packages/DummyApp/Makefile | 2 +- src/packages/DummyApp/icon.png | Bin 0 -> 1294 bytes src/packages/DummyApp/main.css | 7 +++++ 6 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 src/packages/DummyApp/icon.png diff --git a/src/core/gui.coffee b/src/core/gui.coffee index 98711fd..8910ebe 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -102,32 +102,27 @@ self.OS.GUI = _GUI.launch app, args loadApp: (app, ok, err) -> - path = "packages/#{app}/" - _API.script path + "main.js", - (d) -> + path = "os:///packages/#{app}" + path = _OS.setting.system.packages[app].path if _OS.setting.system.packages[app].path + js = path + "/main.js" + js.asFileHandler().read (d) -> #load css file - _API.get "#{path}main.css", - () -> - $ '', { rel: 'stylesheet', type: 'text/css', 'href': "#{path}main.css" } - .appendTo 'head' - , () -> + css = "#{path}/main.css" + css.asFileHandler().onready (d) -> + $ '', { rel: 'stylesheet', type: 'text/css', 'href': "#{_API.handler.get}/#{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 + "#{path}/package.json".asFileHandler().read (data) -> + data.path = path + _OS.APP[app].meta = data + ok app + , "json" 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 + , "script" launch: (app, args) -> if not _OS.APP[app] # first load it @@ -147,7 +142,8 @@ self.OS.GUI = iconclass: meta.iconclass || "" app: app onbtclick: () -> app.toggle() - data.icon = "packages/#{meta.app}/#{meta.icon}" if meta.icon + # TODO: this path is not good, need to create a blob of it + data.icon = "#{_API.handler.get}/#{meta.path}/#{meta.icon}" if meta.icon # TODO: add default app icon class in system setting # so that it can be themed data.iconclass = "fa fa-cogs" if (not meta.icon) and (not meta.iconclass) @@ -369,9 +365,9 @@ self.OS.GUI = "CoreServices/Spotlight", "CoreServices/Calendar" ] + #_GUI.launch "DummyApp" # startup application here _courrier.observable.one "desktoploaded", () -> - console.log "startup app" - _GUI.launch "DummyApp" + #_GUI.launch "DummyApp" #_GUI.launch "NotePad" \ No newline at end of file diff --git a/src/core/handlers/RemoteHandler.coffee b/src/core/handlers/RemoteHandler.coffee index 4dafb8d..e41de56 100644 --- a/src/core/handlers/RemoteHandler.coffee +++ b/src/core/handlers/RemoteHandler.coffee @@ -1,4 +1,6 @@ self.OS.API.handler = + get: "lua-api/fs/get" + scandir: (p, c ) -> path = "lua-api/fs/scandir" _API.post path, { path: p }, c, (e, s) -> @@ -13,11 +15,11 @@ self.OS.API.handler = _API.post path, { path: p }, c, (e, s) -> _courrier.osfail "Fail to get file metadata: #{p}", e, s - readfile: (p, c) -> + readfile: (p, c, t) -> path = "lua-api/fs/get/" _API.get path + p, c, (e, s) -> _courrier.osfail "Fail to read file: #{p}", e, s - , "text" + , t move: (s, d, c) -> path = "lua-api/fs/move" diff --git a/src/core/vfs.coffee b/src/core/vfs.coffee index f2ae311..d0c24de 100644 --- a/src/core/vfs.coffee +++ b/src/core/vfs.coffee @@ -68,9 +68,9 @@ class BasicFileHandler me.ready = true f() - read: (f) -> + read: (f, t) -> me = @ - @onready (() -> me.action "read", null, f) + @onready (() -> me.action "read", t, f) write: (d, f) -> me = @ @@ -136,7 +136,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BasicFileHandler when "read" return _API.handler.scandir @path, f if @info.type is "dir" #read the file - _API.handler.readfile @path, f + _API.handler.readfile @path, f, if p then p else "text" when "mk" return f { error: "#{@path} is not a directory" } if @info.type is "file" _API.handler.mkdir "#{@path}/#{p}", f diff --git a/src/packages/DummyApp/Makefile b/src/packages/DummyApp/Makefile index 159e7bd..b2eb2d7 100644 --- a/src/packages/DummyApp/Makefile +++ b/src/packages/DummyApp/Makefile @@ -4,7 +4,7 @@ jsfiles = cssfiles = main.css -copyfiles = scheme.html package.json +copyfiles = scheme.html package.json icon.png PKG_NAME=DummyApp diff --git a/src/packages/DummyApp/icon.png b/src/packages/DummyApp/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6073c9c6fff7200f09fdf934ac464548ddb76fc0 GIT binary patch literal 1294 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+081LN8NpAc7|f}0F#HyG4` z=sJT2oc*7H;XZ=`P~OC`ZZoJ{WYB{sxW=IQm_Y`j3nB$!UuDpSFpx=z7NE!( z24kSHKr?}CAPHf>RRXy{m2kyCaiD1skvj~^5M}!r93TpSis5$MVo-$`2qb}QhytJs zfn1=Qfh5EnAOnIR7D3oRCqdN1jRlHB*g)?C89)<&B*Y4cI7A~*1Y!=51d0HygV+d> zh1d&`0*c&%g)oo}Gz9JdWClbd+%yOmnFPkv!HWxJfK+cukY6x^&C%Hof&`9oD2W{O5)jkTg~Q|{^Gsl8Rh*#;op-ts@cAo%Ubtu*OK;r&oYic!)))b0oxv2GC1LN@QIPm zg%9_&9xv>Wa#@=HJH^fH%kl+_8xso}=E;A2src%tv%s8fK!-6VdAqwXbg;^L06Clm z9+Absqll>IEGl9-a0Wf+{sa-b$g=% zTiNzS5*?gkWl81cN!n%R+n(E78^<`T)2S@7zf=6|P5#+4^SCQC6$~^a>OBOVT)aeI zJ6+8xopC3ub#j1!ax8oJRHx{aB+A(%|u2HN0sk!owxA*h=Jw6$mQXIXNSt|UN_HQ>P$wC zQdXX0cAtn_P=<8;_Tvi{Pd1NbEBWq`*rMZDbM3QE8}E+RgCdfxu1oH>ru1c9ut{dAwtt@Rw)#sn0HjFIwlR9H?cv z{B-JT*>$n?7mGcY=cyccCAA~j%jh)Y&Xfah@9tgF9ytHN;^*&ef3nDIu;aFjnH+y$ z@8*qvIeGT}U@Tc**RZ|ZzTv+0AN~&?UrPTlGW;y9m1e=SqC+lpinR(g8$%zH2dih1^v)|cB0TnTLy85}Sb4q9e0CFndX8-^I literal 0 HcmV?d00001 diff --git a/src/packages/DummyApp/main.css b/src/packages/DummyApp/main.css index e69de29..01c49a5 100644 --- a/src/packages/DummyApp/main.css +++ b/src/packages/DummyApp/main.css @@ -0,0 +1,7 @@ +.dummyapp-icon { + background-image: url("icon.png"); + background-color: blueviolet; + display: block; + width: 32px; + height: 32px; +} \ No newline at end of file