[mob][auth] Independent applock implemented

This commit is contained in:
Aman Raj Singh Mourya
2024-08-19 18:59:03 +05:30
parent f84054b4ce
commit 1323525cd8
3 changed files with 30 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ import 'package:ente_auth/ui/settings/lock_screen/lock_screen_pin.dart';
import 'package:ente_auth/ui/tools/app_lock.dart';
import 'package:ente_auth/utils/auth_util.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/lock_screen_settings.dart';
import 'package:ente_auth/utils/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -23,7 +24,8 @@ class LocalAuthenticationService {
BuildContext context,
String infoMessage,
) async {
if (await isLocalAuthSupportedOnDevice()) {
if (await isLocalAuthSupportedOnDevice() ||
LockScreenSettings.instance.getIsAppLockSet()) {
AppLock.of(context)!.setEnabled(false);
final result = await requestAuthentication(
context,

View File

@@ -84,13 +84,15 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
},
),
);
await _lockscreenSetting.setAppLockEnabled(result);
await _initializeSettings();
setState(() {
if (result) {
if (result) {
await _configuration.setSystemLockScreen(false);
await _lockscreenSetting.setAppLockEnabled(true);
setState(() {
appLock = _lockscreenSetting.getIsAppLockSet();
}
});
});
}
await _initializeSettings();
}
Future<void> _passwordLock() async {
@@ -101,14 +103,13 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
},
),
);
await _lockscreenSetting.setAppLockEnabled(result);
await _initializeSettings();
setState(() {
if (result) {
if (result) {
await _configuration.setSystemLockScreen(false);
setState(() {
appLock = _lockscreenSetting.getIsAppLockSet();
}
});
});
}
await _initializeSettings();
}
Future<void> _onToggleSwitch() async {

View File

@@ -46,18 +46,20 @@ class LockScreenSettings {
}
Future<void> setHasMigratedLockScreenChanges() async {
if (_preferences.getBool(keyHasMigratedLockScreenChanges) == null ||
getIsAppLockSet() == false) {
await _preferences.setBool(keyHasMigratedLockScreenChanges, true);
final bool passwordEnabled = await isPasswordSet();
final bool pinEnabled = await isPinSet();
final bool systemLockEnabled =
Configuration.instance.shouldShowSystemLockScreen();
if (passwordEnabled || pinEnabled || systemLockEnabled) {
await setAppLockEnabled(true);
}
if (_preferences.getBool(keyHasMigratedLockScreenChanges) != null) {
return;
}
final bool passwordEnabled = await isPasswordSet();
final bool pinEnabled = await isPinSet();
final bool systemLockEnabled =
Configuration.instance.shouldShowSystemLockScreen();
if (passwordEnabled || pinEnabled || systemLockEnabled) {
await setAppLockEnabled(true);
}
await _preferences.setBool(keyHasMigratedLockScreenChanges, true);
}
Future<void> setHideAppContent(bool hideContent) async {