Wallet/js/controllers/head.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-10-27 16:13:06 -03:00
'use strict';
2014-12-03 12:40:13 -03:00
angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, $timeout, notification, identityService, balanceService) {
$scope.username = $rootScope.iden.getName();
2014-10-27 16:13:06 -03:00
$scope.hoverMenu = false;
2014-12-05 11:56:26 -03:00
var isChromeApp = typeof window !== "undefined" && window.chrome && chrome.runtime && chrome.runtime.id;
$scope.hoverIn = function() {
2014-10-27 16:13:06 -03:00
this.hoverMenu = true;
};
$scope.hoverOut = function() {
2014-10-27 16:13:06 -03:00
this.hoverMenu = false;
};
$scope.signout = function() {
$rootScope.signingOut = true;
2014-11-30 00:31:17 -03:00
identityService.signout();
2014-10-27 16:13:06 -03:00
};
2014-10-31 12:14:47 -03:00
$scope.refresh = function() {
var w = $rootScope.wallet;
if (!w) return;
2014-11-30 00:31:17 -03:00
if (w.isComplete()) {
2014-10-31 12:14:47 -03:00
w.sendWalletReady();
2014-11-29 18:35:48 -03:00
balanceService.clearBalanceCache(w);
balanceService.update(w, function() {
$rootScope.$digest();
}, true);
2014-10-31 12:14:47 -03:00
}
};
2014-10-27 16:13:06 -03:00
2014-12-01 11:19:18 -03:00
2014-12-05 11:56:26 -03:00
//Ensures a graceful disconnect
window.onbeforeunload = function() {
$scope.signout();
};
2014-10-27 16:13:06 -03:00
2014-12-05 11:56:26 -03:00
$scope.$on('$destroy', function() {
if (isChromeApp) return;
window.onbeforeunload = undefined;
});
2014-10-27 16:13:06 -03:00
2014-12-03 12:40:13 -03:00
$scope.init = function() {
if (!$rootScope.wallet) return;
2014-12-03 00:36:44 -03:00
2014-12-03 12:40:13 -03:00
$scope.$on('$idleStart', function() {});
2014-10-27 16:13:06 -03:00
$scope.$on('$idleWarn', function(a, countdown) {
$rootScope.countdown = countdown;
$rootScope.sessionExpired = true;
});
$scope.$on('$idleEnd', function() {
$timeout(function() {
$rootScope.sessionExpired = null;
}, 500);
2014-10-27 16:13:06 -03:00
});
$scope.$on('$idleTimeout', function() {
$rootScope.sessionExpired = null;
2014-10-27 16:13:06 -03:00
$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;
});
2014-12-03 12:40:13 -03:00
};
2014-10-27 16:13:06 -03:00
});