mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
Merge pull request #693 from Araxeus/fix-event-listener-overload
fix injectCSS `did-finish-load` listener overload
This commit is contained in:
@ -42,15 +42,22 @@ module.exports.fileExists = (path, callbackIfExists) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cssToInject = new Map();
|
||||||
module.exports.injectCSS = (webContents, filepath, cb = undefined) => {
|
module.exports.injectCSS = (webContents, filepath, cb = undefined) => {
|
||||||
webContents.on("did-finish-load", async () => {
|
if (!cssToInject.size) setupCssInjection(webContents);
|
||||||
await webContents.insertCSS(fs.readFileSync(filepath, "utf8"));
|
|
||||||
if (cb) {
|
cssToInject.set(filepath, cb);
|
||||||
cb();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setupCssInjection = (webContents) => {
|
||||||
|
webContents.on("did-finish-load", () => {
|
||||||
|
cssToInject.forEach(async (cb, filepath) => {
|
||||||
|
await webContents.insertCSS(fs.readFileSync(filepath, "utf8"));
|
||||||
|
cb?.();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.getAllPlugins = () => {
|
module.exports.getAllPlugins = () => {
|
||||||
const isDirectory = (source) => fs.lstatSync(source).isDirectory();
|
const isDirectory = (source) => fs.lstatSync(source).isDirectory();
|
||||||
return fs
|
return fs
|
||||||
|
|||||||
Reference in New Issue
Block a user