Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay bio auth #642

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/data/store/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class SettingStore extends PersistentStore {
/// Only valid on iOS / Android / Windows
late final useBioAuth = property('useBioAuth', false);

/// Delay to lock the App with BioAuth
late final delayBioAuthLock = property('delayBioAuthLock', false);

/// The performance of highlight is bad
late final editorHighlight = property('editorHighlight', true);

Expand Down
18 changes: 17 additions & 1 deletion lib/view/page/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class _HomePageState extends State<HomePage>

bool _switchingPage = false;
bool _shouldAuth = false;
DateTime? _pausedTime;

@override
void dispose() {
Expand Down Expand Up @@ -72,13 +73,28 @@ class _HomePageState extends State<HomePage>

switch (state) {
case AppLifecycleState.resumed:
if (_shouldAuth) _goAuth();
if (_shouldAuth) {
if (Stores.setting.delayBioAuthLock.fetch() && _pausedTime != null) {
if (DateTime.now()
.difference(_pausedTime ?? DateTime.now())
.inSeconds >
10) {
_goAuth();
} else {
_shouldAuth = false;
}
_pausedTime = null;
} else {
_goAuth();
}
}
if (!ServerProvider.isAutoRefreshOn) {
ServerProvider.startAutoRefresh();
}
HomeWidgetMC.update();
break;
case AppLifecycleState.paused:
_pausedTime = DateTime.now();
_shouldAuth = true;
// Keep running in background on Android device
if (isAndroid && Stores.setting.bgRun.fetch()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/view/page/setting/platform/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
_buildAndroidWidgetSharedPreference(),
if (BioAuth.isPlatformSupported)
PlatformPublicSettings.buildBioAuth(),
if (BioAuth.isPlatformSupported)
PlatformPublicSettings.buildBioAuthDelay(),
].map((e) => CardX(child: e)).toList(),
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/view/page/setting/platform/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
_buildWatchApp(),
if (BioAuth.isPlatformSupported)
PlatformPublicSettings.buildBioAuth(),
if (BioAuth.isPlatformSupported)
PlatformPublicSettings.buildBioAuthDelay(),
].map((e) => CardX(child: e)).toList(),
),
);
Expand Down
30 changes: 30 additions & 0 deletions lib/view/page/setting/platform/platform_pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@ import 'package:flutter/material.dart';
import 'package:server_box/data/res/store.dart';

abstract final class PlatformPublicSettings {
static Widget buildBioAuthDelay() {
return FutureWidget<bool>(
future: BioAuth.isAvail,
loading: ListTile(
title: Text(libL10n.bioAuth),
subtitle: const Text('...', style: UIs.textGrey),
),
error: (e, __) => ListTile(
title: Text(libL10n.bioAuth),
subtitle: Text('${libL10n.fail}: $e', style: UIs.textGrey),
),
success: (can) {
return ListTile(
title: Text("Delay before locking the app"),
subtitle: can == true
? Text("Wait for 10 seconds before locking the app")
: const Text(
'Not available',
style: UIs.textGrey,
),
trailing: can == true
? StoreSwitch(
prop: Stores.setting.delayBioAuthLock,
callback: (val) async =>
Stores.setting.delayBioAuthLock.put(val))
: null);
},
);
}

static Widget buildBioAuth() {
return FutureWidget<bool>(
future: BioAuth.isAvail,
Expand Down