Set paths for portable builds

This commit is contained in:
Kyle Spearrin 2018-02-15 15:27:56 -05:00
parent bb52b58d69
commit bcff3f1647
2 changed files with 24 additions and 18 deletions

View File

@ -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 { DesktopMainMessagingService } from './services/desktopMainMessaging.service';
import { DesktopStorageService } from './services/desktopStorage.service'; import { DesktopStorageService } from './services/desktopStorage.service';
@ -22,6 +23,13 @@ export class Main {
powerMonitorMain: PowerMonitorMain; powerMonitorMain: PowerMonitorMain;
constructor() { 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 args = process.argv.slice(1);
const watch = args.some((val) => val === '--watch'); const watch = args.some((val) => val === '--watch');

View File

@ -5,33 +5,31 @@ import { ConstantsService } from 'jslib/services/constants.service';
// tslint:disable-next-line // tslint:disable-next-line
const Store = require('electron-store'); 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 { 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<T>(key: string): Promise<T> { get<T>(key: string): Promise<T> {
const val = store.get(key) as T; const val = this.store.get(key) as T;
return Promise.resolve(val != null ? val : null); return Promise.resolve(val != null ? val : null);
} }
save(key: string, obj: any): Promise<any> { save(key: string, obj: any): Promise<any> {
store.set(key, obj); this.store.set(key, obj);
return Promise.resolve(); return Promise.resolve();
} }
remove(key: string): Promise<any> { remove(key: string): Promise<any> {
store.delete(key); this.store.delete(key);
return Promise.resolve(); return Promise.resolve();
} }
} }