Post message to service worker to sendHeartbeat
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
import WakaTimeCore from './core/WakaTimeCore';
|
import WakaTimeCore from './core/WakaTimeCore';
|
||||||
|
import { PostHeartbeatMessage } from './types/heartbeats';
|
||||||
|
|
||||||
// Add a listener to resolve alarms
|
// Add a listener to resolve alarms
|
||||||
browser.alarms.onAlarm.addListener(async (alarm) => {
|
browser.alarms.onAlarm.addListener(async (alarm) => {
|
||||||
@@ -22,7 +23,7 @@ browser.alarms.create('heartbeatAlarm', { periodInMinutes: 2 });
|
|||||||
* Whenever a active tab is changed it records a heartbeat with that tab url.
|
* Whenever a active tab is changed it records a heartbeat with that tab url.
|
||||||
*/
|
*/
|
||||||
browser.tabs.onActivated.addListener(async () => {
|
browser.tabs.onActivated.addListener(async () => {
|
||||||
console.log('recording a heartbeat - active tab changed ');
|
console.log('recording a heartbeat - active tab changed');
|
||||||
await WakaTimeCore.recordHeartbeat();
|
await WakaTimeCore.recordHeartbeat();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -62,6 +63,12 @@ self.addEventListener('activate', async () => {
|
|||||||
await WakaTimeCore.createDB();
|
await WakaTimeCore.createDB();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
browser.runtime.onMessage.addListener(async (request: PostHeartbeatMessage) => {
|
||||||
|
if (request.recordHeartbeat === true) {
|
||||||
|
await WakaTimeCore.recordHeartbeat(request.projectDetails);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Persistent" service worker via bug exploit
|
* "Persistent" service worker via bug exploit
|
||||||
* https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension
|
* https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension
|
||||||
|
|||||||
@@ -33,5 +33,5 @@
|
|||||||
"page": "options.html"
|
"page": "options.html"
|
||||||
},
|
},
|
||||||
"permissions": ["alarms", "tabs", "storage", "idle"],
|
"permissions": ["alarms", "tabs", "storage", "idle"],
|
||||||
"version": "3.0.18"
|
"version": "3.0.19"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,5 +39,5 @@
|
|||||||
"page": "options.html"
|
"page": "options.html"
|
||||||
},
|
},
|
||||||
"permissions": ["<all_urls>", "alarms", "tabs", "storage", "idle"],
|
"permissions": ["<all_urls>", "alarms", "tabs", "storage", "idle"],
|
||||||
"version": "3.0.18"
|
"version": "3.0.19"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,3 +32,15 @@ export interface SendHeartbeat {
|
|||||||
project: string | null;
|
project: string | null;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProjectDetails {
|
||||||
|
category: string;
|
||||||
|
editor: string;
|
||||||
|
language: string;
|
||||||
|
project: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PostHeartbeatMessage {
|
||||||
|
projectDetails?: ProjectDetails;
|
||||||
|
recordHeartbeat: boolean;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import WakaTimeCore from './core/WakaTimeCore';
|
|
||||||
|
|
||||||
const twoMinutes = 120000;
|
const twoMinutes = 120000;
|
||||||
|
|
||||||
interface DesignProject {
|
interface DesignProject {
|
||||||
@@ -55,9 +53,8 @@ const init = async () => {
|
|||||||
const { hostname } = document.location;
|
const { hostname } = document.location;
|
||||||
|
|
||||||
const projectDetails = getParser[hostname]?.();
|
const projectDetails = getParser[hostname]?.();
|
||||||
|
|
||||||
if (projectDetails) {
|
if (projectDetails) {
|
||||||
await WakaTimeCore.recordHeartbeat(projectDetails);
|
chrome.runtime.sendMessage({ projectDetails, recordHeartbeat: true });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user