chore: change localStorage to indexedDB for caching heartbeats while offline (#166)

This commit is contained in:
Juan Sebastian velez Posada
2023-02-13 19:29:26 -05:00
committed by GitHub
parent be368b520e
commit 0a2326948c
4 changed files with 73 additions and 31 deletions

View File

@@ -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();
});