Fix ENOENT on first install

This commit is contained in:
V 2023-06-21 17:24:50 +02:00
parent fd45068a46
commit 23c0647e6c
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905

View file

@ -4,8 +4,8 @@
* Copyright (c) 2023 Vendicated and Vencord contributors * Copyright (c) 2023 Vendicated and Vencord contributors
*/ */
import { readFileSync, writeFileSync } from "fs"; import { mkdirSync, readFileSync, writeFileSync } from "fs";
import { join } from "path"; import { dirname, join } from "path";
import type { Settings as TSettings } from "shared/settings"; import type { Settings as TSettings } from "shared/settings";
import { SettingsStore } from "shared/utils/SettingsStore"; import { SettingsStore } from "shared/utils/SettingsStore";
@ -25,7 +25,10 @@ function loadSettings<T extends object = any>(file: string, name: string) {
} catch {} } catch {}
const store = new SettingsStore(settings); const store = new SettingsStore(settings);
store.addGlobalChangeListener(o => writeFileSync(file, JSON.stringify(o, null, 4))); store.addGlobalChangeListener(o => {
mkdirSync(dirname(file), { recursive: true });
writeFileSync(file, JSON.stringify(o, null, 4));
});
return store; return store;
} }