Skip to content

Commit ef6fb40

Browse files
committed
Allow user to pass custom CSS file
1 parent a8301f4 commit ef6fb40

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ function onClosed() {
8484

8585
function loadPlugins(win) {
8686
injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
87+
// Load user CSS
88+
const cssFiles = config.get("options.cssFiles");
89+
if (Array.isArray(cssFiles)) {
90+
cssFiles.forEach((cssFile) => {
91+
fileExists(
92+
cssFile,
93+
() => {
94+
injectCSS(win.webContents, cssFile);
95+
},
96+
() => {
97+
console.warn(`CSS file "${cssFile}" does not exist, ignoring`);
98+
}
99+
);
100+
});
101+
}
102+
87103
win.webContents.once("did-finish-load", () => {
88104
if (is.dev()) {
89105
console.log("did finish load");

plugins/utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,16 @@ module.exports.listenAction = (channel, callback) => {
3232
return ipcMain.on(channel, callback);
3333
};
3434

35-
module.exports.fileExists = (path, callbackIfExists) => {
35+
module.exports.fileExists = (
36+
path,
37+
callbackIfExists,
38+
callbackIfError = undefined
39+
) => {
3640
fs.access(path, fs.F_OK, (err) => {
3741
if (err) {
42+
if (callbackIfError) {
43+
callbackIfError();
44+
}
3845
return;
3946
}
4047

0 commit comments

Comments
 (0)