From 7643c6848d7ac595b9c1585d046fde0008da2c7c Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Tue, 8 Oct 2024 09:40:48 +0200 Subject: [PATCH] idb auto closes, so re-open every operation --- src/core/WakaTimeCore.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/core/WakaTimeCore.ts b/src/core/WakaTimeCore.ts index e3a16ba..cb5e504 100644 --- a/src/core/WakaTimeCore.ts +++ b/src/core/WakaTimeCore.ts @@ -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 */ @@ -18,7 +18,6 @@ class WakaTimeCore { lastHeartbeat: Heartbeat | undefined; lastHeartbeatSentAt = 0; lastExtensionState: ExtensionStatus = 'allGood'; - _db: IDBPDatabase | undefined; constructor() { this.tabsWithDevtoolsOpen = []; } @@ -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 {