mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 10:23:54 +00:00
fix: prevent calling service before init
This commit is contained in:
committed by
Carlos Valente
parent
6c20cb5e99
commit
cbf3d566b9
@@ -14,21 +14,24 @@ interface Config {
|
||||
class AppStateService {
|
||||
private config: Low<Config>;
|
||||
private pathToFile: string;
|
||||
private didInit = false;
|
||||
|
||||
constructor(appStatePath: string) {
|
||||
this.pathToFile = appStatePath;
|
||||
const adapter = new JSONFile<Config>(this.pathToFile);
|
||||
this.config = new Low<Config>(adapter, null);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
private async init() {
|
||||
await this.config.read();
|
||||
await this.config.write();
|
||||
this.didInit = true;
|
||||
}
|
||||
|
||||
async get(): Promise<Config> {
|
||||
if (!this.didInit) {
|
||||
await this.init();
|
||||
}
|
||||
await this.config.read();
|
||||
return this.config.data;
|
||||
}
|
||||
@@ -36,6 +39,10 @@ class AppStateService {
|
||||
async updateDatabaseConfig(filename: string): Promise<void> {
|
||||
if (isTest) return;
|
||||
|
||||
if (!this.didInit) {
|
||||
await this.init();
|
||||
}
|
||||
|
||||
this.config.data.lastLoadedProject = filename;
|
||||
await this.config.write();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user