From 6f5e4a00588aefdda7a5a1cfe70935870e7e234a Mon Sep 17 00:00:00 2001 From: Bennett Date: Tue, 22 Sep 2020 20:56:48 +0200 Subject: Unpack recipes and update recipes icons (#292) Co-authored-by: Amine Mouafik --- recipes/rocketchat/webview.js | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 recipes/rocketchat/webview.js (limited to 'recipes/rocketchat/webview.js') diff --git a/recipes/rocketchat/webview.js b/recipes/rocketchat/webview.js new file mode 100644 index 0000000..5ccd0d2 --- /dev/null +++ b/recipes/rocketchat/webview.js @@ -0,0 +1,51 @@ +"use strict"; + +const { + ipcRenderer +} = require('electron'); + +const getTeamIcon = function getTeamIcon() { + console.log('getTeamIcon'); + const manifestElement = document.querySelector('link[rel="manifest"]'); + + if (manifestElement == null) { + return; + } + + const manifestUrl = manifestElement.getAttribute('href'); + console.log(manifestUrl); + + if (manifestUrl == null) { + return; + } + + const xmlhttp = new XMLHttpRequest(); + + xmlhttp.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) { + return; + } + + const response = JSON.parse(this.responseText); + + if (response.icons.length >= 1) { + ipcRenderer.sendToHost('avatar', `${window.location.protocol}//${window.location.host}${response.icons[0].src}`); + } + }; + + xmlhttp.open('GET', manifestUrl, true); + xmlhttp.send(); +}; + +module.exports = Franz => { + const getMessages = function getMessages() { + const directMessages = Math.round(document.querySelectorAll('.unread.unread-mention, .badge--unread').length / 2); + const indirectMessages = Math.round(document.querySelectorAll('.unread:not(.unread-mention), .sidebar-item--unread').length / 2); + Franz.setBadge(directMessages, indirectMessages); + }; + + Franz.loop(getMessages); + setTimeout(() => { + getTeamIcon(); + }, 4000); +}; \ No newline at end of file -- cgit v1.2.3-70-g09d2