Skip to content

Commit

Permalink
fix injectCSS did-finish-load listener overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Apr 17, 2022
1 parent 2305872 commit 2dfe098
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions plugins/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2dfe098

Please sign in to comment.