diff --git a/app/lib/screens/home_screen.dart b/app/lib/screens/home_screen.dart index 9a944020..ca78bbc5 100644 --- a/app/lib/screens/home_screen.dart +++ b/app/lib/screens/home_screen.dart @@ -22,6 +22,7 @@ import 'package:threebotlogin/screens/authentication_screen.dart'; import 'package:threebotlogin/services/socket_service.dart'; import 'package:threebotlogin/services/uni_link_service.dart'; import 'package:threebotlogin/services/shared_preference_service.dart'; +import 'package:threebotlogin/services/notification_service.dart'; import 'package:threebotlogin/widgets/email_verification_needed.dart'; import 'package:app_links/app_links.dart'; @@ -117,6 +118,10 @@ class _HomeScreenState extends ConsumerState void initState() { super.initState(); initUniLinks(); + + WidgetsBinding.instance.addPostFrameCallback((_) { + NotificationService().showNotificationDisabledReminder(); + }); globals.tabController = TabController( initialIndex: 0, length: Globals().router.routes.length, vsync: this); diff --git a/app/lib/services/notification_service.dart b/app/lib/services/notification_service.dart index 55d8d3ce..27fb0a82 100644 --- a/app/lib/services/notification_service.dart +++ b/app/lib/services/notification_service.dart @@ -240,4 +240,43 @@ class NotificationService { logger.i('Notification dismissed: ${receivedAction.title}'); _decrementNotificationCount(); } + + void showNotificationDisabledReminder() async { + if (await AwesomeNotifications().isNotificationAllowed()) return; + + final prefs = await SharedPreferences.getInstance(); + if (prefs.getBool('notification_permission_requested') != true) return; + + const cooldownDays = 7; + const cooldownMs = cooldownDays * 24 * 60 * 60 * 1000; + final lastShown = prefs.getInt('notification_reminder_last_shown') ?? 0; + final now = DateTime.now().millisecondsSinceEpoch; + if (now - lastShown < cooldownMs) return; + + Future.delayed(const Duration(seconds: 1), () { + final context = navigatorKey.currentContext; + if (context == null || !context.mounted) return; + + showDialog( + context: context, + barrierDismissible: true, + routeSettings: const RouteSettings(name: 'notification_disabled_reminder'), + builder: (BuildContext context) { + prefs.setInt('notification_reminder_last_shown', DateTime.now().millisecondsSinceEpoch); + return CustomDialog( + type: DialogType.Warning, + image: Icons.notifications_off, + title: 'Notifications Disabled', + description: 'Notifications are currently disabled. To enable them, please go to your device Settings > Notifications > ThreeFold Connect and enable notifications.', + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () => Navigator.of(context).pop(), + ), + ], + ); + }, + ); + }); + } } diff --git a/app/lib/services/shared_preference_service.dart b/app/lib/services/shared_preference_service.dart index 6738b4d6..b6618d53 100644 --- a/app/lib/services/shared_preference_service.dart +++ b/app/lib/services/shared_preference_service.dart @@ -381,7 +381,13 @@ Future> getWallets() async { Future clearData() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); + // Preserve notification permission flag since it's tied to system permissions + final notificationPermissionRequested = prefs.getBool('notification_permission_requested') ?? false; bool cleared = await prefs.clear(); + // Restore the notification permission flag after clearing + if (notificationPermissionRequested) { + await prefs.setBool('notification_permission_requested', true); + } saveInitDone(); return cleared; }