summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-01 08:22:34 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-01 08:22:34 +0100
commit26e4800ddf9b4384a083f066f2a396b8e5e6c079 (patch)
treeb88d165f89549fe1eca0b04655ac8c439cd595d2 /common
parentad69f9c86b950cc84ca103e65824b9c9129d3999 (diff)
downloadbrowser-extension-26e4800ddf9b4384a083f066f2a396b8e5e6c079.tar.gz
browser-extension-26e4800ddf9b4384a083f066f2a396b8e5e6c079.zip
more improvements for abrowser&librewolf
Diffstat (limited to 'common')
-rw-r--r--common/broadcast.js2
-rw-r--r--common/indexeddb.js43
2 files changed, 22 insertions, 23 deletions
diff --git a/common/broadcast.js b/common/broadcast.js
index 4fc5237..12b365a 100644
--- a/common/broadcast.js
+++ b/common/broadcast.js
@@ -119,6 +119,6 @@ function close(conn)
{
if (conn.type === "sender")
flush(conn);
- conn.port.disconnect();
+ setTimeout(conn.port.disconnect());
}
#EXPORT close
diff --git a/common/indexeddb.js b/common/indexeddb.js
index f916162..bdf71e5 100644
--- a/common/indexeddb.js
+++ b/common/indexeddb.js
@@ -99,9 +99,25 @@ async function idb_del(transaction, store_name, key)
return wait_request(transaction.objectStore(store_name).delete(key));
}
+async function perform_upgrade(event) {
+ const opened_db = event.target.result;
+
+ /* When we move to a new database schema, we will add upgrade logic here. */
+ if (event.oldVersion > 0)
+ throw "bad db version: " + event.oldVersion;
+
+ let store;
+ for (const [store_name, key_mode] of stores)
+ store = opened_db.createObjectStore(store_name, key_mode);
+
+ const ctx = make_context(store.transaction, initial_data.files);
+ await _save_items(initial_data.resources, initial_data.mappings, ctx);
+
+ return opened_db;
+}
+
/* Open haketilo database, asynchronously return an IDBDatabase object. */
-async function get_db()
-{
+async function get_db() {
if (db)
return db;
@@ -109,28 +125,11 @@ async function get_db()
const waiter = new Promise((...cbs) => [resolve, reject] = cbs);
const request = indexedDB.open("haketilo", version_nr(db_version));
- request.onsuccess = resolve;
+ request.onsuccess = ev => resolve(ev.target.result);
request.onerror = ev => reject("db error: " + ev.target.errorCode);
- request.onupgradeneeded = resolve;
-
- const event = await waiter;
- const opened_db = event.target.result;
+ request.onupgradeneeded = ev => perform_upgrade(ev).then(resolve, reject);
- if (event instanceof IDBVersionChangeEvent) {
- /*
- * When we move to a new database schema, we will add upgrade logic
- * here.
- */
- if (event.oldVersion > 0)
- throw "bad db version: " + event.oldVersion;
-
- let store;
- for (const [store_name, key_mode] of stores)
- store = opened_db.createObjectStore(store_name, key_mode);
-
- const ctx = make_context(store.transaction, initial_data.files);
- await _save_items(initial_data.resources, initial_data.mappings, ctx);
- }
+ const opened_db = await waiter;
if (db)
opened_db.close();