Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix kit intro routing

AmanRajSinghMourya069dd3962cb2
diff --git a/mobile/apps/locker/lib/ui/components/legacy_setup_banner.dart b/mobile/apps/locker/lib/ui/components/legacy_setup_banner.dart
index 1a484e2c49..812bf85ca1 100644
--- a/mobile/apps/locker/lib/ui/components/legacy_setup_banner.dart
+++ b/mobile/apps/locker/lib/ui/components/legacy_setup_banner.dart
@@ -100,7 +100,7 @@ class _LegacySetupBannerState extends State<LegacySetupBanner> {
}
void _onSetup() {
- unawaited(openLegacyPage(context));
+ unawaited(openLegacyFromHome(context));
}
Future<void> _onDismiss() async {
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index 7231410494..adb17b3342 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -745,7 +745,7 @@ class _HomePageState extends UploaderPageState<HomePage>
children: [
LockerHomeHeader(
scaffoldKey: scaffoldKey,
- onLegacyTapped: () => unawaited(openLegacyPage(context)),
+ onLegacyTapped: () => unawaited(openLegacyFromHome(context)),
isSyncing: _isSyncing,
),
if (!isHomeEmptyState) _buildSearchBar(),
diff --git a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
index 5223443a36..692589ee12 100644
--- a/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
+++ b/mobile/apps/locker/lib/ui/utils/legacy_utils.dart
@@ -1,6 +1,9 @@
// ignore_for_file: use_build_context_synchronously
+import "package:ente_legacy/pages/create_legacy_kit_sheet.dart";
import "package:ente_legacy/pages/emergency_page.dart";
+import "package:ente_legacy/pages/legacy_kit_intro_page.dart";
+import "package:ente_legacy/services/legacy_kit_service.dart";
import "package:ente_lock_screen/local_authentication_service.dart";
import "package:flutter/material.dart";
import "package:locker/l10n/l10n.dart";
@@ -8,6 +11,21 @@ import "package:locker/services/configuration.dart";
/// Opens the Legacy (Emergency contacts) page after authenticating the user.
Future<void> openLegacyPage(BuildContext context) async {
+ await _openLegacy(context, showIntroWhenNoKits: false);
+}
+
+/// Opens Legacy from a home onboarding entrypoint.
+///
+/// Users without a Legacy kit see the intro before setup. Users with an
+/// existing kit continue to the regular Legacy management page.
+Future<void> openLegacyFromHome(BuildContext context) async {
+ await _openLegacy(context, showIntroWhenNoKits: true);
+}
+
+Future<void> _openLegacy(
+ BuildContext context, {
+ required bool showIntroWhenNoKits,
+}) async {
var hasAuthenticatedForLegacyFlow = await _authenticateForLegacyFlow(
context,
context.l10n.authToManageLegacy,
@@ -16,27 +34,65 @@ Future<void> openLegacyPage(BuildContext context) async {
return;
}
+ final config = Configuration.instance;
+ Future<bool> legacyKitAuthenticator(
+ BuildContext context,
+ String reason,
+ ) async {
+ if (hasAuthenticatedForLegacyFlow) {
+ return true;
+ }
+ hasAuthenticatedForLegacyFlow = await _authenticateForLegacyFlow(
+ context,
+ reason,
+ );
+ return hasAuthenticatedForLegacyFlow;
+ }
+
+ if (showIntroWhenNoKits && await _hasNoLegacyKits()) {
+ if (!context.mounted) {
+ return;
+ }
+ final shouldStart = await showLegacyKitIntroPage(context);
+ if (!shouldStart || !context.mounted) {
+ return;
+ }
+ await showCreateLegacyKitPage(
+ context,
+ accountEmail: config.getEmail() ?? "",
+ isFirstLegacyKit: true,
+ authenticator: legacyKitAuthenticator,
+ );
+ return;
+ }
+
+ if (!context.mounted) {
+ return;
+ }
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return EmergencyPage(
- config: Configuration.instance,
- legacyKitAuthenticator: (context, reason) async {
- if (hasAuthenticatedForLegacyFlow) {
- return true;
- }
- hasAuthenticatedForLegacyFlow = await _authenticateForLegacyFlow(
- context,
- reason,
- );
- return hasAuthenticatedForLegacyFlow;
- },
+ config: config,
+ legacyKitAuthenticator: legacyKitAuthenticator,
);
},
),
);
}
+Future<bool> _hasNoLegacyKits() async {
+ if (!LegacyKitService.instance.isInitialized) {
+ return false;
+ }
+ try {
+ return (await LegacyKitService.instance.getKits()).isEmpty;
+ } catch (_) {
+ // Fall back to EmergencyPage, which owns the existing fetch error handling.
+ return false;
+ }
+}
+
Future<bool> _authenticateForLegacyFlow(BuildContext context, String reason) {
return LocalAuthenticationService.instance.requestLocalAuthentication(
context,