Merge pull request #693 from Araxeus/fix-event-listener-overload

fix injectCSS `did-finish-load` listener overload
This commit is contained in:
th-ch
2022-05-01 22:03:01 +02:00
committed by GitHub

View File

@ -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