Skip to content

Commit 067653b

Browse files
committed
Check new version and more
1 parent 4c46868 commit 067653b

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<widget id="me.zko.ionicnodeclub" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
2+
<widget id="me.zko.ionicnodeclub" version="0.0.4" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
33
<name>Ionic Nodeclub</name>
44
<description>
5-
一个Nodeclub开源社区系统的手机客户端
5+
一个Nodeclub开源社区系统的手机客户端;
66
一个基于Ionic框架的hybrid HTML5 app。
77
</description>
88
<author email="i@zko.me" href="http://zko.me">

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ionic-nodeclub",
3-
"version": "0.0.1",
3+
"version": "0.0.4",
44
"description": "An Ionic project",
55
"dependencies": {},
66
"devDependencies": {
@@ -19,10 +19,11 @@
1919
"org.apache.cordova.inappbrowser",
2020
"com.phonegap.plugins.barcodescanner",
2121
"com.verso.cordova.clipboard",
22-
"nl.x-services.plugins.toast"
22+
"nl.x-services.plugins.toast",
23+
"uk.co.whiteoctober.cordova.appversion"
2324
],
2425
"cordovaPlatforms": [
2526
"android",
2627
"ios"
2728
]
28-
}
29+
}

www/app/settings/settings.controller.coffee

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,42 @@ angular.module('ionic-nodeclub')
33
.controller 'SettingsCtrl', (
44
$scope
55
settings
6+
Restangular
7+
$cordovaAppVersion
68
) ->
79

10+
versionCompare = (v1, v2) ->
11+
return 0 if !v1 or !v2
12+
v1parts = v1.split('.').map(Number)
13+
v2parts = v2.split('.').map(Number)
14+
if v1parts.length > v2parts.length
15+
return 1
16+
if v1parts.length < v2parts.length
17+
return -1
18+
for i in [0...v1parts.length]
19+
if v1parts[i] is v2parts[i]
20+
continue
21+
else if v1parts[i] > v2parts[i]
22+
return 1
23+
else
24+
return -1
25+
return 0
26+
27+
if window.cordova
28+
$cordovaAppVersion.getAppVersion()
29+
.then (version) ->
30+
$scope.appVersion = version
31+
832
angular.extend $scope,
933
settings: settings.get()
34+
appVersion: null
35+
newVersionData: null
1036
updateSettings: ->
1137
settings.set($scope.settings)
1238

13-
# TODO
14-
# 1.打包的时候设置当前版本
15-
# 2.自动检查更新: http://fir.im/api/v2/app/version/5540b7aefe9978f3100002f4
39+
Restangular
40+
.oneUrl('getNewVersion', 'http://fir.im/api/v2/app/version/5540b7aefe9978f3100002f4')
41+
.get()
42+
.then (newVersionData) ->
43+
$scope.newVersionData = newVersionData
44+
$scope.hasNewVersion = versionCompare($scope.newVersionData.versionShort, $scope.appVersion)

www/app/settings/settings.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,19 @@
2828
</label>
2929
</div>
3030

31-
<div class="item">
32-
当前版本<span class="item-note">v0.001</span>
31+
<div class="item"
32+
ng-if="appVersion">
33+
当前版本<span class="item-note">{{::appVersion}}</span>
34+
</div>
35+
<div class="item"
36+
ng-if="appVersion && hasNewVersion">
37+
<a class="button button-positive button-full"
38+
external-link="{{::newVersionData.installUrl}}">
39+
下载更新
40+
<small class="text-note">
41+
{{::newVersionData.versionShort}}
42+
</small>
43+
</a>
3344
</div>
3445

3546
</div>

0 commit comments

Comments
 (0)