From b3c6c0fc9bfa9fb4f30a98cee96a87088568edf3 Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Wed, 4 Sep 2024 20:44:47 +0530 Subject: [PATCH] [mob][photos] Show lockscreen when guestview is enabled and app is killed --- mobile/lib/core/configuration.dart | 9 +++++++++ mobile/lib/main.dart | 3 ++- mobile/lib/ui/tools/lock_screen.dart | 1 + .../ui/viewer/actions/file_selection_actions_widget.dart | 1 + mobile/lib/ui/viewer/file/detail_page.dart | 1 + mobile/lib/ui/viewer/file/file_app_bar.dart | 3 +++ 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart index 16a65d497f..1c555cb877 100644 --- a/mobile/lib/core/configuration.dart +++ b/mobile/lib/core/configuration.dart @@ -71,6 +71,7 @@ class Configuration { "has_selected_all_folders_for_backup"; static const anonymousUserIDKey = "anonymous_user_id"; static const endPointKey = "endpoint"; + static const guestViewKey = "key_guest_view"; static final _logger = Logger("Configuration"); String? _cachedToken; @@ -633,6 +634,14 @@ class Configuration { return _preferences.setBool(keyShowSystemLockScreen, value); } + Future setGuestView(bool value) { + return _preferences.setBool(guestViewKey, value); + } + + bool getGuestView() { + return _preferences.getBool(guestViewKey) ?? false; + } + void setVolatilePassword(String volatilePassword) { _volatilePassword = volatilePassword; } diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index 459a6d041e..a70b59ae07 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -112,7 +112,8 @@ Future _runInForeground(AdaptiveThemeMode? savedThemeMode) async { builder: (args) => EnteApp(_runBackgroundTask, _killBGTask, locale, savedThemeMode), lockScreen: const LockScreen(), - enabled: await Configuration.instance.shouldShowLockScreen(), + enabled: await Configuration.instance.shouldShowLockScreen() || + Configuration.instance.getGuestView(), locale: locale, lightTheme: lightThemeData, darkTheme: darkThemeData, diff --git a/mobile/lib/ui/tools/lock_screen.dart b/mobile/lib/ui/tools/lock_screen.dart index 15f9d0250b..28f9cdcf1f 100644 --- a/mobile/lib/ui/tools/lock_screen.dart +++ b/mobile/lib/ui/tools/lock_screen.dart @@ -345,6 +345,7 @@ class _LockScreenState extends State lockedTimeInSeconds = 15; isTimerRunning = false; }); + await Configuration.instance.setGuestView(false); } else { if (!_hasPlacedAppInBackground) { if (_lockscreenSetting.getInvalidAttemptCount() > 4 && diff --git a/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart index 50c6306322..ca77ec9a8a 100644 --- a/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart +++ b/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart @@ -581,6 +581,7 @@ class _FileSelectionActionsWidgetState "guest_view", ), ); + await Configuration.instance.setGuestView(true); routeToPage(context, page, forceCustomPageRoute: true).ignore(); WidgetsBinding.instance.addPostFrameCallback((_) { Bus.instance.fire(GuestViewEvent(true, false)); diff --git a/mobile/lib/ui/viewer/file/detail_page.dart b/mobile/lib/ui/viewer/file/detail_page.dart index 24dd9c0499..d78c677446 100644 --- a/mobile/lib/ui/viewer/file/detail_page.dart +++ b/mobile/lib/ui/viewer/file/detail_page.dart @@ -156,6 +156,7 @@ class _DetailPageState extends State { final authenticated = await _requestAuthentication(); if (authenticated) { Bus.instance.fire(GuestViewEvent(false, false)); + await Configuration.instance.setGuestView(false); } } }, diff --git a/mobile/lib/ui/viewer/file/file_app_bar.dart b/mobile/lib/ui/viewer/file/file_app_bar.dart index 67b10bb9ad..ce87e4955c 100644 --- a/mobile/lib/ui/viewer/file/file_app_bar.dart +++ b/mobile/lib/ui/viewer/file/file_app_bar.dart @@ -6,6 +6,7 @@ import "package:flutter_svg/flutter_svg.dart"; import "package:local_auth/local_auth.dart"; import 'package:logging/logging.dart'; import 'package:media_extension/media_extension.dart'; +import "package:photos/core/configuration.dart"; import "package:photos/core/event_bus.dart"; import "package:photos/events/guest_view_event.dart"; import "package:photos/generated/l10n.dart"; @@ -475,6 +476,7 @@ class FileAppBarState extends State { Future _onTapGuestView() async { if (await LocalAuthentication().isDeviceSupported()) { Bus.instance.fire(GuestViewEvent(true, true)); + await Configuration.instance.setGuestView(true); } else { await showErrorDialog( context, @@ -492,6 +494,7 @@ class FileAppBarState extends State { ); if (hasAuthenticated) { Bus.instance.fire(GuestViewEvent(false, false)); + await Configuration.instance.setGuestView(false); } } }