From bb21c38ac15351cca03c94f775cdfefe6749f862 Mon Sep 17 00:00:00 2001 From: Nick Denry Date: Sun, 17 May 2020 21:12:36 +0300 Subject: [PATCH] Add checks for a new release available --- app/controllers/about-controller.js | 5 ++- app/controllers/default-controller.js | 44 +++++++++++++++++++++++++-- app/controllers/footer-controller.js | 7 +++++ app/init.js | 8 +++++ app/views/about/page.html | 2 +- app/views/default/page.html | 21 ++++++++++--- app/views/shared/_footer.html | 6 ++-- main.js | 2 +- renderer.js | 1 + resources/css/app.css | 10 ++++++ resources/css/page-default.css | 20 ++++++++++++ 11 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 app/controllers/footer-controller.js diff --git a/app/controllers/about-controller.js b/app/controllers/about-controller.js index 574e832..01b93ab 100644 --- a/app/controllers/about-controller.js +++ b/app/controllers/about-controller.js @@ -1,6 +1,9 @@ let angApp = require(__dirname+'/../init') -angApp.controller('AboutController', function($scope, AppStateService) { +angApp.controller('AboutController', function($scope, AppStateService, AppInfo) { + + $scope.appInfo = AppInfo + $scope.closeAbout = () => { AppStateService.set(AppStateService.previousState) } diff --git a/app/controllers/default-controller.js b/app/controllers/default-controller.js index e016471..c18bd50 100644 --- a/app/controllers/default-controller.js +++ b/app/controllers/default-controller.js @@ -1,5 +1,45 @@ let angApp = require(__dirname+'/../init') -angApp.controller('DefaultController', function($scope) { - // Do nothing atm. +angApp.controller('DefaultController', function($scope, $timeout, $http, AppInfo) { + + $scope.appInfo = AppInfo + + let getUpdateInfo = () => { + $http({ + url: $scope.appInfo.APP_RELEASES_CHECK_URL, + method: 'GET' + }).then((response) => { + let releaseVersion = response.data[0].tag_name + if (releaseVersion == $scope.appInfo.APP_VERSION) { + $scope.checkingForUpdate = 'latest' + } + else { + $scope.checkingForUpdate = 'updateAvailable' + } + }, (error) => { + $scope.checkingForUpdate = 'checkErr' + }) + } + + let checkForUpdate = (timeout = 5000) => { + $scope.checkingForUpdate = 'inProgress' + $timeout(() => { + getUpdateInfo() + }, timeout) + } + + let checkForUpdateDelayed = (timeout = 5000) => { + $timeout(() => { + checkForUpdate() + }, timeout) + } + + checkForUpdateDelayed() + + $scope.checkRetry = ($event) => { + $event.preventDefault() + checkForUpdate() + } + + }) \ No newline at end of file diff --git a/app/controllers/footer-controller.js b/app/controllers/footer-controller.js new file mode 100644 index 0000000..6747c82 --- /dev/null +++ b/app/controllers/footer-controller.js @@ -0,0 +1,7 @@ +let angApp = require(__dirname+'/../init') + +angApp.controller('FooterController', function($scope, AppInfo) { + + $scope.appInfo = AppInfo + +}) \ No newline at end of file diff --git a/app/init.js b/app/init.js index 95a6c9c..69c5575 100644 --- a/app/init.js +++ b/app/init.js @@ -1,4 +1,12 @@ const angular = require('angular') let angApp = angular.module('app', []) +angApp.constant('AppInfo', { + APP_NAME: 'Chimeverse', + APP_VERSION: 'v0.1.52', + APP_HOME: 'https://github.com/nick-denry/Chimeverse', + APP_RELEASES_CHECK_URL: 'https://api.github.com/repos/nick-denry/Chimeverse/releases', + APP_RELEASES_URL: 'https://github.com/nick-denry/Chimeverse/releases' +}); + module.exports = angApp \ No newline at end of file diff --git a/app/views/about/page.html b/app/views/about/page.html index 37e736d..47c8d36 100644 --- a/app/views/about/page.html +++ b/app/views/about/page.html @@ -6,7 +6,7 @@ class="chimeverse-branding__img" />
-

About Chimeverse v.0.1.52

+

About {{appInfo.APP_NAME}} {{appInfo.APP_VERSION}}

Jabber/XMPP client based on Converse.js and Electron
 
diff --git a/app/views/default/page.html b/app/views/default/page.html index e18c18d..de6efd7 100644 --- a/app/views/default/page.html +++ b/app/views/default/page.html @@ -1,9 +1,22 @@ -
-
+
+
-

Chimeverse

-
v0.1.52
+

{{appInfo.APP_NAME}}

+
+ {{appInfo.APP_VERSION}} + + checking for update... + + >_< check for update failed retry + + latest version + + Update available + + +
diff --git a/app/views/shared/_footer.html b/app/views/shared/_footer.html index 6581883..950c838 100644 --- a/app/views/shared/_footer.html +++ b/app/views/shared/_footer.html @@ -1,4 +1,4 @@ -