idb auto closes, so re-open every operation
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { IDBPDatabase, openDB } from 'idb';
|
import { openDB } from 'idb';
|
||||||
import browser, { Tabs } from 'webextension-polyfill';
|
import browser, { Tabs } from 'webextension-polyfill';
|
||||||
/* eslint-disable no-fallthrough */
|
/* eslint-disable no-fallthrough */
|
||||||
/* eslint-disable default-case */
|
/* eslint-disable default-case */
|
||||||
@@ -18,7 +18,6 @@ class WakaTimeCore {
|
|||||||
lastHeartbeat: Heartbeat | undefined;
|
lastHeartbeat: Heartbeat | undefined;
|
||||||
lastHeartbeatSentAt = 0;
|
lastHeartbeatSentAt = 0;
|
||||||
lastExtensionState: ExtensionStatus = 'allGood';
|
lastExtensionState: ExtensionStatus = 'allGood';
|
||||||
_db: IDBPDatabase | undefined;
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.tabsWithDevtoolsOpen = [];
|
this.tabsWithDevtoolsOpen = [];
|
||||||
}
|
}
|
||||||
@@ -28,17 +27,13 @@ class WakaTimeCore {
|
|||||||
* a library that adds promises to IndexedDB and makes it easy to use
|
* a library that adds promises to IndexedDB and makes it easy to use
|
||||||
*/
|
*/
|
||||||
async db() {
|
async db() {
|
||||||
if (!this._db) {
|
return openDB('wakatime', 1, {
|
||||||
const dbConnection = await openDB('wakatime', 1, {
|
upgrade(db) {
|
||||||
upgrade(db) {
|
db.createObjectStore(config.queueName, {
|
||||||
db.createObjectStore(config.queueName, {
|
keyPath: 'id',
|
||||||
keyPath: 'id',
|
});
|
||||||
});
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
this._db = dbConnection;
|
|
||||||
}
|
|
||||||
return this._db;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldSendHeartbeat(heartbeat: Heartbeat): boolean {
|
shouldSendHeartbeat(heartbeat: Heartbeat): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user