move toaster and analytics to platform utils

This commit is contained in:
Kyle Spearrin 2018-10-03 09:42:11 -04:00
parent 6858ee8624
commit 2ca8ac573b
20 changed files with 91 additions and 118 deletions

2
jslib

@ -1 +1 @@
Subproject commit 45341ec408319cbf69a4772e503a3991ae770a49
Subproject commit 6b3dc2344f2db167cbc404d83fa4602a1ca93ef8

View File

@ -1,10 +1,8 @@
import { Component } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { EnvironmentComponent as BaseEnvironmentComponent } from 'jslib/angular/components/environment.component';
@ -13,8 +11,8 @@ import { EnvironmentComponent as BaseEnvironmentComponent } from 'jslib/angular/
templateUrl: 'environment.component.html',
})
export class EnvironmentComponent extends BaseEnvironmentComponent {
constructor(analytics: Angulartics2, toasterService: ToasterService,
environmentService: EnvironmentService, i18nService: I18nService) {
super(analytics, toasterService, environmentService, i18nService);
constructor(platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService,
i18nService: I18nService) {
super(platformUtilsService, environmentService, i18nService);
}
}

View File

@ -1,11 +1,9 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { HintComponent as BaseHintComponent } from 'jslib/angular/components/hint.component';
@ -14,9 +12,8 @@ import { HintComponent as BaseHintComponent } from 'jslib/angular/components/hin
templateUrl: 'hint.component.html',
})
export class HintComponent extends BaseHintComponent {
constructor(router: Router, analytics: Angulartics2,
toasterService: ToasterService, i18nService: I18nService,
apiService: ApiService) {
super(router, analytics, toasterService, i18nService, apiService);
constructor(router: Router, platformUtilsService: PlatformUtilsService,
i18nService: I18nService, apiService: ApiService) {
super(router, i18nService, apiService, platformUtilsService);
}
}

View File

@ -1,9 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
@ -17,11 +14,9 @@ import { LockComponent as BaseLockComponent } from 'jslib/angular/components/loc
templateUrl: 'lock.component.html',
})
export class LockComponent extends BaseLockComponent {
constructor(router: Router, analytics: Angulartics2,
toasterService: ToasterService, i18nService: I18nService,
constructor(router: Router, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, messagingService: MessagingService,
userService: UserService, cryptoService: CryptoService) {
super(router, analytics, toasterService, i18nService, platformUtilsService,
messagingService, userService, cryptoService);
super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService);
}
}

View File

@ -6,13 +6,11 @@ import {
} from '@angular/core';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { EnvironmentComponent } from './environment.component';
import { AuthService } from 'jslib/abstractions/auth.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { SyncService } from 'jslib/abstractions/sync.service';
@ -27,10 +25,10 @@ export class LoginComponent extends BaseLoginComponent {
@ViewChild('environment', { read: ViewContainerRef }) environmentModal: ViewContainerRef;
constructor(authService: AuthService, router: Router,
analytics: Angulartics2, toasterService: ToasterService,
i18nService: I18nService, private syncService: SyncService,
private componentFactoryResolver: ComponentFactoryResolver, storageService: StorageService) {
super(authService, router, analytics, toasterService, i18nService, storageService);
i18nService: I18nService, syncService: SyncService,
private componentFactoryResolver: ComponentFactoryResolver, storageService: StorageService,
platformUtilsService: PlatformUtilsService) {
super(authService, router, platformUtilsService, i18nService, storageService);
super.onSuccessfulLogin = () => {
return syncService.fullSync(true);
};

View File

@ -1,8 +1,5 @@
import { Component } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
@ -15,9 +12,8 @@ import { PremiumComponent as BasePremiumComponent } from 'jslib/angular/componen
templateUrl: 'premium.component.html',
})
export class PremiumComponent extends BasePremiumComponent {
constructor(analytics: Angulartics2, toasterService: ToasterService,
i18nService: I18nService, platformUtilsService: PlatformUtilsService,
constructor(i18nService: I18nService, platformUtilsService: PlatformUtilsService,
tokenService: TokenService, apiService: ApiService) {
super(analytics, toasterService, i18nService, platformUtilsService, tokenService, apiService);
super(i18nService, platformUtilsService, tokenService, apiService);
}
}

View File

@ -1,9 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { AuthService } from 'jslib/abstractions/auth.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
@ -19,11 +16,9 @@ import { RegisterComponent as BaseRegisterComponent } from 'jslib/angular/compon
})
export class RegisterComponent extends BaseRegisterComponent {
constructor(authService: AuthService, router: Router,
analytics: Angulartics2, toasterService: ToasterService,
i18nService: I18nService, cryptoService: CryptoService,
apiService: ApiService, stateService: StateService,
platformUtilsService: PlatformUtilsService) {
super(authService, router, analytics, toasterService, i18nService, cryptoService, apiService, stateService,
platformUtilsService);
super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService);
}
}

View File

@ -39,7 +39,7 @@ export class SettingsComponent implements OnInit {
themeOptions: any[];
constructor(private analytics: Angulartics2, private toasterService: ToasterService,
private i18nService: I18nService, private platformUtilsService: PlatformUtilsService,
i18nService: I18nService, private platformUtilsService: PlatformUtilsService,
private storageService: StorageService, private lockService: LockService,
private stateService: StateService, private messagingService: MessagingService) {
this.lockOptions = [

View File

@ -1,9 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { AuthService } from 'jslib/abstractions/auth.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
@ -18,8 +15,7 @@ import {
})
export class TwoFactorOptionsComponent extends BaseTwoFactorOptionsComponent {
constructor(authService: AuthService, router: Router,
analytics: Angulartics2, toasterService: ToasterService,
i18nService: I18nService, platformUtilsService: PlatformUtilsService) {
super(authService, router, analytics, toasterService, i18nService, platformUtilsService, window);
super(authService, router, i18nService, platformUtilsService, window);
}
}

View File

@ -7,9 +7,6 @@ import {
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { TwoFactorOptionsComponent } from './two-factor-options.component';
import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType';
@ -32,12 +29,10 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
@ViewChild('twoFactorOptions', { read: ViewContainerRef }) twoFactorOptionsModal: ViewContainerRef;
constructor(authService: AuthService, router: Router,
analytics: Angulartics2, toasterService: ToasterService,
i18nService: I18nService, apiService: ApiService,
platformUtilsService: PlatformUtilsService, private syncService: SyncService,
platformUtilsService: PlatformUtilsService, syncService: SyncService,
environmentService: EnvironmentService, private componentFactoryResolver: ComponentFactoryResolver) {
super(authService, router, analytics, toasterService, i18nService, apiService,
platformUtilsService, window, environmentService);
super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService);
super.onSuccessfulLogin = () => {
return syncService.fullSync(true);
};

View File

@ -1,4 +1,10 @@
import { ToasterConfig } from 'angular2-toaster';
import {
BodyOutputType,
Toast,
ToasterConfig,
ToasterContainerComponent,
ToasterService,
} from 'angular2-toaster';
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
import {
@ -6,17 +12,18 @@ import {
ComponentFactoryResolver,
NgZone,
OnInit,
SecurityContext,
Type,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { PremiumComponent } from './accounts/premium.component';
import { SettingsComponent } from './accounts/settings.component';
import { PasswordGeneratorHistoryComponent } from './vault/password-generator-history.component';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ModalComponent } from 'jslib/angular/components/modal.component';
@ -33,7 +40,6 @@ import { LockService } from 'jslib/abstractions/lock.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { NotificationsService } from 'jslib/abstractions/notifications.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SearchService } from 'jslib/abstractions/search.service';
import { SettingsService } from 'jslib/abstractions/settings.service';
import { StorageService } from 'jslib/abstractions/storage.service';
@ -80,13 +86,11 @@ export class AppComponent implements OnInit {
private passwordGenerationService: PasswordGenerationService, private cipherService: CipherService,
private authService: AuthService, private router: Router, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private ngZone: NgZone,
private sanitizer: DomSanitizer, private ngZone: NgZone,
private lockService: LockService, private storageService: StorageService,
private cryptoService: CryptoService, private componentFactoryResolver: ComponentFactoryResolver,
private messagingService: MessagingService, private collectionService: CollectionService,
private searchService: SearchService, private notificationsService: NotificationsService) {
(window as any).BitwardenToasterService = toasterService;
}
private searchService: SearchService, private notificationsService: NotificationsService) { }
ngOnInit() {
this.ngZone.runOutsideAngular(() => {
@ -136,6 +140,15 @@ export class AppComponent implements OnInit {
this.openModal<PasswordGeneratorHistoryComponent>(
PasswordGeneratorHistoryComponent, this.passwordHistoryRef);
break;
case 'showToast':
await this.showToast(message);
break;
case 'analyticsEventTrack':
this.analytics.eventTrack.next({
action: message.action,
properties: { label: message.label },
});
break;
default:
}
});
@ -226,4 +239,31 @@ export class AppComponent implements OnInit {
this.modal = null;
});
}
private async showToast(msg: any) {
const toast: Toast = {
type: msg.type,
title: msg.title,
};
if (typeof (msg.text) === 'string') {
toast.body = msg.text;
} else if (msg.text.length === 1) {
toast.body = msg.text[0];
} else {
let message = '';
msg.text.forEach((t: string) =>
message += ('<p>' + this.sanitizer.sanitize(SecurityContext.HTML, t) + '</p>'));
toast.body = message;
toast.bodyOutputType = BodyOutputType.TrustedHtml;
}
if (msg.options != null) {
if (msg.options.trustedHtml === true) {
toast.bodyOutputType = BodyOutputType.TrustedHtml;
}
if (msg.options.timeout != null && msg.options.timeout > 0) {
toast.timeout = msg.options.timeout;
}
}
this.toasterService.popAsync(toast);
}
}

View File

@ -79,9 +79,9 @@ import { UserService as UserServiceAbstraction } from 'jslib/abstractions/user.s
const logService = new ElectronLogService();
const i18nService = new I18nService(window.navigator.language, './locales');
const stateService = new StateService();
const platformUtilsService = new ElectronPlatformUtilsService(i18nService, true);
const broadcasterService = new BroadcasterService();
const messagingService = new ElectronRendererMessagingService(broadcasterService);
const platformUtilsService = new ElectronPlatformUtilsService(i18nService, messagingService, true);
const storageService: StorageServiceAbstraction = new LowdbStorageService(null, remote.app.getPath('userData'));
const secureStorageService: StorageServiceAbstraction = new ElectronRendererSecureStorageService();
const cryptoFunctionService: CryptoFunctionServiceAbstraction = new WebCryptoFunctionService(window,

View File

@ -3,9 +3,6 @@ import {
OnChanges,
} from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { AuditService } from 'jslib/abstractions/audit.service';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { FolderService } from 'jslib/abstractions/folder.service';
@ -22,10 +19,8 @@ import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/componen
export class AddEditComponent extends BaseAddEditComponent implements OnChanges {
constructor(cipherService: CipherService, folderService: FolderService,
i18nService: I18nService, platformUtilsService: PlatformUtilsService,
analytics: Angulartics2, toasterService: ToasterService,
auditService: AuditService, stateService: StateService) {
super(cipherService, folderService, i18nService, platformUtilsService, analytics,
toasterService, auditService, stateService);
super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService);
}
async ngOnChanges() {

View File

@ -1,8 +1,5 @@
import { Component } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
@ -16,11 +13,9 @@ import { AttachmentsComponent as BaseAttachmentsComponent } from 'jslib/angular/
templateUrl: 'attachments.component.html',
})
export class AttachmentsComponent extends BaseAttachmentsComponent {
constructor(cipherService: CipherService, analytics: Angulartics2,
toasterService: ToasterService, i18nService: I18nService,
constructor(cipherService: CipherService, i18nService: I18nService,
cryptoService: CryptoService, userService: UserService,
platformUtilsService: PlatformUtilsService) {
super(cipherService, analytics, toasterService, i18nService, cryptoService, userService,
platformUtilsService, window);
super(cipherService, i18nService, cryptoService, userService, platformUtilsService, window);
}
}

View File

@ -1,6 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { Component } from '@angular/core';
import { CryptoService } from 'jslib/abstractions/crypto.service';
@ -15,10 +12,8 @@ import { ExportComponent as BaseExportComponent } from 'jslib/angular/components
templateUrl: 'export.component.html',
})
export class ExportComponent extends BaseExportComponent {
constructor(analytics: Angulartics2, toasterService: ToasterService,
cryptoService: CryptoService, i18nService: I18nService,
constructor(cryptoService: CryptoService, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, exportService: ExportService) {
super(analytics, toasterService, cryptoService, i18nService, platformUtilsService,
exportService, window);
super(cryptoService, i18nService, platformUtilsService, exportService, window);
}
}

View File

@ -1,8 +1,5 @@
import { Component } from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { FolderService } from 'jslib/abstractions/folder.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
@ -17,8 +14,7 @@ import {
})
export class FolderAddEditComponent extends BaseFolderAddEditComponent {
constructor(folderService: FolderService, i18nService: I18nService,
analytics: Angulartics2, toasterService: ToasterService,
platformUtilsService: PlatformUtilsService) {
super(folderService, i18nService, analytics, toasterService, platformUtilsService);
super(folderService, i18nService, platformUtilsService);
}
}

View File

@ -1,6 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { Component } from '@angular/core';
import { I18nService } from 'jslib/abstractions/i18n.service';
@ -16,9 +13,8 @@ import {
templateUrl: 'password-generator-history.component.html',
})
export class PasswordGeneratorHistoryComponent extends BasePasswordGeneratorHistoryComponent {
constructor(passwordGenerationService: PasswordGenerationService, analytics: Angulartics2,
platformUtilsService: PlatformUtilsService, i18nService: I18nService,
toasterService: ToasterService) {
super(passwordGenerationService, analytics, platformUtilsService, i18nService, toasterService, window);
constructor(passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService) {
super(passwordGenerationService, platformUtilsService, i18nService, window);
}
}

View File

@ -1,9 +1,4 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import {
Component,
} from '@angular/core';
import { Component } from '@angular/core';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
@ -18,9 +13,8 @@ import {
templateUrl: 'password-generator.component.html',
})
export class PasswordGeneratorComponent extends BasePasswordGeneratorComponent {
constructor(passwordGenerationService: PasswordGenerationService, analytics: Angulartics2,
platformUtilsService: PlatformUtilsService, i18nService: I18nService,
toasterService: ToasterService) {
super(passwordGenerationService, analytics, platformUtilsService, i18nService, toasterService, window);
constructor(passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService) {
super(passwordGenerationService, platformUtilsService, i18nService, window);
}
}

View File

@ -1,6 +1,3 @@
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { Component } from '@angular/core';
import { CipherService } from 'jslib/abstractions/cipher.service';
@ -16,9 +13,8 @@ import {
templateUrl: 'password-history.component.html',
})
export class PasswordHistoryComponent extends BasePasswordHistoryComponent {
constructor(cipherService: CipherService, analytics: Angulartics2,
platformUtilsService: PlatformUtilsService, i18nService: I18nService,
toasterService: ToasterService) {
super(cipherService, analytics, platformUtilsService, i18nService, toasterService, window);
constructor(cipherService: CipherService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService) {
super(cipherService, platformUtilsService, i18nService, window);
}
}

View File

@ -7,9 +7,6 @@ import {
Output,
} from '@angular/core';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { AuditService } from 'jslib/abstractions/audit.service';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
@ -33,14 +30,13 @@ export class ViewComponent extends BaseViewComponent implements OnChanges {
@Output() onViewCipherPasswordHistory = new EventEmitter<CipherView>();
constructor(cipherService: CipherService, totpService: TotpService,
tokenService: TokenService, toasterService: ToasterService,
tokenService: TokenService, i18nService: I18nService,
cryptoService: CryptoService, platformUtilsService: PlatformUtilsService,
i18nService: I18nService, analytics: Angulartics2,
auditService: AuditService, broadcasterService: BroadcasterService,
ngZone: NgZone, changeDetectorRef: ChangeDetectorRef,
userService: UserService) {
super(cipherService, totpService, tokenService, toasterService, cryptoService, platformUtilsService,
i18nService, analytics, auditService, window, broadcasterService, ngZone, changeDetectorRef, userService);
super(cipherService, totpService, tokenService, i18nService, cryptoService, platformUtilsService,
auditService, window, broadcasterService, ngZone, changeDetectorRef, userService);
}
async ngOnChanges() {
@ -48,7 +44,7 @@ export class ViewComponent extends BaseViewComponent implements OnChanges {
}
viewHistory() {
this.analytics.eventTrack.next({ action: 'View Password History' });
this.platformUtilsService.eventTrack('View Password History');
this.onViewCipherPasswordHistory.emit(this.cipher);
}
}