diff --git a/src/js/client.js b/src/js/client.js index 50ea2bfde..ede2cf489 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -967,6 +967,14 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.getPlatformStatus = function (callback) { + get('/api/v1/platform_status', null, function (error, data, status) { + if (error) return callback(error); + if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); + callback(null, data); + }); + }; + Client.prototype.setBackupConfig = function (backupConfig, callback) { post('/api/v1/settings/backup_config', backupConfig, null, function (error, data, status) { if (error) return callback(error); diff --git a/src/js/main.js b/src/js/main.js index fb095ac82..d46c25729 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -3,7 +3,7 @@ /* global angular */ /* global $ */ -angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', '$interval', 'Client', function ($scope, $route, $timeout, $location, $interval, Client) { +angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', '$interval', 'Notification', 'Client', function ($scope, $route, $timeout, $location, $interval, Notification, Client) { $scope.initialized = false; // used to animate the UI $scope.user = Client.getUserInfo(); $scope.installedApps = Client.getInstalledApps(); @@ -87,6 +87,35 @@ angular.module('Application').controller('MainController', ['$scope', '$route', if ($scope.initialized) redirectOnMandatory2FA(); }); + var gPlatformStatusNotification = null; + function trackPlatformStatus() { + Client.getPlatformStatus(function (error, result) { + if (error) return console.error('Failed to get platform status.', error); + + // see box/src/platform.js + if (result.message === 'Ready') { + if (gPlatformStatusNotification) { + gPlatformStatusNotification.kill(); + gPlatformStatusNotification = null; + } + + return; + } + + if (!gPlatformStatusNotification) { + var options = { title: 'Platform status', message: result.message, delay: 'notimeout', replaceMessage: true, closeOnClick: false }; + + Notification.primary(options).then(function (result) { + gPlatformStatusNotification = result; + $timeout(trackPlatformStatus, 1000); + }); + } else { + gPlatformStatusNotification.message = result.message; + $timeout(trackPlatformStatus, 1000); + } + }); + } + function init() { Client.getStatus(function (error, status) { if (error) return Client.initError(error, init); @@ -154,6 +183,8 @@ angular.module('Application').controller('MainController', ['$scope', '$route', $interval(refreshNotifications, 60 * 1000); refreshNotifications(); + trackPlatformStatus(); + $scope.updateSubscriptionStatus(); }); });