mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-04 13:59:09 +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 {
|
class AppStateService {
|
||||||
private config: Low<Config>;
|
private config: Low<Config>;
|
||||||
private pathToFile: string;
|
private pathToFile: string;
|
||||||
|
private didInit = false;
|
||||||
|
|
||||||
constructor(appStatePath: string) {
|
constructor(appStatePath: string) {
|
||||||
this.pathToFile = appStatePath;
|
this.pathToFile = appStatePath;
|
||||||
const adapter = new JSONFile<Config>(this.pathToFile);
|
const adapter = new JSONFile<Config>(this.pathToFile);
|
||||||
this.config = new Low<Config>(adapter, null);
|
this.config = new Low<Config>(adapter, null);
|
||||||
|
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
await this.config.read();
|
await this.config.read();
|
||||||
await this.config.write();
|
await this.config.write();
|
||||||
|
this.didInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(): Promise<Config> {
|
async get(): Promise<Config> {
|
||||||
|
if (!this.didInit) {
|
||||||
|
await this.init();
|
||||||
|
}
|
||||||
await this.config.read();
|
await this.config.read();
|
||||||
return this.config.data;
|
return this.config.data;
|
||||||
}
|
}
|
||||||
@@ -36,6 +39,10 @@ class AppStateService {
|
|||||||
async updateDatabaseConfig(filename: string): Promise<void> {
|
async updateDatabaseConfig(filename: string): Promise<void> {
|
||||||
if (isTest) return;
|
if (isTest) return;
|
||||||
|
|
||||||
|
if (!this.didInit) {
|
||||||
|
await this.init();
|
||||||
|
}
|
||||||
|
|
||||||
this.config.data.lastLoadedProject = filename;
|
this.config.data.lastLoadedProject = filename;
|
||||||
await this.config.write();
|
await this.config.write();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user