2023-01-04 22:18:51 +02:00
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
|
|
|
import FingerprintScanner from 'react-native-fingerprint-scanner';
|
|
|
|
|
|
|
|
export interface SensorInfo {
|
|
|
|
enabled: boolean;
|
|
|
|
sensorsHaveChanged: boolean;
|
|
|
|
supportedSensors: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default async (): Promise<SensorInfo> => {
|
2023-03-22 20:22:58 +02:00
|
|
|
// Early exit if the feature is disabled, so that we don't make any
|
|
|
|
// FingerprintScanner scanner calls, since it seems they can fail and freeze
|
|
|
|
// the app.
|
|
|
|
|
|
|
|
if (!Setting.value('security.biometricsEnabled')) {
|
|
|
|
return {
|
|
|
|
enabled: false,
|
|
|
|
sensorsHaveChanged: false,
|
|
|
|
supportedSensors: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:18:51 +02:00
|
|
|
let hasChanged = false;
|
|
|
|
let supportedSensors = '';
|
|
|
|
|
2023-01-05 15:29:19 +02:00
|
|
|
try {
|
|
|
|
const result = await FingerprintScanner.isSensorAvailable();
|
|
|
|
supportedSensors = result;
|
2023-01-04 22:18:51 +02:00
|
|
|
|
2023-01-05 15:29:19 +02:00
|
|
|
if (result) {
|
|
|
|
if (result !== Setting.value('security.biometricsSupportedSensors')) {
|
|
|
|
hasChanged = true;
|
|
|
|
Setting.setValue('security.biometricsSupportedSensors', result);
|
2023-01-04 22:18:51 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-05 15:29:19 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.warn('Could not check for biometrics sensor:', error);
|
|
|
|
Setting.setValue('security.biometricsSupportedSensors', '');
|
2023-01-04 22:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-01-05 15:29:19 +02:00
|
|
|
enabled: Setting.value('security.biometricsEnabled'),
|
2023-01-04 22:18:51 +02:00
|
|
|
sensorsHaveChanged: hasChanged,
|
|
|
|
supportedSensors,
|
|
|
|
};
|
|
|
|
};
|