diff --git a/src/main.ts b/src/main.ts index de3890b0c3..40941cd5d0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,6 @@ import * as program from 'commander'; import { AuthService } from 'jslib/services/auth.service'; - import { LoginCommand } from './commands/login.command'; import { CryptoService } from 'jslib/services/crypto.service'; @@ -19,13 +18,12 @@ import { NodeMessagingService } from './services/nodeMessaging.service'; const platformUtilsService = new NodePlatformUtilsService(); const cryptoFunctionService = new NodeCryptoFunctionService(); -const storageService = new NodeStorageService('./scratch'); +const storageService = new NodeStorageService('Bitwarden CLI'); const cryptoService = new CryptoService(storageService, storageService, cryptoFunctionService); const appIdService = new AppIdService(storageService); const tokenService = new TokenService(storageService); const messagingService = new NodeMessagingService(); -const apiService = new ApiService(tokenService, platformUtilsService, - (expired: boolean) => { }); +const apiService = new ApiService(tokenService, platformUtilsService, (expired: boolean) => { }); const environmentService = new EnvironmentService(apiService, storageService); const userService = new UserService(tokenService, storageService); const containerService = new ContainerService(cryptoService, platformUtilsService); diff --git a/src/services/nodeStorage.service.ts b/src/services/nodeStorage.service.ts index 28143ee402..8e8242e09d 100644 --- a/src/services/nodeStorage.service.ts +++ b/src/services/nodeStorage.service.ts @@ -4,10 +4,19 @@ import { Utils } from 'jslib/misc/utils'; let localStorage = Utils.isBrowser ? window.localStorage : null; export class NodeStorageService implements StorageService { - constructor(dirLocation: string) { + constructor(appDirName: string) { if (Utils.isNode && localStorage == null) { const LocalStorage = require('node-localstorage').LocalStorage; - localStorage = new LocalStorage(dirLocation); + let path = null; + if (process.platform === 'darwin') { + path = process.env.HOME + 'Library/Application Support'; + } else if (process.platform === 'win32') { + path = process.env.APPDATA; + } else { + path = process.env.HOME + '.config'; + } + path += ('/' + appDirName + '/data'); + localStorage = new LocalStorage(path); } }