From 9b8f01716774a960073e944823ab727cc867a8f6 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Wed, 26 Jul 2023 06:29:03 -0600 Subject: 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 --- recipes/whatsapp/index.js | 37 ++++++++++++--------- recipes/whatsapp/package.json | 2 +- recipes/whatsapp/webview-unsafe.js | 45 +++++++++++++------------- recipes/whatsapp/webview.js | 66 ++++++++++++++++++-------------------- 4 files changed, 76 insertions(+), 74 deletions(-) (limited to 'recipes/whatsapp') 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 @@ -module.exports = (Ferdium) => class Messenger extends Ferdium { - overrideUserAgent() { - return window.navigator.userAgent.replace(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '').trim(); - } +module.exports = Ferdium => + class Messenger extends Ferdium { + overrideUserAgent() { + return window.navigator.userAgent + .replaceAll(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '') + .trim(); + } - modifyRequestHeaders() { - return [ - { - headers: { - 'user-agent': window.navigator.userAgent.replace(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '').trim(), + modifyRequestHeaders() { + return [ + { + headers: { + 'user-agent': window.navigator.userAgent + .replaceAll(/(Ferdium|Electron)\/\S+ \([^)]+\)/g, '') + .trim(), + }, + requestFilters: { + urls: ['*://*/*'], + }, }, - requestFilters: { - urls: ['*://*/*'], - }, - }, - ]; - } -}; + ]; + } + }; 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 @@ { "id": "whatsapp", "name": "WhatsApp", - "version": "3.4.11", + "version": "3.5.0", "license": "MIT", "config": { "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; const PUSHSTATE_THROTTLE_THRESHOLD = 1; window.shPushState = window.history.pushState; -//window.pushStateBehavior = PUSHSTATE_NORMAL; +// window.pushStateBehavior = PUSHSTATE_NORMAL; window.pushStateBehavior = PUSHSTATE_THROTTLE; window.pushStateCount = 0; function pushStateThrottled() { - if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) - { - window.shPushState.apply(window.history, arguments); - window.pushStateCount++; - - if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) - setTimeout(() => { - window.pushStateCount = 0; - }, - 5000); - } - else - { - console.log("Pushstate temporarily blocked!"); - } + if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) { + window.shPushState.apply(window.history, arguments); + window.pushStateCount++; + + if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) + setTimeout(() => { + window.pushStateCount = 0; + }, 5000); + } else { + // eslint-disable-next-line no-console + console.log('Pushstate temporarily blocked!'); + } } function pushStateOneShot() { - window.shPushState.apply(window.history, arguments); + window.shPushState.apply(window.history, arguments); - window.history.pushState = function() {}; + window.history.pushState = function () {}; - console.log("Pushstate Disabled!"); + // eslint-disable-next-line no-console + console.log('Pushstate Disabled!'); } -if (window.pushStateBehavior != PUSHSTATE_NORMAL) -{ - window.history.pushState = - window.pushStateBehavior == PUSHSTATE_THROTTLE ? pushStateThrottled : pushStateOneShot; +if (window.pushStateBehavior != PUSHSTATE_NORMAL) { + window.history.pushState = + window.pushStateBehavior == PUSHSTATE_THROTTLE + ? pushStateThrottled + : pushStateOneShot; } 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 @@ -const _path = _interopRequireDefault(require('path')); - function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : {default: obj}; + return obj && obj.__esModule ? obj : { default: obj }; } +const _path = _interopRequireDefault(require('path')); + module.exports = Ferdium => { - let dbCache + let dbCache; const getMessages = () => { - if(!dbCache) { - const dbsPromise = indexedDB.databases() - dbsPromise.then((databases) => { - for(let index in databases) { - //Wait for model-storage db to be available before calling indexedDB.open(). This is to make sure whatsapp created the model-storage DB - if(databases[index].name === "model-storage") { - const request = window.indexedDB.open("model-storage"); - request.onsuccess = () => { - dbCache = request.result; - //This will be called when db.delete is triggered, we need to close and set dbCache to null to trigger lookup again - dbCache.onversionchange = () => { - dbCache.close() - dbCache = null - }; - } - request.addEventListener('error', () => { - console.error("Opening model-storage database failed:", event); - }) - } - } - }) - } else { + if (dbCache) { let unreadCount = 0; let unreadMutedCount = 0; const txn = dbCache.transaction('chat', 'readonly'); const store = txn.objectStore('chat'); const query = store.getAll(); - query.onsuccess = (event) => { + query.onsuccess = event => { for (const chat of event.target.result) { if (chat.unreadCount > 0) { if (chat.muteExpiration > 0 || chat.isAutoMuted) { @@ -50,11 +29,32 @@ module.exports = Ferdium => { Ferdium.setBadge(unreadCount, unreadMutedCount); }; - query.addEventListener('error', (event) => { - console.error("Loading data from database failed:", event); - }) + query.addEventListener('error', event => { + console.error('Loading data from database failed:', event); + }); + } else { + const dbsPromise = indexedDB.databases(); + dbsPromise.then(databases => { + for (let index in databases) { + //Wait for model-storage db to be available before calling indexedDB.open(). This is to make sure whatsapp created the model-storage DB + if (databases[index].name === 'model-storage') { + const request = window.indexedDB.open('model-storage'); + request.onsuccess = () => { + dbCache = request.result; + // This will be called when db.delete is triggered, we need to close and set dbCache to null to trigger lookup again + dbCache.onversionchange = () => { + dbCache.close(); + dbCache = null; + }; + }; + request.addEventListener('error', () => { + console.error('Opening model-storage database failed:', event); + }); + } + } + }); } - } + }; // inject webview hacking script Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); @@ -74,14 +74,12 @@ module.exports = Ferdium => { Ferdium.releaseServiceWorkers(); }); - Ferdium.handleDarkMode((isEnabled) => { - + Ferdium.handleDarkMode(isEnabled => { if (isEnabled) { document.body.classList.add('dark'); } else { document.body.classList.remove('dark'); } - }); Ferdium.loop(loopFunc); -- cgit v1.2.3-70-g09d2