aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp
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
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')
-rw-r--r--recipes/whatsapp/index.js37
-rw-r--r--recipes/whatsapp/package.json2
-rw-r--r--recipes/whatsapp/webview-unsafe.js45
-rw-r--r--recipes/whatsapp/webview.js66
4 files changed, 76 insertions, 74 deletions
diff --git a/recipes/whatsapp/index.js b/recipes/whatsapp/index.js
index 80eaf51..1392dcb 100644
--- a/recipes/whatsapp/index.js
+++ b/recipes/whatsapp/index.js
@@ -1,18 +1,23 @@
1module.exports = (Ferdium) => class Messenger extends Ferdium { 1module.exports = Ferdium =>
2 overrideUserAgent() { 2 class Messenger extends Ferdium {
3 return window.navigator.userAgent.replace(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '').trim(); 3 overrideUserAgent() {
4 } 4 return window.navigator.userAgent
5 .replaceAll(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '')
6 .trim();
7 }
5 8
6 modifyRequestHeaders() { 9 modifyRequestHeaders() {
7 return [ 10 return [
8 { 11 {
9 headers: { 12 headers: {
10 'user-agent': window.navigator.userAgent.replace(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '').trim(), 13 'user-agent': window.navigator.userAgent
14 .replaceAll(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '')
15 .trim(),
16 },
17 requestFilters: {
18 urls: ['*://*/*'],
19 },
11 }, 20 },
12 requestFilters: { 21 ];
13 urls: ['*://*/*'], 22 }
14 }, 23 };
15 },
16 ];
17 }
18};
diff --git a/recipes/whatsapp/package.json b/recipes/whatsapp/package.json
index 88a7e30..e3a8fa8 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.11", 4 "version": "3.5.0",
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-unsafe.js b/recipes/whatsapp/webview-unsafe.js
index b6b365b..7382f3d 100644
--- a/recipes/whatsapp/webview-unsafe.js
+++ b/recipes/whatsapp/webview-unsafe.js
@@ -5,38 +5,37 @@ const PUSHSTATE_THROTTLE = 1;
5const PUSHSTATE_THROTTLE_THRESHOLD = 1; 5const PUSHSTATE_THROTTLE_THRESHOLD = 1;
6 6
7window.shPushState = window.history.pushState; 7window.shPushState = window.history.pushState;
8//window.pushStateBehavior = PUSHSTATE_NORMAL; 8// window.pushStateBehavior = PUSHSTATE_NORMAL;
9window.pushStateBehavior = PUSHSTATE_THROTTLE; 9window.pushStateBehavior = PUSHSTATE_THROTTLE;
10window.pushStateCount = 0; 10window.pushStateCount = 0;
11 11
12function pushStateThrottled() { 12function pushStateThrottled() {
13 if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) 13 if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) {
14 { 14 window.shPushState.apply(window.history, arguments);
15 window.shPushState.apply(window.history, arguments); 15 window.pushStateCount++;
16 window.pushStateCount++; 16
17 17 if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD)
18 if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) 18 setTimeout(() => {
19 setTimeout(() => { 19 window.pushStateCount = 0;
20 window.pushStateCount = 0; 20 }, 5000);
21 }, 21 } else {
22 5000); 22 // eslint-disable-next-line no-console
23 } 23 console.log('Pushstate temporarily blocked!');
24 else 24 }
25 {
26 console.log("Pushstate temporarily blocked!");
27 }
28} 25}
29 26
30function pushStateOneShot() { 27function pushStateOneShot() {
31 window.shPushState.apply(window.history, arguments); 28 window.shPushState.apply(window.history, arguments);
32 29
33 window.history.pushState = function() {}; 30 window.history.pushState = function () {};
34 31
35 console.log("Pushstate Disabled!"); 32 // eslint-disable-next-line no-console
33 console.log('Pushstate Disabled!');
36} 34}
37 35
38if (window.pushStateBehavior != PUSHSTATE_NORMAL) 36if (window.pushStateBehavior != PUSHSTATE_NORMAL) {
39{ 37 window.history.pushState =
40 window.history.pushState = 38 window.pushStateBehavior == PUSHSTATE_THROTTLE
41 window.pushStateBehavior == PUSHSTATE_THROTTLE ? pushStateThrottled : pushStateOneShot; 39 ? pushStateThrottled
40 : pushStateOneShot;
42} 41}
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);