Skip to content

Commit

Permalink
[auth] Auth lockscreen fixes (#3545)
Browse files Browse the repository at this point in the history
## 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>
  • Loading branch information
ashilkn authored Oct 7, 2024
2 parents b1c3041 + bd01340 commit c56a964
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion auth/lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
22 changes: 21 additions & 1 deletion auth/lib/ui/settings/security_section_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 12 additions & 7 deletions auth/lib/ui/tools/lock_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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: () {
Expand Down
10 changes: 10 additions & 0 deletions auth/lib/utils/lock_screen_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
Expand Down

0 comments on commit c56a964

Please sign in to comment.