From 23b21c940c682b90e6e34856475b728659324a9a Mon Sep 17 00:00:00 2001 From: Germain Date: Wed, 15 Dec 2021 08:34:54 +0000 Subject: [PATCH] Open thread on native notification click (#20176) --- src/vector/platform/ElectronPlatform.tsx | 23 ++++++++++------------- src/vector/platform/WebPlatform.ts | 22 ---------------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 5573db8164..c0b860e4fd 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -368,7 +368,7 @@ export default class ElectronPlatform extends VectorBasePlatform { return true; } - displayNotification(title: string, msg: string, avatarUrl: string, room: Room): Notification { + displayNotification(title: string, msg: string, avatarUrl: string, room: Room, ev?: MatrixEvent): Notification { // GNOME notification spec parses HTML tags for styling... // Electron Docs state all supported linux notification systems follow this markup spec // https://github.com/electron/electron/blob/master/docs/tutorial/desktop-environment-integration.md#linux @@ -379,20 +379,17 @@ export default class ElectronPlatform extends VectorBasePlatform { msg = msg.replace(//g, '>'); } - // Notifications in Electron use the HTML5 notification API - const notifBody = { - body: msg, - silent: true, // we play our own sounds - }; - if (avatarUrl) notifBody['icon'] = avatarUrl; - const notification = new window.Notification(title, notifBody); + const notification = super.displayNotification( + title, + msg, + avatarUrl, + room, + ev, + ); + const handler = notification.onclick as Function; notification.onclick = () => { - dis.dispatch({ - action: 'view_room', - room_id: room.roomId, - }); - window.focus(); + handler?.(); this.ipcCall('focusWindow'); }; diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index fb8a9f18c4..fab4bfa9d9 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -20,7 +20,6 @@ import { UpdateCheckStatus } from "matrix-react-sdk/src/BasePlatform"; import request from 'browser-request'; import dis from 'matrix-react-sdk/src/dispatcher/dispatcher'; import { _t } from 'matrix-react-sdk/src/languageHandler'; -import { Room } from "matrix-js-sdk/src/models/room"; import { hideToast as hideUpdateToast, showToast as showUpdateToast } from "matrix-react-sdk/src/toasts/UpdateToast"; import { Action } from "matrix-react-sdk/src/dispatcher/actions"; import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload'; @@ -78,27 +77,6 @@ export default class WebPlatform extends VectorBasePlatform { }); } - displayNotification(title: string, msg: string, avatarUrl: string, room: Room) { - const notifBody = { - body: msg, - tag: "vector", - silent: true, // we play our own sounds - }; - if (avatarUrl) notifBody['icon'] = avatarUrl; - const notification = new window.Notification(title, notifBody); - - notification.onclick = function() { - dis.dispatch({ - action: 'view_room', - room_id: room.roomId, - }); - window.focus(); - notification.close(); - }; - - return notification; - } - private getMostRecentVersion(): Promise { // We add a cachebuster to the request to make sure that we know about // the most recent version on the origin server. That might not