mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
017f229cfc
A switch in the account settings, inside the app on a device that can unlock that way (iOS LocalAuthentication, Android BiometricPrompt with the screen lock as fallback). Turning it on asks once, so nobody locks themselves out. With it on, TREK asks at launch and after half a minute in the background before showing anything, and the app switcher shows a blurred cover (iOS) or no snapshot (Android) instead of the screen. The setting stays on the device, not the account.
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { ScanFace } from 'lucide-react';
|
|
import { useEffect, useState } from 'react';
|
|
import { useTranslation } from '../../../i18n';
|
|
import {
|
|
appLockSupported,
|
|
biometryAvailable,
|
|
isAppLockEnabled,
|
|
setAppLockEnabled,
|
|
unlockApp,
|
|
} from '../../../native/appLock';
|
|
import MToggle from '../../components/MToggle';
|
|
import { MSetCard, MSetRow } from './MSettingsUi';
|
|
|
|
/**
|
|
* The app lock switch, inside the app on a device that can unlock with Face ID,
|
|
* Touch ID or its passcode. Turning it on asks once, so nobody locks themselves
|
|
* out with a lock that does not work on this phone.
|
|
*/
|
|
export default function MAppLockCard() {
|
|
const { t } = useTranslation();
|
|
const [available, setAvailable] = useState(false);
|
|
const [enabled, setEnabled] = useState(isAppLockEnabled);
|
|
|
|
useEffect(() => {
|
|
if (!appLockSupported()) return;
|
|
void biometryAvailable().then((info) => setAvailable(info.available));
|
|
}, []);
|
|
|
|
if (!available) return null;
|
|
|
|
const toggle = async () => {
|
|
if (enabled) {
|
|
await setAppLockEnabled(false);
|
|
setEnabled(false);
|
|
return;
|
|
}
|
|
if (!(await unlockApp(t('native.lock.reason')))) return;
|
|
await setAppLockEnabled(true);
|
|
setEnabled(true);
|
|
};
|
|
|
|
return (
|
|
<MSetCard title={t('native.lock.settingTitle')} icon={ScanFace} className="mt-3">
|
|
<div className="-mt-[4px]">
|
|
<MSetRow
|
|
first
|
|
label={t('native.lock.setting')}
|
|
sub={t('native.lock.settingHint')}
|
|
trailing={<MToggle checked={enabled} onChange={() => void toggle()} ariaLabel={t('native.lock.setting')} />}
|
|
/>
|
|
</div>
|
|
</MSetCard>
|
|
);
|
|
}
|