mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
Several project files user folder (#617)
* feat: save loaded file across sessions
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Low } from 'lowdb';
|
||||
import { JSONFile } from 'lowdb/node';
|
||||
import { join } from 'path';
|
||||
|
||||
import { getAppDataPath } from '../setup.js';
|
||||
|
||||
interface Config {
|
||||
lastLoadedProject: string;
|
||||
}
|
||||
|
||||
class ConfigService {
|
||||
private config: Low<Config>;
|
||||
private configPath: string;
|
||||
|
||||
constructor() {
|
||||
this.configPath = join(getAppDataPath(), 'config.json');
|
||||
const adapter = new JSONFile<Config>(this.configPath);
|
||||
this.config = new Low<Config>(adapter);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
private async init() {
|
||||
await this.config.read();
|
||||
await this.config.write();
|
||||
}
|
||||
|
||||
async getConfig(): Promise<Config> {
|
||||
await this.config.read();
|
||||
return this.config.data;
|
||||
}
|
||||
|
||||
async updateDatabaseConfig(filename: string): Promise<void> {
|
||||
if (process.env.IS_TEST) return;
|
||||
|
||||
this.config.data.lastLoadedProject = filename;
|
||||
await this.config.write();
|
||||
}
|
||||
}
|
||||
|
||||
export const configService = new ConfigService();
|
||||
Reference in New Issue
Block a user