diff --git a/CHANGELOG.md b/CHANGELOG.md index e9e8d59..059bd1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [next] +- Fixed bug with theme files from user directory trying to load: "an error occurred reading the theme file" - Fixed: config flags not being set correctly - [DEV]: - Logger is now static and will automatically call either ipcRenderer or ipcMain diff --git a/src/pages/settings/theming.ts b/src/pages/settings/theming.ts index b35cfcc..cb0bd2e 100644 --- a/src/pages/settings/theming.ts +++ b/src/pages/settings/theming.ts @@ -1,4 +1,5 @@ import fs from "fs"; +import { Logger } from "../../features/logger"; const cssFilter = (file: string) => file.endsWith(".css"); const sort = (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()); @@ -36,7 +37,7 @@ export const getThemeListFromDirectory = (directory: string): string[] => { makeUserThemesDirectory(directory); return fs.readdirSync(directory).filter(cssFilter).sort(sort); } catch (err) { - console.error(err); + Logger.log(`Failed to get files from ${directory}`, err); return []; } }; @@ -49,6 +50,6 @@ export const makeUserThemesDirectory = (directory: string) => { try { fs.mkdirSync(directory, { recursive: true }); } catch (err) { - console.error(err); + Logger.log(`Failed to make user theme directory: ${directory}`, err); } }; diff --git a/src/preload.ts b/src/preload.ts index ea3077a..3a79da4 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -17,6 +17,7 @@ import { settingsStore } from "./scripts/settings"; import { setTitle } from "./scripts/window-functions"; import { StoreData } from "./features/listenbrainz/models/storeData"; import { MediaStatus } from "./models/mediaStatus"; +import { Logger } from "./features/logger"; const notificationPath = `${app.getPath("userData")}/notification.jpg`; const appName = "Tidal Hifi"; @@ -157,12 +158,14 @@ const elements = { function addCustomCss() { window.addEventListener("DOMContentLoaded", () => { - const selectedTheme = settingsStore.get(settings.theme); + const selectedTheme = settingsStore.get(settings.theme); if (selectedTheme !== "none") { - const themeFile = `${process.resourcesPath}/${selectedTheme}`; + const userThemePath = `${app.getPath("userData")}/themes/${selectedTheme}`; + const resourcesThemePath = `${process.resourcesPath}/${selectedTheme}`; + const themeFile = fs.existsSync(userThemePath) ? userThemePath : resourcesThemePath; fs.readFile(themeFile, "utf-8", (err, data) => { if (err) { - alert("An error ocurred reading the theme file."); + Logger.alert("An error ocurred reading the theme file.", err, alert); return; }