From 2dfe098521e98d9ce0197f5a8e46cc1eedf100e7 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:08:08 +0300 Subject: [PATCH] fix injectCSS `did-finish-load` listener overload --- plugins/utils.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/utils.js b/plugins/utils.js index b265692f..735af3b9 100644 --- a/plugins/utils.js +++ b/plugins/utils.js @@ -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