fix theme loading

This commit is contained in:
smartfrigde 2023-07-18 16:54:04 +02:00
parent 6f6a5b2ca8
commit f2cfcbfb5d
3 changed files with 46 additions and 42 deletions

View file

@ -54,21 +54,28 @@ export function createSettingsWindow(): void {
fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), ""); fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), "");
} }
settingsWindow.webContents.on("did-finish-load", () => { settingsWindow.webContents.on("did-finish-load", () => {
if (!settingsWindow.webContents.isLoading()) { fs.readdirSync(themesFolder).forEach((file) => {
fs.readdirSync(themesFolder).forEach((file) => { try {
try { const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8");
const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); let themeFile = JSON.parse(manifest);
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( settingsWindow.webContents.send(
"themeLoader", "themeLoader",
fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8") fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8")
); );
console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red"); 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) => { ipcMain.on("saveSettings", (_event, args: Settings) => {
console.log(args); console.log(args);

View file

@ -195,16 +195,15 @@ export function createTManagerWindow(): void {
} }
}); });
themeWindow.webContents.on("did-finish-load", () => { themeWindow.webContents.on("did-finish-load", () => {
if (!themeWindow.webContents.isLoading()) { fs.readdirSync(themesFolder).forEach((file) => {
fs.readdirSync(themesFolder).forEach((file) => { try {
try { const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8");
const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); console.log(manifest);
themeWindow.webContents.send("themeManifest", manifest); themeWindow.webContents.send("themeManifest", manifest);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
}); });
}
}); });
managerLoadPage(); managerLoadPage();

View file

@ -195,30 +195,28 @@ async function doAfterDefiningTheWindow(): Promise<void> {
fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), ""); fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), "");
} }
mainWindow.webContents.on("did-finish-load", () => { mainWindow.webContents.on("did-finish-load", () => {
if (!mainWindow.webContents.isLoading()) { fs.readdirSync(themesFolder).forEach((file) => {
fs.readdirSync(themesFolder).forEach((file) => { try {
try { const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8");
const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); let themeFile = JSON.parse(manifest);
let themeFile = JSON.parse(manifest); if (
if ( fs
fs .readFileSync(path.join(userDataPath, "/disabled.txt"))
.readFileSync(path.join(userDataPath, "/disabled.txt")) .toString()
.toString() .includes(themeFile.name.replace(" ", "-"))
.includes(themeFile.name.replace(" ", "-")) ) {
) { console.log(`%cSkipped ${themeFile.name} made by ${themeFile.author}`, "color:red");
console.log(`%cSkipped ${themeFile.name} made by ${themeFile.author}`, "color:red"); } else {
} else { mainWindow.webContents.send(
mainWindow.webContents.send( "themeLoader",
"themeLoader", fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8")
fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8") );
); console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red");
console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red");
}
} catch (err) {
console.error(err);
} }
}); } catch (err) {
} console.error(err);
}
});
}); });
await setMenu(); await setMenu();
mainWindow.on("close", async (e) => { mainWindow.on("close", async (e) => {