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

[auth] Auth lockscreen fixes #3545

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 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 the applock, all data will be lost, and you'll need to reinstall the app."
}
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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names aren't used coherently. getOfflineModeWarningStatus returns a bool but isn't clear how the status and boolean returns are related.

getOfflineModeWarningStatus returns the key ls_show_offline_mode_warning. So it's expected if getOfflineModeWarningStatus returns false, we should not show the warning. But the use of getOfflineModeWarningStatus here isn't following that expectation.

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(true);
} 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) ?? false;
}

Future<void> runLockScreenChangesMigration() async {
if (_preferences.getBool(keyHasMigratedLockScreenChanges) != null) {
return;
Expand Down