mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 08:20:36 +00:00
feat: Finish discovery flow
ref:
This commit is contained in:
@@ -26,6 +26,7 @@ class NotificationService {
|
||||
bool _updateNotificationsEnabled = true;
|
||||
bool _muteForegroundNotifications = true;
|
||||
AppLifecycleState _lifecycleState = AppLifecycleState.resumed;
|
||||
String? _launchPayload;
|
||||
|
||||
// Notification IDs
|
||||
static const int _sarNotificationId = 1000;
|
||||
@@ -103,6 +104,12 @@ class NotificationService {
|
||||
onDidReceiveNotificationResponse: _onNotificationResponse,
|
||||
);
|
||||
|
||||
final launchDetails = await _notificationsPlugin
|
||||
.getNotificationAppLaunchDetails();
|
||||
if (launchDetails?.didNotificationLaunchApp ?? false) {
|
||||
_launchPayload = launchDetails?.notificationResponse?.payload;
|
||||
}
|
||||
|
||||
// Request permissions
|
||||
await _requestPermissions();
|
||||
await _loadPreferences();
|
||||
@@ -295,6 +302,12 @@ class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
String? consumeLaunchPayload() {
|
||||
final payload = _launchPayload;
|
||||
_launchPayload = null;
|
||||
return payload;
|
||||
}
|
||||
|
||||
/// Show urgent notification for SAR marker
|
||||
Future<void> showSarNotification({
|
||||
required SarMarkerType type,
|
||||
@@ -837,6 +850,7 @@ class NotificationService {
|
||||
|
||||
Future<bool> showContactDiscoveredNotification({
|
||||
required String contactKey,
|
||||
String? contactName,
|
||||
}) async {
|
||||
if (!_isInitialized) return false;
|
||||
if (!_permissionGranted) return false;
|
||||
@@ -847,7 +861,10 @@ class NotificationService {
|
||||
? contactKey.substring(0, 12).toUpperCase()
|
||||
: contactKey.toUpperCase();
|
||||
final title = 'New contact discovered';
|
||||
final body = 'New contact $shortKey is available in Discovery.';
|
||||
final resolvedName = contactName?.trim();
|
||||
final body = resolvedName != null && resolvedName.isNotEmpty
|
||||
? '$resolvedName is available in Discovery.'
|
||||
: 'New contact $shortKey is available in Discovery.';
|
||||
final notificationId =
|
||||
_discoveryNotificationId + ((contactKey.hashCode & 0x7fffffff) % 1000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user