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';
|
2021-05-06 20:19:48 +02:00
|
|
|
import { ipcRenderer } from 'electron';
|
2018-02-10 04:47:53 +01:00
|
|
|
|
2021-06-07 19:26:36 +02: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 { 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
|
|
|
|
2021-06-07 19:26:36 +02:00
|
|
|
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
|
2020-11-04 18:09:21 +01:00
|
|
|
|
2021-06-07 19:26:36 +02: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';
|
2021-05-06 20:19:48 +02: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
|
|
|
})
|
2020-11-04 20:00:44 +01:00
|
|
|
export class LockComponent extends BaseLockComponent implements OnDestroy {
|
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,
|
2018-12-26 17:02:02 +01:00
|
|
|
userService: UserService, cryptoService: CryptoService,
|
2020-04-01 17:18:36 +02:00
|
|
|
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) {
|
2019-02-13 16:06:58 +01:00
|
|
|
super(router, i18nService, platformUtilsService, messagingService, userService, cryptoService,
|
2020-11-02 23:11:56 +01:00
|
|
|
storageService, vaultTimeoutService, environmentService, stateService, apiService);
|
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-05-06 20:19:48 +02:00
|
|
|
|
2021-02-03 19:21:22 +01:00
|
|
|
this.route.queryParams.subscribe(params => {
|
2021-05-06 20:19:48 +02:00
|
|
|
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;
|
2021-07-05 00:06:24 +02:00
|
|
|
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:
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
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() {
|
|
|
|
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
|
|
|
}
|