From f2cfcbfb5dad13df306f1e1e36a6b2430d2a612d Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:54:04 +0200 Subject: [PATCH] fix theme loading --- src/settings/main.ts | 25 +++++++++++++++-------- src/themeManager/main.ts | 19 ++++++++--------- src/window.ts | 44 +++++++++++++++++++--------------------- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/settings/main.ts b/src/settings/main.ts index 0862e9e..fe584e2 100644 --- a/src/settings/main.ts +++ b/src/settings/main.ts @@ -54,21 +54,28 @@ export function createSettingsWindow(): void { fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), ""); } settingsWindow.webContents.on("did-finish-load", () => { - if (!settingsWindow.webContents.isLoading()) { - fs.readdirSync(themesFolder).forEach((file) => { - try { - const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); - let themeFile = JSON.parse(manifest); + fs.readdirSync(themesFolder).forEach((file) => { + try { + const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); + let themeFile = JSON.parse(manifest); + if ( + fs + .readFileSync(path.join(userDataPath, "/disabled.txt")) + .toString() + .includes(themeFile.name.replace(" ", "-")) + ) { + console.log(`%cSkipped ${themeFile.name} made by ${themeFile.author}`, "color:red"); + } else { settingsWindow.webContents.send( "themeLoader", fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8") ); console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red"); - } catch (err) { - console.error(err); } - }); - } + } catch (err) { + console.error(err); + } + }); }); ipcMain.on("saveSettings", (_event, args: Settings) => { console.log(args); diff --git a/src/themeManager/main.ts b/src/themeManager/main.ts index 75f170d..b672e9d 100644 --- a/src/themeManager/main.ts +++ b/src/themeManager/main.ts @@ -195,16 +195,15 @@ export function createTManagerWindow(): void { } }); themeWindow.webContents.on("did-finish-load", () => { - if (!themeWindow.webContents.isLoading()) { - fs.readdirSync(themesFolder).forEach((file) => { - try { - const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); - themeWindow.webContents.send("themeManifest", manifest); - } catch (err) { - console.error(err); - } - }); - } + fs.readdirSync(themesFolder).forEach((file) => { + try { + const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); + console.log(manifest); + themeWindow.webContents.send("themeManifest", manifest); + } catch (err) { + console.error(err); + } + }); }); managerLoadPage(); diff --git a/src/window.ts b/src/window.ts index b582aeb..18b058b 100644 --- a/src/window.ts +++ b/src/window.ts @@ -195,30 +195,28 @@ async function doAfterDefiningTheWindow(): Promise { fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), ""); } mainWindow.webContents.on("did-finish-load", () => { - if (!mainWindow.webContents.isLoading()) { - fs.readdirSync(themesFolder).forEach((file) => { - try { - const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); - let themeFile = JSON.parse(manifest); - if ( - fs - .readFileSync(path.join(userDataPath, "/disabled.txt")) - .toString() - .includes(themeFile.name.replace(" ", "-")) - ) { - console.log(`%cSkipped ${themeFile.name} made by ${themeFile.author}`, "color:red"); - } else { - mainWindow.webContents.send( - "themeLoader", - fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8") - ); - console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red"); - } - } catch (err) { - console.error(err); + fs.readdirSync(themesFolder).forEach((file) => { + try { + const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); + let themeFile = JSON.parse(manifest); + if ( + fs + .readFileSync(path.join(userDataPath, "/disabled.txt")) + .toString() + .includes(themeFile.name.replace(" ", "-")) + ) { + console.log(`%cSkipped ${themeFile.name} made by ${themeFile.author}`, "color:red"); + } else { + mainWindow.webContents.send( + "themeLoader", + fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8") + ); + console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red"); } - }); - } + } catch (err) { + console.error(err); + } + }); }); await setMenu(); mainWindow.on("close", async (e) => {