Market now can update package to newer version

This commit is contained in:
Xuan Sang LE 2018-03-21 11:21:33 +01:00
parent 1b4f117060
commit da342ea574
22 changed files with 112 additions and 35 deletions

View File

@ -32,10 +32,10 @@ class BaseModel
render: (p) ->
_GUI.loadScheme p, @, @host
quit: () ->
quit: (force) ->
evt = new _GUI.BaseEvent("exit")
@onexit(evt)
if not evt.prevent
@onexit(evt) if not force
if force or not evt.prevent
delete @.observable
@dialog.quit() if @dialog
_PM.kill @

View File

@ -42,6 +42,46 @@ class FormatedString
args = arguments
@values[i] = args[i] for i in [0..args.length - 1]
class Version
constructor:(@string) ->
arr = @string.split "-"
br =
"r": 3,
"b": 2,
"a": 1
@branch = 3
@branch = br[arr[1]] if arr.length is 2 and br[arr[1]]
mt = arr[0].match /\d+/g
throw new Error __("Version string is in invalid format: {0}", @string) if not mt
@major = 0
@minor = 0
@patch = 0
@major = Number mt[0] if mt.length >= 1
@minor = Number mt[1] if mt.length >= 2
@patch = Number mt[2] if mt.length >= 3
# this function return
# 0 if the version is unchanged
# 1 if the current version is newer
# -1 if the current version is older
compare: (o) ->
other = o.__v()
return 1 if @branch > other.branch
return -1 if @branch < other.branch
return 0 if @major is other.major and @minor is other.minor and @patch is other.patch
return 1 if @major > other.major
return -1 if @major < other.major
return 1 if @minor > other.minor
return -1 if @minor < other.minor
return 1 if @patch > other.patch
return -1
nt: (o) ->
return (@compare o) is 1
ot: (o) ->
return (@compare o) is -1
__v: () -> @
toString: () -> @string
Object.defineProperty Object.prototype, '__',
value: () ->
return @toString()
@ -53,7 +93,8 @@ String.prototype.hash = () ->
i = this.length
hash = (hash * 33) ^ this.charCodeAt(--i) while i
hash >>> 0
String.prototype.__v = () ->
return new Version @
String.prototype.asBase64 = () ->
tmp = encodeURIComponent this
return btoa ( tmp.replace /%([0-9A-F]{2})/g, (match, p1) ->

View File

@ -103,11 +103,11 @@ self.OS or=
delete _PM.processes[app.name][i]
_PM.processes[app.name].splice i, 1
killAll: (app) ->
killAll: (app, force) ->
return unless _PM.processes[app]
tmp = []
tmp.push a for a in _PM.processes[app]
a.quit() for a in tmp
a.quit(force) for a in tmp
cleanup: ->
console.log "Clean up system"

View File

@ -133,10 +133,13 @@ self.OS.GUI =
forceLaunch: (app, args) ->
console.log "This method is used for developing only, please use the launch method instead"
_PM.killAll app
_GUI.unloadApp app
_GUI.launch app, args
unloadApp: (app) ->
_PM.killAll app, true
($ _OS.APP[app].style).remove() if _OS.APP[app] and _OS.APP[app].style
_OS.APP[app] = undefined
_GUI.launch app, args
loadApp: (app, ok, err) ->
path = "os://packages/#{app}"

View File

@ -29,7 +29,7 @@ class ActivityMonitor extends this.OS.GUI.BaseApplication
item = me.grid.get "selected"
return unless item
app = _PM.appByPid item[0].value
app.quit() if app
app.quit(true) if app
header = [{width:50,value: "__(Pid)"},{value:"__(Name)"}, {value:"__(Type)", width:80},{width:75,value: "__(Alive (ms))"}]
@gdata =

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-heartbeat",
"mimes":["none"]

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-cubes",
"mimes":[

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"Internet",
"iconclass":"fa fa-book",
"mimes":["none"]

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"Programming",
"iconclass":"fa fa-puzzle-piece",
"mimes":["none"]

View File

@ -9,7 +9,7 @@
"credit": "dedicated to some one here",
"licences": "GPLv3"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"mimes":["*"]
}

View File

@ -8,7 +8,7 @@
"credit": "dedicated to some one here",
"licences": "GPLv3"
},
"version":"0.1a",
"version":"0.0.2-a",
"category":"System",
"icon": "icon.png",
"mimes":["none"]

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-hdd-o",
"mimes":["dir"]

View File

@ -7,7 +7,7 @@
"email": "xsang.le@gmail.com",
"licences": "GPLv3"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"Office",
"iconclass": "fa fa-sitemap",
"mimes":["text/.*graphviz"]

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"Utils",
"iconclass":"fa fa-leanpub",
"mimes":["text/.*"]

View File

@ -48,9 +48,10 @@ class MarketPlace extends this.OS.GUI.BaseApplication
return unless app
me._gui.launch app.className if app.className
@btinstall.set "onbtclick", (e) ->
me.install e
return me.update() if me.btinstall.get "dirty"
me.install()
@btremove.set "onbtclick", (e) ->
me.uninstall e
me.uninstall()
@bindKey "CTRL-R", () ->
me.openDialog new RepositoryDialog()
fetchApps: (url) ->
@ -67,15 +68,28 @@ class MarketPlace extends this.OS.GUI.BaseApplication
me = @
($ @container).css "visibility", "visible"
( $ @appname ).html d.name
(@find "vstat").set "text", ""
if d.description
d.description.asFileHandler().read (text) ->
converter = new showdown.Converter()
($ me.appdesc).html converter.makeHtml text
else
($ me.appdesc).empty()
if @systemsetting.system.packages[d.className]
pkgcache = @systemsetting.system.packages
@btinstall.set "text", "__(Install)"
@btinstall.set "dirty", false
if pkgcache[d.className]
vs = pkgcache[d.className].version
ovs = d.version
($ @btinstall).hide()
if vs and ovs
vs = vs.__v()
ovs = ovs.__v()
if ovs.nt vs
@btinstall.set "dirty", true
@btinstall.set "text", "__(Update)"
($ @btinstall).show()
(@find "vstat").set "text", __("Your application version is older ({0} < {1})", vs, ovs)
($ @btremove).show()
($ @btexec).show()
else
@ -97,7 +111,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication
}
]
install: (e) ->
install: (f) ->
me = @
app = @applist.get "selected"
return unless app
@ -134,7 +148,7 @@ class MarketPlace extends this.OS.GUI.BaseApplication
, (err, s) ->
return me.error __("Cannot down load the app {0}", err) if err
uninstall: (e) ->
uninstall: (f) ->
me = @
sel = @applist.get "selected"
name = sel.className
@ -148,12 +162,21 @@ class MarketPlace extends this.OS.GUI.BaseApplication
return me.error __("Cannot uninstall package: {0}", r.error) if r.error
me.notify __("Package uninstalled")
delete me.systemsetting.system.packages[name]
window.OS.PM.killAll name
delete window.OS.APP[name]
me._gui.unloadApp name
me._gui.refreshSystemMenu()
me.appDetail sel
f() if f
, __("Uninstall") ,
{ text: __("Uninstall: {0}?", app.name) }
update: () ->
me = @
new Promise (r, e) ->
me.uninstall () ->
r()
.then () ->
me.install()
mkdirs: (n, list, f) ->
me = @
if list.length is 0

View File

@ -61,6 +61,15 @@ afx-app-window[data-id="marketplace-win"] ul[data-id='app-detail'] span{
afx-app-window[data-id="marketplace-win"] span.info-header{
font-weight: bold;
}
afx-app-window[data-id="marketplace-win"] afx-label[data-id="vstat"] {
font-size: 11px;
color: chocolate;
}
afx-app-window[data-id="marketplace-win"] p.stat {
margin: 0;
padding:0;
margin-bottom: 10px;
}
afx-app-window[data-id = "repository-dialog-win"] afx-list-view[data-id="repo-list"] ul.complex-content > li{
font-size: 11px;
font-style: italic;

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-adn",
"mimes":["none"]

View File

@ -7,14 +7,15 @@
<afx-resizer data-width = "3" ></afx-resizer>
<afx-vbox data-id = "container">
<div data-id = "appname" data-height = "25"></div>
<afx-hbox data-height = "25">
<afx-hbox data-height = "grow">
<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>
<afx-button data-id = "bt-install" text = "__(Install)" ></afx-button>
<p class="stat"><afx-label data-id="vstat"></afx-label></p>
</div>
</afx-hbox>
<div>
<div data-height = "grow">
<p data-id = "app-desc"></p>
<ul data-id = "app-detail"></ul>
</div>

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-pencil-square-o",
"mimes":[

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"Utils",
"iconclass":"fa fa-eye",
"mimes":["[^\/]*/.*pdf", "image/.*"]

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-wrench",
"mimes":["none"]

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.1a",
"version":"0.0.1-a",
"category":"System",
"iconclass":"fa fa-terminal",
"mimes":["none"]