chore: change localStorage to indexedDB for caching heartbeats while offline (#166)
This commit is contained in:
committed by
GitHub
parent
be368b520e
commit
0a2326948c
@@ -10,11 +10,7 @@ browser.alarms.onAlarm.addListener(async (alarm) => {
|
||||
// Checks if the user is online and if there are cached heartbeats requests,
|
||||
// if so then procedd to send these payload to wakatime api
|
||||
if (navigator.onLine) {
|
||||
const { cachedHeartbeats } = await browser.storage.sync.get({
|
||||
cachedHeartbeats: [],
|
||||
});
|
||||
await browser.storage.sync.set({ cachedHeartbeats: [] });
|
||||
await WakaTimeCore.sendCachedHeartbeatsRequest(cachedHeartbeats as Record<string, unknown>[]);
|
||||
await WakaTimeCore.sendCachedHeartbeatsRequest();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -54,3 +50,11 @@ browser.tabs.onUpdated.addListener(async (tabId, changeInfo) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates IndexedDB
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
|
||||
*/
|
||||
self.addEventListener('activate', async () => {
|
||||
await WakaTimeCore.createDB();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user