2022-08-09 21:11:51 +02:00
|
|
|
import { Component, NgZone } from "@angular/core";
|
2020-07-23 23:24:35 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2021-05-06 20:19:48 +02:00
|
|
|
import { ipcRenderer } from "electron";
|
2018-02-10 04:47:53 +01:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/components/lock.component";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
|
2022-08-30 22:30:43 +02:00
|
|
|
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service";
|
2018-02-10 04:47:53 +01:00
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
const BroadcasterSubscriptionId = "LockComponent";
|
|
|
|
|
2018-02-10 04:47:53 +01:00
|
|
|
@Component({
|
|
|
|
selector: "app-lock",
|
2018-04-06 18:25:22 +02:00
|
|
|
templateUrl: "lock.component.html",
|
2018-02-10 04:47:53 +01:00
|
|
|
})
|
2022-08-09 21:11:51 +02:00
|
|
|
export class LockComponent extends BaseLockComponent {
|
2021-07-05 00:06:24 +02:00
|
|
|
private deferFocus: boolean = null;
|
|
|
|
|
2018-10-03 15:42:11 +02:00
|
|
|
constructor(
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
2018-04-05 05:01:40 +02:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
messagingService: MessagingService,
|
2021-12-15 23:32:00 +01:00
|
|
|
cryptoService: CryptoService,
|
|
|
|
vaultTimeoutService: VaultTimeoutService,
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
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,
|
2021-11-29 01:21:48 +01:00
|
|
|
private broadcasterService: BroadcasterService,
|
|
|
|
ngZone: NgZone,
|
2021-11-09 19:00:01 +01:00
|
|
|
logService: LogService,
|
2022-10-04 20:43:51 +02:00
|
|
|
keyConnectorService: KeyConnectorService
|
2021-11-09 19:00:01 +01:00
|
|
|
) {
|
2021-12-15 23:32:00 +01:00
|
|
|
super(
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
platformUtilsService,
|
|
|
|
messagingService,
|
|
|
|
cryptoService,
|
|
|
|
vaultTimeoutService,
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService,
|
2021-12-15 23:32:00 +01:00
|
|
|
environmentService,
|
|
|
|
stateService,
|
|
|
|
apiService,
|
|
|
|
logService,
|
2021-11-29 01:21:48 +01:00
|
|
|
keyConnectorService,
|
|
|
|
ngZone
|
|
|
|
);
|
2018-02-24 19:48:55 +01:00
|
|
|
}
|
2020-07-23 23:24:35 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
2021-12-15 23:32:00 +01:00
|
|
|
const autoPromptBiometric = !(await this.stateService.getNoAutoPromptBiometrics());
|
2021-05-06 20:19:48 +02:00
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-02-03 19:21:22 +01:00
|
|
|
this.route.queryParams.subscribe((params) => {
|
2022-10-27 12:49:59 +02:00
|
|
|
setTimeout(async () => {
|
|
|
|
if (!params.promptBiometric || !this.supportsBiometric || !autoPromptBiometric) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (await ipcRenderer.invoke("windowVisible")) {
|
|
|
|
this.unlockBiometric();
|
|
|
|
}
|
|
|
|
}, 1000);
|
2021-12-20 15:47:17 +01: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();
|
2021-12-20 15:47:17 +01:00
|
|
|
break;
|
2021-07-05 00:06:24 +02:00
|
|
|
case "windowIsFocused":
|
|
|
|
if (this.deferFocus === null) {
|
|
|
|
this.deferFocus = !message.windowIsFocused;
|
|
|
|
if (!this.deferFocus) {
|
|
|
|
this.focusInput();
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2021-07-05 00:06:24 +02:00
|
|
|
} else if (this.deferFocus && message.windowIsFocused) {
|
|
|
|
this.focusInput();
|
|
|
|
this.deferFocus = false;
|
2020-07-23 23:24:35 +02:00
|
|
|
}
|
2020-11-04 18:09:21 +01:00
|
|
|
break;
|
2021-07-05 00:06:24 +02:00
|
|
|
default:
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2021-07-05 00:06:24 +02:00
|
|
|
});
|
2020-11-04 18:09:21 +01:00
|
|
|
});
|
2021-07-05 00:06:24 +02:00
|
|
|
this.messagingService.send("getWindowIsFocused");
|
2020-11-04 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:00:44 +01:00
|
|
|
ngOnDestroy() {
|
2022-08-09 21:11:51 +02:00
|
|
|
super.ngOnDestroy();
|
2020-11-04 20:00:44 +01:00
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
onWindowHidden() {
|
|
|
|
this.showPassword = false;
|
2020-07-23 23:24:35 +02:00
|
|
|
}
|
2021-07-05 00:06:24 +02:00
|
|
|
|
|
|
|
private focusInput() {
|
|
|
|
document.getElementById(this.pinLock ? "pin" : "masterPassword").focus();
|
|
|
|
}
|
2018-02-10 04:47:53 +01:00
|
|
|
}
|