feat: theme files are now loaded & applied on startup

This commit is contained in:
Rick van Lieshout 2023-05-10 22:07:11 +02:00
parent a408a6a8cc
commit 1761c8dd40
5 changed files with 29 additions and 12 deletions

View File

@ -66,7 +66,7 @@ function handleFileUploads() {
function refreshSettings() {
adBlock.checked = settingsStore.get(settings.adBlock);
api.checked = settingsStore.get(settings.api);
customCSS.value = settingsStore.get(settings.customCSS);
customCSS.value = settingsStore.get<string, string[]>(settings.customCSS).join("\n");
disableBackgroundThrottle.checked = settingsStore.get(settings.disableBackgroundThrottle);
disableHardwareMediaKeys.checked = settingsStore.get(settings.flags.disableHardwareMediaKeys);
enableCustomHotkeys.checked = settingsStore.get(settings.enableCustomHotkeys);

View File

@ -1,5 +1,6 @@
import { Notification, app, dialog } from "@electron/remote";
import { ipcRenderer } from "electron";
import fs from "fs";
import Player from "mpris-service";
import { globalEvents } from "./constants/globalEvents";
import { settings } from "./constants/settings";
@ -147,8 +148,24 @@ const elements = {
function addCustomCss() {
window.addEventListener("DOMContentLoaded", () => {
const selectedTheme = settingsStore.get(settings.theme);
if (selectedTheme !== "none") {
const themeFile = `${process.resourcesPath}/${selectedTheme}`;
fs.readFile(themeFile, "utf-8", (err, data) => {
if (err) {
alert("An error ocurred reading the theme file.");
return;
}
const themeStyle = document.createElement("style");
themeStyle.innerHTML = data;
document.head.appendChild(themeStyle);
});
}
// read customCSS (it will override the theme)
const style = document.createElement("style");
style.innerHTML = settingsStore.get(settings.customCSS);
style.innerHTML = settingsStore.get<string, string[]>(settings.customCSS).join("\n");
document.head.appendChild(style);
});
}

10
src/themes/Blood.scss Normal file
View File

@ -0,0 +1,10 @@
$foreground: red;
$background: black;
span {
color: $foreground;
}
.sidebar--WvRg_ {
background-color: $background;
}

View File

@ -1,3 +0,0 @@
h2 {
color: black;
}

View File

@ -1,7 +0,0 @@
h1 {
color: black;
.title {
color: blue;
}
}