mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-28 02:08:22 +01:00
add Market Place
This commit is contained in:
parent
b9a4448cb8
commit
98d57e0bd3
2
Makefile
2
Makefile
@ -22,7 +22,7 @@ coffees= src/core/core.coffee\
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
packages = CoreServices NotePad wTerm ActivityMonitor DummyApp Files MarkOn MarketPlace Blogger Preview
|
packages = CoreServices NotePad wTerm ActivityMonitor Files MarkOn MarketPlace Blogger Preview
|
||||||
|
|
||||||
main: build_coffees build_tags build_themes schemes libs build_packages
|
main: build_coffees build_tags build_themes schemes libs build_packages
|
||||||
- cp src/index.html $(BUILDDIR)/
|
- cp src/index.html $(BUILDDIR)/
|
||||||
|
@ -19,6 +19,12 @@ String.prototype.unescape = () ->
|
|||||||
d = d.replace /\\f/g, "\f"
|
d = d.replace /\\f/g, "\f"
|
||||||
d = d.replace /\\r/g, "\r"
|
d = d.replace /\\r/g, "\r"
|
||||||
d
|
d
|
||||||
|
String.prototype.asUnit8Array = () ->
|
||||||
|
bytes = []
|
||||||
|
for i in [0..(@length - 1)]
|
||||||
|
bytes.push @charCodeAt i
|
||||||
|
bytes = new Uint8Array(bytes)
|
||||||
|
return bytes
|
||||||
|
|
||||||
Date.prototype.toString = () ->
|
Date.prototype.toString = () ->
|
||||||
dd = @getDate()
|
dd = @getDate()
|
||||||
@ -202,11 +208,11 @@ self.OS.API =
|
|||||||
packages:
|
packages:
|
||||||
fetch: (f) ->
|
fetch: (f) ->
|
||||||
_API.handler.packages {
|
_API.handler.packages {
|
||||||
command: "list", args: { paths: _OS.setting.system.pkgpaths }
|
command: "list", args: { paths: (v for k, v of _OS.setting.system.pkgpaths) }
|
||||||
}, f
|
}, f
|
||||||
cache: (f) ->
|
cache: (f) ->
|
||||||
_API.handler.packages {
|
_API.handler.packages {
|
||||||
command: "cache", args: { paths: _OS.setting.system.pkgpaths }
|
command: "cache", args: { paths: (v for k, v of _OS.setting.system.pkgpaths) }
|
||||||
}, f
|
}, f
|
||||||
|
|
||||||
search: (text) ->
|
search: (text) ->
|
||||||
|
@ -7,6 +7,16 @@ self.OS.GUI =
|
|||||||
CTRL: {}
|
CTRL: {}
|
||||||
SHIFT: {}
|
SHIFT: {}
|
||||||
META: {}
|
META: {}
|
||||||
|
SYS_MENU: [
|
||||||
|
{
|
||||||
|
text: "Applications",
|
||||||
|
child: [],
|
||||||
|
dataid: "sys-apps"
|
||||||
|
iconclass: "fa fa-adn",
|
||||||
|
onmenuselect: (d) ->
|
||||||
|
_GUI.launch d.item.data.app
|
||||||
|
}
|
||||||
|
]
|
||||||
htmlToScheme: (html, app, parent) ->
|
htmlToScheme: (html, app, parent) ->
|
||||||
scheme = $.parseHTML html
|
scheme = $.parseHTML html
|
||||||
($ parent).append scheme
|
($ parent).append scheme
|
||||||
@ -324,38 +334,32 @@ self.OS.GUI =
|
|||||||
alert "System fall: Cannot init desktop manager"
|
alert "System fall: Cannot init desktop manager"
|
||||||
console.log s, e
|
console.log s, e
|
||||||
|
|
||||||
|
refreshSystemMenu: () ->
|
||||||
|
_GUI.SYS_MENU.length = 1
|
||||||
|
_GUI.SYS_MENU[0].child.length = 0
|
||||||
|
_GUI.SYS_MENU[0].child.push v for k, v of _OS.setting.system.packages when (v and v.app)
|
||||||
|
_GUI.SYS_MENU.push v for k, v of _OS.setting.system.menu
|
||||||
|
_GUI.SYS_MENU.push
|
||||||
|
text: "Toggle Full screen",
|
||||||
|
dataid: "os-fullsize",
|
||||||
|
iconclass: "fa fa-tv"
|
||||||
|
_GUI.SYS_MENU.push
|
||||||
|
text: "Log out",
|
||||||
|
dataid: "sys-logout",
|
||||||
|
iconclass: "fa fa-user-times"
|
||||||
buildSystemMenu: () ->
|
buildSystemMenu: () ->
|
||||||
|
|
||||||
menu =
|
menu =
|
||||||
text: ""
|
text: ""
|
||||||
iconclass: "fa fa-eercast"
|
iconclass: "fa fa-eercast"
|
||||||
dataid: "sys-menu-root"
|
dataid: "sys-menu-root"
|
||||||
child: [
|
child: _GUI.SYS_MENU
|
||||||
{
|
|
||||||
text: "Application",
|
|
||||||
child: ( v for k, v of _OS.setting.system.packages when v.app ),
|
|
||||||
dataid: "sys-apps"
|
|
||||||
iconclass: "fa fa-adn",
|
|
||||||
onmenuselect: (d) ->
|
|
||||||
_GUI.launch d.item.data.app
|
|
||||||
}
|
|
||||||
]
|
|
||||||
menu.child = menu.child.concat (v for k, v of _OS.setting.system.menu)
|
|
||||||
menu.child.push
|
|
||||||
text: "Toggle Full screen",
|
|
||||||
dataid: "os-fullsize",
|
|
||||||
iconclass: "fa fa-tv"
|
|
||||||
menu.child.push
|
|
||||||
text: "Log out",
|
|
||||||
dataid: "sys-logout",
|
|
||||||
iconclass: "fa fa-user-times"
|
|
||||||
menu.onmenuselect = (d) ->
|
menu.onmenuselect = (d) ->
|
||||||
return _OS.exit() if d.item.data.dataid is "sys-logout"
|
return _OS.exit() if d.item.data.dataid is "sys-logout"
|
||||||
return _GUI.toggleFullscreen() if d.item.data.dataid is "os-fullsize"
|
return _GUI.toggleFullscreen() if d.item.data.dataid is "os-fullsize"
|
||||||
_GUI.launch d.item.data.app unless d.item.data.dataid
|
_GUI.launch d.item.data.app unless d.item.data.dataid
|
||||||
|
menu = [menu]
|
||||||
|
($ "[data-id = 'os_menu']", "#syspanel")[0].set "items", menu
|
||||||
|
|
||||||
($ "[data-id = 'os_menu']", "#syspanel")[0].set "items", [menu]
|
|
||||||
#console.log menu
|
#console.log menu
|
||||||
|
|
||||||
|
|
||||||
@ -399,6 +403,7 @@ self.OS.GUI =
|
|||||||
v.mime = "antos/app"
|
v.mime = "antos/app"
|
||||||
v.iconclass = "fa fa-adn" unless v.iconclass or v.icon
|
v.iconclass = "fa fa-adn" unless v.iconclass or v.icon
|
||||||
_OS.setting.system.packages = if r.result then r.result else
|
_OS.setting.system.packages = if r.result then r.result else
|
||||||
|
_GUI.refreshSystemMenu()
|
||||||
_GUI.buildSystemMenu()
|
_GUI.buildSystemMenu()
|
||||||
# push startup services
|
# push startup services
|
||||||
# TODO: get services list from user setting
|
# TODO: get services list from user setting
|
||||||
|
@ -27,10 +27,10 @@
|
|||||||
apps: []
|
apps: []
|
||||||
} if not _OS.setting.system.startup
|
} if not _OS.setting.system.startup
|
||||||
|
|
||||||
_OS.setting.system.pkgpaths = [
|
_OS.setting.system.pkgpaths = {
|
||||||
"home:///.packages",
|
user: "home:///.packages",
|
||||||
"os:///packages"
|
system: "os:///packages"
|
||||||
] unless _OS.setting.system.pkgpaths
|
} unless _OS.setting.system.pkgpaths
|
||||||
_OS.setting.system.menu = {} unless _OS.setting.system.menu
|
_OS.setting.system.menu = {} unless _OS.setting.system.menu
|
||||||
_OS.setting.system.repositories = [] unless _OS.setting.system.repositories
|
_OS.setting.system.repositories = [] unless _OS.setting.system.repositories
|
||||||
_OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme
|
_OS.setting.appearance.theme = "antos" unless _OS.setting.appearance.theme
|
||||||
|
@ -163,11 +163,7 @@ class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
|||||||
.then (r) ->
|
.then (r) ->
|
||||||
_API.loaded q, "OK"
|
_API.loaded q, "OK"
|
||||||
return f r.body unless p is "binary"
|
return f r.body unless p is "binary"
|
||||||
bytes = []
|
f r.body.asUnit8Array()
|
||||||
for i in [0..(r.body.length - 1)]
|
|
||||||
bytes.push r.body.charCodeAt i
|
|
||||||
bytes = new Uint8Array(bytes)
|
|
||||||
f bytes
|
|
||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
_API.loaded q, "FAIL"
|
_API.loaded q, "FAIL"
|
||||||
_courrier.oserror "VFS cannot get read #{me.path}", (_API.throwe "OS.VFS"), err
|
_courrier.oserror "VFS cannot get read #{me.path}", (_API.throwe "OS.VFS"), err
|
||||||
|
15
src/libs/jszip.min.js
vendored
Executable file
15
src/libs/jszip.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
@ -4,7 +4,7 @@ jsfiles =
|
|||||||
|
|
||||||
cssfiles = main.css
|
cssfiles = main.css
|
||||||
|
|
||||||
copyfiles = repositorydia.html scheme.html package.json
|
copyfiles = scheme.html package.json
|
||||||
|
|
||||||
|
|
||||||
PKG_NAME=MarketPlace
|
PKG_NAME=MarketPlace
|
||||||
|
@ -3,7 +3,8 @@ class RepositoryDialog extends this.OS.GUI.BaseDialog
|
|||||||
super "RepositoryDialog"
|
super "RepositoryDialog"
|
||||||
|
|
||||||
init: () ->
|
init: () ->
|
||||||
@render "#{@meta().path}/repositorydia.html"
|
@_gui.htmlToScheme RepositoryDialog.scheme, @, @host
|
||||||
|
#@render "#{@meta().path}/repositorydia.html"
|
||||||
|
|
||||||
main: () ->
|
main: () ->
|
||||||
me = @
|
me = @
|
||||||
@ -15,4 +16,18 @@ class RepositoryDialog extends this.OS.GUI.BaseDialog
|
|||||||
($ me.url).html e.data.url
|
($ me.url).html e.data.url
|
||||||
@list.set "items", ls
|
@list.set "items", ls
|
||||||
|
|
||||||
|
RepositoryDialog.scheme = """
|
||||||
|
<afx-app-window data-id = "repository-dialog-win" apptitle="Repositories" width="250" height="250">
|
||||||
|
<afx-vbox >
|
||||||
|
<afx-list-view data-id="repo-list"></afx-list-view>
|
||||||
|
<div data-id="repo-url" data-height="grow"></div>
|
||||||
|
<afx-hbox data-height = "30">
|
||||||
|
<afx-button data-id = "btadd" text = "[+]" data-width="30"></afx-button>
|
||||||
|
<afx-button data-id = "btdel" text = "[-]" data-width="30"></afx-button>
|
||||||
|
<div></div>
|
||||||
|
<afx-button data-id = "btquit" text = "Cancel" data-width="50"></afx-button>
|
||||||
|
</afx-hbox>
|
||||||
|
</afx-vbox>
|
||||||
|
</afx-app-window>
|
||||||
|
"""
|
||||||
this.OS.register "RepositoryDialog", RepositoryDialog
|
this.OS.register "RepositoryDialog", RepositoryDialog
|
@ -1,13 +1,15 @@
|
|||||||
|
self = this
|
||||||
class MarketPlace extends this.OS.GUI.BaseApplication
|
class MarketPlace extends this.OS.GUI.BaseApplication
|
||||||
constructor: (args) ->
|
constructor: (args) ->
|
||||||
super "MarketPlace", args
|
super "MarketPlace", args
|
||||||
|
|
||||||
main: () ->
|
main: () ->
|
||||||
me = @
|
me = @
|
||||||
|
@installdir = @systemsetting.system.pkgpaths.user
|
||||||
# test repository
|
# test repository
|
||||||
@systemsetting.system.repositories.push {
|
@systemsetting.system.repositories.push {
|
||||||
text: "Antos repository"
|
text: "Antos repository"
|
||||||
url: "http://127.0.0.1:9191/repo/packages.json"
|
url: "https://os.localhost:9195/repo/packages.json"
|
||||||
name: "Antos repository"
|
name: "Antos repository"
|
||||||
selected:true
|
selected:true
|
||||||
} if @systemsetting.system.repositories.length is 0
|
} if @systemsetting.system.repositories.length is 0
|
||||||
@ -34,6 +36,10 @@ class MarketPlace extends this.OS.GUI.BaseApplication
|
|||||||
return unless app
|
return unless app
|
||||||
me._gui.launch app.className if app.className
|
me._gui.launch app.className if app.className
|
||||||
@btinstall.set "onbtclick", (e) ->
|
@btinstall.set "onbtclick", (e) ->
|
||||||
|
me.install e
|
||||||
|
@btremove.set "onbtclick", (e) ->
|
||||||
|
me.uninstall e
|
||||||
|
@bindKey "CTRL-R", () ->
|
||||||
me.openDialog "RepositoryDialog"
|
me.openDialog "RepositoryDialog"
|
||||||
fetchApps: (url) ->
|
fetchApps: (url) ->
|
||||||
me = @
|
me = @
|
||||||
@ -63,4 +69,97 @@ class MarketPlace extends this.OS.GUI.BaseApplication
|
|||||||
for k, v of d when k isnt "name" and k isnt "description"
|
for k, v of d when k isnt "name" and k isnt "description"
|
||||||
($ @appdetail).append $("<li>").append(($ "<span class= 'info-header'>").html k).append $("<span>").html v
|
($ @appdetail).append $("<li>").append(($ "<span class= 'info-header'>").html k).append $("<span>").html v
|
||||||
|
|
||||||
|
menu: () ->
|
||||||
|
me = @
|
||||||
|
return [
|
||||||
|
{ text: "Options", child: [
|
||||||
|
{ text: "Repositories", shortcut: "C-R" }
|
||||||
|
] , onmenuselect: (e) ->
|
||||||
|
me.openDialog "RepositoryDialog"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
install: (e) ->
|
||||||
|
me = @
|
||||||
|
app = @applist.get "selected"
|
||||||
|
return unless app
|
||||||
|
# get blob file
|
||||||
|
@_api.blob app.download, (data) ->
|
||||||
|
JSZip.loadAsync(data).then (zip) ->
|
||||||
|
pth = "#{me.installdir}/#{app.className}"
|
||||||
|
dir = [pth]
|
||||||
|
files = []
|
||||||
|
for name, file of zip.files
|
||||||
|
if file.dir
|
||||||
|
dir.push(pth + "/" + name)
|
||||||
|
else
|
||||||
|
files.push name
|
||||||
|
idx = files.indexOf "package.json"
|
||||||
|
return me.error "Invalid package: Meta data file not found" if idx < 0
|
||||||
|
# create all directory
|
||||||
|
me.mkdirs app.className, dir, () ->
|
||||||
|
me.installFile app.className, zip, files, () ->
|
||||||
|
zip.file("package.json").async("string").then (d) ->
|
||||||
|
v = JSON.parse d
|
||||||
|
console.log v
|
||||||
|
v.text = v.name
|
||||||
|
v.filename = app.className
|
||||||
|
v.type = "app"
|
||||||
|
v.mime = "antos/app"
|
||||||
|
v.iconclass = "fa fa-adn" unless v.iconclass or v.icon
|
||||||
|
v.path = pth
|
||||||
|
me.systemsetting.system.packages[app.className] = v
|
||||||
|
me.notify "Application installed"
|
||||||
|
me._gui.refreshSystemMenu()
|
||||||
|
me.appDetail app
|
||||||
|
.catch (err) ->
|
||||||
|
me.error "Error reading package meta data: " + err
|
||||||
|
|
||||||
|
, (err, s) ->
|
||||||
|
return me.error "Cannot down load the app #{err}" if err
|
||||||
|
uninstall: (e) ->
|
||||||
|
me = @
|
||||||
|
app = @applist.get "selected"
|
||||||
|
name = app.className
|
||||||
|
return unless app
|
||||||
|
app = @systemsetting.system.packages[app.className]
|
||||||
|
return unless app
|
||||||
|
@openDialog "YesNoDialog",
|
||||||
|
(d) ->
|
||||||
|
return unless d
|
||||||
|
app.path.asFileHandler().remove (r) ->
|
||||||
|
me.error "Cannot uninstall package: #{r.error}" if r.error
|
||||||
|
me.notify "Package uninstalled"
|
||||||
|
me.systemsetting.system.packages[name] = undefined
|
||||||
|
me._gui.refreshSystemMenu()
|
||||||
|
me.appDetail app
|
||||||
|
, "Uninstall" ,
|
||||||
|
{ text: "Uninstall : #{app.name} ?" }
|
||||||
|
mkdirs: (n, list, f) ->
|
||||||
|
me = @
|
||||||
|
if list.length is 0
|
||||||
|
f() if f
|
||||||
|
return
|
||||||
|
dir = (list.splice 0, 1)[0].asFileHandler()
|
||||||
|
path = dir.parent()
|
||||||
|
dname = dir.basename
|
||||||
|
path.asFileHandler().mk dname, (r) ->
|
||||||
|
return me.mkdirs n, list, f if r.result
|
||||||
|
me.error "Cannot create #{path}/#{dir}"
|
||||||
|
|
||||||
|
installFile: (n, zip, files, f) ->
|
||||||
|
me = @
|
||||||
|
if files.length is 0
|
||||||
|
f() if f
|
||||||
|
return
|
||||||
|
file = (files.splice 0, 1)[0]
|
||||||
|
path = "#{me.installdir}/#{n}/#{file}"
|
||||||
|
zip.file(file).async("uint8array").then (d) ->
|
||||||
|
fp = path.asFileHandler()
|
||||||
|
fp.cache = new Blob [d], { type: "octet/stream" }
|
||||||
|
fp.write "text/plain", (r) ->
|
||||||
|
return me.installFile n, zip, files, f if r.result
|
||||||
|
me.error "Cannot install #{path}"
|
||||||
|
|
||||||
|
MarketPlace.dependencies = [ "jszip.min" ]
|
||||||
this.OS.register "MarketPlace", MarketPlace
|
this.OS.register "MarketPlace", MarketPlace
|
@ -1,12 +0,0 @@
|
|||||||
<afx-app-window data-id = "repository-dialog-win" apptitle="Repositories" width="250" height="250">
|
|
||||||
<afx-vbox >
|
|
||||||
<afx-list-view data-id="repo-list"></afx-list-view>
|
|
||||||
<div data-id="repo-url" data-height="grow"></div>
|
|
||||||
<afx-hbox data-height = "30">
|
|
||||||
<afx-button data-id = "btadd" text = "[+]" data-width="30"></afx-button>
|
|
||||||
<afx-button data-id = "btdel" text = "[-]" data-width="30"></afx-button>
|
|
||||||
<div></div>
|
|
||||||
<afx-button data-id = "btquit" text = "Cancel" data-width="50"></afx-button>
|
|
||||||
</afx-hbox>
|
|
||||||
</afx-vbox>
|
|
||||||
</afx-app-window>
|
|
Loading…
Reference in New Issue
Block a user