mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#165 new: bio auth
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:get_it/get_it.dart';
|
||||
import 'package:toolbox/core/channel/bg_run.dart';
|
||||
import 'package:toolbox/core/channel/home_widget.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/core/utils/platform/auth.dart';
|
||||
import 'package:toolbox/core/utils/platform/base.dart';
|
||||
import 'package:toolbox/data/res/github_id.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
@@ -46,6 +47,7 @@ class _HomePageState extends State<HomePage>
|
||||
late S _s;
|
||||
|
||||
bool _switchingPage = false;
|
||||
bool _isAuthing = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -81,6 +83,7 @@ class _HomePageState extends State<HomePage>
|
||||
|
||||
switch (state) {
|
||||
case AppLifecycleState.resumed:
|
||||
_auth();
|
||||
if (!Providers.server.isAutoRefreshOn) {
|
||||
Providers.server.startAutoRefresh();
|
||||
}
|
||||
@@ -338,6 +341,8 @@ class _HomePageState extends State<HomePage>
|
||||
|
||||
@override
|
||||
Future<void> afterFirstLayout(BuildContext context) async {
|
||||
// Auth required for first launch
|
||||
_auth();
|
||||
if (Stores.setting.autoCheckAppUpdate.fetch()) {
|
||||
doUpdate(context);
|
||||
}
|
||||
@@ -385,4 +390,32 @@ class _HomePageState extends State<HomePage>
|
||||
Loggers.app.warning('Update json settings failed', e, trace);
|
||||
}
|
||||
}
|
||||
|
||||
void _auth() {
|
||||
if (Stores.setting.useBioAuth.fetch()) {
|
||||
if (!_isAuthing) {
|
||||
_isAuthing = true;
|
||||
BioAuth.auth(_s.authRequired).then(
|
||||
(val) {
|
||||
switch (val) {
|
||||
case AuthResult.success:
|
||||
// wait for animation
|
||||
Future.delayed(
|
||||
const Duration(seconds: 1), () => _isAuthing = false);
|
||||
break;
|
||||
case AuthResult.fail:
|
||||
case AuthResult.cancel:
|
||||
_isAuthing = false;
|
||||
_auth();
|
||||
break;
|
||||
case AuthResult.notAvail:
|
||||
_isAuthing = false;
|
||||
Stores.setting.useBioAuth.put(false);
|
||||
break;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user