Auto lock option label
This commit is contained in:
parent
fa93c26744
commit
36b39ffaf5
|
@ -2,6 +2,7 @@ import * as LocalAuthentication from 'expo-local-authentication';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
|
import { isIOS } from './deviceInfo';
|
||||||
|
|
||||||
export const saveLastLocalAuthenticationSession = async(server) => {
|
export const saveLastLocalAuthenticationSession = async(server) => {
|
||||||
console.log('saveLastLocalAuthenticationSession -> server', server);
|
console.log('saveLastLocalAuthenticationSession -> server', server);
|
||||||
|
@ -32,10 +33,13 @@ export const localAuthenticate = async(server) => {
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('localAuthenticate -> serverRecord', serverRecord);
|
||||||
if (serverRecord?.autoLock) {
|
if (serverRecord?.autoLock) {
|
||||||
const diffToLastSession = moment().diff(serverRecord?.lastLocalAuthenticatedSession, 'seconds');
|
const diffToLastSession = moment().diff(serverRecord?.lastLocalAuthenticatedSession, 'seconds');
|
||||||
|
console.log('localAuthenticate -> diffToLastSession', diffToLastSession);
|
||||||
if (diffToLastSession >= serverRecord?.autoLockTime) {
|
if (diffToLastSession >= serverRecord?.autoLockTime) {
|
||||||
const supported = await LocalAuthentication.supportedAuthenticationTypesAsync();
|
const supported = await LocalAuthentication.supportedAuthenticationTypesAsync();
|
||||||
|
console.log('localAuthenticate -> supported', supported);
|
||||||
const authResult = await LocalAuthentication.authenticateAsync();
|
const authResult = await LocalAuthentication.authenticateAsync();
|
||||||
if (authResult?.success) {
|
if (authResult?.success) {
|
||||||
await saveLastLocalAuthenticationSession(server);
|
await saveLastLocalAuthenticationSession(server);
|
||||||
|
@ -47,3 +51,19 @@ export const localAuthenticate = async(server) => {
|
||||||
}
|
}
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const supportedAuthenticationLabel = async() => {
|
||||||
|
const supported = await LocalAuthentication.supportedAuthenticationTypesAsync();
|
||||||
|
console.log('supportedAuthenticationLabel -> supported', supported);
|
||||||
|
|
||||||
|
const enrolled = await LocalAuthentication.isEnrolledAsync();
|
||||||
|
console.log('supportedAuthenticationLabel -> enrolled', enrolled);
|
||||||
|
|
||||||
|
if (supported.includes(LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION)) {
|
||||||
|
return isIOS ? 'FaceID' : 'facial recognition';
|
||||||
|
}
|
||||||
|
if (supported.includes(LocalAuthentication.AuthenticationType.FINGERPRINT)) {
|
||||||
|
return isIOS ? 'TouchID' : 'fingerprint';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
|
@ -16,11 +16,12 @@ import Separator from '../containers/Separator';
|
||||||
import ListItem from '../containers/ListItem';
|
import ListItem from '../containers/ListItem';
|
||||||
import { CustomIcon } from '../lib/Icons';
|
import { CustomIcon } from '../lib/Icons';
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
|
import { supportedAuthenticationLabel } from '../utils/localAuthentication';
|
||||||
|
|
||||||
const DEFAULT_AUTO_LOCK = [
|
const DEFAULT_AUTO_LOCK = [
|
||||||
{
|
{
|
||||||
title: 'After 1 minute',
|
title: 'After 1 minute',
|
||||||
value: 60
|
value: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'After 5 minutes',
|
title: 'After 5 minutes',
|
||||||
|
@ -80,7 +81,8 @@ class ScreenLockConfigView extends React.Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
autoLock: false,
|
autoLock: false,
|
||||||
autoLockTime: null,
|
autoLockTime: null,
|
||||||
supported: []
|
supported: [],
|
||||||
|
autoLockLabel: ''
|
||||||
};
|
};
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
@ -95,6 +97,9 @@ class ScreenLockConfigView extends React.Component {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO: raise error in case server wasn't found and pop?
|
// TODO: raise error in case server wasn't found and pop?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const autoLockLabel = await supportedAuthenticationLabel();
|
||||||
|
this.setState({ autoLockLabel });
|
||||||
}
|
}
|
||||||
|
|
||||||
save = async() => {
|
save = async() => {
|
||||||
|
@ -175,7 +180,7 @@ class ScreenLockConfigView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { autoLock, supported } = this.state;
|
const { autoLock, supported, autoLockLabel } = this.state;
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
return (
|
return (
|
||||||
<SafeAreaView
|
<SafeAreaView
|
||||||
|
@ -190,7 +195,7 @@ class ScreenLockConfigView extends React.Component {
|
||||||
>
|
>
|
||||||
<Separator theme={theme} />
|
<Separator theme={theme} />
|
||||||
<ListItem
|
<ListItem
|
||||||
title='Unlock with METHODHERE'
|
title={`Unlock with ${ autoLockLabel }`}
|
||||||
right={() => this.renderSwitch()}
|
right={() => this.renderSwitch()}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue