Setup CI tests (#100)
* use @xarc/xrun to streamline tasks in an imperative manner * add lint-staged/husky for git hook tasks * run prettier across all files * fixing tests * add ci test workflow * add a ci workflow * remove precommit in favor of husky * add .prettierrc.js * reformat with prettier
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* global browser */
|
||||
|
||||
// Core
|
||||
var WakaTimeCore = require("./core/WakaTimeCore").default;
|
||||
var WakaTimeCore = require('./core/WakaTimeCore').default;
|
||||
|
||||
// initialize class
|
||||
var wakatime = new WakaTimeCore();
|
||||
@@ -12,46 +12,40 @@ var connections = {};
|
||||
|
||||
// Add a listener to resolve alarms
|
||||
browser.alarms.onAlarm.addListener(function (alarm) {
|
||||
// |alarm| can be undefined because onAlarm also gets called from
|
||||
// window.setTimeout on old chrome versions.
|
||||
if (alarm && alarm.name == 'heartbeatAlarm') {
|
||||
// |alarm| can be undefined because onAlarm also gets called from
|
||||
// window.setTimeout on old chrome versions.
|
||||
if (alarm && alarm.name == 'heartbeatAlarm') {
|
||||
console.log('recording a heartbeat - alarm triggered');
|
||||
|
||||
console.log('recording a heartbeat - alarm triggered');
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new alarm for heartbeats.
|
||||
browser.alarms.create('heartbeatAlarm', {periodInMinutes: 2});
|
||||
browser.alarms.create('heartbeatAlarm', { periodInMinutes: 2 });
|
||||
|
||||
/**
|
||||
* Whenever a active tab is changed it records a heartbeat with that tab url.
|
||||
*/
|
||||
browser.tabs.onActivated.addListener(function (activeInfo) {
|
||||
browser.tabs.get(activeInfo.tabId).then(function (tab) {
|
||||
console.log('recording a heartbeat - active tab changed');
|
||||
|
||||
browser.tabs.get(activeInfo.tabId).then(function (tab) {
|
||||
|
||||
console.log('recording a heartbeat - active tab changed');
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
});
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Whenever a active window is changed it records a heartbeat with the active tab url.
|
||||
*/
|
||||
browser.windows.onFocusChanged.addListener(function (windowId) {
|
||||
if (windowId != browser.windows.WINDOW_ID_NONE) {
|
||||
console.log('recording a heartbeat - active window changed');
|
||||
|
||||
if (windowId != browser.windows.WINDOW_ID_NONE) {
|
||||
console.log('recording a heartbeat - active window changed');
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
} else {
|
||||
console.log('lost focus');
|
||||
}
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
} else {
|
||||
console.log('lost focus');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -59,57 +53,49 @@ browser.windows.onFocusChanged.addListener(function (windowId) {
|
||||
* currently active and if it is, then it records a heartbeat.
|
||||
*/
|
||||
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
if (changeInfo.status === 'complete') {
|
||||
// Get current tab URL.
|
||||
browser.tabs.query({ currentWindow: true, active: true }).then(function (tabs) {
|
||||
// If tab updated is the same as active tab
|
||||
if (tabId == tabs[0].id) {
|
||||
console.log('recording a heartbeat - tab updated');
|
||||
|
||||
if (changeInfo.status === 'complete') {
|
||||
// Get current tab URL.
|
||||
browser.tabs.query({currentWindow: true, active: true}).then(function(tabs) {
|
||||
// If tab updated is the same as active tab
|
||||
if (tabId == tabs[0].id) {
|
||||
console.log('recording a heartbeat - tab updated');
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* This is in charge of detecting if devtools are opened or closed
|
||||
* and sending a heartbeat depending on that.
|
||||
*/
|
||||
browser.runtime.onConnect.addListener(function (port) {
|
||||
if (port.name == 'devtools-page') {
|
||||
// Listen to messages sent from the DevTools page
|
||||
port.onMessage.addListener(function (message, sender, sendResponse) {
|
||||
if (message.name == 'init') {
|
||||
connections[message.tabId] = port;
|
||||
|
||||
if (port.name == "devtools-page") {
|
||||
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||
|
||||
// Listen to messages sent from the DevTools page
|
||||
port.onMessage.addListener(function (message, sender, sendResponse) {
|
||||
if (message.name == "init") {
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
});
|
||||
|
||||
connections[message.tabId] = port;
|
||||
port.onDisconnect.addListener(function (port) {
|
||||
var tabs = Object.keys(connections);
|
||||
|
||||
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||
for (var i = 0, len = tabs.length; i < len; i++) {
|
||||
if (connections[tabs[i]] == port) {
|
||||
delete connections[tabs[i]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
}
|
||||
});
|
||||
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||
|
||||
port.onDisconnect.addListener(function (port) {
|
||||
|
||||
var tabs = Object.keys(connections);
|
||||
|
||||
for (var i = 0, len = tabs.length; i < len; i ++) {
|
||||
if (connections[tabs[i]] == port) {
|
||||
delete connections[tabs[i]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
|
||||
|
||||
wakatime.recordHeartbeat();
|
||||
});
|
||||
|
||||
}
|
||||
wakatime.recordHeartbeat();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user