1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-30 08:26:59 +02:00

Mobile: Add log info for biometrics feature

This commit is contained in:
Laurent Cozic 2023-04-08 10:40:53 +02:00
parent 46425b920c
commit efdbaeb397
3 changed files with 38 additions and 1 deletions

View File

@ -5,6 +5,9 @@ import { View, Dimensions, Alert, Button } from 'react-native';
import FingerprintScanner from 'react-native-fingerprint-scanner';
import { SensorInfo } from './sensorInfo';
import { _ } from '@joplin/lib/locale';
import Logger from '@joplin/lib/Logger';
const logger = Logger.create('BiometricPopup');
interface Props {
themeId: number;
@ -21,12 +24,22 @@ export default (props: Props) => {
const [display, setDisplay] = useState(!!props.sensorInfo.supportedSensors && (props.sensorInfo.enabled || !initialPromptDone));
const [tryBiometricsCheck, setTryBiometricsCheck] = useState(initialPromptDone);
logger.info('Render start');
logger.info('initialPromptDone', initialPromptDone);
logger.info('display', display);
logger.info('tryBiometricsCheck', tryBiometricsCheck);
logger.info('props.sensorInfo', props.sensorInfo);
useEffect(() => {
if (!display || !tryBiometricsCheck) return;
const biometricsCheck = async () => {
logger.info('biometricsCheck: start');
try {
logger.info('biometricsCheck: authenticate...');
await FingerprintScanner.authenticate({ description: _('Verify your identity') });
logger.info('biometricsCheck: authenticate done');
setTryBiometricsCheck(false);
setDisplay(false);
} catch (error) {
@ -35,6 +48,8 @@ export default (props: Props) => {
} finally {
FingerprintScanner.release();
}
logger.info('biometricsCheck: end');
};
void biometricsCheck();
@ -45,6 +60,9 @@ export default (props: Props) => {
if (!display) return;
const complete = (enableBiometrics: boolean) => {
logger.info('complete: start');
logger.info('complete: enableBiometrics:', enableBiometrics);
setInitialPromptDone(true);
Setting.setValue('security.biometricsInitialPromptDone', true);
Setting.setValue('security.biometricsEnabled', enableBiometrics);
@ -59,6 +77,8 @@ export default (props: Props) => {
type: 'BIOMETRICS_DONE_SET',
value: true,
});
logger.info('complete: end');
};
Alert.alert(
@ -87,12 +107,18 @@ export default (props: Props) => {
}, []);
useEffect(() => {
logger.info('effect 1: start');
if (!display) {
logger.info('effect 1: display', display);
props.dispatch({
type: 'BIOMETRICS_DONE_SET',
value: true,
});
}
logger.info('effect 1: end');
}, [display, props.dispatch]);
const renderTryAgainButton = () => {

View File

@ -1,5 +1,7 @@
import Logger from '@joplin/lib/Logger';
import Setting from '@joplin/lib/models/Setting';
import FingerprintScanner from 'react-native-fingerprint-scanner';
const logger = Logger.create('sensorInfo');
export interface SensorInfo {
enabled: boolean;
@ -12,6 +14,9 @@ export default async (): Promise<SensorInfo> => {
// FingerprintScanner scanner calls, since it seems they can fail and freeze
// the app.
logger.info('Start');
logger.info('security.biometricsEnabled', Setting.value('security.biometricsEnabled'));
if (!Setting.value('security.biometricsEnabled')) {
return {
enabled: false,
@ -24,7 +29,9 @@ export default async (): Promise<SensorInfo> => {
let supportedSensors = '';
try {
logger.info('Getting isSensorAvailable...');
const result = await FingerprintScanner.isSensorAvailable();
logger.info('isSensorAvailable result', result);
supportedSensors = result;
if (result) {
@ -34,7 +41,7 @@ export default async (): Promise<SensorInfo> => {
}
}
} catch (error) {
console.warn('Could not check for biometrics sensor:', error);
logger.warn('Could not check for biometrics sensor:', error);
Setting.setValue('security.biometricsSupportedSensors', '');
}

View File

@ -984,6 +984,10 @@ class AppComponent extends React.Component {
const biometricIsEnabled = !!this.state.sensorInfo && this.state.sensorInfo.enabled;
const shouldShowMainContent = !biometricIsEnabled || this.props.biometricsDone;
logger.info('root.biometrics: biometricIsEnabled', biometricIsEnabled);
logger.info('root.biometrics: shouldShowMainContent', shouldShowMainContent);
logger.info('root.biometrics: this.state.sensorInfo', this.state.sensorInfo);
const mainContent = (
<View style={{ flex: 1, backgroundColor: theme.backgroundColor }}>
<SideMenu