fix injectCSS did-finish-load listener overload

This commit is contained in:
Araxeus
2022-04-17 18:08:08 +03:00
parent 23058729f3
commit 2dfe098521

View File

@ -42,15 +42,22 @@ module.exports.fileExists = (path, callbackIfExists) => {
});
};
const cssToInject = new Map();
module.exports.injectCSS = (webContents, filepath, cb = undefined) => {
webContents.on("did-finish-load", async () => {
await webContents.insertCSS(fs.readFileSync(filepath, "utf8"));
if (cb) {
cb();
}
});
if (!cssToInject.size) setupCssInjection(webContents);
cssToInject.set(filepath, 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 = () => {
const isDirectory = (source) => fs.lstatSync(source).isDirectory();
return fs