69 lines
1.7 KiB
TypeScript

import ElectronStore from 'electron-store';
import { app } from 'electron';
import path from 'path';
const STORE_KEY_STARTUPHIDEWINDOW = 'options.startupHideWindow';
const STORE_KEY_DOWNLOADFOLDER = 'options.downloadPath';
const DOWNLOAD_FOLDER_PATH = 'DS Talk Download';
export class Storage {
private readonly store: ElectronStore<any>;
constructor() {
this.store = new ElectronStore({
cwd: path.join(__dirname, '..', '..', '..', '/bin/'),
schema: {
options: {
type: 'object',
properties: {
startupHideWindow: {
type: 'boolean'
},
downloadPath: {
type: 'string'
}
},
default: {
startupHideWindow: false,
downloadPath: path.join(
app.getPath('documents'),
DOWNLOAD_FOLDER_PATH
)
}
}
},
encryptionKey: 'ucap',
fileExtension: 'dat'
});
}
get startupHideWindow(): boolean {
return this.store.get(STORE_KEY_STARTUPHIDEWINDOW, false);
}
set startupHideWindow(startupHideWindow: boolean) {
this.store.set(STORE_KEY_STARTUPHIDEWINDOW, startupHideWindow);
}
get downloadPath(): string {
return this.store.get(STORE_KEY_DOWNLOADFOLDER, false);
}
set downloadPath(downloadPath: string) {
this.store.set(STORE_KEY_DOWNLOADFOLDER, downloadPath);
}
get constDefaultDownloadFolder(): string {
return DOWNLOAD_FOLDER_PATH;
}
reset(): void {
this.store.set({
options: {
startupHideWindow: false,
downloadPath: path.join(app.getPath('documents'), DOWNLOAD_FOLDER_PATH)
}
});
}
}
export const appStorage: Storage = new Storage();