diff --git a/src/services/data.ts b/src/services/data.ts index 37b40b9..3c717cf 100644 --- a/src/services/data.ts +++ b/src/services/data.ts @@ -1,15 +1,22 @@ +interface Data { + limboMode: boolean +} + export default class DataService { private static file: Bun.BunFile | undefined; - private static _data: Record = {}; + private static _data: Data = { + // default values (will be overwritten) + limboMode: false + }; static async load() { this.file = Bun.file("./data.json"); if (!(await this.file.exists())) - await Bun.write(this.file, JSON.stringify({}, null, 2)); - this._data = await this.file.json(); + await Bun.write(this.file, JSON.stringify(this._data, null, 2)); + this._data = { ...this._data, ...(await this.file.json()) }; } - static set data(data: Record) { + static set data(data: Data) { if (!this.file) throw new Error("DataService is not loaded. Please call DataService.load()"); this._data = data; void Bun.write(this.file, JSON.stringify(this._data, null, 2));