prevent API request every time checkAuth is called from switching tabs

This commit is contained in:
Mario Basic
2015-06-27 00:20:39 +02:00
parent 8b77268728
commit 12b153b323
3 changed files with 124 additions and 141 deletions

View File

@@ -83,9 +83,6 @@ class WakaTime {
* and sends it to WakaTime for logging.
*/
recordHeartbeat() {
this.checkAuth().done(data => {
if (data !== false) {
chrome.storage.sync.get({
loggingEnabled: config.loggingEnabled,
@@ -138,14 +135,6 @@ class WakaTime {
}
});
}
else {
// User is not logged in.
// Change extension icon to red color.
changeExtensionState('notSignedIn');
}
});
}
/**
* Creates payload for the heartbeat and returns it as JSON.
@@ -239,17 +228,21 @@ class WakaTime {
contentType: 'application/json',
method: method,
data: payload,
statusCode: {
401: function () {
changeExtensionState('notSignedIn');
},
201: function () {
// nothing to do here
}
},
success: (response) => {
deferredObject.resolve(this);
},
error: (xhr, status, err) => {
console.error(config.heartbeatApiUrl, status, err.toString());
deferredObject.resolve(this);
}
});

View File

@@ -636,10 +636,6 @@ var WakaTime = (function () {
value: function recordHeartbeat() {
var _this = this;
this.checkAuth().done(function (data) {
if (data !== false) {
chrome.storage.sync.get({
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
@@ -686,13 +682,6 @@ var WakaTime = (function () {
changeExtensionState('notLogging');
}
});
} else {
// User is not logged in.
// Change extension icon to red color.
changeExtensionState('notSignedIn');
}
});
}
}, {
key: '_preparePayload',
@@ -798,12 +787,16 @@ var WakaTime = (function () {
contentType: 'application/json',
method: method,
data: payload,
statusCode: {
401: function _() {
changeExtensionState('notSignedIn');
},
201: function _() {}
},
success: function success(response) {
deferredObject.resolve(_this3);
},
error: function error(xhr, status, err) {
console.error(config.heartbeatApiUrl, status, err.toString());
deferredObject.resolve(_this3);
@@ -820,6 +813,8 @@ var WakaTime = (function () {
exports['default'] = WakaTime;
module.exports = exports['default'];
// nothing to do here
},{"../helpers/changeExtensionState":8,"./../config":5,"./../helpers/contains":10,"./../helpers/getDomainFromUrl":11,"./../helpers/in_array":12,"jquery":26,"moment":28}],7:[function(require,module,exports){
/* global chrome */

View File

@@ -263,10 +263,6 @@ var WakaTime = (function () {
value: function recordHeartbeat() {
var _this = this;
this.checkAuth().done(function (data) {
if (data !== false) {
chrome.storage.sync.get({
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
@@ -313,13 +309,6 @@ var WakaTime = (function () {
changeExtensionState('notLogging');
}
});
} else {
// User is not logged in.
// Change extension icon to red color.
changeExtensionState('notSignedIn');
}
});
}
}, {
key: '_preparePayload',
@@ -425,12 +414,16 @@ var WakaTime = (function () {
contentType: 'application/json',
method: method,
data: payload,
statusCode: {
401: function _() {
changeExtensionState('notSignedIn');
},
201: function _() {}
},
success: function success(response) {
deferredObject.resolve(_this3);
},
error: function error(xhr, status, err) {
console.error(config.heartbeatApiUrl, status, err.toString());
deferredObject.resolve(_this3);
@@ -447,6 +440,8 @@ var WakaTime = (function () {
exports['default'] = WakaTime;
module.exports = exports['default'];
// nothing to do here
},{"../helpers/changeExtensionState":5,"./../config":2,"./../helpers/contains":7,"./../helpers/getDomainFromUrl":8,"./../helpers/in_array":9,"jquery":10,"moment":11}],4:[function(require,module,exports){
/* global chrome */