Page MenuHomePhabricator

D9963.diff
No OneTemporary

D9963.diff

diff --git a/desktop/src/main.js b/desktop/src/main.js
--- a/desktop/src/main.js
+++ b/desktop/src/main.js
@@ -291,22 +291,25 @@
(async () => {
await app.whenReady();
+ const handleNotificationClick = (threadID?: string) => {
+ if (mainWindow && threadID) {
+ mainWindow.webContents.send('on-notification-clicked', {
+ threadID,
+ });
+ } else if (threadID) {
+ show(`chat/thread/${threadID}/`);
+ } else {
+ show();
+ }
+ };
+
if (app.isPackaged) {
try {
initAutoUpdate();
} catch (error) {
console.error(error);
}
-
- listenForNotifications(threadID => {
- if (mainWindow) {
- mainWindow.webContents.send('on-notification-clicked', {
- threadID,
- });
- } else {
- show(`chat/thread/${threadID}/`);
- }
- });
+ listenForNotifications(handleNotificationClick);
ipcMain.on('fetch-device-token', sendDeviceTokenToWebApp);
}
diff --git a/desktop/src/push-notifications.js b/desktop/src/push-notifications.js
--- a/desktop/src/push-notifications.js
+++ b/desktop/src/push-notifications.js
@@ -92,8 +92,24 @@
function showNewNotification(
payload: { +[string]: mixed },
- handleClick: (threadID: string) => void,
+ handleClick: (threadID?: string) => void,
) {
+ const windowsIconPath = resolve(__dirname, '../icons/icon.ico');
+ if (
+ typeof payload.error === 'string' &&
+ typeof payload.displayErrorMessage === 'boolean'
+ ) {
+ const notif = new Notification({
+ title: 'Comm notification',
+ body: payload.displayErrorMessage ? payload.error : undefined,
+ icon: process.platform === 'win32' ? windowsIconPath : undefined,
+ });
+
+ notif.on('click', () => handleClick());
+ notif.show();
+ return;
+ }
+
if (
typeof payload.title !== 'string' ||
typeof payload.body !== 'string' ||
@@ -102,7 +118,6 @@
return;
}
const { title, body, threadID } = payload;
- const windowsIconPath = resolve(__dirname, '../icons/icon.ico');
const notif = new Notification({
title,
body,
@@ -112,7 +127,7 @@
notif.show();
}
-function listenForNotifications(handleClick: (threadID: string) => void) {
+function listenForNotifications(handleClick: (threadID?: string) => void) {
if (process.platform === 'darwin') {
pushNotifications.on('received-apns-notification', (event, userInfo) => {
showNewNotification(userInfo, handleClick);

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 2:27 AM (20 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609807
Default Alt Text
D9963.diff (2 KB)

Event Timeline