2
0
mirror of https://github.com/frappe/books.git synced 2024-11-12 16:36:27 +00:00
books/fyo/demux/config.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
672 B
TypeScript
Raw Normal View History

import { ConfigMap } from 'fyo/core/types';
2023-07-10 09:12:20 +00:00
import type { IPC } from 'main/preload';
export class Config {
2023-07-10 09:12:20 +00:00
config: Map<string, unknown> | IPC['store'];
constructor(isElectron: boolean) {
this.config = new Map();
if (isElectron) {
2023-07-10 09:12:20 +00:00
this.config = ipc.store;
}
}
get<K extends keyof ConfigMap>(
key: K,
defaultValue?: ConfigMap[K]
): ConfigMap[K] | undefined {
const value = this.config.get(key) as ConfigMap[K] | undefined;
return value ?? defaultValue;
}
set<K extends keyof ConfigMap>(key: K, value: ConfigMap[K]) {
this.config.set(key, value);
}
delete(key: keyof ConfigMap) {
this.config.delete(key);
}
}