bitwarden-estensione-browser/apps/desktop/src/main/biometric/biometric.windows.main.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-04-05 16:54:44 +02:00
import { ipcMain } from "electron";
2022-06-14 17:10:53 +02:00
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { biometrics } from "@bitwarden/desktop-native";
import { WindowMain } from "../window.main";
2022-04-05 16:54:44 +02:00
import { BiometricMain } from "./biometric.main";
2022-04-05 16:54:44 +02:00
export default class BiometricWindowsMain implements BiometricMain {
constructor(
private i18nservice: I18nService,
private windowMain: WindowMain,
private stateService: StateService,
private logService: LogService
) {}
async init() {
let supportsBiometric = false;
try {
supportsBiometric = await this.supportsBiometric();
} catch (e) {
this.logService.error(e);
2022-04-05 16:54:44 +02:00
}
await this.stateService.setEnableBiometric(supportsBiometric);
await this.stateService.setBiometricText("unlockWithWindowsHello");
await this.stateService.setNoAutoPromptBiometricsText("autoPromptWindowsHello");
2022-04-05 16:54:44 +02:00
ipcMain.handle("biometric", async () => {
return await this.authenticateBiometric();
2022-04-05 16:54:44 +02:00
});
}
async supportsBiometric(): Promise<boolean> {
try {
return await biometrics.available();
2022-04-05 16:54:44 +02:00
} catch {
return false;
2022-04-05 16:54:44 +02:00
}
}
async authenticateBiometric(): Promise<boolean> {
const hwnd = this.windowMain.win.getNativeWindowHandle();
return await biometrics.prompt(hwnd, this.i18nservice.t("windowsHelloConsentMessage"));
2022-04-05 16:54:44 +02:00
}
}