mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
9877bf4fd3
- allow nulls in converter else not not null'll fail
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
import config from 'utils/config';
|
|
|
|
export class Config {
|
|
#useElectronConfig: boolean;
|
|
fallback: Map<string, unknown> = new Map();
|
|
constructor(isElectron: boolean) {
|
|
this.#useElectronConfig = isElectron;
|
|
}
|
|
|
|
get store(): Record<string, unknown> {
|
|
if (this.#useElectronConfig) {
|
|
return config.store;
|
|
} else {
|
|
const store: Record<string, unknown> = {};
|
|
|
|
for (const key of this.fallback.keys()) {
|
|
store[key] = this.fallback.get(key);
|
|
}
|
|
|
|
return store;
|
|
}
|
|
}
|
|
|
|
get(key: string, defaultValue?: unknown): unknown {
|
|
if (this.#useElectronConfig) {
|
|
return config.get(key, defaultValue);
|
|
} else {
|
|
return this.fallback.get(key) ?? defaultValue;
|
|
}
|
|
}
|
|
|
|
set(key: string, value: unknown) {
|
|
if (this.#useElectronConfig) {
|
|
config.set(key, value);
|
|
} else {
|
|
this.fallback.set(key, value);
|
|
}
|
|
}
|
|
|
|
delete(key: string) {
|
|
if (this.#useElectronConfig) {
|
|
config.delete(key);
|
|
} else {
|
|
this.fallback.delete(key);
|
|
}
|
|
}
|
|
|
|
clear() {
|
|
if (this.#useElectronConfig) {
|
|
config.clear();
|
|
} else {
|
|
this.fallback.clear();
|
|
}
|
|
}
|
|
}
|