diff --git a/src/main.ts b/src/main.ts index 1bb9049..bd3d116 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,11 @@ import {createSplashWindow} from "./splash/main"; export let iconPath: string; export let settings: any; export let customTitlebar: boolean; +app.on("render-process-gone", (event, webContents, details) => { + if (details.reason == "crashed") { + app.relaunch(); + } +}); async function args(): Promise { let argNum = 2; if (process.argv[0] == "electron") argNum++; diff --git a/src/settings/main.ts b/src/settings/main.ts index 433a40f..0862e9e 100644 --- a/src/settings/main.ts +++ b/src/settings/main.ts @@ -54,19 +54,21 @@ export function createSettingsWindow(): void { fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), ""); } settingsWindow.webContents.on("did-finish-load", () => { - fs.readdirSync(themesFolder).forEach((file) => { - try { - const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); - let themeFile = JSON.parse(manifest); - 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); - } - }); + if (!settingsWindow.webContents.isLoading()) { + fs.readdirSync(themesFolder).forEach((file) => { + try { + const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); + let themeFile = JSON.parse(manifest); + 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); + } + }); + } }); ipcMain.on("saveSettings", (_event, args: Settings) => { console.log(args); diff --git a/src/themeManager/main.ts b/src/themeManager/main.ts index 87415af..75f170d 100644 --- a/src/themeManager/main.ts +++ b/src/themeManager/main.ts @@ -195,14 +195,16 @@ export function createTManagerWindow(): void { } }); themeWindow.webContents.on("did-finish-load", () => { - 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); - } - }); + 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); + } + }); + } }); managerLoadPage(); diff --git a/src/window.ts b/src/window.ts index 7925784..caf222f 100644 --- a/src/window.ts +++ b/src/window.ts @@ -198,28 +198,30 @@ async function doAfterDefiningTheWindow(): Promise { fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), ""); } mainWindow.webContents.on("did-finish-load", () => { - 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"); + 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); } - } catch (err) { - console.error(err); - } - }); + }); + } }); await setMenu(); mainWindow.on("close", async (e) => { @@ -370,9 +372,11 @@ export async function createInviteWindow(code: string): Promise { }); inviteWindow.loadURL(formInviteURL); inviteWindow.webContents.once("did-finish-load", () => { - inviteWindow.show(); - inviteWindow.webContents.once("will-navigate", () => { - inviteWindow.close(); - }); + if (!mainWindow.webContents.isLoading()) { + inviteWindow.show(); + inviteWindow.webContents.once("will-navigate", () => { + inviteWindow.close(); + }); + } }); }