1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

electron storage implementation

This commit is contained in:
Kyle Spearrin
2019-03-11 22:36:29 -04:00
parent 650ab56353
commit 49e06e77c4
3 changed files with 120 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
import * as fs from 'fs';
import { StorageService } from '../../abstractions/storage.service';
import { NodeUtils } from '../../misc/nodeUtils';
// tslint:disable-next-line
const Store = require('electron-store');
export class ElectronStorageService implements StorageService {
private store: any;
constructor(dir: string, defaults = {}) {
if (!fs.existsSync(dir)) {
NodeUtils.mkdirpSync(dir, '700');
}
const storeConfig: any = {
defaults: defaults,
name: 'data',
};
this.store = new Store(storeConfig);
}
get<T>(key: string): Promise<T> {
const val = this.store.get(key) as T;
return Promise.resolve(val != null ? val : null);
}
save(key: string, obj: any): Promise<any> {
this.store.set(key, obj);
return Promise.resolve();
}
remove(key: string): Promise<any> {
this.store.delete(key);
return Promise.resolve();
}
}