diff options
author | Balaji Vijayakumar <kuttibalaji.v6@gmail.com> | 2022-11-24 20:36:23 +0530 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-11-24 21:54:51 +0530 |
commit | 79f531aca517b3e5d507d8709d47aa7f9a37359b (patch) | |
tree | e684b0042665c5c188f6cdd69eb49f5de0478c53 /recipes/whatsapp/webview.js | |
parent | ci: add recipe version bump check in PRs (#236) (diff) | |
download | ferdium-recipes-79f531aca517b3e5d507d8709d47aa7f9a37359b.tar.gz ferdium-recipes-79f531aca517b3e5d507d8709d47aa7f9a37359b.tar.zst ferdium-recipes-79f531aca517b3e5d507d8709d47aa7f9a37359b.zip |
fix whatsapp initial loading issue
Diffstat (limited to 'recipes/whatsapp/webview.js')
-rw-r--r-- | recipes/whatsapp/webview.js | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js index 8a5f830..89bc673 100644 --- a/recipes/whatsapp/webview.js +++ b/recipes/whatsapp/webview.js | |||
@@ -4,24 +4,38 @@ function _interopRequireDefault(obj) { | |||
4 | return obj && obj.__esModule ? obj : {default: obj}; | 4 | return obj && obj.__esModule ? obj : {default: obj}; |
5 | } | 5 | } |
6 | 6 | ||
7 | let getMessages = () => { | ||
8 | /* stub until db is connected*/ | ||
9 | } | ||
10 | |||
11 | module.exports = Ferdium => { | 7 | module.exports = Ferdium => { |
12 | const request = window.indexedDB.open("model-storage"); | 8 | let dbCache |
13 | request.onsuccess = () => { | 9 | |
14 | const db = request.result; | 10 | const getMessages = () => { |
15 | 11 | if(!dbCache) { | |
16 | getMessages = () => { | 12 | const dbsPromise = indexedDB.databases() |
13 | dbsPromise.then((databases) => { | ||
14 | for(let index in databases) { | ||
15 | //Wait for model-storage db to be available before calling indexedDB.open(). This is to make sure whatsapp created the model-storage DB | ||
16 | if(databases[index].name === "model-storage") { | ||
17 | const request = window.indexedDB.open("model-storage"); | ||
18 | request.onsuccess = () => { | ||
19 | dbCache = request.result; | ||
20 | //This will be called when db.delete is triggered, we need to close and set dbCache to null to trigger lookup again | ||
21 | dbCache.onversionchange = () => { | ||
22 | dbCache.close() | ||
23 | dbCache = null | ||
24 | }; | ||
25 | } | ||
26 | request.addEventListener('error', () => { | ||
27 | console.error("Opening model-storage database failed:", event); | ||
28 | }) | ||
29 | } | ||
30 | } | ||
31 | }) | ||
32 | } else { | ||
17 | let unreadCount = 0; | 33 | let unreadCount = 0; |
18 | let unreadMutedCount = 0; | 34 | let unreadMutedCount = 0; |
19 | 35 | ||
20 | const txn = db.transaction('chat', 'readonly'); | 36 | const txn = dbCache.transaction('chat', 'readonly'); |
21 | const store = txn.objectStore('chat'); | 37 | const store = txn.objectStore('chat'); |
22 | |||
23 | const query = store.getAll(); | 38 | const query = store.getAll(); |
24 | |||
25 | query.onsuccess = (event) => { | 39 | query.onsuccess = (event) => { |
26 | for (const chat of event.target.result) { | 40 | for (const chat of event.target.result) { |
27 | if (chat.unreadCount > 0) { | 41 | if (chat.unreadCount > 0) { |
@@ -40,11 +54,7 @@ module.exports = Ferdium => { | |||
40 | console.error("Loading data from database failed:", event); | 54 | console.error("Loading data from database failed:", event); |
41 | }) | 55 | }) |
42 | } | 56 | } |
43 | }; | 57 | } |
44 | |||
45 | request.addEventListener('error', (event) => { | ||
46 | console.error("Opening model-storage database failed:", event); | ||
47 | }) | ||
48 | 58 | ||
49 | // inject webview hacking script | 59 | // inject webview hacking script |
50 | Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); | 60 | Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); |