update to zjs81/dev commit d5f54df
This commit is contained in:
commit
cf027c974f
64 files changed
+2972
-1129
No files matched your search
@@ -3,7 +3,9 @@ import 'dart:ui';
|
||||
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
import '../helpers/message_url_image_helper.dart';
|
||||
import '../helpers/reaction_helper.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
@@ -196,14 +198,40 @@ class NotificationService {
|
||||
return text;
|
||||
}
|
||||
|
||||
Future<String?> _resolveNotificationImagePath(
|
||||
String text, {
|
||||
required bool urlImagesEnabled,
|
||||
}) async {
|
||||
if (!urlImagesEnabled) return null;
|
||||
|
||||
final imageUrl = await MessageUrlImageHelper.parseVerified(text);
|
||||
if (imageUrl == null) return null;
|
||||
|
||||
try {
|
||||
// Cache the image so notification platforms can read it from disk.
|
||||
final imageFile = await DefaultCacheManager().getSingleFile(imageUrl);
|
||||
if (!imageFile.existsSync()) return null;
|
||||
return imageFile.path;
|
||||
} catch (e) {
|
||||
debugPrint('Failed to resolve notification image: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showMessageNotificationImpl({
|
||||
required String contactName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
String? contactId,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
if (!await _ensureCanNotify()) return;
|
||||
|
||||
final imagePath = await _resolveNotificationImagePath(
|
||||
message,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
);
|
||||
|
||||
final androidDetails = AndroidNotificationDetails(
|
||||
'messages',
|
||||
'Messages',
|
||||
@@ -212,6 +240,12 @@ class NotificationService {
|
||||
priority: Priority.high,
|
||||
icon: '@mipmap/ic_launcher',
|
||||
number: badgeCount,
|
||||
styleInformation: imagePath != null
|
||||
? BigPictureStyleInformation(
|
||||
FilePathAndroidBitmap(imagePath),
|
||||
summaryText: formatNotificationText(message),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
|
||||
final iosDetails = DarwinNotificationDetails(
|
||||
@@ -219,6 +253,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final macDetails = DarwinNotificationDetails(
|
||||
@@ -226,6 +265,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final notificationDetails = NotificationDetails(
|
||||
@@ -299,11 +343,17 @@ class NotificationService {
|
||||
Future<void> _showChannelMessageNotificationImpl({
|
||||
required String channelName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
int? channelIndex,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
if (!await _ensureCanNotify()) return;
|
||||
|
||||
final imagePath = await _resolveNotificationImagePath(
|
||||
message,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
);
|
||||
|
||||
final androidDetails = AndroidNotificationDetails(
|
||||
'channel_messages',
|
||||
'Channel Messages',
|
||||
@@ -312,6 +362,12 @@ class NotificationService {
|
||||
priority: Priority.high,
|
||||
icon: '@mipmap/ic_launcher',
|
||||
number: badgeCount,
|
||||
styleInformation: imagePath != null
|
||||
? BigPictureStyleInformation(
|
||||
FilePathAndroidBitmap(imagePath),
|
||||
summaryText: formatNotificationText(message),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
|
||||
final iosDetails = DarwinNotificationDetails(
|
||||
@@ -319,6 +375,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final macDetails = DarwinNotificationDetails(
|
||||
@@ -326,6 +387,11 @@ class NotificationService {
|
||||
presentBadge: true,
|
||||
presentSound: true,
|
||||
badgeNumber: badgeCount,
|
||||
attachments: imagePath != null
|
||||
? <DarwinNotificationAttachment>[
|
||||
DarwinNotificationAttachment(imagePath),
|
||||
]
|
||||
: null,
|
||||
);
|
||||
|
||||
final notificationDetails = NotificationDetails(
|
||||
@@ -448,6 +514,7 @@ class NotificationService {
|
||||
Future<void> showMessageNotification({
|
||||
required String contactName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
String? contactId,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
@@ -458,6 +525,7 @@ class NotificationService {
|
||||
type: _NotificationType.message,
|
||||
title: contactName,
|
||||
body: message,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
id: contactId,
|
||||
badgeCount: badgeCount,
|
||||
),
|
||||
@@ -485,6 +553,7 @@ class NotificationService {
|
||||
required String channelName,
|
||||
required String senderName,
|
||||
required String message,
|
||||
required bool urlImagesEnabled,
|
||||
int? channelIndex,
|
||||
int? badgeCount,
|
||||
}) async {
|
||||
@@ -495,6 +564,7 @@ class NotificationService {
|
||||
type: _NotificationType.channelMessage,
|
||||
title: channelName,
|
||||
body: '$senderName: $message',
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
id: channelIndex?.toString(),
|
||||
badgeCount: badgeCount,
|
||||
),
|
||||
@@ -556,6 +626,7 @@ class NotificationService {
|
||||
await _showMessageNotificationImpl(
|
||||
contactName: notification.title,
|
||||
message: notification.body,
|
||||
urlImagesEnabled: notification.urlImagesEnabled,
|
||||
contactId: notification.id,
|
||||
badgeCount: notification.badgeCount,
|
||||
);
|
||||
@@ -571,6 +642,7 @@ class NotificationService {
|
||||
await _showChannelMessageNotificationImpl(
|
||||
channelName: notification.title,
|
||||
message: notification.body,
|
||||
urlImagesEnabled: notification.urlImagesEnabled,
|
||||
channelIndex: int.tryParse(notification.id ?? ''),
|
||||
badgeCount: notification.badgeCount,
|
||||
);
|
||||
@@ -647,6 +719,7 @@ class _PendingNotification {
|
||||
final _NotificationType type;
|
||||
final String title;
|
||||
final String body;
|
||||
final bool urlImagesEnabled;
|
||||
final String? id;
|
||||
final int? badgeCount;
|
||||
|
||||
@@ -654,6 +727,7 @@ class _PendingNotification {
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.body,
|
||||
this.urlImagesEnabled = false,
|
||||
this.id,
|
||||
this.badgeCount,
|
||||
});
|
||||
|
||||
@@ -4,6 +4,16 @@ import '../models/path_selection.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
|
||||
/// Companion firmware (MeshCore commit 4a869163, 2025-12-30) replaces the CLI
|
||||
/// frame timestamp with the companion node's RTC for TXT_TYPE_CLI_DATA, so a
|
||||
/// plain "clock sync" sets the repeater clock to the node clock. The official
|
||||
/// meshcore-cli translates it to an explicit `time <epoch>` command instead;
|
||||
/// do the same so the repeater always gets the phone's time.
|
||||
String normalizeRepeaterClockSyncCommand(String command, {int? nowSeconds}) {
|
||||
final epoch = nowSeconds ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
return command.trim().toLowerCase() == 'clock sync' ? 'time $epoch' : command;
|
||||
}
|
||||
|
||||
class RepeaterCommandService {
|
||||
final MeshCoreConnector _connector;
|
||||
final Map<String, Completer<String>> _pendingCommands = {};
|
||||
@@ -25,6 +35,7 @@ class RepeaterCommandService {
|
||||
Function(int)? onAttempt,
|
||||
int retries = maxRetries,
|
||||
}) async {
|
||||
command = normalizeRepeaterClockSyncCommand(command);
|
||||
final attemptCount = retries < 1 ? 1 : retries;
|
||||
final selection = await _connector.preparePathForContactSend(repeater);
|
||||
|
||||
|
||||
Reference in new issue
Block a user