diff --git a/jslib b/jslib index 45341ec4..6b3dc234 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 45341ec408319cbf69a4772e503a3991ae770a49 +Subproject commit 6b3dc2344f2db167cbc404d83fa4602a1ca93ef8 diff --git a/src/app/accounts/environment.component.ts b/src/app/accounts/environment.component.ts index 0bf26249..5e06b3a6 100644 --- a/src/app/accounts/environment.component.ts +++ b/src/app/accounts/environment.component.ts @@ -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(environmentService: EnvironmentService, i18nService: I18nService, + platformUtilsService: PlatformUtilsService) { + super(platformUtilsService, environmentService, i18nService); } } diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 237e3f57..49a59f53 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -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 { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/login.component'; @@ -26,10 +24,9 @@ export class LoginComponent extends BaseLoginComponent { @ViewChild('environment', { read: ViewContainerRef }) environmentModal: ViewContainerRef; constructor(authService: AuthService, router: Router, - analytics: Angulartics2, toasterService: ToasterService, i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver, - storageService: StorageService) { - super(authService, router, analytics, toasterService, i18nService, storageService); + storageService: StorageService, platformUtilsService: PlatformUtilsService) { + super(authService, router, platformUtilsService, i18nService, storageService); super.successRoute = '/tabs/dashboard'; } diff --git a/src/app/accounts/two-factor-options.component.ts b/src/app/accounts/two-factor-options.component.ts index 6ab0be4f..6db002ad 100644 --- a/src/app/accounts/two-factor-options.component.ts +++ b/src/app/accounts/two-factor-options.component.ts @@ -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); } } diff --git a/src/app/accounts/two-factor.component.ts b/src/app/accounts/two-factor.component.ts index f4786c69..29d2b325 100644 --- a/src/app/accounts/two-factor.component.ts +++ b/src/app/accounts/two-factor.component.ts @@ -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'; @@ -31,12 +28,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, environmentService: EnvironmentService, private componentFactoryResolver: ComponentFactoryResolver) { - super(authService, router, analytics, toasterService, i18nService, apiService, - platformUtilsService, window, environmentService); + super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService); super.successRoute = '/tabs/dashboard'; } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9e8020f7..289f3c95 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,24 +1,26 @@ import { + BodyOutputType, + Toast, ToasterConfig, ToasterContainerComponent, + ToasterService, } from 'angular2-toaster'; +import { Angulartics2 } from 'angulartics2'; import { Angulartics2GoogleAnalytics } from 'angulartics2/ga'; import { Component, ComponentFactoryResolver, NgZone, - OnDestroy, OnInit, + SecurityContext, Type, ViewChild, ViewContainerRef, } from '@angular/core'; +import { DomSanitizer } from '@angular/platform-browser'; import { Router } from '@angular/router'; -import { ToasterService } from 'angular2-toaster'; -import { Angulartics2 } from 'angulartics2'; - import { ModalComponent } from 'jslib/angular/components/modal.component'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; @@ -27,14 +29,11 @@ import { ApiService } from 'jslib/abstractions/api.service'; import { AuthService } from 'jslib/abstractions/auth.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; -import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { TokenService } from 'jslib/abstractions/token.service'; import { UserService } from 'jslib/abstractions/user.service'; -import { ConstantsService } from 'jslib/services/constants.service'; - import { ConfigurationService } from '../services/configuration.service'; import { SyncService } from '../services/sync.service'; @@ -66,12 +65,12 @@ export class AppComponent implements OnInit { private tokenService: TokenService, private storageService: StorageService, 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 componentFactoryResolver: ComponentFactoryResolver, private messagingService: MessagingService, private configurationService: ConfigurationService, private syncService: SyncService, private stateService: StateService, private apiService: ApiService) { - (window as any).BitwardenToasterService = toasterService; - } + (window as any).BitwardenToasterService = toasterService; + } ngOnInit() { this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { @@ -125,6 +124,15 @@ export class AppComponent implements OnInit { this.messagingService.send('scheduleNextDirSync'); break; + case 'showToast': + this.showToast(message); + break; + case 'analyticsEventTrack': + this.analytics.eventTrack.next({ + action: message.action, + properties: { label: message.label }, + }); + break; default: } }); @@ -166,4 +174,31 @@ export class AppComponent implements OnInit { this.modal = null; }); } + + private 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 += ('
' + this.sanitizer.sanitize(SecurityContext.HTML, t) + '
')); + 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); + } } diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 1b7db3c4..f888678e 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -56,9 +56,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 NodeCryptoFunctionService(); diff --git a/tsconfig.json b/tsconfig.json index f30379af..c95cd8f9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,12 +17,6 @@ "@angular/*": [ "node_modules/@angular/*" ], - "angular2-toaster": [ - "node_modules/angular2-toaster" - ], - "angulartics2": [ - "node_modules/angulartics2" - ], "electron": [ "node_modules/electron" ],