diff --git a/assets/localization/en.json b/assets/localization/en.json index 6f3203472..cb45ecf7f 100644 --- a/assets/localization/en.json +++ b/assets/localization/en.json @@ -387,6 +387,7 @@ "settings.EmailSentSuccessMessage": "An email to reset your password has been sent!", "settings.EmailUpdated": "Email Updated", "settings.EmailValidation": "Invalid Email Address", + "settings.EnableInAppNotifications": "Enable In-App Notifications", "settings.EnableModule": "Enable {}", "settings.EnabledProfile": "Enabled Profile", "settings.EncryptionKey": "Encryption Key", diff --git a/lib/core/database/luna_database.dart b/lib/core/database/luna_database.dart index 9c06d3bcb..8ab558f3d 100644 --- a/lib/core/database/luna_database.dart +++ b/lib/core/database/luna_database.dart @@ -20,6 +20,7 @@ enum LunaDatabaseValue { QUICK_ACTIONS_SEARCH, USE_24_HOUR_TIME, DEFAULT_LAUNCH_MODULE, + ENABLE_IN_APP_NOTIFICATIONS, } class LunaDatabase extends LunaModuleDatabase { @@ -167,6 +168,8 @@ extension LunaDatabaseValueExtension on LunaDatabaseValue { return value is LunaModule; case LunaDatabaseValue.NETWORKING_TLS_VALIDATION: return value is bool; + case LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS: + return value is bool; } } @@ -208,6 +211,8 @@ extension LunaDatabaseValueExtension on LunaDatabaseValue { return LunaModule.DASHBOARD; case LunaDatabaseValue.NETWORKING_TLS_VALIDATION: return false; + case LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS: + return true; } } } diff --git a/lib/firebase/messaging.dart b/lib/firebase/messaging.dart index 798cbb7d1..c4aa1afc3 100644 --- a/lib/firebase/messaging.dart +++ b/lib/firebase/messaging.dart @@ -79,6 +79,8 @@ class LunaFirebaseMessaging { /// This listens on [FirebaseMessaging.onMessage], where the application must be open and in the foreground. StreamSubscription registerOnMessageListener() { return onMessage.listen((message) { + if (LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.data) return; + LunaModule? module = LunaModule.DASHBOARD.fromKey(message.data['module']); showLunaSnackBar( title: message.notification?.title ?? 'Unknown Content', diff --git a/lib/modules/settings/routes/notifications/route.dart b/lib/modules/settings/routes/notifications/route.dart index 9a4804839..d317590f6 100644 --- a/lib/modules/settings/routes/notifications/route.dart +++ b/lib/modules/settings/routes/notifications/route.dart @@ -63,12 +63,25 @@ class _State extends State<_Widget> with LunaScrollControllerMixin { trailing: const LunaIconButton.arrow(), onTap: LunaLinks.NOTIFICATIONS_GETTING_STARTED.launch, ), + _enableInAppNotifications(), LunaDivider(), ..._modules(), ], ); } + Widget _enableInAppNotifications() { + return LunaBlock( + title: 'settings.EnableInAppNotifications'.tr(), + trailing: LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.listen( + builder: (context, box, _) => LunaSwitch( + value: LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.data, + onChanged: LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.put, + ), + ), + ); + } + List _modules() { List modules = []; for (LunaModule module in LunaModule.values) { diff --git a/localization/settings/en.json b/localization/settings/en.json index f0aa1060d..775f95965 100644 --- a/localization/settings/en.json +++ b/localization/settings/en.json @@ -121,6 +121,7 @@ "settings.EmailSentSuccessMessage": "An email to reset your password has been sent!", "settings.EmailUpdated": "Email Updated", "settings.EmailValidation": "Invalid Email Address", + "settings.EnableInAppNotifications": "Enable In-App Notifications", "settings.EnableModule": "Enable {}", "settings.EnabledProfile": "Enabled Profile", "settings.EncryptionKey": "Encryption Key",