copay/js/controllers/head.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-10-27 12:13:06 -07:00
'use strict';
2014-12-03 07:40:13 -08:00
angular.module('copayApp.controllers').controller('HeadController', function($scope, $rootScope, $filter, $timeout, notification, identityService, balanceService) {
2015-02-04 07:30:12 -08:00
$scope.username = $rootScope.iden ? $rootScope.iden.getName() : '';
2014-10-27 12:13:06 -07:00
$scope.hoverMenu = false;
2014-12-05 06:56:26 -08:00
var isChromeApp = typeof window !== "undefined" && window.chrome && chrome.runtime && chrome.runtime.id;
$scope.hoverIn = function() {
2014-10-27 12:13:06 -07:00
this.hoverMenu = true;
};
$scope.hoverOut = function() {
2014-10-27 12:13:06 -07:00
this.hoverMenu = false;
};
$scope.signout = function() {
2014-11-29 19:31:17 -08:00
identityService.signout();
2014-10-27 12:13:06 -07:00
};
2014-10-31 08:14:47 -07:00
$scope.refresh = function() {
var w = $rootScope.wallet;
if (!w) return;
2014-11-29 19:31:17 -08:00
if (w.isComplete()) {
2014-10-31 08:14:47 -07:00
w.sendWalletReady();
2014-11-29 13:35:48 -08:00
balanceService.clearBalanceCache(w);
balanceService.update(w, function() {
$rootScope.$digest();
}, true);
2014-10-31 08:14:47 -07:00
}
};
2014-10-27 12:13:06 -07:00
2014-12-01 06:19:18 -08:00
2014-12-05 06:56:26 -08:00
//Ensures a graceful disconnect
window.onbeforeunload = function() {
$scope.signout();
};
2014-10-27 12:13:06 -07:00
2014-12-05 06:56:26 -08:00
$scope.$on('$destroy', function() {
if (isChromeApp) return;
window.onbeforeunload = undefined;
});
2014-10-27 12:13:06 -07:00
2014-12-03 07:40:13 -08:00
$scope.init = function() {
if (!$rootScope.wallet) return;
2014-12-02 19:36:44 -08:00
2015-03-30 13:20:13 -07:00
$scope.$on('IdleStart', function() {});
$scope.$on('IdleWarn', function(a, countdown) {
$rootScope.countdown = countdown;
$rootScope.sessionExpired = true;
2015-03-30 13:20:13 -07:00
$rootScope.$apply();
});
2015-03-30 13:20:13 -07:00
$scope.$on('IdleEnd', function() {
$timeout(function() {
$rootScope.sessionExpired = null;
}, 500);
2014-10-27 12:13:06 -07:00
});
2015-03-30 13:20:13 -07:00
$scope.$on('IdleTimeout', function() {
$rootScope.sessionExpired = null;
2014-10-27 12:13:06 -07:00
$scope.signout();
notification.warning('Session closed', 'Session closed because a long time of inactivity');
});
2015-03-30 13:20:13 -07:00
$scope.$on('Keepalive', function() {
2014-10-27 12:13:06 -07:00
if ($rootScope.wallet) {
$rootScope.wallet.keepAlive();
}
});
$rootScope.$watch('title', function(newTitle, oldTitle) {
$scope.title = newTitle;
});
2014-12-03 07:40:13 -08:00
};
2014-10-27 12:13:06 -07:00
});