aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp
diff options
context:
space:
mode:
authorLibravatar Balaji Vijayakumar <kuttibalaji.v6@gmail.com>2022-11-24 20:36:23 +0530
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-11-24 21:54:51 +0530
commit79f531aca517b3e5d507d8709d47aa7f9a37359b (patch)
treee684b0042665c5c188f6cdd69eb49f5de0478c53 /recipes/whatsapp
parentci: add recipe version bump check in PRs (#236) (diff)
downloadferdium-recipes-79f531aca517b3e5d507d8709d47aa7f9a37359b.tar.gz
ferdium-recipes-79f531aca517b3e5d507d8709d47aa7f9a37359b.tar.zst
ferdium-recipes-79f531aca517b3e5d507d8709d47aa7f9a37359b.zip
fix whatsapp initial loading issue
Diffstat (limited to 'recipes/whatsapp')
-rw-r--r--recipes/whatsapp/package.json2
-rw-r--r--recipes/whatsapp/webview.js44
2 files changed, 28 insertions, 18 deletions
diff --git a/recipes/whatsapp/package.json b/recipes/whatsapp/package.json
index e4701a5..8a38be6 100644
--- a/recipes/whatsapp/package.json
+++ b/recipes/whatsapp/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "whatsapp", 2 "id": "whatsapp",
3 "name": "WhatsApp", 3 "name": "WhatsApp",
4 "version": "3.4.7", 4 "version": "3.4.8",
5 "license": "MIT", 5 "license": "MIT",
6 "config": { 6 "config": {
7 "serviceURL": "https://web.whatsapp.com", 7 "serviceURL": "https://web.whatsapp.com",
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
7let getMessages = () => {
8 /* stub until db is connected*/
9}
10
11module.exports = Ferdium => { 7module.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'));