Merge branch 'master' into feature/enhanced-input-ui

This commit is contained in:
Rohid
2024-08-30 15:32:45 +06:00
6 changed files with 27 additions and 29 deletions

View File

@@ -10,7 +10,7 @@ Note: Activity from this Chrome extension will not display on leaderboards, so i
[![Chrome](https://wakatime.com/static/img/chrome-web-store.png)](https://chrome.google.com/webstore/detail/wakatime/jnbbnacmeggbgdjgaoojpmhdlkkpblgi)
[![Firefox](https://wakatime.com/static/img/firefox-addon.png)](https://addons.mozilla.org/en-US/firefox/addon/wakatime/)
[![Firefox](https://wakatime.com/static/img/firefox-addon.png)](https://addons.mozilla.org/en-US/firefox/addon/wakatimes/)
[![Edge](https://wakatime.com/static/img/microsoft-extension.png)](https://microsoftedge.microsoft.com/addons/detail/wakatime/cdnpfnaadjmaplhghnlonephmabegadl)

View File

@@ -53,7 +53,7 @@ export interface Config {
/**
* API key use to query wakatime api
*/
apiKey: '';
apiKey: string;
apiUrl: string;
colors: Colors;
/**
@@ -66,14 +66,14 @@ export interface Config {
* no activity in the browser for x second
*/
detectionIntervalInSeconds: number;
devSites: string[];
/**
* Url to which to send the heartbeat
*/
heartbeatApiEndPoint: string;
hostname: string;
/**
* Is logging enabled
*/
@@ -89,6 +89,7 @@ export interface Config {
*/
name: string;
nonTrackableSites: string[];
queueName: string;
socialMediaSites: string[];
states: ExtensionStatus[];
/**
@@ -163,6 +164,8 @@ const config: Config = {
nonTrackableSites: ['chrome://', 'about:'],
queueName: 'heartbeatQueue',
socialMediaSites: [
'facebook.com',
'instagram.com',

View File

@@ -29,18 +29,10 @@ class WakaTimeCore {
*/
async createDB() {
const dbConnection = await openDB('wakatime', 1, {
upgrade(db, oldVersion) {
// Create a store of objects
const store = db.createObjectStore('heartbeatQueue', {
upgrade(db) {
db.createObjectStore(config.queueName, {
keyPath: 'id',
});
// Switch over the oldVersion, *without breaks*, to allow the database to be incrementally upgraded.
switch (oldVersion) {
case 0:
// Placeholder to execute when database is created (oldVersion is 0)
case 1:
store.createIndex('id', 'id');
}
},
});
this.db = dbConnection;
@@ -123,7 +115,7 @@ class WakaTimeCore {
if (!this.shouldSendHeartbeat(heartbeat)) return;
// append heartbeat to queue
await this.db?.add('heartbeatQueue', heartbeat);
await this.db?.add(config.queueName, heartbeat);
await this.sendHeartbeats();
}
@@ -185,14 +177,15 @@ class WakaTimeCore {
return;
}
const heartbeats = (await this.db?.getAll('heartbeatQueue', undefined, 50)) as
const heartbeats = (await this.db?.getAll(config.queueName, undefined, 50)) as
| Heartbeat[]
| undefined;
if (!heartbeats || heartbeats.length === 0) return;
await this.db?.delete(
'heartbeatQueue',
heartbeats.map((heartbeat) => heartbeat.id),
await Promise.all(
heartbeats.map((heartbeat) => {
return this.db?.delete(config.queueName, heartbeat.id);
}),
);
const userAgent = await this.getUserAgent();
@@ -226,7 +219,7 @@ class WakaTimeCore {
console.error(data.error);
return;
}
if (response.status === 201) {
if (response.status === 202) {
await Promise.all(
(data.responses ?? []).map(async (resp, respNumber) => {
if (resp[0].error) {
@@ -234,7 +227,7 @@ class WakaTimeCore {
console.error(resp[0].error);
} else if (resp[1] === 201 && resp[0].data?.id) {
await changeExtensionStatus('allGood');
// await this.db?.delete('heartbeatQueue', resp[0].data.id);
// await this.db?.delete(config.queueName, resp[0].data.id);
} else {
if (resp[1] !== 400) {
await this.putHeartbeatsBackInQueue(heartbeats.filter((h, i) => i === respNumber));
@@ -258,7 +251,7 @@ class WakaTimeCore {
async putHeartbeatsBackInQueue(heartbeats: Heartbeat[]): Promise<void> {
await Promise.all(
heartbeats.map(async (heartbeat) => this.db?.add('heartbeatQueue', heartbeat)),
heartbeats.map(async (heartbeat) => this.db?.add(config.queueName, heartbeat)),
);
}

View File

@@ -31,6 +31,7 @@ export const getSettings = async (): Promise<Settings> => {
customProjectNames: [],
denyList: [],
hostname: config.hostname,
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
loggingType: config.loggingType,
socialMediaSites: config.socialMediaSites,

View File

@@ -70,10 +70,7 @@ const GitHub: HeartbeatParser = (url: string) => {
};
}
const body = document.getElementsByTagName('body').item(0);
if (!body) return;
const repo = body
const repo = document
.querySelector('meta[name=octolytics-dimension-repository_nwo]')
?.getAttribute('content');
if (repo?.split('/')[1] !== match[0]) return;

View File

@@ -40,6 +40,8 @@ chrome.runtime.onMessage.addListener(
return;
}
const heartbeat = site.parser(request.url);
sendResponse({ heartbeat: site.parser(request.url) });
}
},
@@ -50,6 +52,10 @@ document.body.addEventListener('click', sendHeartbeat, true);
document.body.addEventListener('keypress', sendHeartbeat, true);
const checkIfInAMeeting = () => {
if (!window.location.href.startsWith('https://meet.google.com/')) {
return;
}
const isActiveMeeting = !!document.querySelector('[data-meeting-title]');
if (isActiveMeeting) {
sendHeartbeat();
@@ -59,6 +65,4 @@ const checkIfInAMeeting = () => {
};
// Google Meet
if (window.location.href.startsWith('https://meet.google.com/')) {
checkIfInAMeeting();
}
checkIfInAMeeting();