copay/js/controllers/head.js

74 lines
1.9 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, $timeout, notification, identityService, balanceService) {
$scope.username = $rootScope.iden ? $rootScope.iden.getName() : '';
$scope.hoverMenu = false;
var isChromeApp = typeof window !== "undefined" && window.chrome && chrome.runtime && chrome.runtime.id;
$scope.hoverIn = function() {
this.hoverMenu = true;
};
$scope.hoverOut = function() {
this.hoverMenu = false;
};
$scope.signout = function() {
identityService.signout();
};
$scope.refresh = function() {
var w = $rootScope.wallet;
if (!w) return;
if (w.isComplete()) {
w.sendWalletReady();
balanceService.clearBalanceCache(w);
balanceService.update(w, function() {
$rootScope.$digest();
}, true);
}
};
//Ensures a graceful disconnect
window.onbeforeunload = function() {
$scope.signout();
};
$scope.$on('$destroy', function() {
if (isChromeApp) return;
window.onbeforeunload = undefined;
});
$scope.init = function() {
if (!$rootScope.wallet) return;
$scope.$on('IdleStart', function() {});
$scope.$on('IdleWarn', function(a, countdown) {
$rootScope.countdown = countdown;
$rootScope.sessionExpired = true;
$rootScope.$apply();
});
$scope.$on('IdleEnd', function() {
$timeout(function() {
$rootScope.sessionExpired = null;
}, 500);
});
$scope.$on('IdleTimeout', function() {
$rootScope.sessionExpired = null;
$scope.signout();
notification.warning('Session closed', 'Session closed because a long time of inactivity');
});
$scope.$on('Keepalive', function() {
if ($rootScope.wallet) {
$rootScope.wallet.keepAlive();
}
});
$rootScope.$watch('title', function(newTitle, oldTitle) {
$scope.title = newTitle;
});
};
});