Skip to content

Commit a0543d1

Browse files
authored
Merge pull request #800 from th-ch/custom-css-file
Allow user to pass custom CSS file
2 parents a8301f4 + e62ee35 commit a0543d1

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-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 themes = config.get("options.themes");
89+
if (Array.isArray(themes)) {
90+
themes.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");

menu.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,34 @@ const mainMenuTemplate = (win) => {
100100
config.set("options.ForceShowLikeButtons", item.checked);
101101
},
102102
},
103+
{
104+
label: "Theme",
105+
submenu: [
106+
{
107+
label: "No theme",
108+
type: "radio",
109+
checked: !config.get("options.themes"), // todo rename "themes"
110+
click: () => {
111+
config.set("options.themes", []);
112+
},
113+
},
114+
{ type: "separator" },
115+
{
116+
label: "Import custom CSS file",
117+
type: "radio",
118+
checked: false,
119+
click: async () => {
120+
const { filePaths } = await dialog.showOpenDialog({
121+
filters: [{ name: "CSS Files", extensions: ["css"] }],
122+
properties: ["openFile", "multiSelections"],
123+
});
124+
if (filePaths) {
125+
config.set("options.themes", filePaths);
126+
}
127+
},
128+
},
129+
],
130+
},
103131
],
104132
},
105133
{

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

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ If you get an error "is damaged and can’t be opened." when launching the app,
9797

9898
> If using `Hide Menu` option - you can show the menu with the `alt` key (or `escape` if using the in-app-menu plugin)
9999
100+
## Themes
101+
102+
You can load CSS files to change the look of the application (Options > Visual Tweaks > Themes).
103+
104+
Some predefined themes are available in https://github.com/OceanicSquirrel/themes-for-ytmdesktop-player.
105+
100106
## Dev
101107

102108
```sh

0 commit comments

Comments
 (0)