From 1a5a2916c26c17e11c378cbff6b305acc0e582b8 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 15 Aug 2014 12:49:16 -0400 Subject: [PATCH] give lock preference to the new instance --- config.js | 2 +- js/models/core/WalletLock.js | 16 ++++++++++------ js/routes.js | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config.js b/config.js index a9a61a6bf..659457933 100644 --- a/config.js +++ b/config.js @@ -89,7 +89,7 @@ path: '/', verbose: 1, // will duplicate itself after each try reconnectDelay: 5000, - idleDurationMin: 1 + idleDurationMin: 4 }, // blockchain service API config diff --git a/js/models/core/WalletLock.js b/js/models/core/WalletLock.js index 4e57250ca..329f5d9eb 100644 --- a/js/models/core/WalletLock.js +++ b/js/models/core/WalletLock.js @@ -10,7 +10,7 @@ function WalletLock(storage, walletId, timeoutMin) { this.storage = storage; this.timeoutMin = timeoutMin || 5; this.key = WalletLock._keyFor(walletId); - this.keepAlive(); + this._setLock(); } WalletLock._keyFor = function(walletId) { return 'lock' + '::' + walletId; @@ -29,17 +29,21 @@ WalletLock.prototype._isLockedByOther = function() { }; +WalletLock.prototype._setLock = function() { + this.storage.setGlobal(this.key, { + sessionId: this.sessionId, + expireTs: Date.now() + this.timeoutMin * 60 * 1000, + }); +}; + + WalletLock.prototype.keepAlive = function() { preconditions.checkState(this.sessionId); var t = this._isLockedByOther(); if (t) throw new Error('Wallet is already open. Close it to proceed or wait '+ t + ' seconds if you close it already' ); - - this.storage.setGlobal(this.key, { - sessionId: this.sessionId, - expireTs: Date.now() + this.timeoutMin * 60 * 1000, - }); + this._setLock(); }; diff --git a/js/routes.js b/js/routes.js index 93011afd4..c40a6179c 100644 --- a/js/routes.js +++ b/js/routes.js @@ -77,7 +77,7 @@ angular var timeout = config.wallet.idleDurationMin * 60 || 300; $idleProvider.idleDuration(timeout); // in seconds $idleProvider.warningDuration(20); // in seconds - $keepaliveProvider.interval(5); // in seconds + $keepaliveProvider.interval(2); // in seconds }) .run(function($rootScope, $location, $idle) { $idle.watch();