Heartbeats are now triggered by on activated and on updated tab events.
This commit is contained in:
@@ -1,14 +1,4 @@
|
||||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
// What to do when the event page first loads?
|
||||
//
|
||||
// Functional style
|
||||
//
|
||||
// 1. Run a function every 2 mins DONE
|
||||
// 2. Check if the user is active (not idle)
|
||||
// If the user is active, get the current active tab URL
|
||||
// and send heartbeat to wakatime.
|
||||
//
|
||||
|
||||
'use strict';
|
||||
|
||||
var WakaTime = require('./WakaTime');
|
||||
@@ -25,7 +15,7 @@ function resolveAlarm(alarm) {
|
||||
// window.setTimeout on old chrome versions.
|
||||
if (alarm && alarm.name == 'heartbeatAlarm') {
|
||||
|
||||
console.log('heartbeatAlarm triggered');
|
||||
console.log('recording a heartbeat - alarm triggered');
|
||||
|
||||
var wakatime = new WakaTime();
|
||||
|
||||
@@ -37,7 +27,43 @@ function resolveAlarm(alarm) {
|
||||
chrome.alarms.onAlarm.addListener(resolveAlarm);
|
||||
|
||||
// Create a new alarm for heartbeats.
|
||||
chrome.alarms.create('heartbeatAlarm', { periodInMinutes: 1 });
|
||||
chrome.alarms.create('heartbeatAlarm', { periodInMinutes: 2 });
|
||||
|
||||
/**
|
||||
* Whenever a active tab is changed it records a heartbeat with that tab url.
|
||||
*/
|
||||
chrome.tabs.onActivated.addListener(function (activeInfo) {
|
||||
|
||||
chrome.tabs.get(activeInfo.tabId, function (tab) {
|
||||
|
||||
console.log('recording a heartbeat - active tab changed');
|
||||
|
||||
var wakatime = new WakaTime();
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Whenever any tab is updated it checks if the updated tab is the tab that is
|
||||
* currently active and if it is, then it records a heartbeat.
|
||||
*/
|
||||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
|
||||
if (changeInfo.status === 'complete') {
|
||||
// Get current tab URL.
|
||||
chrome.tabs.query({ active: true }, function (tabs) {
|
||||
// If tab updated is the same as active tab
|
||||
if (tabId == tabs[0].id) {
|
||||
console.log('recording a heartbeat - tab updated');
|
||||
|
||||
var wakatime = new WakaTime();
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
},{"./WakaTime":3}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
@@ -230,7 +256,7 @@ var WakaTime = (function () {
|
||||
|
||||
console.log(payload);
|
||||
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
// Send entity in heartbeat
|
||||
else if (loggingType == 'url') {
|
||||
@@ -238,7 +264,7 @@ var WakaTime = (function () {
|
||||
|
||||
console.log(payload);
|
||||
|
||||
//this.sendAjaxRequestToApi(payload);
|
||||
_this3.sendAjaxRequestToApi(payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user