π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Fix local gallery account handoff (#11139)
Aman Raj4a9887e3c9e3
diff --git a/mobile/apps/photos/changes/fix-local-gallery-account-handoff.md b/mobile/apps/photos/changes/fix-local-gallery-account-handoff.mdnew file mode 100644index 0000000000..8264976af6--- /dev/null+++ b/mobile/apps/photos/changes/fix-local-gallery-account-handoff.md@@ -0,0 +1 @@+- Fix backup folder selection when switching from local gallery to an account.diff --git a/mobile/apps/photos/lib/services/sync/local_sync_service.dart b/mobile/apps/photos/lib/services/sync/local_sync_service.dartindex 194a8c7711..b54e31a39e 100644--- a/mobile/apps/photos/lib/services/sync/local_sync_service.dart+++ b/mobile/apps/photos/lib/services/sync/local_sync_service.dart@@ -144,8 +144,16 @@ class LocalSyncService {toTime: syncStartTime,);}- if (!hasCompletedFirstImport()) {+ final hasCompletedInitialImport = hasCompletedFirstImport();+ final shouldCompleteLocalGalleryHandoff =+ !isLocalGalleryMode && localSettings.isFromLocalGalleryToEnte;+ if (!hasCompletedInitialImport || shouldCompleteLocalGalleryHandoff) {await _prefs.setBool(kHasCompletedFirstImportKey, true);+ if (isLocalGalleryMode) {+ await localSettings.setIsFromLocalGalleryToEnte(true);+ } else if (shouldCompleteLocalGalleryHandoff) {+ await localSettings.setIsFromLocalGalleryToEnte(false);+ }if (backupPreferenceService.hasSkippedOnboardingPermission) {await backupPreferenceService.setOnboardingPermissionSkipped(false);}@@ -317,6 +325,11 @@ class LocalSyncService {/// bypass it (e.g., onboarding skipped or only-new backup). Falls back to the/// stored completion value otherwise.bool hasCompletedFirstImportOrBypassed() {+ if (!isLocalGalleryMode &&+ Configuration.instance.hasConfiguredAccount() &&+ localSettings.isFromLocalGalleryToEnte) {+ return false;+ }if (hasCompletedFirstImport()) {return true;}diff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dartindex ce93e666e8..26a4b7abb4 100644--- a/mobile/apps/photos/lib/settings/local_settings.dart+++ b/mobile/apps/photos/lib/settings/local_settings.dart@@ -111,6 +111,9 @@ class LocalSettings {"media_management_hint_delete_attempts";static const _kMediaManagementHintDismissedAt ="media_management_hint_dismissed_at";+ static const _kIsFromLocalGalleryToEnte =+ "ls.pending_backup_selection_from_local_import";+static const _kWidgetHideTextFlags = "ls.widget_hide_text_flags";/// Key used by the native (Android/iOS) widget providers to read the@@ -136,6 +139,17 @@ class LocalSettings {/// the second app open (after onboarding).bool localGalleryModeEnabledThisSession = false;+ /// Set after the first local-gallery import completes before an account is+ /// configured. When the user later signs in or signs up, the online flow+ /// replays first-import completion once so backup-folder selection can run+ /// against the imported local rows, then clears this marker.+ bool get isFromLocalGalleryToEnte =>+ _prefs.getBool(_kIsFromLocalGalleryToEnte) ?? false;++ Future<void> setIsFromLocalGalleryToEnte(bool value) async {+ await _prefs.setBool(_kIsFromLocalGalleryToEnte, value);+ }+LocalSettings(this._prefs);bool _getFlag(LocalGalleryFlag flag) {diff --git a/mobile/apps/photos/lib/ui/account/password_entry_page.dart b/mobile/apps/photos/lib/ui/account/password_entry_page.dartindex 6ad09601b1..d4a01173a9 100644--- a/mobile/apps/photos/lib/ui/account/password_entry_page.dart+++ b/mobile/apps/photos/lib/ui/account/password_entry_page.dart@@ -377,7 +377,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {);Configuration.instance.resetVolatilePassword();await dialog.hide();- onDone() async {+ Future<void> onDone() async {final dialog = createProgressDialog(context,AppLocalizations.of(context).pleaseWait,@@ -387,9 +387,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {await UserService.instance.setAttributes(result);await dialog.hide();Configuration.instance.resetVolatilePassword();- Bus.instance.fire(AccountConfiguredEvent());- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(+ await Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (BuildContext context) {return getSubscriptionPage(isOnBoarding: true);@@ -397,6 +395,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {),(route) => route.isFirst,);+ Bus.instance.fire(AccountConfiguredEvent());} catch (e, s) {_logger.severe("Failed to configure account", e, s);await dialog.hide();diff --git a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart b/mobile/apps/photos/lib/ui/home/landing_page_widget.dartindex 5db8c428f1..a725626aac 100644--- a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart+++ b/mobile/apps/photos/lib/ui/home/landing_page_widget.dart@@ -25,10 +25,11 @@ import 'package:photos/ui/payment/subscription.dart';import "package:photos/ui/settings/developer_settings_tap_area.dart";import "package:photos/ui/settings/developer_settings_widget.dart";import "package:photos/ui/settings/language_picker.dart";-import 'package:photos/ui/tabs/home_widget.dart';class LandingPageWidget extends StatefulWidget {- const LandingPageWidget({super.key});+ const LandingPageWidget({required this.onStartWithoutAccount, super.key});++ final VoidCallback onStartWithoutAccount;@overrideState<LandingPageWidget> createState() => _LandingPageWidgetState();@@ -298,12 +299,8 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {);}- Future<void> _navigateWithoutAccount() async {- await Navigator.of(context).push(- MaterialPageRoute(- builder: (_) => const HomeWidget(startWithoutAccount: true),- ),- );+ void _navigateWithoutAccount() {+ widget.onStartWithoutAccount();}Future<void> _navigateToSignUpPage() async {diff --git a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dartindex b6041b5845..fad3fb6841 100644--- a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart+++ b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart@@ -27,7 +27,6 @@ import 'package:photos/ui/notification/toast.dart';import 'package:photos/ui/payment/subscription_common_widgets.dart';import 'package:photos/ui/payment/subscription_plan_widget.dart';import "package:photos/ui/payment/view_add_on_widget.dart";-import "package:photos/ui/tabs/home_widget.dart";import 'package:photos/utils/dialog_util.dart';import 'package:url_launcher/url_launcher_string.dart';@@ -675,16 +674,8 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {}if (selectedProductID == freeProductID) {+ Navigator.of(context).popUntil((route) => route.isFirst);Bus.instance.fire(SubscriptionPurchasedEvent());- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return const HomeWidget();- },- ),- (route) => false,- );unawaited(_billingService.verifySubscription(freeProductID,diff --git a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dartindex afea5644dd..f1317bfd6f 100644--- a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart+++ b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart@@ -25,7 +25,6 @@ import 'package:photos/ui/payment/payment_web_page.dart';import 'package:photos/ui/payment/subscription_common_widgets.dart';import 'package:photos/ui/payment/subscription_plan_widget.dart';import "package:photos/ui/payment/view_add_on_widget.dart";-import "package:photos/ui/tabs/home_widget.dart";import 'package:photos/utils/dialog_util.dart';import 'package:url_launcher/url_launcher_string.dart';@@ -644,16 +643,8 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {}if (selectedPlanProductID == freeProductID) {+ Navigator.of(context).popUntil((route) => route.isFirst);Bus.instance.fire(SubscriptionPurchasedEvent());- // ignore: unawaited_futures- Navigator.of(context).pushAndRemoveUntil(- MaterialPageRoute(- builder: (BuildContext context) {- return const HomeWidget();- },- ),- (route) => false,- );unawaited(_billingService.verifySubscription(freeProductID,diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dartindex b9f862eb79..eaa6355892 100644--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart@@ -92,9 +92,7 @@ import "package:photos/utils/intent_util.dart";import "package:receive_sharing_intent/receive_sharing_intent.dart";class HomeWidget extends StatefulWidget {- const HomeWidget({super.key, this.startWithoutAccount = false});-- final bool startWithoutAccount;+ const HomeWidget({super.key});@overrideState<StatefulWidget> createState() => _HomeWidgetState();@@ -124,6 +122,7 @@ class _HomeWidgetState extends State<HomeWidget> {bool _personSyncTriggered = false;bool _collectionsSyncTriggered = false;bool _isShowingChangeLog = false;+ bool _startWithoutAccount = false;final isOnSearchTabNotifier = ValueNotifier<bool>(false);final ValueNotifier<bool> _isAlbumsSearchActiveNotifier = ValueNotifier<bool>(false,@@ -154,6 +153,12 @@ class _HomeWidgetState extends State<HomeWidget> {final DiffFetcher _diffFetcher = DiffFetcher();+ void _startWithoutAccountFlow() {+ setState(() {+ _startWithoutAccount = true;+ });+ }+@overridevoid initState() {_logger.info("initstate");@@ -205,6 +210,7 @@ class _HomeWidgetState extends State<HomeWidget> {_accountConfiguredEvent = Bus.instance.on<AccountConfiguredEvent>().listen((event,) {+ _startWithoutAccount = false;setState(() {});// fetch user flags on loginif (!isLocalGalleryMode) {@@ -220,6 +226,7 @@ class _HomeWidgetState extends State<HomeWidget> {_logger.info('logged out, selectTab index to 0');_selectedTabIndex = 0;_selectedTabIndexNotifier.value = 0;+ _startWithoutAccount = false;if (mounted) {setState(() {});}@@ -822,11 +829,13 @@ class _HomeWidgetState extends State<HomeWidget> {onPopInvokedWithResult: (didPop, _) async {if (didPop) return;final isStartWithoutAccountFlow =- widget.startWithoutAccount &&+ _startWithoutAccount &&!Configuration.instance.hasConfiguredAccount() &&!localSettings.isAppModeSet;if (isStartWithoutAccountFlow) {- Navigator.pop(context);+ setState(() {+ _startWithoutAccount = false;+ });return;}if (_selectedTabIndex == 0) {@@ -949,7 +958,7 @@ class _HomeWidgetState extends State<HomeWidget> {final isOnLandingPage =!Configuration.instance.hasConfiguredAccount() &&!isLocalGalleryMode &&- !widget.startWithoutAccount;+ !_startWithoutAccount;final isOnOnlineGrantPermissionScreen =Configuration.instance.hasConfiguredAccount() &&!isLocalGalleryMode &&@@ -979,14 +988,14 @@ class _HomeWidgetState extends State<HomeWidget> {if (!Configuration.instance.hasConfiguredAccount()) {_closeDrawerIfOpen();final shouldBootstrapLocalGalleryEntryFlow =- widget.startWithoutAccount && !localGalleryMode;+ _startWithoutAccount && !localGalleryMode;final hasPersistedLocalGalleryMode =localSettings.isAppModeSet && localGalleryMode;final canResumePersistedLocalGalleryMode =hasPersistedLocalGalleryMode &&permissionService.hasGrantedPermissions();final shouldUseLocalGalleryEntryFlow =- widget.startWithoutAccount || canResumePersistedLocalGalleryMode;+ _startWithoutAccount || canResumePersistedLocalGalleryMode;if (shouldBootstrapLocalGalleryEntryFlow) {return const GrantPermissionsWidget(startWithoutAccount: true);@@ -995,7 +1004,9 @@ class _HomeWidgetState extends State<HomeWidget> {return const GrantPermissionsWidget(startWithoutAccount: true);}if (!shouldUseLocalGalleryEntryFlow) {- return const LandingPageWidget();+ return LandingPageWidget(+ onStartWithoutAccount: _startWithoutAccountFlow,+ );}}_ensurePersonSync();@@ -1349,7 +1360,9 @@ class _HomeWidgetState extends State<HomeWidget> {if (!permissionService.hasGrantedPermissions()) {return false;}- return !LocalSyncService.instance.hasCompletedFirstImportOrBypassed();+ final isFirstImportCompletedOrBypassed = LocalSyncService.instance+ .hasCompletedFirstImportOrBypassed();+ return !isFirstImportCompletedOrBypassed;}void _ensurePersonSync() {