From 79e8fc2fac69858321f6ad3f2b922e650eaeaefb Mon Sep 17 00:00:00 2001 From: TC Date: Tue, 12 Jan 2021 22:52:21 +0100 Subject: [PATCH 1/3] Fix downloader plugin with context isolation --- plugins/downloader/front.js | 44 ++++++++++++---------- plugins/downloader/templates/download.html | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/plugins/downloader/front.js b/plugins/downloader/front.js index 0045928173..d235da65ef 100644 --- a/plugins/downloader/front.js +++ b/plugins/downloader/front.js @@ -1,3 +1,5 @@ +const { contextBridge } = require("electron"); + const { ElementFromFile, templatePath, triggerAction } = require("../utils"); const { ACTIONS, CHANNEL } = require("./actions.js"); const { downloadVideoToMP3 } = require("./youtube-dl"); @@ -28,26 +30,28 @@ const reinit = () => { } }; -global.download = () => { - const videoUrl = window.location.href; - - downloadVideoToMP3( - videoUrl, - (feedback) => { - if (!progress) { - console.warn("Cannot update progress"); - } else { - progress.innerHTML = feedback; - } - }, - (error) => { - triggerAction(CHANNEL, ACTIONS.ERROR, error); - reinit(); - }, - reinit, - pluginOptions - ); -}; +contextBridge.exposeInMainWorld("downloader", { + download: () => { + const videoUrl = window.location.href; + + downloadVideoToMP3( + videoUrl, + (feedback) => { + if (!progress) { + console.warn("Cannot update progress"); + } else { + progress.innerHTML = feedback; + } + }, + (error) => { + triggerAction(CHANNEL, ACTIONS.ERROR, error); + reinit(); + }, + reinit, + pluginOptions + ); + }, +}); function observeMenu(options) { pluginOptions = { ...pluginOptions, ...options }; diff --git a/plugins/downloader/templates/download.html b/plugins/downloader/templates/download.html index 138464fbc3..7f9ab3ceaf 100644 --- a/plugins/downloader/templates/download.html +++ b/plugins/downloader/templates/download.html @@ -4,7 +4,7 @@ tabindex="-1" aria-disabled="false" aria-selected="false" - onclick="download()" + onclick="downloader.download()" >