diff --git a/src/main.ts b/src/main.ts index 8ab5669dd0d..a22bec397c0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,5 @@ -import { BrowserWindow } from 'electron'; +import { app, BrowserWindow } from 'electron'; +import * as path from 'path'; import { DesktopMainMessagingService } from './services/desktopMainMessaging.service'; import { DesktopStorageService } from './services/desktopStorage.service'; @@ -22,6 +23,13 @@ export class Main { powerMonitorMain: PowerMonitorMain; constructor() { + // Set paths for portable builds + if (process.env.PORTABLE_EXECUTABLE_DIR != null) { + const appDataPath = path.join(process.env.PORTABLE_EXECUTABLE_DIR, 'bitwarden-appdata'); + app.setPath('userData', appDataPath); + app.setPath('logs', path.join(appDataPath, 'logs')); + } + const args = process.argv.slice(1); const watch = args.some((val) => val === '--watch'); diff --git a/src/services/desktopStorage.service.ts b/src/services/desktopStorage.service.ts index ee615adaddf..f2dac40fce6 100644 --- a/src/services/desktopStorage.service.ts +++ b/src/services/desktopStorage.service.ts @@ -5,33 +5,31 @@ import { ConstantsService } from 'jslib/services/constants.service'; // tslint:disable-next-line const Store = require('electron-store'); -const storeConfig: any = { - defaults: {} as any, - name: 'bitwarden-data', -}; - -// Default lock options to "on restart". -storeConfig.defaults[ConstantsService.lockOptionKey] = -1; -// Portable builds should not use app data -if (process.env.PORTABLE_EXECUTABLE_DIR != null) { - storeConfig.cwd = process.env.PORTABLE_EXECUTABLE_DIR; -} - -const store = new Store(storeConfig); - export class DesktopStorageService 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(key: string): Promise { - const val = store.get(key) as T; + const val = this.store.get(key) as T; return Promise.resolve(val != null ? val : null); } save(key: string, obj: any): Promise { - store.set(key, obj); + this.store.set(key, obj); return Promise.resolve(); } remove(key: string): Promise { - store.delete(key); + this.store.delete(key); return Promise.resolve(); } }