diff --git a/index.js b/index.js index a083d4d9..10b6f2d9 100644 --- a/index.js +++ b/index.js @@ -86,7 +86,9 @@ function createMainWindow() { backgroundColor: "#000", show: false, webPreferences: { - contextIsolation: true, + // TODO: re-enable contextIsolation once it can work with ffmepg.wasm + // Possible bundling? https://github.com/ffmpegwasm/ffmpeg.wasm/issues/126 + contextIsolation: false, preload: path.join(__dirname, "preload.js"), nodeIntegrationInSubFrames: true, nativeWindowOpen: true, // window.open return Window object(like in regular browsers), not BrowserWindowProxy diff --git a/plugins/downloader/front.js b/plugins/downloader/front.js index 00459281..732fd161 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,6 +30,9 @@ const reinit = () => { } }; +// TODO: re-enable once contextIsolation is set to true +// contextBridge.exposeInMainWorld("downloader", { +// download: () => { global.download = () => { const videoUrl = window.location.href; @@ -48,6 +53,7 @@ global.download = () => { pluginOptions ); }; +// }); function observeMenu(options) { pluginOptions = { ...pluginOptions, ...options }; diff --git a/plugins/navigation/actions.js b/plugins/navigation/actions.js index 83947a63..69c8536b 100644 --- a/plugins/navigation/actions.js +++ b/plugins/navigation/actions.js @@ -1,24 +1,24 @@ -const { triggerAction } = require('../utils'); +const { triggerAction } = require("../utils"); const CHANNEL = "navigation"; const ACTIONS = { - NEXT: "next", - BACK: 'back', -} + NEXT: "next", + BACK: "back", +}; function goToNextPage() { - triggerAction(CHANNEL, ACTIONS.NEXT); + triggerAction(CHANNEL, ACTIONS.NEXT); } function goToPreviousPage() { - triggerAction(CHANNEL, ACTIONS.BACK); + triggerAction(CHANNEL, ACTIONS.BACK); } module.exports = { - CHANNEL: CHANNEL, - ACTIONS: ACTIONS, - global: { - goToNextPage: goToNextPage, - goToPreviousPage: goToPreviousPage, - } + CHANNEL: CHANNEL, + ACTIONS: ACTIONS, + actions: { + goToNextPage: goToNextPage, + goToPreviousPage: goToPreviousPage, + }, }; diff --git a/plugins/navigation/back.js b/plugins/navigation/back.js index 54ee18a7..6d0d0a2a 100644 --- a/plugins/navigation/back.js +++ b/plugins/navigation/back.js @@ -1,23 +1,23 @@ const path = require("path"); const { injectCSS, listenAction } = require("../utils"); -const { ACTIONS, CHANNEL } = require("./actions.js"); +const { ACTIONS, CHANNEL } = require("./actions.js"); function handle(win) { injectCSS(win.webContents, path.join(__dirname, "style.css")); listenAction(CHANNEL, (event, action) => { switch (action) { - case ACTIONS.NEXT: + case ACTIONS.NEXT: if (win.webContents.canGoForward()) { win.webContents.goForward(); } break; - case ACTIONS.BACK: + case ACTIONS.BACK: if (win.webContents.canGoBack()) { win.webContents.goBack(); } break; - default: + default: console.log("Unknown action: " + action); } }); diff --git a/preload.js b/preload.js index 362c9170..c3d51d16 100644 --- a/preload.js +++ b/preload.js @@ -1,6 +1,6 @@ const path = require("path"); -const { remote } = require("electron"); +const { contextBridge, remote } = require("electron"); const config = require("./config"); const { fileExists } = require("./plugins/utils"); @@ -10,7 +10,10 @@ const plugins = config.plugins.getEnabled(); plugins.forEach(([plugin, options]) => { const pluginPath = path.join(__dirname, "plugins", plugin, "actions.js"); fileExists(pluginPath, () => { - const actions = require(pluginPath).global || {}; + const actions = require(pluginPath).actions || {}; + + // TODO: re-enable once contextIsolation is set to true + // contextBridge.exposeInMainWorld(plugin + "Actions", actions); Object.keys(actions).forEach((actionName) => { global[actionName] = actions[actionName]; });