Merge branch 'master' into master
This commit is contained in:
@@ -142,11 +142,12 @@ var Options = React.createClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SitesList
|
<SitesList
|
||||||
handleChange={that._updateWhitelistState}
|
handleChange={that._updateWhitelistState}
|
||||||
label="Whitelist"
|
label="Whitelist"
|
||||||
sites={that.state.whitelist}
|
sites={that.state.whitelist}
|
||||||
helpText="Sites that you want to show in your reports." />
|
placeholder="http://google.com http://myproject.com@@MyProject"
|
||||||
|
helpText="Sites that you want to show in your reports. You can assign URL to project by adding @@YourProject at the end of line." />
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ var Wakatime = React.createClass({
|
|||||||
totalTimeLoggedToday: grand_total.text
|
totalTimeLoggedToday: grand_total.text
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
wakatime.recordHeartbeat();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changeExtensionState('notSignedIn');
|
changeExtensionState('notSignedIn');
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
var $ = require('jquery');
|
var $ = require('jquery');
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
|
|
||||||
var config = require('./../config');
|
var config = require('./../config');
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
@@ -29,7 +28,6 @@ class WakaTimeCore {
|
|||||||
|
|
||||||
getTotalTimeLoggedToday() {
|
getTotalTimeLoggedToday() {
|
||||||
var deferredObject = $.Deferred();
|
var deferredObject = $.Deferred();
|
||||||
|
|
||||||
var today = moment().format('YYYY-MM-DD');
|
var today = moment().format('YYYY-MM-DD');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -63,14 +61,10 @@ class WakaTimeCore {
|
|||||||
url: config.currentUserApiUrl,
|
url: config.currentUserApiUrl,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: (data) => {
|
success: (data) => {
|
||||||
|
|
||||||
deferredObject.resolve(data.data);
|
deferredObject.resolve(data.data);
|
||||||
|
|
||||||
},
|
},
|
||||||
error: (xhr, status, err) => {
|
error: (xhr, status, err) => {
|
||||||
|
|
||||||
console.error(config.currentUserApiUrl, status, err.toString());
|
console.error(config.currentUserApiUrl, status, err.toString());
|
||||||
|
|
||||||
deferredObject.resolve(false);
|
deferredObject.resolve(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -83,7 +77,6 @@ class WakaTimeCore {
|
|||||||
* and sends it to WakaTime for logging.
|
* and sends it to WakaTime for logging.
|
||||||
*/
|
*/
|
||||||
recordHeartbeat() {
|
recordHeartbeat() {
|
||||||
|
|
||||||
browser.storage.sync.get({
|
browser.storage.sync.get({
|
||||||
loggingEnabled: config.loggingEnabled,
|
loggingEnabled: config.loggingEnabled,
|
||||||
loggingStyle: config.loggingStyle,
|
loggingStyle: config.loggingStyle,
|
||||||
@@ -91,24 +84,27 @@ class WakaTimeCore {
|
|||||||
whitelist: ''
|
whitelist: ''
|
||||||
}).then((items) => {
|
}).then((items) => {
|
||||||
if (items.loggingEnabled === true) {
|
if (items.loggingEnabled === true) {
|
||||||
|
|
||||||
changeExtensionState('allGood');
|
changeExtensionState('allGood');
|
||||||
|
|
||||||
browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => {
|
browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => {
|
||||||
|
|
||||||
if (newState === 'active') {
|
if (newState === 'active') {
|
||||||
// Get current tab URL.
|
// Get current tab URL.
|
||||||
browser.tabs.query({active: true}).then((tabs) => {
|
browser.tabs.query({active: true}).then((tabs) => {
|
||||||
|
|
||||||
var currentActiveTab = tabs[0];
|
var currentActiveTab = tabs[0];
|
||||||
|
|
||||||
var debug = false;
|
var debug = false;
|
||||||
|
|
||||||
// If the current active tab has devtools open
|
// If the current active tab has devtools open
|
||||||
if (in_array(currentActiveTab.id, this.tabsWithDevtoolsOpen)) debug = true;
|
if (in_array(currentActiveTab.id, this.tabsWithDevtoolsOpen)) {
|
||||||
|
debug = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (items.loggingStyle == 'blacklist') {
|
if (items.loggingStyle == 'blacklist') {
|
||||||
if (! contains(currentActiveTab.url, items.blacklist)) {
|
if (! contains(currentActiveTab.url, items.blacklist)) {
|
||||||
this.sendHeartbeat(currentActiveTab.url, debug);
|
this.sendHeartbeat({
|
||||||
|
url: currentActiveTab.url,
|
||||||
|
project: null,
|
||||||
|
}, debug);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changeExtensionState('blacklisted');
|
changeExtensionState('blacklisted');
|
||||||
@@ -117,8 +113,9 @@ class WakaTimeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (items.loggingStyle == 'whitelist') {
|
if (items.loggingStyle == 'whitelist') {
|
||||||
if (contains(currentActiveTab.url, items.whitelist)) {
|
var heartbeat = this.getHeartbeat(currentActiveTab.url, items.whitelist);
|
||||||
this.sendHeartbeat(currentActiveTab.url, debug);
|
if (heartbeat.url) {
|
||||||
|
this.sendHeartbeat(heartbeat, debug);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changeExtensionState('whitelisted');
|
changeExtensionState('whitelisted');
|
||||||
@@ -136,21 +133,65 @@ class WakaTimeCore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an array from list using \n as delimiter
|
||||||
|
* and checks if any element in list is contained in the url.
|
||||||
|
* Also checks if element is assigned to a project using @@ as delimiter
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @param list
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
getHeartbeat(url, list) {
|
||||||
|
var lines = list.split('\n');
|
||||||
|
|
||||||
|
for (var i = 0; i < lines.length; i ++) {
|
||||||
|
// Trim all lines from the list one by one
|
||||||
|
var cleanLine = lines[i].trim();
|
||||||
|
|
||||||
|
// If by any chance one line in the list is empty, ignore it
|
||||||
|
if (cleanLine === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If url contains the current line return object
|
||||||
|
if (url.indexOf(cleanLine.split('@@')[0]) > -1) {
|
||||||
|
if (cleanLine.split('@@')[1]) {
|
||||||
|
return {
|
||||||
|
url: cleanLine.split('@@')[0],
|
||||||
|
project: cleanLine.split('@@')[1]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {
|
||||||
|
url: cleanLine.split('@@')[0],
|
||||||
|
project: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
url: null,
|
||||||
|
project: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates payload for the heartbeat and returns it as JSON.
|
* Creates payload for the heartbeat and returns it as JSON.
|
||||||
*
|
*
|
||||||
* @param entity
|
* @param heartbeat
|
||||||
* @param type
|
* @param type
|
||||||
* @param debug
|
* @param debug
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_preparePayload(entity, type, debug = false) {
|
_preparePayload(heartbeat, type, debug = false) {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
entity: entity,
|
entity: heartbeat.url,
|
||||||
type: type,
|
type: type,
|
||||||
time: moment().format('X'),
|
time: moment().format('X'),
|
||||||
project: '<<LAST_PROJECT>>',
|
project: heartbeat.project || '<<LAST_PROJECT>>',
|
||||||
is_debugging: debug,
|
is_debugging: debug,
|
||||||
plugin: 'browser-wakatime/' + config.version
|
plugin: 'browser-wakatime/' + config.version
|
||||||
});
|
});
|
||||||
@@ -176,40 +217,30 @@ class WakaTimeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the entity and logging type it creates a payload and
|
* Given the heartbeat and logging type it creates a payload and
|
||||||
* sends an ajax post request to the API.
|
* sends an ajax post request to the API.
|
||||||
*
|
*
|
||||||
* @param entity
|
* @param heartbeat
|
||||||
* @param debug
|
* @param debug
|
||||||
*/
|
*/
|
||||||
sendHeartbeat(entity, debug) {
|
sendHeartbeat(heartbeat, debug) {
|
||||||
|
|
||||||
var payload = null;
|
var payload = null;
|
||||||
|
|
||||||
this._getLoggingType().done((loggingType) => {
|
this._getLoggingType().done((loggingType) => {
|
||||||
|
|
||||||
// Get only the domain from the entity.
|
// Get only the domain from the entity.
|
||||||
// And send that in heartbeat
|
// And send that in heartbeat
|
||||||
if (loggingType == 'domain') {
|
if (loggingType == 'domain') {
|
||||||
|
heartbeat.url = getDomainFromUrl(heartbeat.url);
|
||||||
var domain = getDomainFromUrl(entity);
|
payload = this._preparePayload(heartbeat, 'domain', debug);
|
||||||
|
|
||||||
payload = this._preparePayload(domain, 'domain', debug);
|
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
this.sendAjaxRequestToApi(payload);
|
this.sendAjaxRequestToApi(payload);
|
||||||
|
|
||||||
}
|
}
|
||||||
// Send entity in heartbeat
|
// Send entity in heartbeat
|
||||||
else if (loggingType == 'url') {
|
else if (loggingType == 'url') {
|
||||||
payload = this._preparePayload(entity, 'url', debug);
|
payload = this._preparePayload(heartbeat, 'url', debug);
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
this.sendAjaxRequestToApi(payload);
|
this.sendAjaxRequestToApi(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 51 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 50 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 58 KiB |
Reference in New Issue
Block a user