add shared library support

This commit is contained in:
Xuan Sang LE
2018-02-16 18:38:14 +01:00
parent dad5993c20
commit 13c6a1e9ff
23 changed files with 309 additions and 61 deletions

View File

@ -17,7 +17,7 @@ class SubWindow extends this.OS.GUI.BaseModel
@parent.meta()
show: () ->
@trigger 'focus'
($ @scheme).css "z-index", window._zindex+2
($ @scheme).css "z-index", window._zindex + 2
hide: () ->
@trigger 'hide'
@ -182,7 +182,7 @@ this.OS.register "InfoDialog", InfoDialog
class YesNoDialog extends BasicDialog
constructor: () ->
super "YesNoDialog", {
tags: [{ tag: "afx-label", att: "style = 'padding:10px;'" }],
tags: [{ tag: "afx-label", att: "style = 'padding-left:10px;'" }],
width: 300,
height: 100,
resizable: true,

View File

@ -20,6 +20,11 @@ class BaseModel
@dialog.quit() if @dialog
_PM.kill @
path: () ->
mt = @meta()
return mt.path if mt and mt.path
return null
init: ->
#implement by sub class
onexit: (e) ->

View File

@ -3,6 +3,7 @@ self.OS.API =
# fetch user data, used by the API to make requests
# handlers are defined in /src/handlers
handler: { }
shared: {} # shared libraries
#request a user data
post: (p, d, c, f) ->
q = _courrier.getMID()
@ -115,6 +116,33 @@ self.OS.API =
path = "resources/#{r}"
_API.get path, c, f
require: (l,f) ->
path = "os:///scripts/"
if not _API.shared[l]
js = "#{path}#{l}.js"
js.asFileHandler().onready (d) ->
_API.shared[l] = true
el = $ '<script>', { src: "#{_API.handler.get}/#{js}" }
.appendTo 'head'
#load css file
css = "#{path}#{l}.css"
css.asFileHandler().onready (d) ->
el = $ '<link>', { rel: 'stylesheet', type: 'text/css', 'href': "#{_API.handler.get}/#{css}" }
.appendTo 'head'
, () ->
console.log "loaded", l
_courrier.trigger "sharedlibraryloaded", l
f() if f
else
console.log l, "Library exist, no need to load"
_courrier.trigger "sharedlibraryloaded", l
requires:(libs, f) ->
return f() unless libs.length > 0
_courrier.observable.one "sharedlibraryloaded", (l) ->
libs.splice 0, 1
_API.requires libs, f
_API.require libs[0], null
packages:
fetch: (f) ->
_API.handler.packages {

View File

@ -44,21 +44,27 @@ self.OS or=
pidalloc: 0
processes: {}
createProcess: (app, cls, args) ->
#if it is single ton
# and a process is existing
# just return it
if cls.singleton and _PM.processes[app] and _PM.processes[app].length == 1
_PM.processes[app][0].show()
f = () ->
#if it is single ton
# and a process is existing
# just return it
if cls.singleton and _PM.processes[app] and _PM.processes[app].length == 1
_PM.processes[app][0].show()
else
_PM.processes[app] = [] if not _PM.processes[app]
obj = new cls(args)
obj.birth = (new Date).getTime()
_PM.pidalloc++
obj.pid = _PM.pidalloc
_PM.processes[app].push obj
if cls.type is 1 then _GUI.dock obj, cls.meta else _GUI.attachservice obj
if cls.type is 2
_courrier.trigger "srvroutineready", app
if cls.dependencies
libs = (v for v in cls.dependencies)
_API.requires libs, f
else
_PM.processes[app] = [] if not _PM.processes[app]
obj = new cls(args)
obj.birth = (new Date).getTime()
_PM.pidalloc++
obj.pid = _PM.pidalloc
_PM.processes[app].push obj
if cls.type is 1 then _GUI.dock obj, cls.meta else _GUI.attachservice obj
if cls.type is 2
_courrier.trigger "srvroutineready", app
f()
appByPid: (pid) ->
app = undefined
find = (l) ->

View File

@ -5,8 +5,8 @@ class DB
_API.handler.dbquery "save", { table: @table, data: d }, f
delete: (c, f) ->
rq = { table: @table }
return _courrier.oserror "Unknown condition for delete command",
(_API.throwe "OS.DB"), c unless c and c inst ""
return ( _courrier.oserror "Unknown condition for delete command",
(_API.throwe "OS.DB"), c ) unless c and c isnt ""
if isNaN c
rq.cond = c
else

View File

@ -26,12 +26,12 @@ self.OS.GUI =
.attr "href", path
pushServices: (srvs) ->
f = (v) ->
_courrier.observable.one "srvroutineready", () -> _GUI.pushService v
return unless srvs.length > 0
_courrier.observable.one "srvroutineready", () ->
srvs.splice 0, 1
_GUI.pushServices srvs
_GUI.pushService srvs[0]
srvs.splice 0, 1
f i for i in srvs
openDialog: (d, f, title, data) ->
if _GUI.dialog
_GUI.dialog.show()

View File

@ -1,5 +1,5 @@
self.OS.API.HOST = self.location.hostname+ (if self.location.port then":#{self.location.port}" else "")
self.OS.API.REST = "https://#{self.OS.API.HOST}/lua-api"
self.OS.API.REST = "#{self.location.protocol}//#{self.OS.API.HOST}/lua-api"
_REST = self.OS.API.REST
self.OS.API.handler =

View File

@ -7,7 +7,7 @@
<afx-label color = {item.color} iconclass = {item.iconclass} icon = {item.icon} text = {item.text}></afx-label>
<i if = {item.closable} class = "closable" click = {parent._remove}></i>
<ul if = {item.complex} class = "complex-content">
<li each = {ctn,j in item.content} class = {ctn.class}>{ctn.text}</li>
<li each = {ctn,j in item.detail} class = {ctn.class}>{ctn.text}</li>
</ul>
</li>
</ul>

View File

@ -70,7 +70,7 @@ class BaseFileHandler
me = @
me.meta (d) ->
if d.error
return if err then err d else _courrier.osfail d.error, (_API.throwe "OS.VFS"), d.error
return if err then err d else _courrier.osfail "#{me.path}: #{d.error}", (_API.throwe "OS.VFS"), d.error
me.info = d.result
me.ready = true
f()
@ -164,7 +164,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BaseFileHandler
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^(home|shared|desktop|os)$", RemoteFileHandler
self.OS.API.VFS.register "^(home|shared|desktop|os|Untitled)$", RemoteFileHandler
# Application Handler
class ApplicationHandler extends self.OS.API.VFS.BaseFileHandler
@ -206,4 +206,53 @@ class ApplicationHandler extends self.OS.API.VFS.BaseFileHandler
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^app$", ApplicationHandler
self.OS.API.VFS.register "^app$", ApplicationHandler
class BlobFileHandler extends self.OS.API.VFS.BaseFileHandler
constructor: (path, mime, data) ->
super path
@cache = data if data
@info =
mime: mime
path: path
size: if data then data.length else 0
name: @basename
type: "file"
meta: (f) ->
f()
onchange: (f) ->
@onchange = f
action: (n, p, f) ->
me = @
switch n
when "read"
return f { result: @cache }
when "mk"
return
when "write"
@cache = p
@onchange @ if @onchange
f { result: true }
when "upload"
# install
return
when "remove"
#uninstall
return
when "download"
blob = new Blob [@cache], { type: "octet/stream" }
_API.saveblob me.basename, blob
when "move"
return
else
return _courrier.osfail "VFS unknown action: #{n}", (_API.throwe "OS.VFS"), n
self.OS.API.VFS.register "^blob$", BlobFileHandler