From 8477741d82e4ebac9ffb7ff90dde1dec063eaed0 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Wed, 20 Apr 2022 00:51:03 -0500 Subject: Remove duplicate code and reuse 'Ferdium.openNewWindow()' --- recipes/discord/package.json | 2 +- recipes/discord/webview.js | 46 +++++++++++------------------------------- recipes/skype/package.json | 2 +- recipes/skype/webview.js | 20 ++---------------- recipes/steamchat/package.json | 2 +- recipes/steamchat/webview.js | 20 ++++++++---------- recipes/zoom/package.json | 2 +- recipes/zoom/webview.js | 46 +++++++++++------------------------------- 8 files changed, 38 insertions(+), 102 deletions(-) diff --git a/recipes/discord/package.json b/recipes/discord/package.json index 1dc89b4..0fa9651 100644 --- a/recipes/discord/package.json +++ b/recipes/discord/package.json @@ -1,7 +1,7 @@ { "id": "discord", "name": "Discord", - "version": "1.7.0", + "version": "1.7.1", "license": "MIT", "config": { "serviceURL": "https://discordapp.com/login", diff --git a/recipes/discord/webview.js b/recipes/discord/webview.js index 16a3a1a..0dd0e38 100644 --- a/recipes/discord/webview.js +++ b/recipes/discord/webview.js @@ -4,7 +4,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -module.exports = (Ferdium, settings) => { +module.exports = Ferdium => { const getMessages = () => { let directCount = 0; const directCountPerServer = document.querySelectorAll( @@ -26,40 +26,18 @@ module.exports = (Ferdium, settings) => { Ferdium.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"]'); + 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 (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/ferdium/ferdium-app/issues/1697) - let win = new Ferdium.BrowserWindow({ - width: 800, - height: window.innerHeight, - minWidth: 600, - webPreferences: { - partition: `persist:service-${settings.id}`, - // TODO: Aren't these needed here? - // contextIsolation: false, - }, - }); - win.loadURL(url); - win.on('closed', () => { - win = null; - }); - } + if (url.includes('views/imgpsh_fullsize_anim')) { + event.preventDefault(); + event.stopPropagation(); + Ferdium.openNewWindow(url); } - }, - true, - ); + } + }, true); }; diff --git a/recipes/skype/package.json b/recipes/skype/package.json index a3a0840..afebf64 100644 --- a/recipes/skype/package.json +++ b/recipes/skype/package.json @@ -1,7 +1,7 @@ { "id": "skype", "name": "Skype", - "version": "3.5.0", + "version": "3.5.1", "license": "MIT", "config": { "serviceURL": "https://web.skype.com/", diff --git a/recipes/skype/webview.js b/recipes/skype/webview.js index ca0befb..47b6f27 100644 --- a/recipes/skype/webview.js +++ b/recipes/skype/webview.js @@ -2,7 +2,7 @@ const _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -module.exports = (Ferdium, settings) => { +module.exports = Ferdium => { const getMessages = () => { let count = 0; const container = document.querySelector('[role="tablist"] > button > div'); @@ -30,7 +30,6 @@ module.exports = (Ferdium, settings) => { Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); - // 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"]'); @@ -41,22 +40,7 @@ module.exports = (Ferdium, settings) => { 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/ferdium/ferdium-app/issues/1697) - let win = new Ferdium.BrowserWindow({ - width: 800, - height: window.innerHeight, - minWidth: 600, - webPreferences: { - partition: `persist:service-${settings.id}`, - // TODO: Aren't these needed here? - // contextIsolation: false, - } - }); - win.loadURL(url); - win.on('closed', () => { - win = null; - }); + Ferdium.openNewWindow(url); } } }, true); diff --git a/recipes/steamchat/package.json b/recipes/steamchat/package.json index ffc6230..28434b1 100644 --- a/recipes/steamchat/package.json +++ b/recipes/steamchat/package.json @@ -1,7 +1,7 @@ { "id": "steamchat", "name": "SteamChat", - "version": "1.4.0", + "version": "1.4.1", "license": "MIT", "config": { "serviceURL": "https://steamcommunity.com/chat", diff --git a/recipes/steamchat/webview.js b/recipes/steamchat/webview.js index cfe84f3..1188c71 100644 --- a/recipes/steamchat/webview.js +++ b/recipes/steamchat/webview.js @@ -30,17 +30,13 @@ module.exports = Ferdium => { Ferdium.loop(getMessages); - document.addEventListener( - 'click', - event => { - const link = event.target.closest('a[href^="http"]'); + document.addEventListener('click', event => { + const link = event.target.closest('a[href^="http"]'); - if (link && link.getAttribute('target') === '_top') { - event.preventDefault(); - event.stopPropagation(); - Ferdium.openNewWindow(link.getAttribute('href')); - } - }, - true, - ); + if (link && link.getAttribute('target') === '_top') { + event.preventDefault(); + event.stopPropagation(); + Ferdium.openNewWindow(link.getAttribute('href')); + } + }, true); }; diff --git a/recipes/zoom/package.json b/recipes/zoom/package.json index ce12ff9..82117f7 100644 --- a/recipes/zoom/package.json +++ b/recipes/zoom/package.json @@ -1,7 +1,7 @@ { "id": "zoom", "name": "Zoom", - "version": "1.3.0", + "version": "1.3.1", "license": "MIT", "config": { "serviceURL": "https://zoom.us/join", diff --git a/recipes/zoom/webview.js b/recipes/zoom/webview.js index 16a3a1a..0dd0e38 100644 --- a/recipes/zoom/webview.js +++ b/recipes/zoom/webview.js @@ -4,7 +4,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -module.exports = (Ferdium, settings) => { +module.exports = Ferdium => { const getMessages = () => { let directCount = 0; const directCountPerServer = document.querySelectorAll( @@ -26,40 +26,18 @@ module.exports = (Ferdium, settings) => { Ferdium.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"]'); + 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 (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/ferdium/ferdium-app/issues/1697) - let win = new Ferdium.BrowserWindow({ - width: 800, - height: window.innerHeight, - minWidth: 600, - webPreferences: { - partition: `persist:service-${settings.id}`, - // TODO: Aren't these needed here? - // contextIsolation: false, - }, - }); - win.loadURL(url); - win.on('closed', () => { - win = null; - }); - } + if (url.includes('views/imgpsh_fullsize_anim')) { + event.preventDefault(); + event.stopPropagation(); + Ferdium.openNewWindow(url); } - }, - true, - ); + } + }, true); }; -- cgit v1.2.3-54-g00ecf