Skip to content

Commit

Permalink
idb auto closes, so re-open every operation
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Oct 8, 2024
1 parent 46a1d3b commit 7643c68
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/core/WakaTimeCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDBPDatabase, openDB } from 'idb';
import { openDB } from 'idb';
import browser, { Tabs } from 'webextension-polyfill';
/* eslint-disable no-fallthrough */
/* eslint-disable default-case */
Expand All @@ -18,7 +18,6 @@ class WakaTimeCore {
lastHeartbeat: Heartbeat | undefined;
lastHeartbeatSentAt = 0;
lastExtensionState: ExtensionStatus = 'allGood';
_db: IDBPDatabase | undefined;
constructor() {
this.tabsWithDevtoolsOpen = [];
}
Expand All @@ -28,17 +27,13 @@ class WakaTimeCore {
* a library that adds promises to IndexedDB and makes it easy to use
*/
async db() {
if (!this._db) {
const dbConnection = await openDB('wakatime', 1, {
upgrade(db) {
db.createObjectStore(config.queueName, {
keyPath: 'id',
});
},
});
this._db = dbConnection;
}
return this._db;
return openDB('wakatime', 1, {
upgrade(db) {
db.createObjectStore(config.queueName, {
keyPath: 'id',
});
},
});
}

shouldSendHeartbeat(heartbeat: Heartbeat): boolean {
Expand Down

0 comments on commit 7643c68

Please sign in to comment.