From d8d1ee30229c8223910744d6a1771d1062dcc467 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Thu, 29 Oct 2020 16:35:09 -0400 Subject: [PATCH 1/7] Handle main window hide --- jslib | 2 +- src/app/accounts/lock.component.ts | 7 +++++-- src/app/accounts/login.component.ts | 7 +++++-- src/app/accounts/register.component.ts | 7 +++++-- src/app/accounts/set-password.component.ts | 6 ++++-- src/app/vault/add-edit.component.ts | 7 +++++-- src/app/vault/export.component.ts | 7 +++++-- src/main.ts | 3 +++ 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/jslib b/jslib index d84d6da7f7..4258077179 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit d84d6da7f77ec89ba69299b1ff982f083fd77203 +Subproject commit 4258077179afa09f57712d2c9d05a9dff0b2f583 diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 33b6d5ae80..657c0110ce 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -17,6 +17,8 @@ import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + @Component({ selector: 'app-lock', templateUrl: 'lock.component.html', @@ -27,9 +29,10 @@ export class LockComponent extends BaseLockComponent { userService: UserService, cryptoService: CryptoService, storageService: StorageService, vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService, stateService: StateService, - apiService: ApiService, private route: ActivatedRoute) { + apiService: ApiService, broadcasterService: BroadcasterService, + private route: ActivatedRoute) { super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService, - storageService, vaultTimeoutService, environmentService, stateService, apiService); + storageService, vaultTimeoutService, environmentService, stateService, apiService, broadcasterService); } async ngOnInit() { diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 1b06d85b5b..8fb75c7afe 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -22,6 +22,8 @@ import { SyncService } from 'jslib/abstractions/sync.service'; import { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/login.component'; import { ModalComponent } from 'jslib/angular/components/modal.component'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + @Component({ selector: 'app-login', templateUrl: 'login.component.html', @@ -35,9 +37,10 @@ export class LoginComponent extends BaseLoginComponent { syncService: SyncService, private componentFactoryResolver: ComponentFactoryResolver, platformUtilsService: PlatformUtilsService, stateService: StateService, environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService, - cryptoFunctionService: CryptoFunctionService, storageService: StorageService) { + cryptoFunctionService: CryptoFunctionService, storageService: StorageService, + broadcasterService: BroadcasterService) { super(authService, router, platformUtilsService, i18nService, stateService, environmentService, - passwordGenerationService, cryptoFunctionService, storageService); + passwordGenerationService, cryptoFunctionService, broadcasterService, storageService); super.onSuccessfulLogin = () => { return syncService.fullSync(true); }; diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index 19fa0c1962..c6910fe1a7 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -9,6 +9,8 @@ import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { RegisterComponent as BaseRegisterComponent } from 'jslib/angular/components/register.component'; @Component({ @@ -19,8 +21,9 @@ export class RegisterComponent extends BaseRegisterComponent { constructor(authService: AuthService, router: Router, i18nService: I18nService, cryptoService: CryptoService, apiService: ApiService, stateService: StateService, - platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService) { + platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService, + broadcasterService: BroadcasterService) { super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService, - passwordGenerationService); + passwordGenerationService, broadcasterService); } } diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts index 295ded430f..0e9a9b3e03 100644 --- a/src/app/accounts/set-password.component.ts +++ b/src/app/accounts/set-password.component.ts @@ -15,6 +15,8 @@ import { PolicyService } from 'jslib/abstractions/policy.service'; import { SyncService } from 'jslib/abstractions/sync.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { SetPasswordComponent as BaseSetPasswordComponent, } from 'jslib/angular/components/set-password.component'; @@ -28,9 +30,9 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { cryptoService: CryptoService, messagingService: MessagingService, userService: UserService, passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService, policyService: PolicyService, router: Router, - syncService: SyncService, route: ActivatedRoute) { + syncService: SyncService, route: ActivatedRoute, broadcasterService: BroadcasterService) { super(i18nService, cryptoService, messagingService, userService, passwordGenerationService, - platformUtilsService, policyService, router, apiService, syncService, route); + platformUtilsService, policyService, router, apiService, syncService, route, broadcasterService); } get masterPasswordScoreWidth() { diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index ed0d529d84..937dfbfdaa 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -16,6 +16,8 @@ import { UserService } from 'jslib/abstractions/user.service'; import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + @Component({ selector: 'app-vault-add-edit', templateUrl: 'add-edit.component.html', @@ -25,9 +27,10 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, userService: UserService, collectionService: CollectionService, - messagingService: MessagingService, eventService: EventService) { + messagingService: MessagingService, eventService: EventService, + broadcasterService: BroadcasterService) { super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, - userService, collectionService, messagingService, eventService); + userService, collectionService, messagingService, eventService, broadcasterService); } async ngOnInit() { diff --git a/src/app/vault/export.component.ts b/src/app/vault/export.component.ts index eac41c806e..1fb5d0c70a 100644 --- a/src/app/vault/export.component.ts +++ b/src/app/vault/export.component.ts @@ -8,6 +8,8 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { ExportComponent as BaseExportComponent } from 'jslib/angular/components/export.component'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + @Component({ selector: 'app-export', templateUrl: 'export.component.html', @@ -15,7 +17,8 @@ import { ExportComponent as BaseExportComponent } from 'jslib/angular/components export class ExportComponent extends BaseExportComponent { constructor(cryptoService: CryptoService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, exportService: ExportService, - eventService: EventService) { - super(cryptoService, i18nService, platformUtilsService, exportService, eventService, window); + eventService: EventService, broadcasterService: BroadcasterService) { + super(cryptoService, i18nService, platformUtilsService, exportService, eventService, window, + broadcasterService); } } diff --git a/src/main.ts b/src/main.ts index e582c4cffc..49317e077f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -149,6 +149,9 @@ export class Main { event.preventDefault(); this.processDeepLink([url]); }); + + // Handle visibility event(s) + this.windowMain.win.on('hide', () => this.messagingService.send('hideMain')); }, (e: any) => { // tslint:disable-next-line console.error(e); From 5ff545e5417bbed7974110086aea149762436969 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:08:39 -0500 Subject: [PATCH 2/7] Undo broadcast service refs (not needed) --- jslib | 2 +- src/app/vault/add-edit.component.ts | 7 ++----- src/app/vault/export.component.ts | 7 ++----- src/main.ts | 3 --- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/jslib b/jslib index 4258077179..0e9e73ce95 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 4258077179afa09f57712d2c9d05a9dff0b2f583 +Subproject commit 0e9e73ce95a321ee05edbb62c50f9e1828f69c5a diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 937dfbfdaa..ed0d529d84 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -16,8 +16,6 @@ import { UserService } from 'jslib/abstractions/user.service'; import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component'; -import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; - @Component({ selector: 'app-vault-add-edit', templateUrl: 'add-edit.component.html', @@ -27,10 +25,9 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, userService: UserService, collectionService: CollectionService, - messagingService: MessagingService, eventService: EventService, - broadcasterService: BroadcasterService) { + messagingService: MessagingService, eventService: EventService) { super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, - userService, collectionService, messagingService, eventService, broadcasterService); + userService, collectionService, messagingService, eventService); } async ngOnInit() { diff --git a/src/app/vault/export.component.ts b/src/app/vault/export.component.ts index 1fb5d0c70a..eac41c806e 100644 --- a/src/app/vault/export.component.ts +++ b/src/app/vault/export.component.ts @@ -8,8 +8,6 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { ExportComponent as BaseExportComponent } from 'jslib/angular/components/export.component'; -import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; - @Component({ selector: 'app-export', templateUrl: 'export.component.html', @@ -17,8 +15,7 @@ import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; export class ExportComponent extends BaseExportComponent { constructor(cryptoService: CryptoService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, exportService: ExportService, - eventService: EventService, broadcasterService: BroadcasterService) { - super(cryptoService, i18nService, platformUtilsService, exportService, eventService, window, - broadcasterService); + eventService: EventService) { + super(cryptoService, i18nService, platformUtilsService, exportService, eventService, window); } } diff --git a/src/main.ts b/src/main.ts index 49317e077f..e582c4cffc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -149,9 +149,6 @@ export class Main { event.preventDefault(); this.processDeepLink([url]); }); - - // Handle visibility event(s) - this.windowMain.win.on('hide', () => this.messagingService.send('hideMain')); }, (e: any) => { // tslint:disable-next-line console.error(e); From 4a18a4eb937e7b09c65e44d5aae1548fe1512c02 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:11:56 -0500 Subject: [PATCH 3/7] cont. removing broadcast srv jslib refs --- src/app/accounts/lock.component.ts | 7 ++----- src/app/accounts/login.component.ts | 7 ++----- src/app/accounts/register.component.ts | 7 ++----- src/app/accounts/set-password.component.ts | 6 ++---- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 657c0110ce..33b6d5ae80 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -17,8 +17,6 @@ import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; -import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; - @Component({ selector: 'app-lock', templateUrl: 'lock.component.html', @@ -29,10 +27,9 @@ export class LockComponent extends BaseLockComponent { userService: UserService, cryptoService: CryptoService, storageService: StorageService, vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService, stateService: StateService, - apiService: ApiService, broadcasterService: BroadcasterService, - private route: ActivatedRoute) { + apiService: ApiService, private route: ActivatedRoute) { super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService, - storageService, vaultTimeoutService, environmentService, stateService, apiService, broadcasterService); + storageService, vaultTimeoutService, environmentService, stateService, apiService); } async ngOnInit() { diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 8fb75c7afe..1b06d85b5b 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -22,8 +22,6 @@ import { SyncService } from 'jslib/abstractions/sync.service'; import { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/login.component'; import { ModalComponent } from 'jslib/angular/components/modal.component'; -import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; - @Component({ selector: 'app-login', templateUrl: 'login.component.html', @@ -37,10 +35,9 @@ export class LoginComponent extends BaseLoginComponent { syncService: SyncService, private componentFactoryResolver: ComponentFactoryResolver, platformUtilsService: PlatformUtilsService, stateService: StateService, environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService, - cryptoFunctionService: CryptoFunctionService, storageService: StorageService, - broadcasterService: BroadcasterService) { + cryptoFunctionService: CryptoFunctionService, storageService: StorageService) { super(authService, router, platformUtilsService, i18nService, stateService, environmentService, - passwordGenerationService, cryptoFunctionService, broadcasterService, storageService); + passwordGenerationService, cryptoFunctionService, storageService); super.onSuccessfulLogin = () => { return syncService.fullSync(true); }; diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index c6910fe1a7..19fa0c1962 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -9,8 +9,6 @@ import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; -import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; - import { RegisterComponent as BaseRegisterComponent } from 'jslib/angular/components/register.component'; @Component({ @@ -21,9 +19,8 @@ export class RegisterComponent extends BaseRegisterComponent { constructor(authService: AuthService, router: Router, i18nService: I18nService, cryptoService: CryptoService, apiService: ApiService, stateService: StateService, - platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService, - broadcasterService: BroadcasterService) { + platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService) { super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService, - passwordGenerationService, broadcasterService); + passwordGenerationService); } } diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts index 0e9a9b3e03..295ded430f 100644 --- a/src/app/accounts/set-password.component.ts +++ b/src/app/accounts/set-password.component.ts @@ -15,8 +15,6 @@ import { PolicyService } from 'jslib/abstractions/policy.service'; import { SyncService } from 'jslib/abstractions/sync.service'; import { UserService } from 'jslib/abstractions/user.service'; -import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; - import { SetPasswordComponent as BaseSetPasswordComponent, } from 'jslib/angular/components/set-password.component'; @@ -30,9 +28,9 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { cryptoService: CryptoService, messagingService: MessagingService, userService: UserService, passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService, policyService: PolicyService, router: Router, - syncService: SyncService, route: ActivatedRoute, broadcasterService: BroadcasterService) { + syncService: SyncService, route: ActivatedRoute) { super(i18nService, cryptoService, messagingService, userService, passwordGenerationService, - platformUtilsService, policyService, router, apiService, syncService, route, broadcasterService); + platformUtilsService, policyService, router, apiService, syncService, route); } get masterPasswordScoreWidth() { From c001a00f820560084602d1380ebdd189c5f7c28c Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Wed, 4 Nov 2020 12:09:21 -0500 Subject: [PATCH 4/7] Hide hidden fields on hide/minimize --- jslib | 2 +- src/app/accounts/lock.component.ts | 27 ++++++++++++++++-- src/app/accounts/login.component.ts | 27 +++++++++++++++++- src/app/accounts/register.component.ts | 33 ++++++++++++++++++++-- src/app/accounts/set-password.component.ts | 31 ++++++++++++++++++-- src/app/vault/add-edit.component.ts | 31 ++++++++++++++++++-- src/app/vault/export.component.ts | 33 ++++++++++++++++++++-- src/app/vault/view.component.ts | 26 +++++++++++++++++ src/main.ts | 8 ++++++ 9 files changed, 204 insertions(+), 14 deletions(-) diff --git a/jslib b/jslib index 0e9e73ce95..1beb30d111 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 0e9e73ce95a321ee05edbb62c50f9e1828f69c5a +Subproject commit 1beb30d11193bcb2e57fbdb8a147ddcb0c0ddbc2 diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 33b6d5ae80..24cc7a1022 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -1,4 +1,7 @@ -import { Component } from '@angular/core'; +import { + Component, + NgZone, +} from '@angular/core'; import { ActivatedRoute, Router, @@ -15,8 +18,12 @@ import { StorageService } from 'jslib/abstractions/storage.service'; import { UserService } from 'jslib/abstractions/user.service'; import { VaultTimeoutService } from 'jslib/abstractions/vaultTimeout.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { LockComponent as BaseLockComponent } from 'jslib/angular/components/lock.component'; +const BroadcasterSubscriptionId = 'LockComponent'; + @Component({ selector: 'app-lock', templateUrl: 'lock.component.html', @@ -27,7 +34,8 @@ export class LockComponent extends BaseLockComponent { userService: UserService, cryptoService: CryptoService, storageService: StorageService, vaultTimeoutService: VaultTimeoutService, environmentService: EnvironmentService, stateService: StateService, - apiService: ApiService, private route: ActivatedRoute) { + apiService: ApiService, private route: ActivatedRoute, + private broadcasterService: BroadcasterService, private ngZone: NgZone) { super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService, storageService, vaultTimeoutService, environmentService, stateService, apiService); } @@ -39,5 +47,20 @@ export class LockComponent extends BaseLockComponent { setTimeout(() => this.unlockBiometric(), 1000); } }); + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + } + + onWindowHidden() { + this.showPassword = false; } } diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 1b06d85b5b..4affb59122 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -1,6 +1,7 @@ import { Component, ComponentFactoryResolver, + NgZone, ViewChild, ViewContainerRef, } from '@angular/core'; @@ -19,9 +20,13 @@ import { StateService } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { SyncService } from 'jslib/abstractions/sync.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/login.component'; import { ModalComponent } from 'jslib/angular/components/modal.component'; +const BroadcasterSubscriptionId = 'LoginComponent'; + @Component({ selector: 'app-login', templateUrl: 'login.component.html', @@ -35,7 +40,8 @@ export class LoginComponent extends BaseLoginComponent { syncService: SyncService, private componentFactoryResolver: ComponentFactoryResolver, platformUtilsService: PlatformUtilsService, stateService: StateService, environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService, - cryptoFunctionService: CryptoFunctionService, storageService: StorageService) { + cryptoFunctionService: CryptoFunctionService, storageService: StorageService, + private broadcasterService: BroadcasterService, private ngZone: NgZone) { super(authService, router, platformUtilsService, i18nService, stateService, environmentService, passwordGenerationService, cryptoFunctionService, storageService); super.onSuccessfulLogin = () => { @@ -43,6 +49,21 @@ export class LoginComponent extends BaseLoginComponent { }; } + async ngOnInit() { + await super.ngOnInit(); + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + } + settings() { const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const modal = this.environmentModal.createComponent(factory).instance; @@ -61,4 +82,8 @@ export class LoginComponent extends BaseLoginComponent { modal.close(); }); } + + onWindowHidden() { + this.showPassword = false; + } } diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index 19fa0c1962..ce43790b3b 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -1,4 +1,8 @@ -import { Component } from '@angular/core'; +import { + Component, + OnInit, + NgZone, +} from '@angular/core'; import { Router } from '@angular/router'; import { ApiService } from 'jslib/abstractions/api.service'; @@ -9,18 +13,41 @@ import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { RegisterComponent as BaseRegisterComponent } from 'jslib/angular/components/register.component'; +const BroadcasterSubscriptionId = 'RegisterComponent'; + @Component({ selector: 'app-register', templateUrl: 'register.component.html', }) -export class RegisterComponent extends BaseRegisterComponent { +export class RegisterComponent extends BaseRegisterComponent implements OnInit { constructor(authService: AuthService, router: Router, i18nService: I18nService, cryptoService: CryptoService, apiService: ApiService, stateService: StateService, - platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService) { + platformUtilsService: PlatformUtilsService, passwordGenerationService: PasswordGenerationService, + private broadcasterService: BroadcasterService, private ngZone: NgZone) { super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService, passwordGenerationService); } + + async ngOnInit() { + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + } + + onWindowHidden() { + this.showPassword = false; + } } diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts index 295ded430f..b0b0827ca2 100644 --- a/src/app/accounts/set-password.component.ts +++ b/src/app/accounts/set-password.component.ts @@ -1,4 +1,7 @@ -import { Component } from '@angular/core'; +import { + Component, + NgZone, +} from '@angular/core'; import { ActivatedRoute, @@ -15,6 +18,10 @@ import { PolicyService } from 'jslib/abstractions/policy.service'; import { SyncService } from 'jslib/abstractions/sync.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + +const BroadcasterSubscriptionId = 'SetPasswordComponent'; + import { SetPasswordComponent as BaseSetPasswordComponent, } from 'jslib/angular/components/set-password.component'; @@ -28,7 +35,8 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { cryptoService: CryptoService, messagingService: MessagingService, userService: UserService, passwordGenerationService: PasswordGenerationService, platformUtilsService: PlatformUtilsService, policyService: PolicyService, router: Router, - syncService: SyncService, route: ActivatedRoute) { + syncService: SyncService, route: ActivatedRoute, + private broadcasterService: BroadcasterService, private ngZone: NgZone) { super(i18nService, cryptoService, messagingService, userService, passwordGenerationService, platformUtilsService, policyService, router, apiService, syncService, route); } @@ -62,4 +70,23 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { return this.masterPasswordScore != null ? this.i18nService.t('weak') : null; } } + + async ngOnInit() { + await super.ngOnInit(); + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + } + + onWindowHidden() { + this.showPassword = false; + } } diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index ed0d529d84..699d155e89 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -1,6 +1,7 @@ import { Component, OnChanges, + NgZone, } from '@angular/core'; import { AuditService } from 'jslib/abstractions/audit.service'; @@ -14,8 +15,12 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; import { UserService } from 'jslib/abstractions/user.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component'; +const BroadcasterSubscriptionId = 'AddEditComponent'; + @Component({ selector: 'app-vault-add-edit', templateUrl: 'add-edit.component.html', @@ -25,13 +30,25 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, userService: UserService, collectionService: CollectionService, - messagingService: MessagingService, eventService: EventService) { + messagingService: MessagingService, eventService: EventService, + private broadcasterService: BroadcasterService, private ngZone: NgZone) { super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService, userService, collectionService, messagingService, eventService); } async ngOnInit() { - // We use ngOnChanges instead. + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + // We use ngOnChanges for everything else instead. } async ngOnChanges() { @@ -46,4 +63,14 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges } super.load(); } + + onWindowHidden() { + this.showPassword = false; + this.showCardCode = false; + if (this.cipher !== null && this.cipher.hasFields) { + this.cipher.fields.forEach(field => { + field.showValue = false; + }); + } + } } diff --git a/src/app/vault/export.component.ts b/src/app/vault/export.component.ts index eac41c806e..5b43cf7c1c 100644 --- a/src/app/vault/export.component.ts +++ b/src/app/vault/export.component.ts @@ -1,4 +1,8 @@ -import { Component } from '@angular/core'; +import { + Component, + OnInit, + NgZone, +} from '@angular/core'; import { CryptoService } from 'jslib/abstractions/crypto.service'; import { EventService } from 'jslib/abstractions/event.service'; @@ -6,16 +10,39 @@ import { ExportService } from 'jslib/abstractions/export.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + import { ExportComponent as BaseExportComponent } from 'jslib/angular/components/export.component'; +const BroadcasterSubscriptionId = 'ExportComponent'; + @Component({ selector: 'app-export', templateUrl: 'export.component.html', }) -export class ExportComponent extends BaseExportComponent { +export class ExportComponent extends BaseExportComponent implements OnInit { constructor(cryptoService: CryptoService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, exportService: ExportService, - eventService: EventService) { + eventService: EventService, private broadcasterService: BroadcasterService, + private ngZone: NgZone) { super(cryptoService, i18nService, platformUtilsService, exportService, eventService, window); } + + async ngOnInit() { + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + } + + onWindowHidden() { + this.showPassword = false; + } } diff --git a/src/app/vault/view.component.ts b/src/app/vault/view.component.ts index 60c4c0dba9..73e260110c 100644 --- a/src/app/vault/view.component.ts +++ b/src/app/vault/view.component.ts @@ -25,6 +25,8 @@ import { ViewComponent as BaseViewComponent } from 'jslib/angular/components/vie import { CipherView } from 'jslib/models/view/cipherView'; +const BroadcasterSubscriptionId = 'ViewComponent'; + @Component({ selector: 'app-vault-view', templateUrl: 'view.component.html', @@ -42,6 +44,20 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { super(cipherService, totpService, tokenService, i18nService, cryptoService, platformUtilsService, auditService, window, broadcasterService, ngZone, changeDetectorRef, userService, eventService); } + ngOnInit() { + super.ngOnInit(); + this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { + this.ngZone.run(() => { + switch (message.command) { + case 'windowHidden': + this.onWindowHidden(); + break; + + default: + } + }); + }); + } async ngOnChanges() { await super.load(); @@ -56,4 +72,14 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { super.copy(value, typeI18nKey, aType); this.messagingService.send('minimizeOnCopy'); } + + onWindowHidden() { + this.showPassword = false; + this.showCardCode = false; + if (this.cipher !== null && this.cipher.hasFields) { + this.cipher.fields.forEach(field => { + field.showValue = false; + }); + } + } } diff --git a/src/main.ts b/src/main.ts index e582c4cffc..2388577fc8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -149,6 +149,14 @@ export class Main { event.preventDefault(); this.processDeepLink([url]); }); + + // Handle window visibility events + this.windowMain.win.on('hide', () => { + this.messagingService.send('windowHidden'); + }); + this.windowMain.win.on('minimize', () => { + this.messagingService.send('windowHidden'); + }); }, (e: any) => { // tslint:disable-next-line console.error(e); From fe031ac6b8212ecd01c43c416c3e5dc7db978465 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Wed, 4 Nov 2020 12:19:56 -0500 Subject: [PATCH 5/7] remove trailing whitespace for lint errors --- src/app/accounts/lock.component.ts | 1 - src/app/accounts/login.component.ts | 1 - src/app/accounts/register.component.ts | 1 - src/app/accounts/set-password.component.ts | 1 - src/app/vault/add-edit.component.ts | 1 - src/app/vault/export.component.ts | 1 - src/app/vault/view.component.ts | 1 - 7 files changed, 7 deletions(-) diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 24cc7a1022..8603d67bff 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -53,7 +53,6 @@ export class LockComponent extends BaseLockComponent { case 'windowHidden': this.onWindowHidden(); break; - default: } }); diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 4affb59122..013aba98f8 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -57,7 +57,6 @@ export class LoginComponent extends BaseLoginComponent { case 'windowHidden': this.onWindowHidden(); break; - default: } }); diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index ce43790b3b..3c7fd8f826 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -40,7 +40,6 @@ export class RegisterComponent extends BaseRegisterComponent implements OnInit { case 'windowHidden': this.onWindowHidden(); break; - default: } }); diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts index b0b0827ca2..d7e186b090 100644 --- a/src/app/accounts/set-password.component.ts +++ b/src/app/accounts/set-password.component.ts @@ -79,7 +79,6 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { case 'windowHidden': this.onWindowHidden(); break; - default: } }); diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 699d155e89..4571223c0f 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -43,7 +43,6 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges case 'windowHidden': this.onWindowHidden(); break; - default: } }); diff --git a/src/app/vault/export.component.ts b/src/app/vault/export.component.ts index 5b43cf7c1c..0e563e9e01 100644 --- a/src/app/vault/export.component.ts +++ b/src/app/vault/export.component.ts @@ -35,7 +35,6 @@ export class ExportComponent extends BaseExportComponent implements OnInit { case 'windowHidden': this.onWindowHidden(); break; - default: } }); diff --git a/src/app/vault/view.component.ts b/src/app/vault/view.component.ts index 73e260110c..0ba3a5cd07 100644 --- a/src/app/vault/view.component.ts +++ b/src/app/vault/view.component.ts @@ -52,7 +52,6 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { case 'windowHidden': this.onWindowHidden(); break; - default: } }); From c9c6a1139056ec5be61be7a238a2f38c3674bf70 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Wed, 4 Nov 2020 12:22:17 -0500 Subject: [PATCH 6/7] update jslib --- jslib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jslib b/jslib index 1beb30d111..9aa3cbf73d 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 1beb30d11193bcb2e57fbdb8a147ddcb0c0ddbc2 +Subproject commit 9aa3cbf73d9df9a2641654270911359593bcb5c5 From 97e982bf01dcbb49148d5c0362049b7f60d79c30 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Wed, 4 Nov 2020 14:00:44 -0500 Subject: [PATCH 7/7] onDestroy needed for broadcast subscriptions --- src/app/accounts/lock.component.ts | 7 ++++++- src/app/accounts/login.component.ts | 7 ++++++- src/app/accounts/register.component.ts | 7 ++++++- src/app/accounts/set-password.component.ts | 7 ++++++- src/app/vault/add-edit.component.ts | 7 ++++++- src/app/vault/export.component.ts | 5 +++++ src/app/vault/view.component.ts | 5 +++++ 7 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/app/accounts/lock.component.ts b/src/app/accounts/lock.component.ts index 8603d67bff..d0ebe32eb6 100644 --- a/src/app/accounts/lock.component.ts +++ b/src/app/accounts/lock.component.ts @@ -1,5 +1,6 @@ import { Component, + OnDestroy, NgZone, } from '@angular/core'; import { @@ -28,7 +29,7 @@ const BroadcasterSubscriptionId = 'LockComponent'; selector: 'app-lock', templateUrl: 'lock.component.html', }) -export class LockComponent extends BaseLockComponent { +export class LockComponent extends BaseLockComponent implements OnDestroy { constructor(router: Router, i18nService: I18nService, platformUtilsService: PlatformUtilsService, messagingService: MessagingService, userService: UserService, cryptoService: CryptoService, @@ -59,6 +60,10 @@ export class LockComponent extends BaseLockComponent { }); } + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + onWindowHidden() { this.showPassword = false; } diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 013aba98f8..d0d0ba0b13 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -1,6 +1,7 @@ import { Component, ComponentFactoryResolver, + OnDestroy, NgZone, ViewChild, ViewContainerRef, @@ -31,7 +32,7 @@ const BroadcasterSubscriptionId = 'LoginComponent'; selector: 'app-login', templateUrl: 'login.component.html', }) -export class LoginComponent extends BaseLoginComponent { +export class LoginComponent extends BaseLoginComponent implements OnDestroy { @ViewChild('environment', { read: ViewContainerRef, static: true }) environmentModal: ViewContainerRef; showingModal = false; @@ -63,6 +64,10 @@ export class LoginComponent extends BaseLoginComponent { }); } + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + settings() { const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const modal = this.environmentModal.createComponent(factory).instance; diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index 3c7fd8f826..c2e26bb916 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -1,5 +1,6 @@ import { Component, + OnDestroy, OnInit, NgZone, } from '@angular/core'; @@ -23,7 +24,7 @@ const BroadcasterSubscriptionId = 'RegisterComponent'; selector: 'app-register', templateUrl: 'register.component.html', }) -export class RegisterComponent extends BaseRegisterComponent implements OnInit { +export class RegisterComponent extends BaseRegisterComponent implements OnInit, OnDestroy { constructor(authService: AuthService, router: Router, i18nService: I18nService, cryptoService: CryptoService, apiService: ApiService, stateService: StateService, @@ -46,6 +47,10 @@ export class RegisterComponent extends BaseRegisterComponent implements OnInit { }); } + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + onWindowHidden() { this.showPassword = false; } diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts index d7e186b090..b412c5b515 100644 --- a/src/app/accounts/set-password.component.ts +++ b/src/app/accounts/set-password.component.ts @@ -1,5 +1,6 @@ import { Component, + OnDestroy, NgZone, } from '@angular/core'; @@ -30,7 +31,7 @@ import { selector: 'app-set-password', templateUrl: 'set-password.component.html', }) -export class SetPasswordComponent extends BaseSetPasswordComponent { +export class SetPasswordComponent extends BaseSetPasswordComponent implements OnDestroy { constructor(apiService: ApiService, i18nService: I18nService, cryptoService: CryptoService, messagingService: MessagingService, userService: UserService, passwordGenerationService: PasswordGenerationService, @@ -85,6 +86,10 @@ export class SetPasswordComponent extends BaseSetPasswordComponent { }); } + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + onWindowHidden() { this.showPassword = false; } diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 4571223c0f..2fb79fd7e0 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -1,6 +1,7 @@ import { Component, OnChanges, + OnDestroy, NgZone, } from '@angular/core'; @@ -25,7 +26,7 @@ const BroadcasterSubscriptionId = 'AddEditComponent'; selector: 'app-vault-add-edit', templateUrl: 'add-edit.component.html', }) -export class AddEditComponent extends BaseAddEditComponent implements OnChanges { +export class AddEditComponent extends BaseAddEditComponent implements OnChanges, OnDestroy { constructor(cipherService: CipherService, folderService: FolderService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, auditService: AuditService, stateService: StateService, @@ -55,6 +56,10 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges await this.load(); } + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + async load() { if (document.querySelectorAll('app-vault-add-edit .ng-dirty').length === 0 || (this.cipher != null && this.cipherId !== this.cipher.id)) { diff --git a/src/app/vault/export.component.ts b/src/app/vault/export.component.ts index 0e563e9e01..8d42599f18 100644 --- a/src/app/vault/export.component.ts +++ b/src/app/vault/export.component.ts @@ -1,5 +1,6 @@ import { Component, + OnDestroy, OnInit, NgZone, } from '@angular/core'; @@ -41,6 +42,10 @@ export class ExportComponent extends BaseExportComponent implements OnInit { }); } + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + onWindowHidden() { this.showPassword = false; } diff --git a/src/app/vault/view.component.ts b/src/app/vault/view.component.ts index 0ba3a5cd07..f8e411d908 100644 --- a/src/app/vault/view.component.ts +++ b/src/app/vault/view.component.ts @@ -58,6 +58,11 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { }); } + ngOnDestroy() { + super.ngOnDestroy(); + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + async ngOnChanges() { await super.load(); }