Skip to content

Commit

Permalink
added update check via github release api
Browse files Browse the repository at this point in the history
  • Loading branch information
kraiz committed Nov 3, 2014
1 parent b5a4f3c commit 86e56cc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

.navbar-status-label {
width: 75px;
min-width: 75px;
display: block;
float: left;
}
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="js/app.js"></script>
<script src="js/filters.js"></script>
<script src="js/services/rpc.js"></script>
<script src="js/services/update.js"></script>
<script src="js/controllers/main.js"></script>
<script src="js/controllers/hubs.js"></script>
<script src="js/controllers/browse.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion app/js/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

var EiskaltApp = angular.module('EiskaltApp', ['ngRoute', 'ngStorage', 'ngSanitize', 'luegg.directives', 'ui.bootstrap',
'angularBootstrapNavTree', 'EiskaltRPC', 'EiskaltFilters']);
'angularBootstrapNavTree', 'UpdateCheck', 'EiskaltRPC', 'EiskaltFilters']);

EiskaltApp.value('settings', {
version: '0.3.0',

This comment has been minimized.

Copy link
@mmrose

mmrose Nov 5, 2014

Collaborator

Since the commit tag indicates a version 0.4.0, should this also be version 0.4.0?

This comment has been minimized.

Copy link
@kraiz

kraiz Nov 5, 2014

Author Collaborator

I'm sure i set this to 0.4.0 but i'm also remembering that i decreased it for testing the update check.
Thanks for noting! I'll fix this and rerelease it as 0.4.1 soon.

updateUrl: 'https://api.github.com/repos/kraiz/icecult/releases',
chatMessagesKept: 250,
refresh: {
hashAndRatio: 5000,
Expand Down
5 changes: 4 additions & 1 deletion app/js/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

EiskaltApp.controller('MainCtrl', function ($scope, $location, $interval, settings, EiskaltRPC) {
EiskaltApp.controller('MainCtrl', function ($scope, $location, $interval, settings, EiskaltRPC, UpdateCheck) {
$scope.navbarCollapsed = true;
$scope.ratio = {
bandwidth_up: 0,
Expand All @@ -12,6 +12,9 @@ EiskaltApp.controller('MainCtrl', function ($scope, $location, $interval, settin
client: settings.version,
daemon: data
};
UpdateCheck.getNewerVersion($scope.version).success(function(newerVersion) {
$scope.newerVersion = newerVersion;
});
});

var refreshData = function () {
Expand Down
33 changes: 33 additions & 0 deletions app/js/services/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

angular.module('UpdateCheck', []).factory('UpdateCheck', function($http, settings) {

var api = settings.updateUrl + '?callback=JSON_CALLBACK';

var find = function(arr, name) {
console.log(name, arr);
var filtered = arr.filter(function(e) { return e.name === name});
console.log(filtered);
return filtered.length ? filtered[0] : null
}

var newVersion = function(currentVersion) {
var promise = $http.jsonp(api);
promise.success = function(fn) {
promise.then(function(response) {
if (response.status !== 200) {
fn(null);
}
var versions = response.data.data;
var latest = versions[0];
var current = find(versions, currentVersion.client);
fn(new Date(current.published_at) < new Date(latest.published_at) ? latest : null);
});
}
return promise;
}

return {
getNewerVersion: newVersion
}
});
14 changes: 14 additions & 0 deletions app/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,19 @@
{{ queue.size | numeraljs:'0.0 b' }}
</div>
</div>
<div class="navbar-right navbar-status" ng-show="newerVersion">
<div>
<span class="navbar-status-label">
<span class="glyphicon glyphicon-check"></span>
Update available:
</span>
{{ newerVersion.name }}
</div>
<div>
<a href="{{ newerVersion.html_url }}" target="_blank">
Download
</a>
</div>
</div>
</div>
</div>

0 comments on commit 86e56cc

Please sign in to comment.