[auth] Auth lockscreen fixes (#3545)

## Description

1. Removed the logout button from the lockscreen if app in without
backup state
2. Show a warning dialog when user try to set the app lock for the 1st
time

## Tests
<img
src="https://github.com/user-attachments/assets/1f12d651-12ee-4ad5-9a17-cc0c0b3c4d61"
width=200>
This commit is contained in:
Ashil
2024-10-07 14:02:00 +05:30
committed by GitHub
4 changed files with 45 additions and 9 deletions

View File

@@ -483,5 +483,6 @@
"importFailureDescNew": "Could not parse the selected file.",
"appLockNotEnabled": "App lock not enabled",
"appLockNotEnabledDescription": "Please enable app lock from Security > App Lock",
"authToViewPasskey": "Please authenticate to view passkey"
"authToViewPasskey": "Please authenticate to view passkey",
"appLockOfflineModeWarning": "You have chosen to proceed without backups. If you forget your applock, you will be locked out from accessing your data."
}

View File

@@ -10,14 +10,17 @@ import 'package:ente_auth/services/user_service.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/account/request_pwd_verification_page.dart';
import 'package:ente_auth/ui/account/sessions_page.dart';
import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/captioned_text_widget.dart';
import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
import 'package:ente_auth/ui/components/menu_item_widget.dart';
import 'package:ente_auth/ui/components/models/button_result.dart';
import 'package:ente_auth/ui/components/toggle_switch_widget.dart';
import 'package:ente_auth/ui/settings/common_settings.dart';
import 'package:ente_auth/ui/settings/lock_screen/lock_screen_options.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/navigation_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
@@ -146,10 +149,27 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
ButtonResult? result;
if (_config.hasOptedForOfflineMode() &&
LockScreenSettings.instance.getOfflineModeWarningStatus()) {
result = await showChoiceActionSheet(
context,
title: context.l10n.warning,
body: context.l10n.appLockOfflineModeWarning,
secondButtonLabel: context.l10n.cancel,
firstButtonLabel: context.l10n.ok,
);
if (result?.action == ButtonAction.first) {
await LockScreenSettings.instance
.setOfflineModeWarningStatus(false);
} else {
return;
}
}
if (await Configuration.instance.shouldShowLockScreen()) {
final bool result = await requestAuthentication(
context,
context.l10n.about,
context.l10n.authToChangeLockscreenSetting,
);
if (result) {
await Navigator.of(context).push(

View File

@@ -33,6 +33,9 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
int remainingTimeInSeconds = 0;
final _lockscreenSetting = LockScreenSettings.instance;
late Brightness _platformBrightness;
final bool hasOptedForOfflineMode =
Configuration.instance.hasOptedForOfflineMode();
@override
void initState() {
_logger.info("initiatingState");
@@ -53,13 +56,15 @@ class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
return Scaffold(
appBar: AppBar(
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.logout_outlined),
color: Theme.of(context).iconTheme.color,
onPressed: () {
_onLogoutTapped(context);
},
),
leading: hasOptedForOfflineMode
? const SizedBox.shrink()
: IconButton(
icon: const Icon(Icons.logout_outlined),
color: Theme.of(context).iconTheme.color,
onPressed: () {
_onLogoutTapped(context);
},
),
),
body: GestureDetector(
onTap: () {

View File

@@ -23,6 +23,8 @@ class LockScreenSettings {
static const keyAppLockSet = "ls_is_app_lock_set";
static const keyHasMigratedLockScreenChanges =
"ls_has_migrated_lock_screen_changes";
static const keyShowOfflineModeWarning = "ls_show_offline_mode_warning";
final List<Duration> autoLockDurations = const [
Duration(milliseconds: 650),
Duration(seconds: 5),
@@ -47,6 +49,14 @@ class LockScreenSettings {
await runLockScreenChangesMigration();
}
Future<void> setOfflineModeWarningStatus(bool value) async {
await _preferences.setBool(keyShowOfflineModeWarning, value);
}
bool getOfflineModeWarningStatus() {
return _preferences.getBool(keyShowOfflineModeWarning) ?? true;
}
Future<void> runLockScreenChangesMigration() async {
if (_preferences.getBool(keyHasMigratedLockScreenChanges) != null) {
return;