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

move common electron code to jslib

This commit is contained in:
Kyle Spearrin
2018-04-24 16:00:20 -04:00
parent 768ab7dd0a
commit 5d3b99ce6f
9 changed files with 1353 additions and 13 deletions

View File

@@ -0,0 +1,35 @@
import { StorageService } from '../../abstractions/storage.service';
import { ConstantsService } from '../../services/constants.service';
// tslint:disable-next-line
const Store = require('electron-store');
export class ElectronStorageService implements StorageService {
private store: any;
constructor() {
const storeConfig: any = {
defaults: {} as any,
name: 'data',
};
// Default lock options to "on restart".
storeConfig.defaults[ConstantsService.lockOptionKey] = -1;
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();
}
}