From a1a7a4e5d2868dcec98db86c2692e65800a4fb57 Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Thu, 7 Oct 2021 11:01:41 +0200 Subject: fix: discord does not show notifications (#734) --- recipes/discord/package.json | 2 +- recipes/discord/webview.js | 95 +++++++++++++++++++++++--------------------- 2 files changed, 50 insertions(+), 47 deletions(-) (limited to 'recipes') diff --git a/recipes/discord/package.json b/recipes/discord/package.json index a9fe8dd..175b4ce 100644 --- a/recipes/discord/package.json +++ b/recipes/discord/package.json @@ -1,7 +1,7 @@ { "id": "discord", "name": "Discord", - "version": "1.4.4", + "version": "1.4.5", "license": "MIT", "config": { "serviceURL": "https://discordapp.com/login", diff --git a/recipes/discord/webview.js b/recipes/discord/webview.js index 2687948..cf13cc9 100644 --- a/recipes/discord/webview.js +++ b/recipes/discord/webview.js @@ -1,28 +1,25 @@ const _path = _interopRequireDefault(require('path')); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} module.exports = (Ferdi, settings) => { const getMessages = () => { - let count = 0; - const container = document.querySelector('[role="tablist"] > [title="Chats"] > div'); + let directCount = 0; + const directCountPerServer = document.querySelectorAll( + '[class*="lowerBadge-"] [class*="numberBadge-"]', + ); - if (container) { - const children = container.children; - - if (children.length === 3) { - const elementContainer = children[children.length - 1]; - - if (elementContainer) { - const element = elementContainer.querySelector('[data-text-as-pseudo-element]'); - if (element && element.dataset) { - count = Ferdi.safeParseInt(element.dataset.textAsPseudoElement); - } - } - } + for (const directCountBadge of directCountPerServer) { + directCount += Ferdi.safeParseInt(directCountBadge.textContent); } - Ferdi.setBadge(count); + const indirectCountPerServer = document.querySelectorAll( + '[class*="modeUnread-"]', + ).length; + + Ferdi.setBadge(directCount, indirectCountPerServer); }; Ferdi.loop(getMessages); @@ -30,34 +27,40 @@ module.exports = (Ferdi, settings) => { Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); // TODO: This whole block is duplicated between the 'discord' and 'skype' recipes - reuse - document.addEventListener('click', event => { - const link = event.target.closest('a[href^="http"]'); - const button = event.target.closest('button[title^="http"]'); - - if (link || button) { - const url = link ? link.getAttribute('href') : button.getAttribute('title'); - - if (url.includes('views/imgpsh_fullsize_anim')) { - event.preventDefault(); - event.stopPropagation(); - // TODO: Can we send an ipc event 'open-browser-window' to open the child window? (see the slack recipe for how to send an ipc message) - // TODO: Can we change the slack recipe to add a clickHandler for screensharing/video calls? (https://github.com/getferdi/ferdi/issues/1697) - let win = new Ferdi.BrowserWindow({ - width: 800, - height: window.innerHeight, - minWidth: 600, - webPreferences: { - partition: `persist:service-${settings.id}` - // TODO: Aren't these needed here? - // contextIsolation: false, - // enableRemoteModule: true, - } - }); - win.loadURL(url); - win.on('closed', () => { - win = null; - }); + document.addEventListener( + 'click', + event => { + const link = event.target.closest('a[href^="http"]'); + const button = event.target.closest('button[title^="http"]'); + + if (link || button) { + const url = link + ? link.getAttribute('href') + : button.getAttribute('title'); + + if (url.includes('views/imgpsh_fullsize_anim')) { + event.preventDefault(); + event.stopPropagation(); + // TODO: Can we send an ipc event 'open-browser-window' to open the child window? (see the slack recipe for how to send an ipc message) + // TODO: Can we change the slack recipe to add a clickHandler for screensharing/video calls? (https://github.com/getferdi/ferdi/issues/1697) + let win = new Ferdi.BrowserWindow({ + width: 800, + height: window.innerHeight, + minWidth: 600, + webPreferences: { + partition: `persist:service-${settings.id}`, + // TODO: Aren't these needed here? + // contextIsolation: false, + // enableRemoteModule: true, + }, + }); + win.loadURL(url); + win.on('closed', () => { + win = null; + }); + } } - } - }, true); + }, + true, + ); }; -- cgit v1.2.3-54-g00ecf