Improve reloading with biometrics
This commit is contained in:
parent
3f98c18f76
commit
e52a506d86
|
@ -199,6 +199,12 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||||
await this.systemService.clearPendingClipboard();
|
await this.systemService.clearPendingClipboard();
|
||||||
await this.systemService.startProcessReload(this.authService);
|
await this.systemService.startProcessReload(this.authService);
|
||||||
break;
|
break;
|
||||||
|
case "startProcessReload":
|
||||||
|
this.systemService.startProcessReload(this.authService);
|
||||||
|
break;
|
||||||
|
case "cancelProcessReload":
|
||||||
|
this.systemService.cancelProcessReload();
|
||||||
|
break;
|
||||||
case "reloadProcess":
|
case "reloadProcess":
|
||||||
(window.location as any).reload(true);
|
(window.location as any).reload(true);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -121,7 +121,8 @@ export class Main {
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.windowMain,
|
this.windowMain,
|
||||||
this.stateService,
|
this.stateService,
|
||||||
this.logService
|
this.logService,
|
||||||
|
this.messagingService
|
||||||
);
|
);
|
||||||
|
|
||||||
this.desktopCredentialStorageListener = new DesktopCredentialStorageListener(
|
this.desktopCredentialStorageListener = new DesktopCredentialStorageListener(
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { mock } from "jest-mock-extended";
|
||||||
|
|
||||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
||||||
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
||||||
|
|
||||||
import { WindowMain } from "../window.main";
|
import { WindowMain } from "../window.main";
|
||||||
|
@ -16,9 +17,16 @@ describe("biometrics tests", function () {
|
||||||
const windowMain = mock<WindowMain>();
|
const windowMain = mock<WindowMain>();
|
||||||
const stateService = mock<StateService>();
|
const stateService = mock<StateService>();
|
||||||
const logService = mock<LogService>();
|
const logService = mock<LogService>();
|
||||||
|
const messagingService = mock<MessagingService>();
|
||||||
|
|
||||||
it("Should call the platformspecific methods", () => {
|
it("Should call the platformspecific methods", () => {
|
||||||
const sut = new BiometricsService(i18nService, windowMain, stateService, logService);
|
const sut = new BiometricsService(
|
||||||
|
i18nService,
|
||||||
|
windowMain,
|
||||||
|
stateService,
|
||||||
|
logService,
|
||||||
|
messagingService
|
||||||
|
);
|
||||||
|
|
||||||
const mockService = mock<BiometricsServiceAbstraction>();
|
const mockService = mock<BiometricsServiceAbstraction>();
|
||||||
(sut as any).platformSpecificService = mockService;
|
(sut as any).platformSpecificService = mockService;
|
||||||
|
@ -42,7 +50,13 @@ describe("biometrics tests", function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const sut = new BiometricsService(i18nService, windowMain, stateService, logService);
|
const sut = new BiometricsService(
|
||||||
|
i18nService,
|
||||||
|
windowMain,
|
||||||
|
stateService,
|
||||||
|
logService,
|
||||||
|
messagingService
|
||||||
|
);
|
||||||
|
|
||||||
it("Should create a biometrics service specific for Windows", () => {
|
it("Should create a biometrics service specific for Windows", () => {
|
||||||
const internalService = (sut as any).platformSpecificService;
|
const internalService = (sut as any).platformSpecificService;
|
||||||
|
@ -68,7 +82,13 @@ describe("biometrics tests", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should create a biometrics service specific for MacOs", () => {
|
it("Should create a biometrics service specific for MacOs", () => {
|
||||||
const sut = new BiometricsService(i18nService, windowMain, stateService, logService);
|
const sut = new BiometricsService(
|
||||||
|
i18nService,
|
||||||
|
windowMain,
|
||||||
|
stateService,
|
||||||
|
logService,
|
||||||
|
messagingService
|
||||||
|
);
|
||||||
const internalService = (sut as any).platformSpecificService;
|
const internalService = (sut as any).platformSpecificService;
|
||||||
expect(internalService).not.toBeNull();
|
expect(internalService).not.toBeNull();
|
||||||
expect(internalService).toBeInstanceOf(BiometricDarwinMain);
|
expect(internalService).toBeInstanceOf(BiometricDarwinMain);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
||||||
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
||||||
|
|
||||||
import { WindowMain } from "../window.main";
|
import { WindowMain } from "../window.main";
|
||||||
|
@ -13,7 +14,8 @@ export class BiometricsService implements BiometricsServiceAbstraction {
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private windowMain: WindowMain,
|
private windowMain: WindowMain,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
private logService: LogService
|
private logService: LogService,
|
||||||
|
private messagingService: MessagingService
|
||||||
) {
|
) {
|
||||||
this.loadPlatformSpecificService();
|
this.loadPlatformSpecificService();
|
||||||
}
|
}
|
||||||
|
@ -52,6 +54,11 @@ export class BiometricsService implements BiometricsServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async authenticateBiometric(): Promise<boolean> {
|
async authenticateBiometric(): Promise<boolean> {
|
||||||
return await this.platformSpecificService.authenticateBiometric();
|
this.messagingService.send("cancelProcessReload");
|
||||||
|
const response = await this.platformSpecificService.authenticateBiometric();
|
||||||
|
if (!response) {
|
||||||
|
this.messagingService.send("startProcessReload");
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,34 +45,23 @@ export class SystemService implements SystemServiceAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cancelProcessReload();
|
this.cancelProcessReload();
|
||||||
this.reloadInterval = setInterval(async () => await this.executeProcessReload(), 10000);
|
await this.executeProcessReload();
|
||||||
}
|
|
||||||
|
|
||||||
private async inactiveMoreThanSeconds(seconds: number): Promise<boolean> {
|
|
||||||
const lastActive = await this.stateService.getLastActive();
|
|
||||||
if (lastActive != null) {
|
|
||||||
const diffMs = new Date().getTime() - lastActive;
|
|
||||||
return diffMs >= seconds * 1000;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async executeProcessReload() {
|
private async executeProcessReload() {
|
||||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
|
||||||
const doRefresh =
|
|
||||||
accounts == null ||
|
|
||||||
Object.keys(accounts).length == 0 ||
|
|
||||||
(await this.inactiveMoreThanSeconds(5));
|
|
||||||
|
|
||||||
const biometricLockedFingerprintValidated =
|
const biometricLockedFingerprintValidated =
|
||||||
await this.stateService.getBiometricFingerprintValidated();
|
await this.stateService.getBiometricFingerprintValidated();
|
||||||
if (doRefresh && !biometricLockedFingerprintValidated) {
|
if (!biometricLockedFingerprintValidated) {
|
||||||
clearInterval(this.reloadInterval);
|
clearInterval(this.reloadInterval);
|
||||||
this.reloadInterval = null;
|
this.reloadInterval = null;
|
||||||
this.messagingService.send("reloadProcess");
|
this.messagingService.send("reloadProcess");
|
||||||
if (this.reloadCallback != null) {
|
if (this.reloadCallback != null) {
|
||||||
await this.reloadCallback();
|
await this.reloadCallback();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.reloadInterval == null) {
|
||||||
|
this.reloadInterval = setInterval(async () => await this.executeProcessReload(), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue