import { ipcMain , systemPreferences } from "electron" ; import { BiometricMain } from "jslib-common/abstractions/biometric.main" ; import { I18nService } from "jslib-common/abstractions/i18n.service" ; import { StateService } from "jslib-common/abstractions/state.service" ; export default class BiometricDarwinMain implements BiometricMain { isError : boolean = false ; constructor ( private i18nservice , private stateService ) { } async init ( ) { await this . stateService . setEnableBiometric ( await this . supportsBiometric ( ) ) ; await this . stateService . setBiometricText ( "unlockWithTouchId" ) ; await this . stateService . setNoAutoPromptBiometricsText ( "noAutoPromptTouchId" ) ; ipcMain . on ( "biometric" , async ( event , message ) => { event . returnValue = await this . authenticateBiometric ( ) ; } ) ; } supportsBiometric ( ) { return Promise . resolve ( systemPreferences . canPromptTouchID ( ) ) ; } async authenticateBiometric ( ) { try { await systemPreferences . promptTouchID ( this . i18nservice . t ( "touchIdConsentMessage" ) ) ; return true ; } catch { return false ; } } }