add market place

This commit is contained in:
Xuan Sang LE 2020-05-19 01:03:49 +02:00
parent d1e8fd91dc
commit ff6f480f08
14 changed files with 353 additions and 216 deletions

View File

@ -49,10 +49,7 @@ coffees= src/core/core.coffee \
src/core/tags/SystemPanelTag.coffee \
src/antos.coffee
packages = CoreServices Files Setting CodePad
packages = CoreServices Files Setting CodePad MarketPlace
main: initd build_coffees build_themes libs build_packages languages
- cp src/index.html $(BUILDDIR)/

View File

@ -290,7 +290,7 @@ SelectionDialog.scheme = """
<afx-hbox data-height="30">
<div />
<afx-button data-id = "btnOk" text = "__(Ok)" data-width = "40" />
<afx-button data-id = "btnCancel" text = "__(Cancels)" data-width = "50" />
<afx-button data-id = "btnCancel" text = "__(Cancel)" data-width = "50" />
</afx-hbox>
</afx-vbox>
<div data-width = "10" />

View File

@ -208,14 +208,14 @@ Ant.OS.API =
r.responseType = "arraybuffer"
r.onload = (e) ->
if @status is 200 and @readyState is 4
resolve @response
Ant.OS.API.loaded q, p, "OK"
resolve @response
else
reject e, @
Ant.OS.API.loaded q, p, "FAIL"
reject Ant.OS.API.throwe __("Unable to get blob: {0}", p)
Ant.OS.API.loading q, p
r.send()
upload: (p, d) ->
new Promise (resolve, reject) ->
q = Ant.OS.announcer.getMID()

View File

@ -1,7 +1,7 @@
{
"app":"{0}",
"name":"{0}",
"description":"",
"description":"{0}",
"info":{
"author": "",
"email": ""

View File

@ -16,78 +16,67 @@
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
class RepositoryDialog extends this.OS.GUI.BaseDialog
class RepositoryDialog extends this.OS.GUI.subwindows.SelectionDialog
constructor: () ->
super "RepositoryDialog"
init: () ->
@_gui.htmlToScheme RepositoryDialog.scheme, @, @host
#@render "#{@meta().path}/repositorydia.html"
super()
main: () ->
me = @
@list = @find "repo-list"
@list.set "onlistdbclick", (e) ->
selidx = me.list.get "selidx"
return unless selidx >= 0
sel = me.systemsetting.system.repositories[selidx]
me.openDialog "PromptDialog", (e) ->
m = e.match /\[([^\]]*)\]\s*(.*)/
return me.error "Wrong format: it should be [name] url" if not m or m.length isnt 3
sel.name = m[1]
sel.text = sel.name
sel.url = m[2]
me.refreshList()
, __("Edit repository"), { label: __("Format : [name] url"), value: "[#{e.data.text}] #{e.data.url}" }
@list = @find "list"
$((@find "btnOk")).hide()
@list.set "buttons", [
{
text: "+",
onbtclick: () ->
me.openDialog "PromptDialog", (e) ->
m = e.match /\[([^\]]*)\]\s*(.*)/
return me.error __("Wrong format: it should be [name] url") if not m or m.length isnt 3
me.systemsetting.system.repositories.push {
name: m[1],
onbtclick: () =>
@openDialog("PromptDialog", {
title: __("Add repository"),
label: __("Format : [name] url")
}).then (e) =>
m = e.match /\[([^\]]*)\]\s*(.+)/
if not m or m.length isnt 3
return @error __("Wrong format: it should be [name] url")
repo = {
url: m[2],
text: m[1],
i: me.systemsetting.system.repositories.length
text: m[1]
}
me.refreshList()
, __("Add repository"), { label: __("Format : [name] url") }
@systemsetting.system.repositories.push repo
@list.push repo
},
{
text: "-",
onbtclick: () ->
selidx = me.list.get "selidx"
onbtclick: () =>
el = @list.get "selectedItem"
return unless el
selidx = $(el).index()
return unless selidx >= 0
me.systemsetting.system.repositories.splice selidx, selidx
me.refreshList()
@systemsetting.system.repositories.splice selidx, selidx
@list.remove el
},
{
iconclass: "fa fa-pencil",
onbtclick: () => @editRepo()
}
]
(@find "btquit").set "onbtclick", (e) -> me.quit()
@refreshList()
refreshList: () ->
ls = ({
text: v.name,
iconclass: "fa fa-link",
url: v.url,
complex: true,
detail: [{ text: v.url }]
} for v in @systemsetting.system.repositories)
@list.set "items", ls
editRepo: () ->
el = @list.get "selectedItem"
return unless el
selidx = $(el).index()
return unless selidx >= 0
data = el.get "data"
sel = @systemsetting.system.repositories[selidx]
@openDialog("PromptDialog", {
title: __("Edit repository"),
label: __("Format : [name] url"),
value: "[#{data.text}] #{data.url}"
}).then (e) =>
m = e.match /\[([^\]]*)\]\s*(.+)/
if not m or m.length isnt 3
return @error __("Wrong format: it should be [name] url")
data.text = m[1]
data.url = m[2]
@list.update()
@list.unselect()
onexit: (e) ->
@parent.repo.set "items", @systemsetting.system.repositories
@parent.dialog = undefined if @parent
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 style = "text-align:right; padding:5px" data-height="30" >
<afx-button data-id = "btquit" text = "__(Cancel)"></afx-button>
</div>
</afx-vbox>
</afx-app-window>
"""
@parent.refreshRepoList()
super.onexit e

View File

@ -16,25 +16,27 @@
# You should have received a copy of the GNU General Public License
#along with this program. If not, see https://www.gnu.org/licenses/.
self = this
class MarketPlace extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "MarketPlace", args
main: () ->
me = @
@installdir = @systemsetting.system.pkgpaths.user
# test repository
@apps_meta = []
@repo = @find "repo"
@repo.set "onlistselect", (e) ->
return unless e.data
me.fetchApps e.data.url
@repo.set "items", @systemsetting.system.repositories
@repo.set "onlistselect", (e) =>
data = e.data.item.get("data")
return unless data
@fetchApps data
@refreshRepoList()
@applist = @find "applist"
@applist.set "onlistselect", (e) ->
return unless e.data
me.appDetail e.data
@applist.set "onlistselect", (e) =>
data = e.data.item.get("data")
@appDetail data
@container = @find "container"
@appname = @find "appname"
@appdesc = @find "app-desc"
@ -42,39 +44,105 @@ class MarketPlace extends this.OS.GUI.BaseApplication
@btinstall = @find "bt-install"
@btremove = @find "bt-remove"
@btexec = @find "bt-exec"
($ @container ).css "visibility", "hidden"
@btexec.set "onbtclick", (e) ->
app = me.applist.get "selected"
return unless app
me._gui.launch app.className if app.className
@btinstall.set "onbtclick", (e) ->
return me.update() if me.btinstall.get "dirty"
me.install()
@btremove.set "onbtclick", (e) ->
me.uninstall()
@bindKey "CTRL-R", () ->
me.openDialog new RepositoryDialog()
fetchApps: (url) ->
me = @
@_api.get url, ( d ) ->
for v in d
v.text = v.name
v.iconclass = "fa fa-adn"
me.applist.set "items", d
, (e, s) ->
me.error __("Fail to fetch packages list from: {0}", url)
@searchbox = @find "searchbox"
($ @container).css "visibility", "hidden"
@btexec.set "onbtclick", (e) =>
el = @applist.get "selectedItem"
return unless el
app = el.get("data")
@_gui.launch app.className if app.className
@btinstall.set "onbtclick", (e) =>
if @btinstall.get "dirty"
return @update()
.then () => @notify __("Package updated")
.catch (e) => @error e.toString(), e
@remoteInstall()
.then () => @notify __("Package installed")
.catch (e) => @error e.toString(), e
@btremove.set "onbtclick", (e) =>
@uninstall()
.then () => @notify __("Packaged uninstalled")
.catch (e) => @error e.toString(), e
@bindKey "CTRL-R", () =>
@menuOptionsHandle "repos"
$(@searchbox).keyup (e) => @search e
refreshRepoList: () ->
list = (v for v in @systemsetting.system.repositories)
list.unshift {
text: "Installed"
}
@repo.set "data", list
search: (e) ->
switch e.which
when 37
e.preventDefault()
when 38
@applist.selectPrev()
e.preventDefault()
when 39
e.preventDefault()
when 40
@applist.selectNext()
e.preventDefault()
when 13
e.preventDefault()
else
text = @searchbox.value
@applist.set "data", (v for v in @apps_meta) if text.length is 2
return if text.length < 3
result = []
term = new RegExp text, 'i'
result.push v for v in @apps_meta when v.text.match term
@applist.set "data", result
fetchApps: (data) ->
if not data.url
pkgcache = @systemsetting.system.packages
list = []
for k, v of pkgcache
list.push {
className: v.app,
name: v.name,
text: v.name,
icon: v.icon,
iconclass: v.iconclass,
category: v.category,
author: v.info.author,
version: v.version,
description: "#{v.path}/REAME.md"
}
@apps_meta = list
@applist.set "data", list
return
@_api.get data.url
.then ( d ) =>
for v in d
v.text = v.name
v.iconclass = "fa fa-adn"
@apps_meta = d
@applist.set "data", d
.catch (e) ->
@error __("Fail to fetch packages list from: {0}", data.url), e
appDetail: (d) ->
me = @
($ @container).css "visibility", "visible"
( $ @appname ).html d.name
(@find "vstat").set "text", ""
if d.description
d.description.asFileHandler().read (text) ->
d.description.asFileHandle().read().then (text) =>
converter = new showdown.Converter()
($ me.appdesc).html converter.makeHtml text
($ @appdesc).html(converter.makeHtml text)
.catch (e) => @notify __("Unable to read package description")
else
($ me.appdesc).empty()
($ @appdesc).empty()
pkgcache = @systemsetting.system.packages
@btinstall.set "text", "__(Install)"
@btinstall.set "dirty", false
@ -89,7 +157,8 @@ class MarketPlace extends this.OS.GUI.BaseApplication
@btinstall.set "dirty", true
@btinstall.set "text", "__(Update)"
($ @btinstall).show()
(@find "vstat").set "text", __("Your application version is older ({0} < {1})", vs, ovs)
(@find "vstat").set "text",
__("Your application version is older ({0} < {1})", vs, ovs)
($ @btremove).show()
($ @btexec).show()
else
@ -98,111 +167,185 @@ class MarketPlace extends this.OS.GUI.BaseApplication
($ @btexec).hide()
($ @appdetail).empty()
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
for k, v of d when k isnt "name" and k isnt "description" and k isnt "domel"
($ @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 new RepositoryDialog()
{
text: "__(Options)", child: [
{ text: "__(Repositories)", shortcut: "C-R", id: "repos" },
{ text: "__(Install from zip)", shortcut: "C-I", id: "install" }
] , onchildselect: (e) =>
@menuOptionsHandle e.data.item.get("data").id
}
]
install: (f) ->
me = @
app = @applist.get "selected"
menuOptionsHandle: (id) ->
switch id
when "repos"
@openDialog new RepositoryDialog(), {
title: __("Repositories"),
data: @systemsetting.system.repositories
}
when "install"
@localInstall().then () =>
@notify __("Package installed")
.catch (e) => @error __("Unable to install package"), e
else
remoteInstall: () ->
el = @applist.get "selectedItem"
return unless el
app = el.get "data"
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
new Promise (resolve, reject) =>
@_api.blob app.download
.then (data) =>
@install data, app
.then () -> resolve()
.catch (e) -> reject(e)
.catch (e) -> reject e
localInstall: () ->
new Promise (resolve, reject) =>
@openDialog("FileDialog", {
title: "__(Select package archive)",
mimes: [".*/zip"]
}).then (d) =>
d.file.path.asFileHandle().read("binary").then (data) =>
@install data
.then (n) =>
@repo.unselect()
@repo.set "selected", 0
apps = (v.className for v in @applist.get("data"))
idx = apps.indexOf n
if idx >= 0
@applist.set "selected", idx
resolve()
.catch (e) -> reject(e)
.catch (e) -> reject e
.catch (e) -> reject e
install: (data, meta) ->
new Promise (resolve, reject) =>
JSZip.loadAsync(data).then (zip) =>
zip.file("package.json").async("string").then (d) =>
v = JSON.parse d
pth = "#{@installdir}/#{v.app}"
dir = [pth]
files = []
for name, file of zip.files
if file.dir
dir.push(pth + "/" + name)
else
files.push name
# create all directory
@mkdirs(dir).then () =>
@installFile(v.app, zip, files).then () =>
app_meta = {
className: v.app,
name: v.name,
text: v.name,
icon: v.icon,
iconclass: v.iconclass,
category: v.category,
author: v.info.author,
version: v.version,
description: if meta then meta.description else undefined,
download: if meta then meta.download else undefined
}
v.text = v.name
v.filename = app.className
v.filename = v.app
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: {0}", err)
, (err, s) ->
return me.error __("Cannot down load the app {0}", err) if err
uninstall: (f) ->
me = @
sel = @applist.get "selected"
name = sel.className
return unless sel
app = @systemsetting.system.packages[sel.className]
return unless app
@openDialog "YesNoDialog",
(d) ->
@systemsetting.system.packages[v.app] = v
@notify __("Application installed")
@appDetail app_meta
resolve(v.name)
.catch (e) -> reject e
.catch (e) -> reject e
.catch (err) -> reject err
.catch (e) -> reject e
uninstall: () ->
new Promise (resolve, reject) =>
el = @applist.get "selectedItem"
return unless el
sel = el.get "data"
return unless sel
name = sel.className
app = @systemsetting.system.packages[sel.className]
return unless app
@openDialog("YesNoDialog", {
title: __("Uninstall") ,
text: __("Uninstall: {0}?", app.name)
}).then (d) =>
return unless d
app.path.asFileHandler().remove (r) ->
return me.error __("Cannot uninstall package: {0}", r.error) if r.error
me.notify __("Package uninstalled")
delete me.systemsetting.system.packages[name]
me._gui.unloadApp name
me._gui.refreshSystemMenu()
me.appDetail sel
f() if f
, __("Uninstall") ,
{ text: __("Uninstall: {0}?", app.name) }
app.path.asFileHandle().remove().then (r) =>
if r.error
return reject @_api.throwe __("Cannot uninstall package: {0}", r.error)
@notify __("Package uninstalled")
delete @systemsetting.system.packages[name]
@_gui.unloadApp name
if sel.download
@appDetail sel
else
@applist.remove el
($ @container).css "visibility", "hidden"
resolve()
.catch (e) -> reject e
.catch (e) -> reject e
update: () ->
me = @
new Promise (r, e) ->
me.uninstall () ->
r()
.then () ->
me.install()
new Promise (resolve, reject) =>
@uninstall().then () =>
@remoteInstall()
.then () -> resolve()
.catch (e) -> reject e
.catch (e) -> reject e
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 {0}", "#{path}/#{dir}")
mkdirs: (list) ->
new Promise (resolve, reject) =>
return resolve() if list.length is 0
dir = (list.splice 0, 1)[0].asFileHandle()
path = dir.parent()
dname = dir.basename
path.asFileHandle().mk dname
.then (r) =>
return reject(@_api.throwe __("Cannot create {0}", "#{path}/#{dir}")) if r.error
@mkdirs list
.then () -> resolve()
.catch (e) -> reject e
.catch (e) -> reject e
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 {0}", path)
installFile: (n, zip, files) ->
new Promise (resolve, reject) =>
return resolve() if files.length is 0
file = (files.splice 0, 1)[0]
path = "#{@installdir}/#{n}/#{file}"
zip.file(file).async("uint8array").then (d) =>
fp = path.asFileHandle()
fp.cache = new Blob [d], { type: "octet/stream" }
fp.write "text/plain"
.then (r) =>
return reject @_api.throwe(__("Cannot install {0}", path)) if r.error
@installFile n, zip, files
.then () -> resolve()
.catch (e) -> reject()
.catch (e) -> reject e
.catch (e) -> reject e
MarketPlace.dependencies = [ "jszip.min", "showdown.min" ]
MarketPlace.dependencies = [
"os://scripts/jszip.min.js",
"os://scripts/showdown.min.js"
]
MarketPlace.singleton = true
this.OS.register "MarketPlace", MarketPlace

View File

@ -1,17 +1,9 @@
afx-app-window[data-id ='marketplace-win'] afx-resizer{
background-color: transparent;
border-left: 1px solid #cbcbcb;
}
afx-app-window[data-id ='marketplace-win'] afx-list-view[data-id='applist']{
background-color: #f6F6F6;
padding:0;
}
afx-app-window[data-id="marketplace-win"] afx-list-view[data-id='repo'] div.list-container{
z-index: 10;
}
afx-app-window[data-id="marketplace-win"] afx-vbox[data-id='container'] {
color: #414339;
overflow-y: auto;
}
afx-app-window[data-id="marketplace-win"] afx-vbox[data-id='container'] afx-hbox {
@ -21,7 +13,6 @@ afx-app-window[data-id="marketplace-win"] div[data-id='appname'] {
font-weight: bold;
font-size: 20px;
padding: 10px;
color: #414339;
}
afx-app-window[data-id="marketplace-win"] div[data-id='appname']:before {
@ -30,7 +21,6 @@ afx-app-window[data-id="marketplace-win"] div[data-id='appname']:before {
font-size: 25px;
font-style: normal;
margin-right: 10px;
color: #414339;
}
afx-app-window[data-id="marketplace-win"] p[data-id='app-desc'] {
text-align: justify;
@ -47,6 +37,23 @@ afx-app-window[data-id="marketplace-win"] ul[data-id='app-detail'] {
display: table;
margin: 0;
}
afx-app-window[data-id="marketplace-win"] afx-hbox[data-id="search-container"] {
border-bottom: 1px solid #afafaf;
}
afx-app-window[data-id="marketplace-win"] afx-hbox[data-id="search-container"] input{
border: 0;
background-color: transparent;
}
afx-app-window[data-id="marketplace-win"] div[data-id="searchicon"]:before{
content: "\f002";
display: block;
background-color:transparent;
color:#afafaf;
font-family: "FontAwesome";
padding-top: 3px;
padding-left:3px;
/* font-size: 25px; */
}
afx-app-window[data-id="marketplace-win"] ul[data-id='app-detail'] li{
padding:0;
margin: 0;

View File

@ -1,7 +1,7 @@
{
"app":"MarketPlace",
"name":"Application store",
"description":"Application store and repository management",
"description":"Application store",
"info":{
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
@ -9,5 +9,6 @@
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-adn",
"mimes":["none"]
"mimes":["none"],
"locales": {}
}

View File

@ -1,13 +1,17 @@
<afx-app-window data-id = "marketplace-win" apptitle="MarketPlace" width="500" height="400">
<afx-hbox >
<afx-vbox data-width = "172" data-id = "sidebar" min-width="172">
<afx-list-view data-id = "repo" dropdown = "true" data-height= "30" width = "150"></afx-list-view>
<afx-list-view data-id = "repo" dropdown = "true" data-height= "25" width = "150"></afx-list-view>
<afx-hbox data-height= "23" data-id="search-container">
<div data-width="17" data-id="searchicon"></div>
<input data-id = "searchbox" />
</afx-hbox>
<afx-list-view data-id = "applist" dropdown = "false" width = "150"></afx-list-view>
</afx-vbox>
<afx-resizer data-width = "3" ></afx-resizer>
<afx-vbox data-id = "container">
<div data-id = "appname" data-height = "25"></div>
<afx-hbox data-height = "grow">
<afx-hbox data-height = "30">
<div style = "text-align:left;">
<afx-button data-id = "bt-remove" text = "__(Uninstall)"></afx-button>
<afx-button data-id = "bt-exec" text = "__(Launch)"></afx-button>

View File

@ -102,14 +102,12 @@ afx-file-view afx-tree-view .afx-tree-view-item:before{
content: "\f016";
font-family: "FontAwesome";
font-size: 16px;
color: #414339;
font-style: normal;
font-weight: normal;
}
afx-file-view afx-tree-view div.afx_tree_item_selected, afx-file-view afx-tree-view div.afx_tree_item_selected:hover{
background-color: transparent;
color:#414339;
}
afx-file-view afx-tree-view li.itemname{

View File

@ -29,7 +29,7 @@ afx-list-view > div.list-container > ul > afx-list-item > li.selected{
}
afx-list-view.dropdown > div.list-container > ul{
border:1px solid #a6a6a6;
border:1px solid #262626;
box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.65);
border-radius: 3px;
max-height: 150px;
@ -42,7 +42,7 @@ afx-list-view.dropdown div.list-container div{
color: white;
padding-top:3px;
padding-bottom: 3px;
border:1px solid #a6a6a6;
border:1px solid #262626;
border-radius: 3px;
background-color: transparent;
height: 17px;
@ -55,14 +55,12 @@ afx-list-view.dropdown div.list-container div:before {
font-family: "FontAwesome";
font-size: 11px;
font-style: normal;
color: #414339;
position: absolute;
top:25%;
right: 5px;
}
afx-list-view.dropdown > div.list-container > ul li:hover{
background-color: #dcdcdc;
color: #414339;
background-color: #464646;
}
afx-list-view ul.complex-content{
padding: 0;

View File

@ -1,3 +1,4 @@
afx-resizer {
background-color: #868686;
background-color: transparent;
border-left: 1px solid #262626;
}

View File

@ -101,14 +101,12 @@ afx-file-view afx-tree-view .afx-tree-view-item:before{
content: "\f016";
font-family: "FontAwesome";
font-size: 16px;
color: #414339;
font-style: normal;
font-weight: normal;
}
afx-file-view afx-tree-view div.afx_tree_item_selected, afx-file-view afx-tree-view div.afx_tree_item_selected:hover{
background-color: transparent;
color:#414339;
}
afx-file-view afx-tree-view li.itemname{

View File

@ -1,3 +1,4 @@
afx-resizer {
background-color: #cbcbcb;
background-color: transparent;
border-left: 1px solid #868686;
}