2020-07-23 19:32:20 +02:00
|
|
|
import { I18nService, StorageService } from '../abstractions';
|
|
|
|
|
|
|
|
import { ipcMain, systemPreferences } from 'electron';
|
|
|
|
import { BiometricMain } from '../abstractions/biometric.main';
|
|
|
|
import { ConstantsService } from '../services';
|
|
|
|
import { ElectronConstants } from './electronConstants';
|
|
|
|
|
|
|
|
export default class BiometricDarwinMain implements BiometricMain {
|
2020-08-01 01:42:13 +02:00
|
|
|
isError: boolean = false;
|
|
|
|
|
2020-07-23 19:32:20 +02:00
|
|
|
constructor(private storageService: StorageService, private i18nservice: I18nService) {}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
this.storageService.save(ElectronConstants.enableBiometric, await this.supportsBiometric());
|
|
|
|
this.storageService.save(ConstantsService.biometricText, 'unlockWithTouchId');
|
|
|
|
|
|
|
|
ipcMain.on('biometric', async (event: any, message: any) => {
|
|
|
|
event.returnValue = await this.requestCreate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
supportsBiometric(): Promise<boolean> {
|
|
|
|
return Promise.resolve(systemPreferences.canPromptTouchID());
|
|
|
|
}
|
|
|
|
|
|
|
|
async requestCreate(): Promise<boolean> {
|
|
|
|
try {
|
|
|
|
await systemPreferences.promptTouchID(this.i18nservice.t('touchIdConsentMessage'));
|
|
|
|
return true;
|
|
|
|
} catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|