From 6e5a2c626c612f42b52fa82f6a93fa63f9718b8a Mon Sep 17 00:00:00 2001 From: Mastermindzh Date: Tue, 9 May 2023 23:57:16 +0200 Subject: [PATCH] feat: theme selection is now stored in the config file --- src/constants/settings.ts | 1 + src/pages/settings/preload.ts | 15 +++++++++++++-- src/scripts/settings.ts | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 04444e6..df2c39f 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -33,6 +33,7 @@ export const settings = { singleInstance: "singleInstance", skipArtists: "skipArtists", skippedArtists: "skippedArtists", + theme: "theme", trayIcon: "trayIcon", updateFrequency: "updateFrequency", windowBounds: { diff --git a/src/pages/settings/preload.ts b/src/pages/settings/preload.ts index b91479b..b693af4 100644 --- a/src/pages/settings/preload.ts +++ b/src/pages/settings/preload.ts @@ -22,6 +22,7 @@ let adBlock: HTMLInputElement, singleInstance: HTMLInputElement, skipArtists: HTMLInputElement, skippedArtists: HTMLInputElement, + theme: HTMLSelectElement, trayIcon: HTMLInputElement, updateFrequency: HTMLInputElement; @@ -79,6 +80,7 @@ function refreshSettings() { port.value = settingsStore.get(settings.apiSettings.port); singleInstance.checked = settingsStore.get(settings.singleInstance); skipArtists.checked = settingsStore.get(settings.skipArtists); + theme.value = settingsStore.get(settings.theme); skippedArtists.value = settingsStore.get(settings.skippedArtists).join("\n"); trayIcon.checked = settingsStore.get(settings.trayIcon); updateFrequency.value = settingsStore.get(settings.updateFrequency); @@ -110,8 +112,8 @@ function restart() { * Bind UI components to functions after DOMContentLoaded */ window.addEventListener("DOMContentLoaded", () => { - function get(id: string): HTMLInputElement { - return document.getElementById(id) as HTMLInputElement; + function get(id: string): T { + return document.getElementById(id) as T; } 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", () => { refreshSettings(); }); @@ -165,6 +174,7 @@ window.addEventListener("DOMContentLoaded", () => { notifications = get("notifications"); playBackControl = get("playBackControl"); port = get("port"); + theme = get("themesList"); trayIcon = get("trayIcon"); skipArtists = get("skipArtists"); skippedArtists = get("skippedArtists"); @@ -190,6 +200,7 @@ window.addEventListener("DOMContentLoaded", () => { addInputListener(skipArtists, settings.skipArtists); addTextAreaListener(skippedArtists, settings.skippedArtists); addInputListener(singleInstance, settings.singleInstance); + addSelectListener(theme, settings.theme); addInputListener(trayIcon, settings.trayIcon); addInputListener(updateFrequency, settings.updateFrequency); }); diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 8697d6c..b20b6ae 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -30,6 +30,7 @@ export const settingsStore = new Store({ singleInstance: true, skipArtists: false, skippedArtists: [""], + theme: "none", trayIcon: true, updateFrequency: 500, windowBounds: { width: 800, height: 600 },