feat: theme selection is now stored in the config file

This commit is contained in:
Rick van Lieshout 2023-05-09 23:57:16 +02:00
parent 4350ab9bd9
commit 6e5a2c626c
3 changed files with 15 additions and 2 deletions

View File

@ -33,6 +33,7 @@ export const settings = {
singleInstance: "singleInstance", singleInstance: "singleInstance",
skipArtists: "skipArtists", skipArtists: "skipArtists",
skippedArtists: "skippedArtists", skippedArtists: "skippedArtists",
theme: "theme",
trayIcon: "trayIcon", trayIcon: "trayIcon",
updateFrequency: "updateFrequency", updateFrequency: "updateFrequency",
windowBounds: { windowBounds: {

View File

@ -22,6 +22,7 @@ let adBlock: HTMLInputElement,
singleInstance: HTMLInputElement, singleInstance: HTMLInputElement,
skipArtists: HTMLInputElement, skipArtists: HTMLInputElement,
skippedArtists: HTMLInputElement, skippedArtists: HTMLInputElement,
theme: HTMLSelectElement,
trayIcon: HTMLInputElement, trayIcon: HTMLInputElement,
updateFrequency: HTMLInputElement; updateFrequency: HTMLInputElement;
@ -79,6 +80,7 @@ function refreshSettings() {
port.value = settingsStore.get(settings.apiSettings.port); port.value = settingsStore.get(settings.apiSettings.port);
singleInstance.checked = settingsStore.get(settings.singleInstance); singleInstance.checked = settingsStore.get(settings.singleInstance);
skipArtists.checked = settingsStore.get(settings.skipArtists); skipArtists.checked = settingsStore.get(settings.skipArtists);
theme.value = settingsStore.get(settings.theme);
skippedArtists.value = settingsStore.get<string, string[]>(settings.skippedArtists).join("\n"); skippedArtists.value = settingsStore.get<string, string[]>(settings.skippedArtists).join("\n");
trayIcon.checked = settingsStore.get(settings.trayIcon); trayIcon.checked = settingsStore.get(settings.trayIcon);
updateFrequency.value = settingsStore.get(settings.updateFrequency); updateFrequency.value = settingsStore.get(settings.updateFrequency);
@ -110,8 +112,8 @@ function restart() {
* Bind UI components to functions after DOMContentLoaded * Bind UI components to functions after DOMContentLoaded
*/ */
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
function get(id: string): HTMLInputElement { function get<T = HTMLInputElement>(id: string): T {
return document.getElementById(id) as HTMLInputElement; return document.getElementById(id) as T;
} }
getThemeFiles(); getThemeFiles();
@ -143,6 +145,13 @@ window.addEventListener("DOMContentLoaded", () => {
}); });
} }
function addSelectListener(source: HTMLSelectElement, key: string) {
source.addEventListener("change", () => {
settingsStore.set(key, source.value);
ipcRenderer.send(globalEvents.storeChanged);
});
}
ipcRenderer.on("refreshData", () => { ipcRenderer.on("refreshData", () => {
refreshSettings(); refreshSettings();
}); });
@ -165,6 +174,7 @@ window.addEventListener("DOMContentLoaded", () => {
notifications = get("notifications"); notifications = get("notifications");
playBackControl = get("playBackControl"); playBackControl = get("playBackControl");
port = get("port"); port = get("port");
theme = get<HTMLSelectElement>("themesList");
trayIcon = get("trayIcon"); trayIcon = get("trayIcon");
skipArtists = get("skipArtists"); skipArtists = get("skipArtists");
skippedArtists = get("skippedArtists"); skippedArtists = get("skippedArtists");
@ -190,6 +200,7 @@ window.addEventListener("DOMContentLoaded", () => {
addInputListener(skipArtists, settings.skipArtists); addInputListener(skipArtists, settings.skipArtists);
addTextAreaListener(skippedArtists, settings.skippedArtists); addTextAreaListener(skippedArtists, settings.skippedArtists);
addInputListener(singleInstance, settings.singleInstance); addInputListener(singleInstance, settings.singleInstance);
addSelectListener(theme, settings.theme);
addInputListener(trayIcon, settings.trayIcon); addInputListener(trayIcon, settings.trayIcon);
addInputListener(updateFrequency, settings.updateFrequency); addInputListener(updateFrequency, settings.updateFrequency);
}); });

View File

@ -30,6 +30,7 @@ export const settingsStore = new Store({
singleInstance: true, singleInstance: true,
skipArtists: false, skipArtists: false,
skippedArtists: [""], skippedArtists: [""],
theme: "none",
trayIcon: true, trayIcon: true,
updateFrequency: 500, updateFrequency: 500,
windowBounds: { width: 800, height: 600 }, windowBounds: { width: 800, height: 600 },