Skip to content

Commit

Permalink
Clicking on notification should show the window now
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Oct 22, 2020
1 parent cf86d32 commit 2dda28d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@ if (!singleInstanceLock) {
mainWindow.webContents.send("themes-changed", true)
);

ipcMain.on("activate-window-and-tab", (_, tabid) =>
mainWindow.webContents.send("activate-window-and-tab", tabid)
);

// Set global settings whenever they are changed
ipcMain.on("settings-changed", () => setGlobalSettings());

Expand Down
23 changes: 10 additions & 13 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altus",
"version": "3.17.0",
"version": "3.18.0",
"description": "Electron-based desktop wrapper for WhatsApp Web",
"homepage": "https://altus.amanharwara.xyz",
"repository": {
Expand Down Expand Up @@ -53,8 +53,7 @@
"background": "build/background.png",
"icon": "build/icon.icns",
"iconSize": 100,
"contents": [
{
"contents": [{
"x": 380,
"y": 280,
"type": "link",
Expand All @@ -77,15 +76,13 @@
"allowToChangeInstallationDirectory": "true"
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
}
],
"target": [{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
}],
"icon": "build/icon.ico"
},
"linux": {
Expand All @@ -100,4 +97,4 @@
"resolutions": {
"minimist": ">=0.2.1"
}
}
}
5 changes: 5 additions & 0 deletions src/windows/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,8 @@ ipcRenderer.on("previous-tab", () => {
tabs.toggle(tabItem.previousSibling.querySelector("a"));
}
});

ipcRenderer.on("activate-window-and-tab", (e, tabid) => {
remote.getCurrentWindow().show();
tabs.toggle(document.querySelector(`[data-tab-id="${tabid}"]`));
});
28 changes: 14 additions & 14 deletions src/windows/main/util/toggleNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* @param {boolean} firstStart Whether the function is being run at the start of the app
*/
function toggleNotifications(whatsAppElement, setting, firstStart) {
let whatsapp = whatsAppElement;
if (firstStart) {
whatsapp.addEventListener('dom-ready', () => {
if (!setting) {
whatsapp.executeJavaScript(`window.Notification = ''`);
}
});
} else {
if (!setting) {
whatsapp.executeJavaScript(`window.Notification = ''`);
}
}
let whatsapp = whatsAppElement;
if (firstStart) {
whatsapp.addEventListener("dom-ready", () => {
remote.webContents
.fromId(whatsapp.getWebContentsId())
.send("toggle-notification", setting);
});
} else {
remote.webContents
.fromId(whatsapp.getWebContentsId())
.send("toggle-notification", setting);
}
}

module.exports = {
toggleNotifications
}
toggleNotifications,
};
38 changes: 38 additions & 0 deletions src/windows/main/whatsapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,41 @@ function confirm_remove_quick_reply(tab_id, reply_id) {
ipcRenderer.on("format-text", (_, wrapper) => {
format_selected_text(wrapper);
});

const NotificationProxy = window.Notification;

ipcRenderer.on("toggle-notification", (_, setting) => {
if (!setting) {
window.Notification = "";
} else {
let NativeNotification = Notification;
Notification = function (title, options) {
var notification = new NativeNotification(title, options);

notification.addEventListener("click", function () {
ipcRenderer.send(
"activate-window-and-tab",
document.body.dataset.tabid
);
});

notification.addEventListener = function () {
return true;
};
notification.attachEvent = function () {
return true;
};
notification.addListener = function () {
return true;
};

return notification;
};

Notification.prototype = NativeNotification.prototype;
Notification.permission = NativeNotification.permission;
Notification.requestPermission = NativeNotification.requestPermission.bind(
Notification
);
}
});

0 comments on commit 2dda28d

Please sign in to comment.