From 86e56ccc0c16d3e470d8a99bb20616136bb5d071 Mon Sep 17 00:00:00 2001 From: kraiz Date: Mon, 3 Nov 2014 22:12:07 +0100 Subject: [PATCH] added update check via github release api --- app/css/app.css | 2 +- app/index.html | 1 + app/js/app.js | 3 ++- app/js/controllers/main.js | 5 ++++- app/js/services/update.js | 33 +++++++++++++++++++++++++++++++++ app/partials/navbar.html | 14 ++++++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 app/js/services/update.js diff --git a/app/css/app.css b/app/css/app.css index 7962c5c..82c0566 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -12,7 +12,7 @@ } .navbar-status-label { - width: 75px; + min-width: 75px; display: block; float: left; } diff --git a/app/index.html b/app/index.html index 148c8f7..305d78d 100644 --- a/app/index.html +++ b/app/index.html @@ -17,6 +17,7 @@ + diff --git a/app/js/app.js b/app/js/app.js index d277a53..d89574c 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -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', + updateUrl: 'https://api.github.com/repos/kraiz/icecult/releases', chatMessagesKept: 250, refresh: { hashAndRatio: 5000, diff --git a/app/js/controllers/main.js b/app/js/controllers/main.js index 443c83c..e5c9aeb 100644 --- a/app/js/controllers/main.js +++ b/app/js/controllers/main.js @@ -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, @@ -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 () { diff --git a/app/js/services/update.js b/app/js/services/update.js new file mode 100644 index 0000000..811bd7b --- /dev/null +++ b/app/js/services/update.js @@ -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 + } +}); diff --git a/app/partials/navbar.html b/app/partials/navbar.html index 2574c4f..113e917 100644 --- a/app/partials/navbar.html +++ b/app/partials/navbar.html @@ -77,5 +77,19 @@ {{ queue.size | numeraljs:'0.0 b' }} +