aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp/webview.js
diff options
context:
space:
mode:
authorLibravatar MCMXC <16797721+mcmxcdev@users.noreply.github.com>2023-07-26 06:29:03 -0600
committerLibravatar GitHub <noreply@github.com>2023-07-26 17:59:03 +0530
commit9b8f01716774a960073e944823ab727cc867a8f6 (patch)
tree732b83770baa78f5cf12776aaa33ce65bebfa418 /recipes/whatsapp/webview.js
parentAdd Excalidraw recipe (#393) (diff)
downloadferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.tar.gz
ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.tar.zst
ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.zip
chore: improve lint setup (#397)
- update eslint config to closely mirror the ones from ferdium-app - add .eslintignore - opt in to eslint `reportUnusedDisableDirectives` config option - remove `trailingComma: all` from `prettier` config which is default in `prettier` v3 - autofix or disable a lot of lint issues throughout codebase - add `volta` configuration to `package.json` to autoload correct `node` and `pnpm` versions - upgrade all `eslint` and `prettier` related dependencies to latest - update lint:fix npm script - reformat touched files with prettier - bumped up minor version for all recipes that have changes - introduced injection of 'service.css' where it was missing in many recipes --------- Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'recipes/whatsapp/webview.js')
-rw-r--r--recipes/whatsapp/webview.js66
1 files changed, 32 insertions, 34 deletions
diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js
index e2496be..26f2a3a 100644
--- a/recipes/whatsapp/webview.js
+++ b/recipes/whatsapp/webview.js
@@ -1,42 +1,21 @@
1const _path = _interopRequireDefault(require('path'));
2
3function _interopRequireDefault(obj) { 1function _interopRequireDefault(obj) {
4 return obj && obj.__esModule ? obj : {default: obj}; 2 return obj && obj.__esModule ? obj : { default: obj };
5} 3}
6 4
5const _path = _interopRequireDefault(require('path'));
6
7module.exports = Ferdium => { 7module.exports = Ferdium => {
8 let dbCache 8 let dbCache;
9 9
10 const getMessages = () => { 10 const getMessages = () => {
11 if(!dbCache) { 11 if (dbCache) {
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 {
33 let unreadCount = 0; 12 let unreadCount = 0;
34 let unreadMutedCount = 0; 13 let unreadMutedCount = 0;
35 14
36 const txn = dbCache.transaction('chat', 'readonly'); 15 const txn = dbCache.transaction('chat', 'readonly');
37 const store = txn.objectStore('chat'); 16 const store = txn.objectStore('chat');
38 const query = store.getAll(); 17 const query = store.getAll();
39 query.onsuccess = (event) => { 18 query.onsuccess = event => {
40 for (const chat of event.target.result) { 19 for (const chat of event.target.result) {
41 if (chat.unreadCount > 0) { 20 if (chat.unreadCount > 0) {
42 if (chat.muteExpiration > 0 || chat.isAutoMuted) { 21 if (chat.muteExpiration > 0 || chat.isAutoMuted) {
@@ -50,11 +29,32 @@ module.exports = Ferdium => {
50 Ferdium.setBadge(unreadCount, unreadMutedCount); 29 Ferdium.setBadge(unreadCount, unreadMutedCount);
51 }; 30 };
52 31
53 query.addEventListener('error', (event) => { 32 query.addEventListener('error', event => {
54 console.error("Loading data from database failed:", event); 33 console.error('Loading data from database failed:', event);
55 }) 34 });
35 } else {
36 const dbsPromise = indexedDB.databases();
37 dbsPromise.then(databases => {
38 for (let index in databases) {
39 //Wait for model-storage db to be available before calling indexedDB.open(). This is to make sure whatsapp created the model-storage DB
40 if (databases[index].name === 'model-storage') {
41 const request = window.indexedDB.open('model-storage');
42 request.onsuccess = () => {
43 dbCache = request.result;
44 // This will be called when db.delete is triggered, we need to close and set dbCache to null to trigger lookup again
45 dbCache.onversionchange = () => {
46 dbCache.close();
47 dbCache = null;
48 };
49 };
50 request.addEventListener('error', () => {
51 console.error('Opening model-storage database failed:', event);
52 });
53 }
54 }
55 });
56 } 56 }
57 } 57 };
58 58
59 // inject webview hacking script 59 // inject webview hacking script
60 Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); 60 Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js'));
@@ -74,14 +74,12 @@ module.exports = Ferdium => {
74 Ferdium.releaseServiceWorkers(); 74 Ferdium.releaseServiceWorkers();
75 }); 75 });
76 76
77 Ferdium.handleDarkMode((isEnabled) => { 77 Ferdium.handleDarkMode(isEnabled => {
78
79 if (isEnabled) { 78 if (isEnabled) {
80 document.body.classList.add('dark'); 79 document.body.classList.add('dark');
81 } else { 80 } else {
82 document.body.classList.remove('dark'); 81 document.body.classList.remove('dark');
83 } 82 }
84
85 }); 83 });
86 84
87 Ferdium.loop(loopFunc); 85 Ferdium.loop(loopFunc);