bitwarden-estensione-browser/src/app/accounts/lock.component.ts

102 lines
4.2 KiB
TypeScript
Raw Normal View History

2020-11-04 18:09:21 +01:00
import {
Component,
NgZone,
2021-02-03 19:21:22 +01:00
OnDestroy,
2020-11-04 18:09:21 +01:00
} from '@angular/core';
2020-07-23 23:24:35 +02:00
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { ipcRenderer } from 'electron';
2018-02-10 04:47:53 +01:00
import { ApiService } from 'jslib-common/abstractions/api.service';
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
import { UserService } from 'jslib-common/abstractions/user.service';
import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.service';
2018-02-10 04:47:53 +01:00
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
2020-11-04 18:09:21 +01:00
import { LockComponent as BaseLockComponent } from 'jslib-angular/components/lock.component';
2018-04-05 05:01:40 +02:00
2021-09-20 10:41:57 +02:00
import { ConstantsService } from 'jslib-common/services/constants.service';
2020-11-04 18:09:21 +01:00
const BroadcasterSubscriptionId = 'LockComponent';
2018-02-10 04:47:53 +01:00
@Component({
selector: 'app-lock',
templateUrl: 'lock.component.html',
2018-02-10 04:47:53 +01:00
})
export class LockComponent extends BaseLockComponent implements OnDestroy {
private deferFocus: boolean = null;
constructor(router: Router, i18nService: I18nService,
2018-04-05 05:01:40 +02:00
platformUtilsService: PlatformUtilsService, messagingService: MessagingService,
userService: UserService, cryptoService: CryptoService,
storageService: StorageService, vaultTimeoutService: VaultTimeoutService,
2020-07-23 23:24:35 +02:00
environmentService: EnvironmentService, stateService: StateService,
2020-11-04 18:09:21 +01:00
apiService: ApiService, private route: ActivatedRoute,
private broadcasterService: BroadcasterService, private ngZone: NgZone,
logService: LogService, keyConnectorService: KeyConnectorService) {
2019-02-13 16:06:58 +01:00
super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService,
storageService, vaultTimeoutService, environmentService, stateService, apiService, logService,
keyConnectorService);
2018-02-24 19:48:55 +01:00
}
2020-07-23 23:24:35 +02:00
async ngOnInit() {
await super.ngOnInit();
2021-09-20 10:41:57 +02:00
const autoPromptBiometric = !await this.storageService.get<boolean>(ConstantsService.disableAutoBiometricsPromptKey);
2021-02-03 19:21:22 +01:00
this.route.queryParams.subscribe(params => {
if (this.supportsBiometric && params.promptBiometric && autoPromptBiometric) {
setTimeout(async() => {
if (await ipcRenderer.invoke('windowVisible')) {
this.unlockBiometric();
}
}, 1000);
2020-07-23 23:24:35 +02:00
}
});
2020-11-04 18:09:21 +01:00
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
this.ngZone.run(() => {
switch (message.command) {
case 'windowHidden':
this.onWindowHidden();
break;
case 'windowIsFocused':
if (this.deferFocus === null) {
this.deferFocus = !message.windowIsFocused;
if (!this.deferFocus) {
this.focusInput();
}
} else if (this.deferFocus && message.windowIsFocused) {
this.focusInput();
this.deferFocus = false;
}
break;
2020-11-04 18:09:21 +01:00
default:
}
});
});
this.messagingService.send('getWindowIsFocused');
2020-11-04 18:09:21 +01:00
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
2020-11-04 18:09:21 +01:00
onWindowHidden() {
this.showPassword = false;
2020-07-23 23:24:35 +02:00
}
private focusInput() {
document.getElementById(this.pinLock ? 'pin' : 'masterPassword').focus();
}
2018-02-10 04:47:53 +01:00
}