import { debounce } from '../utils/debounce';
const TIMEOUT = 300;
const debouncedSave = debounce(window.electron.savePersistentStorage, TIMEOUT);
class PeristentStorage {
    constructor() {
        this.storage = window.electron.loadPersistentStorage();
    }
    set(key, value) {
        this.storage[key] = value;
        debouncedSave(this.storage);
    }
    get(key, initialValue) {
        if (this.storage[key] === undefined && initialValue !== undefined) {
            this.set(key, initialValue);
        }
        return this.storage[key];
    }
    saveImmediately() {
        window.electron.savePersistentStorage(this.storage);
    }
}
export const persistentStorage = new PeristentStorage();
