mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
Fix downloader plugin with context isolation
This commit is contained in:
@ -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;
|
||||
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
|
||||
);
|
||||
};
|
||||
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 };
|
||||
|
||||
Reference in New Issue
Block a user