Delay bio auth (#642)
This commit is contained in:
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:responsive_framework/responsive_framework.dart';
|
||||
import 'package:server_box/core/chan.dart';
|
||||
import 'package:server_box/data/model/app/tab.dart';
|
||||
import 'package:server_box/data/provider/app.dart';
|
||||
import 'package:server_box/data/provider/server.dart';
|
||||
import 'package:server_box/data/res/build_data.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
@@ -28,6 +27,7 @@ class _HomePageState extends State<HomePage>
|
||||
|
||||
bool _switchingPage = false;
|
||||
bool _shouldAuth = false;
|
||||
DateTime? _pausedTime;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -62,13 +62,27 @@ class _HomePageState extends State<HomePage>
|
||||
|
||||
switch (state) {
|
||||
case AppLifecycleState.resumed:
|
||||
if (_shouldAuth) _goAuth();
|
||||
if (_shouldAuth) {
|
||||
final delay = Stores.setting.delayBioAuthLock.fetch();
|
||||
if (delay > 0 && _pausedTime != null) {
|
||||
final now = DateTime.now();
|
||||
if (now.difference(_pausedTime ?? now).inSeconds > delay) {
|
||||
_goAuth();
|
||||
} else {
|
||||
_shouldAuth = false;
|
||||
}
|
||||
_pausedTime = null;
|
||||
} else {
|
||||
_goAuth();
|
||||
}
|
||||
}
|
||||
if (!ServerProvider.isAutoRefreshOn) {
|
||||
ServerProvider.startAutoRefresh();
|
||||
}
|
||||
MethodChans.updateHomeWidget();
|
||||
break;
|
||||
case AppLifecycleState.paused:
|
||||
_pausedTime = DateTime.now();
|
||||
_shouldAuth = true;
|
||||
// Keep running in background on Android device
|
||||
if (isAndroid && Stores.setting.bgRun.fetch()) {
|
||||
@@ -89,7 +103,6 @@ class _HomePageState extends State<HomePage>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
AppProvider.ctx = context;
|
||||
final isMobile = ResponsiveBreakpoints.of(context).isMobile;
|
||||
|
||||
return Scaffold(
|
||||
|
||||
@@ -232,11 +232,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final e = pkis[index];
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.only(left: 10, right: 15),
|
||||
leading: Radio<int>(
|
||||
value: index,
|
||||
groupValue: _keyIdx.value,
|
||||
onChanged: (value) => _keyIdx.value = value,
|
||||
),
|
||||
leading: Radio<int>(value: index),
|
||||
title: Text(e.id, textAlign: TextAlign.start),
|
||||
subtitle: Text(e.type ?? l10n.unknown, textAlign: TextAlign.start, style: UIs.textGrey),
|
||||
trailing: Btn.icon(
|
||||
@@ -254,7 +250,10 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
onTap: () => PrivateKeyEditPage.route.go(context),
|
||||
),
|
||||
);
|
||||
return _keyIdx.listenVal((_) => Column(children: tiles)).cardx;
|
||||
return RadioGroup<int>(
|
||||
onChanged: (val) => _keyIdx.value = val,
|
||||
child: _keyIdx.listenVal((_) => Column(children: tiles)).cardx,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ extension _App on _AppSettingsPageState {
|
||||
_buildThemeMode(),
|
||||
_buildAppColor(),
|
||||
_buildCheckUpdate(),
|
||||
PlatformPublicSettings.buildBioAuth(),
|
||||
PlatformPublicSettings.buildBioAuth,
|
||||
if (specific != null) specific,
|
||||
_buildAppMore(),
|
||||
];
|
||||
|
||||
@@ -3,23 +3,47 @@ import 'package:flutter/material.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
|
||||
abstract final class PlatformPublicSettings {
|
||||
static Widget buildBioAuth() {
|
||||
static Widget get buildBioAuth {
|
||||
return ExpandTile(title: Text(libL10n.bioAuth), children: [_buildBioAuth(), _buildBioAuthDelay()]);
|
||||
}
|
||||
|
||||
static Widget _buildBioAuthDelay() {
|
||||
return FutureWidget<bool>(
|
||||
future: LocalAuth.isAvail,
|
||||
loading: ListTile(
|
||||
title: Text(libL10n.delay),
|
||||
subtitle: const Text('...', style: UIs.textGrey),
|
||||
),
|
||||
error: (e, _) => ListTile(
|
||||
title: Text(libL10n.delay),
|
||||
subtitle: Text('${libL10n.fail}: $e', style: UIs.textGrey),
|
||||
),
|
||||
success: (can) {
|
||||
return ListTile(
|
||||
title: Text(libL10n.delay),
|
||||
trailing: can == true ? Stores.setting.delayBioAuthLock.fieldWidget() : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _buildBioAuth() {
|
||||
return FutureWidget<bool>(
|
||||
future: LocalAuth.isAvail,
|
||||
loading: ListTile(
|
||||
leading: const Icon(Icons.fingerprint),
|
||||
title: Text(libL10n.bioAuth),
|
||||
title: Text(libL10n.switch_),
|
||||
subtitle: const Text('...', style: UIs.textGrey),
|
||||
),
|
||||
error: (e, _) => ListTile(
|
||||
title: Text(libL10n.bioAuth),
|
||||
title: Text(libL10n.switch_),
|
||||
subtitle: Text('${libL10n.fail}: $e', style: UIs.textGrey),
|
||||
),
|
||||
success: (can) {
|
||||
can ??= false;
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.fingerprint),
|
||||
title: Text(libL10n.bioAuth),
|
||||
title: Text(libL10n.switch_),
|
||||
subtitle: can ? null : Text(libL10n.notExistFmt(libL10n.bioAuth), style: UIs.textGrey),
|
||||
trailing: can
|
||||
? StoreSwitch(
|
||||
|
||||
Reference in New Issue
Block a user