Allow user to pass custom CSS file

This commit is contained in:
TC
2022-08-21 23:36:02 +02:00
parent a8301f44be
commit ef6fb402bf
2 changed files with 24 additions and 1 deletions

View File

@ -84,6 +84,22 @@ function onClosed() {
function loadPlugins(win) {
injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
// Load user CSS
const cssFiles = config.get("options.cssFiles");
if (Array.isArray(cssFiles)) {
cssFiles.forEach((cssFile) => {
fileExists(
cssFile,
() => {
injectCSS(win.webContents, cssFile);
},
() => {
console.warn(`CSS file "${cssFile}" does not exist, ignoring`);
}
);
});
}
win.webContents.once("did-finish-load", () => {
if (is.dev()) {
console.log("did finish load");

View File

@ -32,9 +32,16 @@ module.exports.listenAction = (channel, callback) => {
return ipcMain.on(channel, callback);
};
module.exports.fileExists = (path, callbackIfExists) => {
module.exports.fileExists = (
path,
callbackIfExists,
callbackIfError = undefined
) => {
fs.access(path, fs.F_OK, (err) => {
if (err) {
if (callbackIfError) {
callbackIfError();
}
return;
}