mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-24 11:55:50 +01:00
Set paths for portable builds
This commit is contained in:
parent
bb52b58d69
commit
bcff3f1647
10
src/main.ts
10
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');
|
||||
|
||||
|
@ -5,33 +5,31 @@ import { ConstantsService } from 'jslib/services/constants.service';
|
||||
// tslint:disable-next-line
|
||||
const Store = require('electron-store');
|
||||
|
||||
export class DesktopStorageService implements StorageService {
|
||||
private store: any;
|
||||
|
||||
constructor() {
|
||||
const storeConfig: any = {
|
||||
defaults: {} as any,
|
||||
name: 'bitwarden-data',
|
||||
name: '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;
|
||||
this.store = new Store(storeConfig);
|
||||
}
|
||||
|
||||
const store = new Store(storeConfig);
|
||||
|
||||
export class DesktopStorageService implements StorageService {
|
||||
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);
|
||||
}
|
||||
|
||||
save(key: string, obj: any): Promise<any> {
|
||||
store.set(key, obj);
|
||||
this.store.set(key, obj);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
remove(key: string): Promise<any> {
|
||||
store.delete(key);
|
||||
this.store.delete(key);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user