From a143fd723c43181847a18a8b2d3cd61f9f34cdbc Mon Sep 17 00:00:00 2001 From: Daffa Mumtaz Date: Thu, 1 Jun 2023 15:45:54 +0700 Subject: [PATCH] fix: notification not working --- src/Main/MainWindow.js | 8 +++++--- src/Renderer/CustomNotification.js | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Main/MainWindow.js b/src/Main/MainWindow.js index 7f311a9..6f6dd1e 100644 --- a/src/Main/MainWindow.js +++ b/src/Main/MainWindow.js @@ -13,7 +13,7 @@ const getPixels = require("get-pixels"); // const getPortSync = require('get-port-sync'); const ICON_PATH = path.join(__dirname, '../icons/logo256x256.png'); -const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Chrome/107.0.5304.141 Safari/605.1.15'; +const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'; NotifyConfig.closeReplacedNotify = true; @@ -291,6 +291,7 @@ module.exports = class MainWindow extends BrowserWindow { this.recentNotification[tag] = { id: Math.floor(Math.random() * 999999) + 1, messages: [body], + timeout: null, } } @@ -301,6 +302,7 @@ module.exports = class MainWindow extends BrowserWindow { } async chatNotification(options) { + const TIMEOUT = 5000; const { title, icon, tag } = options; const { id, body } = this.groupNotification(options) const desktopEntry = path.join(homedir, '.local/share/applications/WALC.desktop'); @@ -310,7 +312,7 @@ module.exports = class MainWindow extends BrowserWindow { summary: title, replacesId: id, body: this.formatNotification(body), - timeout: 5000, + timeout: TIMEOUT, appName: 'WALC', hints: { desktopEntry, @@ -356,7 +358,7 @@ module.exports = class MainWindow extends BrowserWindow { const pieBrowser = await pie.connect(app, puppeteer); console.log('Creating whatsapp client'); - this.whatsapp = new Client(pieBrowser, this); + this.whatsapp = new Client(pieBrowser, this, { userAgent }); this.whatsappReady = false; this.whatsapp.on('ready', () => { diff --git a/src/Renderer/CustomNotification.js b/src/Renderer/CustomNotification.js index 6e614d1..bfc3d8e 100644 --- a/src/Renderer/CustomNotification.js +++ b/src/Renderer/CustomNotification.js @@ -5,7 +5,7 @@ class LegacyNotification extends Notification { constructor(title, options) { if(Settings.get('notification.enabled.value')) { const { tag, renotify, ...filteredOptions } = options; - // console.log('notify', options); + // console.log('notify legacy', options); super(title, filteredOptions); this.addEventListener('click', function () { @@ -17,35 +17,34 @@ class LegacyNotification extends Notification { class ServerNotification { constructor(title, options = {}) { - // console.log('notify', options); + // console.log('notify server', options); this.__serverNotif(title, options); } async __serverNotif(title, options) { if(options.tag) { try { - /** - * parse encoded tag, format (without square brackets): - * - * [boolean]_[user-serialized-id]_[alphanumeric] - * - * NOTE: what the boolean and alphanumeric value is for is currently unknown - * FIXME: parsing should be done server side, the other data could be useful - */ - const match = options.tag.match(/\w+_(\d+@c.us)_/); + const match = options.tag.match(/(\d+@c.us)/); if (match && match.length && match[1]) { await window.Store?.Contact?.find(match[1]); options.tag = match[1]; + } else { + delete options.tag; } } catch(err) { delete options.tag; } } - const serverNotif = { + /** + * NOTE: Sending non-standard JavaScript types such as DOM objects or special Electron objects will throw an exception. + * The options object potentially contains function + * @see https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrenderersendchannel-args + */ + const serverNotif = JSON.parse(JSON.stringify({ ...options, title, icon: await this.__getIcon(options.icon), - }; + })); ipcRenderer.invoke('instance.main.chatNotification', 'walc', serverNotif); }