Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions app/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -117,6 +118,10 @@ class _HomeScreenState extends ConsumerState<HomeScreen>
void initState() {
super.initState();
initUniLinks();

WidgetsBinding.instance.addPostFrameCallback((_) {
NotificationService().showNotificationDisabledReminder();
});

globals.tabController = TabController(
initialIndex: 0, length: Globals().router.routes.length, vsync: this);
Expand Down
39 changes: 39 additions & 0 deletions app/lib/services/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Widget>[
TextButton(
child: const Text('Close'),
onPressed: () => Navigator.of(context).pop(),
),
],
);
},
);
});
}
}
6 changes: 6 additions & 0 deletions app/lib/services/shared_preference_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,13 @@ Future<List<WalletData>> getWallets() async {

Future<bool> 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;
}
Expand Down