Skip to content

Commit

Permalink
Merge pull request #800 from th-ch/custom-css-file
Browse files Browse the repository at this point in the history
Allow user to pass custom CSS file
  • Loading branch information
th-ch authored Aug 25, 2022
2 parents a8301f4 + e62ee35 commit a0543d1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ function onClosed() {

function loadPlugins(win) {
injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
// Load user CSS
const themes = config.get("options.themes");
if (Array.isArray(themes)) {
themes.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");
Expand Down
28 changes: 28 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,34 @@ const mainMenuTemplate = (win) => {
config.set("options.ForceShowLikeButtons", item.checked);
},
},
{
label: "Theme",
submenu: [
{
label: "No theme",
type: "radio",
checked: !config.get("options.themes"), // todo rename "themes"
click: () => {
config.set("options.themes", []);
},
},
{ type: "separator" },
{
label: "Import custom CSS file",
type: "radio",
checked: false,
click: async () => {
const { filePaths } = await dialog.showOpenDialog({
filters: [{ name: "CSS Files", extensions: ["css"] }],
properties: ["openFile", "multiSelections"],
});
if (filePaths) {
config.set("options.themes", filePaths);
}
},
},
],
},
],
},
{
Expand Down
9 changes: 8 additions & 1 deletion plugins/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ If you get an error "is damaged and can’t be opened." when launching the app,

> If using `Hide Menu` option - you can show the menu with the `alt` key (or `escape` if using the in-app-menu plugin)
## Themes

You can load CSS files to change the look of the application (Options > Visual Tweaks > Themes).

Some predefined themes are available in https://github.com/OceanicSquirrel/themes-for-ytmdesktop-player.

## Dev

```sh
Expand Down

0 comments on commit a0543d1

Please sign in to comment.