Skip to content

Commit

Permalink
fix: notification not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzombiee2361 committed Jun 1, 2023
1 parent da89cd5 commit a143fd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/Main/MainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -291,6 +291,7 @@ module.exports = class MainWindow extends BrowserWindow {
this.recentNotification[tag] = {
id: Math.floor(Math.random() * 999999) + 1,
messages: [body],
timeout: null,
}
}

Expand All @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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', () => {
Expand Down
25 changes: 12 additions & 13 deletions src/Renderer/CustomNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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);
}

Expand Down

0 comments on commit a143fd7

Please sign in to comment.