fix window state breaking

This commit is contained in:
smartfrigde 2024-01-28 15:59:47 +01:00
parent 2f93146a15
commit 6aa0c65b87

View file

@ -27,13 +27,17 @@ export async function sleep(ms: number): Promise<void> {
export async function checkIfConfigIsBroken(): Promise<void> { export async function checkIfConfigIsBroken(): Promise<void> {
try { try {
let rawdata = fs.readFileSync(getConfigLocation(), "utf-8"); let settingsData = fs.readFileSync(getConfigLocation(), "utf-8");
JSON.parse(rawdata); JSON.parse(settingsData);
console.log("Config is fine"); console.log("Config is fine");
let windowData = fs.readFileSync(getWindowStateLocation(), "utf-8");
JSON.parse(windowData);
console.log("Window config is fine");
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.log("Detected a corrupted config"); console.log("Detected a corrupted config");
setup(); setup();
fs.writeFileSync(getWindowStateLocation(), "{}", "utf-8");
dialog.showErrorBox( dialog.showErrorBox(
"Oops, something went wrong.", "Oops, something went wrong.",
"ArmCord has detected that your configuration file is corrupted, please restart the app and set your settings again. If this issue persists, report it on the support server/Github issues." "ArmCord has detected that your configuration file is corrupted, please restart the app and set your settings again. If this issue persists, report it on the support server/Github issues."
@ -215,6 +219,11 @@ export interface WindowState {
y: number; y: number;
isMaximized: boolean; isMaximized: boolean;
} }
function getWindowStateLocation() {
const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/");
return `${storagePath}window.json`;
}
export async function setWindowState(object: WindowState): Promise<void> { export async function setWindowState(object: WindowState): Promise<void> {
const userDataPath = app.getPath("userData"); const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/"); const storagePath = path.join(userDataPath, "/storage/");