13 changed files with 257 additions and 3 deletions
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
import { Injectable } from '@angular/core'; |
||||
|
||||
import { |
||||
MessagingService, |
||||
PlatformUtilsService, |
||||
} from 'jslib/abstractions'; |
||||
|
||||
@Injectable() |
||||
export class DesktopMessagingService implements MessagingService { |
||||
send(subscriber: string, arg: any = {}) { |
||||
const message = Object.assign({}, { command: subscriber }, arg); |
||||
// TODO
|
||||
} |
||||
} |
||||
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
import { Injectable } from '@angular/core'; |
||||
|
||||
import { DeviceType } from 'jslib/enums'; |
||||
|
||||
import { PlatformUtilsService } from 'jslib/abstractions'; |
||||
|
||||
const AnalyticsIds = { |
||||
[DeviceType.Windows]: 'UA-81915606-17', |
||||
[DeviceType.Linux]: 'UA-81915606-19', |
||||
[DeviceType.MacOs]: 'UA-81915606-18', |
||||
}; |
||||
|
||||
@Injectable() |
||||
export class DesktopPlatformUtilsService implements PlatformUtilsService { |
||||
private deviceCache: DeviceType = null; |
||||
private analyticsIdCache: string = null; |
||||
|
||||
getDevice(): DeviceType { |
||||
if (!this.deviceCache) { |
||||
switch (process.platform) { |
||||
case 'win32': |
||||
this.deviceCache = DeviceType.Windows; |
||||
break; |
||||
case 'darwin': |
||||
this.deviceCache = DeviceType.MacOs; |
||||
break; |
||||
case 'linux': |
||||
this.deviceCache = DeviceType.Linux; |
||||
break; |
||||
default: |
||||
this.deviceCache = DeviceType.Linux; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return this.deviceCache; |
||||
} |
||||
|
||||
getDeviceString(): string { |
||||
return DeviceType[this.getDevice()].toLowerCase(); |
||||
} |
||||
|
||||
isFirefox(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
isChrome(): boolean { |
||||
return true; |
||||
} |
||||
|
||||
isEdge(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
isOpera(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
isVivaldi(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
isSafari(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
analyticsId(): string { |
||||
if (this.analyticsIdCache) { |
||||
return this.analyticsIdCache; |
||||
} |
||||
|
||||
// FIX?
|
||||
// this.analyticsIdCache = AnalyticsIds[this.getDevice() as DeviceType];
|
||||
return this.analyticsIdCache; |
||||
} |
||||
|
||||
getDomain(uriString: string): string { |
||||
return uriString; |
||||
} |
||||
|
||||
isViewOpen(): boolean { |
||||
return true; |
||||
} |
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core'; |
||||
import { getPassword, setPassword, deletePassword } from 'keytar'; |
||||
|
||||
import { StorageService } from 'jslib/abstractions'; |
||||
|
||||
@Injectable() |
||||
export class DesktopSecureStorageService implements StorageService { |
||||
async get<T>(key: string): Promise<T> { |
||||
const val: string = await getPassword('bitwarden', key); |
||||
return val ? JSON.parse(val) as T : null |
||||
} |
||||
|
||||
async save(key: string, obj: any): Promise<any> { |
||||
await setPassword('bitwarden', key, JSON.stringify(obj)); |
||||
} |
||||
|
||||
async remove(key: string): Promise<any> { |
||||
await deletePassword('bitwarden', key); |
||||
} |
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@angular/core'; |
||||
|
||||
import { StorageService } from 'jslib/abstractions'; |
||||
|
||||
const Store = require('electron-store'); |
||||
const store = new Store(); |
||||
|
||||
@Injectable() |
||||
export class DesktopStorageService implements StorageService { |
||||
get<T>(key: string): Promise<T> { |
||||
const val = store.get(key) as T; |
||||
return Promise.resolve(val ? val : null); |
||||
} |
||||
|
||||
save(key: string, obj: any): Promise<any> { |
||||
store.set(key, obj); |
||||
return Promise.resolve(); |
||||
} |
||||
|
||||
remove(key: string): Promise<any> { |
||||
store.delete(key); |
||||
return Promise.resolve(); |
||||
} |
||||
} |
||||
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
import { NgModule } from '@angular/core'; |
||||
|
||||
import { DesktopMessagingService } from './desktopMessaging.service'; |
||||
import { DesktopPlatformUtilsService } from './desktopPlatformUtils.service'; |
||||
import { DesktopStorageService } from './desktopStorage.service'; |
||||
import { DesktopSecureStorageService } from './desktopSecureStorage.service'; |
||||
|
||||
import { |
||||
ApiService, |
||||
AppIdService, |
||||
AuthService, |
||||
CipherService, |
||||
CollectionService, |
||||
ConstantsService, |
||||
ContainerService, |
||||
CryptoService, |
||||
EnvironmentService, |
||||
FolderService, |
||||
LockService, |
||||
PasswordGenerationService, |
||||
SettingsService, |
||||
SyncService, |
||||
TokenService, |
||||
TotpService, |
||||
UserService, |
||||
UtilsService, |
||||
} from 'jslib/services'; |
||||
|
||||
import { |
||||
ApiService as ApiServiceAbstraction, |
||||
AppIdService as AppIdServiceAbstraction, |
||||
AuthService as AuthServiceAbstraction, |
||||
CipherService as CipherServiceAbstraction, |
||||
CollectionService as CollectionServiceAbstraction, |
||||
CryptoService as CryptoServiceAbstraction, |
||||
EnvironmentService as EnvironmentServiceAbstraction, |
||||
FolderService as FolderServiceAbstraction, |
||||
LockService as LockServiceAbstraction, |
||||
MessagingService as MessagingServiceAbstraction, |
||||
PasswordGenerationService as PasswordGenerationServiceAbstraction, |
||||
PlatformUtilsService as PlatformUtilsServiceAbstraction, |
||||
SettingsService as SettingsServiceAbstraction, |
||||
StorageService as StorageServiceAbstraction, |
||||
SyncService as SyncServiceAbstraction, |
||||
TokenService as TokenServiceAbstraction, |
||||
TotpService as TotpServiceAbstraction, |
||||
UserService as UserServiceAbstraction, |
||||
UtilsService as UtilsServiceAbstraction, |
||||
} from 'jslib/abstractions'; |
||||
|
||||
const utilsService = new UtilsService(); |
||||
const platformUtilsService = new DesktopPlatformUtilsService(); |
||||
const messagingService = new DesktopMessagingService(); |
||||
const storageService: StorageServiceAbstraction = new DesktopStorageService(); |
||||
//const secureStorageService: StorageServiceAbstraction = new DesktopSecureStorageService();
|
||||
const constantsService = new ConstantsService({}, 0); |
||||
const cryptoService = new CryptoService(storageService, storageService); |
||||
const tokenService = new TokenService(storageService); |
||||
const appIdService = new AppIdService(storageService); |
||||
const apiService = new ApiService(tokenService, platformUtilsService, |
||||
(expired: boolean) => { /* log out */ }); |
||||
const environmentService = new EnvironmentService(apiService, storageService); |
||||
const userService = new UserService(tokenService, storageService); |
||||
const settingsService = new SettingsService(userService, storageService); |
||||
const cipherService = new CipherService(cryptoService, userService, settingsService, |
||||
apiService, storageService); |
||||
const folderService = new FolderService(cryptoService, userService, |
||||
() => 'No Folder', apiService, storageService); |
||||
const collectionService = new CollectionService(cryptoService, userService, storageService); |
||||
const lockService = new LockService(cipherService, folderService, collectionService, |
||||
cryptoService, platformUtilsService, storageService, |
||||
() => { /* set icon */ }, () => { /* refresh badge and menu */ }); |
||||
const syncService = new SyncService(userService, apiService, settingsService, |
||||
folderService, cipherService, cryptoService, collectionService, |
||||
storageService, messagingService, (expired: boolean) => { /* log out */ }); |
||||
const passwordGenerationService = new PasswordGenerationService(cryptoService, storageService); |
||||
const totpService = new TotpService(storageService); |
||||
const containerService = new ContainerService(cryptoService, platformUtilsService); |
||||
const authService: AuthServiceAbstraction = new AuthService(cryptoService, apiService, |
||||
userService, tokenService, appIdService, platformUtilsService, constantsService, |
||||
messagingService); |
||||
|
||||
@NgModule({ |
||||
imports: [], |
||||
declarations: [], |
||||
providers: [ |
||||
{ provide: AuthServiceAbstraction, useValue: authService }, |
||||
], |
||||
}) |
||||
export class ServicesModule { |
||||
} |
||||
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
declare function require(s: string): any; |
||||
declare function escape(s: string): string; |
||||
declare function unescape(s: string): string; |
||||
Loading…
Reference in new issue