From c5d2a889d4cb44f995d74051f83628b505383093 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 19 Sep 2021 00:41:52 +0200 Subject: fix: privileged API access Privileged browser APIs should be accessed from webview.js via the Ferdi parameter to the exported function. If any service is broken (e.g., screen sharing), then most likely we have to fix recipe.js or screenshare.js --- recipes/slack/package.json | 2 +- recipes/slack/webview.js | 62 +++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'recipes/slack') diff --git a/recipes/slack/package.json b/recipes/slack/package.json index 7c87e93..877bd8e 100644 --- a/recipes/slack/package.json +++ b/recipes/slack/package.json @@ -1,7 +1,7 @@ { "id": "slack", "name": "Slack", - "version": "1.3.0", + "version": "1.3.1", "license": "MIT", "config": { "serviceURL": "https://{teamId}.slack.com", diff --git a/recipes/slack/webview.js b/recipes/slack/webview.js index 1a12e80..3064e79 100644 --- a/recipes/slack/webview.js +++ b/recipes/slack/webview.js @@ -2,37 +2,6 @@ const _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -const getTeamIcon = function getTeamIcon(count = 0) { - let countTeamIconCheck = count; - let bgUrl = null; - const teamMenu = document.querySelector('#team-menu-trigger, .p-ia__sidebar_header__team_name'); - - if (teamMenu) { - teamMenu.click(); - const icon = document.querySelector('.c-team_icon'); - - if (icon) { - bgUrl = window.getComputedStyle(icon, null).getPropertyValue('background-image'); - bgUrl = /^url\((['"]?)(.*)\1\)$/.exec(bgUrl); - bgUrl = bgUrl ? bgUrl[2] : ''; - } - - setTimeout(() => { - document.querySelector('.ReactModal__Overlay').click(); - }, 10); - } - - countTeamIconCheck += 1; - - if (bgUrl) { - Ferdi.ipcRenderer.sendToHost('avatar', bgUrl); - } else if (countTeamIconCheck <= 5) { - setTimeout(() => { - getTeamIcon(countTeamIconCheck + 1); - }, 2000); - } -}; - const SELECTOR_CHANNELS_UNREAD = '.p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)'; module.exports = Ferdi => { @@ -44,6 +13,37 @@ module.exports = Ferdi => { Ferdi.loop(getMessages); + const getTeamIcon = function getTeamIcon(count = 0) { + let countTeamIconCheck = count; + let bgUrl = null; + const teamMenu = document.querySelector('#team-menu-trigger, .p-ia__sidebar_header__team_name'); + + if (teamMenu) { + teamMenu.click(); + const icon = document.querySelector('.c-team_icon'); + + if (icon) { + bgUrl = window.getComputedStyle(icon, null).getPropertyValue('background-image'); + bgUrl = /^url\((['"]?)(.*)\1\)$/.exec(bgUrl); + bgUrl = bgUrl ? bgUrl[2] : ''; + } + + setTimeout(() => { + document.querySelector('.ReactModal__Overlay').click(); + }, 10); + } + + countTeamIconCheck += 1; + + if (bgUrl) { + Ferdi.ipcRenderer.sendToHost('avatar', bgUrl); + } else if (countTeamIconCheck <= 5) { + setTimeout(() => { + getTeamIcon(countTeamIconCheck + 1); + }, 2000); + } + }; + setTimeout(() => { getTeamIcon(); }, 4000); -- cgit v1.2.3-70-g09d2