fix: repeatedly auth (#294 #320)

This commit is contained in:
lollipopkit
2024-03-27 18:48:01 -06:00
parent f5d5bf9c37
commit dacc042a85
4 changed files with 11 additions and 16 deletions

View File

@@ -32,36 +32,28 @@ abstract final class BioAuth {
biometrics.contains(BiometricType.fingerprint); biometrics.contains(BiometricType.fingerprint);
} }
static void auth([int count = 0]) async { static Future<void> go([int count = 0]) async {
if (Stores.setting.useBioAuth.fetch()) { if (Stores.setting.useBioAuth.fetch()) {
if (!_isAuthing) { if (!_isAuthing) {
_isAuthing = true; _isAuthing = true;
final val = await authWithResult(); final val = await goWithResult();
switch (val) { switch (val) {
case AuthResult.success: case AuthResult.success:
// wait for animation
Future.delayed(
isIOS
? const Duration(milliseconds: 1300)
: const Duration(seconds: 1),
() => _isAuthing = false,
);
break; break;
case AuthResult.fail: case AuthResult.fail:
case AuthResult.cancel: case AuthResult.cancel:
_isAuthing = false; go(count + 1);
auth(count + 1);
break; break;
case AuthResult.notAvail: case AuthResult.notAvail:
_isAuthing = false;
Stores.setting.useBioAuth.put(false); Stores.setting.useBioAuth.put(false);
break; break;
} }
_isAuthing = false;
} }
} }
} }
static Future<AuthResult> authWithResult() async { static Future<AuthResult> goWithResult() async {
if (!await isAvail) return AuthResult.notAvail; if (!await isAvail) return AuthResult.notAvail;
try { try {
await _auth.stopAuthentication(); await _auth.stopAuthentication();

View File

@@ -62,5 +62,8 @@ abstract final class GithubIds {
'Tridays', 'Tridays',
'Nebulosa-Cat', 'Nebulosa-Cat',
'dani7959', 'dani7959',
'MoMingRose',
'sakalakagg',
'cz32483490',
}; };
} }

View File

@@ -82,13 +82,13 @@ class _HomePageState extends State<HomePage>
switch (state) { switch (state) {
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
BioAuth.auth();
if (!Pros.server.isAutoRefreshOn) { if (!Pros.server.isAutoRefreshOn) {
Pros.server.startAutoRefresh(); Pros.server.startAutoRefresh();
} }
HomeWidgetMC.update(); HomeWidgetMC.update();
break; break;
case AppLifecycleState.paused: case AppLifecycleState.paused:
BioAuth.go();
// Keep running in background on Android device // Keep running in background on Android device
if (isAndroid && Stores.setting.bgRun.fetch()) { if (isAndroid && Stores.setting.bgRun.fetch()) {
// Keep this if statement single // Keep this if statement single
@@ -316,7 +316,7 @@ ${GithubIds.participants.map((e) => '[$e](${e.url})').join(' ')}
@override @override
Future<void> afterFirstLayout(BuildContext context) async { Future<void> afterFirstLayout(BuildContext context) async {
// Auth required for first launch // Auth required for first launch
BioAuth.auth(); BioAuth.go();
if (Stores.setting.autoCheckAppUpdate.fetch()) { if (Stores.setting.autoCheckAppUpdate.fetch()) {
doUpdate(context); doUpdate(context);

View File

@@ -36,7 +36,7 @@ abstract final class PlatformPublicSettings {
return; return;
} }
// Only auth when turn off (val == false) // Only auth when turn off (val == false)
final result = await BioAuth.authWithResult(); final result = await BioAuth.goWithResult();
// If failed, turn on again // If failed, turn on again
if (result != AuthResult.success) { if (result != AuthResult.success) {
Stores.setting.useBioAuth.put(true); Stores.setting.useBioAuth.put(true);