Merge remote-tracking branch 'origin/dev' into fix/ui-issues
# Conflicts: # untranslated.json
This commit is contained in:
commit
7c2f481520
52 files changed
+1397
-111
No files matched your search
@@ -38,7 +38,8 @@ import '../services/image_codec_service.dart';
|
||||
import '../services/received_image_store.dart';
|
||||
import '../services/message_retry_service.dart';
|
||||
import '../services/path_history_service.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/app_settings_service.dart'
|
||||
show AppSettingsService, ChannelNotificationMode;
|
||||
import '../services/background_service.dart';
|
||||
import '../services/timeout_prediction_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
@@ -298,6 +299,22 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
Stopwatch? _airtimeBumpStopwatch;
|
||||
int _prevTotalAirSecs = 0;
|
||||
int? _batteryMillivolts;
|
||||
// Thresholds (percent) that trigger a low-battery notification once per
|
||||
// crossing, re-arming 5 points above the threshold after recharge.
|
||||
static const List<int> _lowBatteryThresholds = [25, 10];
|
||||
final Set<int> _batteryAlertedThresholds = {};
|
||||
// Consecutive readings that newly crossed a threshold. Alerts need
|
||||
// [_lowBatteryConfirmReadings] in a row so a single TX-load voltage sag
|
||||
// doesn't notify.
|
||||
int _lowBatteryReadingStreak = 0;
|
||||
// Device key the posted low-battery notifications were scoped to, kept so
|
||||
// they can still be cancelled after the session's identity is cleared.
|
||||
String? _lowBatteryAlertDeviceKey;
|
||||
static const int _lowBatteryConfirmReadings = 2;
|
||||
// Readings below this are treated as "no battery sensor" (boards without
|
||||
// one report 0 mV). Any single Li cell, including LiFePO4 (2600 mV empty),
|
||||
// is protection-cut well above 2 V, so lower values are not real readings.
|
||||
static const int _minPlausibleBatteryMillivolts = 2000;
|
||||
double? _selfLatitude;
|
||||
double? _selfLongitude;
|
||||
final List<DirectRepeater> _directRepeaters = List.empty(growable: true);
|
||||
@@ -691,6 +708,9 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
/// from ver code 8.
|
||||
bool get supportsNodeDiscover => (_firmwareVerCode ?? 0) >= 8;
|
||||
|
||||
/// CMD_SET_PATH_HASH_MODE exists from ver code 10 (v1.14.0).
|
||||
bool get supportsPathHashMode => (_firmwareVerCode ?? 0) >= 10;
|
||||
|
||||
/// CMD_GET/SET_DEFAULT_FLOOD_SCOPE exist from ver code 11 (v1.15.0).
|
||||
bool get supportsDefaultFloodScope => (_firmwareVerCode ?? 0) >= 11;
|
||||
|
||||
@@ -1256,8 +1276,9 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
/// (notification shade, watch, or Android Auto).
|
||||
Future<void> handleNotificationReply(NotificationReply reply) async {
|
||||
if (reply.action == NotificationReplyAction.mute) {
|
||||
await _appSettingsService?.muteChannel(
|
||||
await _appSettingsService?.setChannelNotificationMode(
|
||||
_channelDisplayName(reply.channelIndex!),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await _notificationService.clearChannelNotification(
|
||||
reply.channelIndex!,
|
||||
@@ -6501,6 +6522,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
_batteryMillivolts = reader.readUInt16LE();
|
||||
_storageUsedKb = reader.readUInt32LE();
|
||||
_storageTotalKb = reader.readUInt32LE();
|
||||
_checkLowBatteryThresholds();
|
||||
final volts = (_batteryMillivolts! / 1000.0).toStringAsFixed(2);
|
||||
_appDebugLogService?.info(
|
||||
'Pulled battery: $volts V ($_batteryMillivolts mV)',
|
||||
@@ -6515,6 +6537,64 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void _checkLowBatteryThresholds() {
|
||||
final millivolts = _batteryMillivolts;
|
||||
if (millivolts == null || millivolts < _minPlausibleBatteryMillivolts) {
|
||||
return;
|
||||
}
|
||||
// Until the device identity (and so its saved chemistry) is known, the
|
||||
// percentage falls back to NMC and can read low for e.g. LiFePO4 packs.
|
||||
// Skip evaluation; the next battery poll re-checks once identity is set.
|
||||
if (batteryDeviceKey == null || _appSettingsService == null) return;
|
||||
final percent = batteryPercent;
|
||||
if (percent == null) return;
|
||||
|
||||
// Only the lowest newly crossed threshold notifies; higher ones crossed
|
||||
// in the same reading are marked as alerted silently.
|
||||
final newlyCrossed = <int>[];
|
||||
for (final threshold in _lowBatteryThresholds) {
|
||||
if (percent <= threshold &&
|
||||
!_batteryAlertedThresholds.contains(threshold)) {
|
||||
newlyCrossed.add(threshold);
|
||||
} else if (percent > threshold + 5 &&
|
||||
_batteryAlertedThresholds.contains(threshold)) {
|
||||
// Re-arm once the battery recovers 5 points above the threshold,
|
||||
// so a recharge + discharge cycle alerts again without flapping.
|
||||
_batteryAlertedThresholds.remove(threshold);
|
||||
final alertDeviceKey = _lowBatteryAlertDeviceKey;
|
||||
if (alertDeviceKey != null) {
|
||||
unawaited(
|
||||
_notificationService.clearLowBatteryNotifications(alertDeviceKey, [
|
||||
threshold,
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newlyCrossed.isEmpty) {
|
||||
_lowBatteryReadingStreak = 0;
|
||||
return;
|
||||
}
|
||||
// Debounce: wait for consecutive low readings before alerting.
|
||||
if (++_lowBatteryReadingStreak < _lowBatteryConfirmReadings) return;
|
||||
_lowBatteryReadingStreak = 0;
|
||||
_batteryAlertedThresholds.addAll(newlyCrossed);
|
||||
final deviceKey = batteryDeviceKey!;
|
||||
_lowBatteryAlertDeviceKey = deviceKey;
|
||||
final lowestNewlyCrossed = newlyCrossed.reduce((a, b) => a < b ? a : b);
|
||||
if (!(_appSettingsService?.settings.notificationsEnabled ?? false)) {
|
||||
return;
|
||||
}
|
||||
unawaited(
|
||||
_notificationService.showLowBatteryNotification(
|
||||
deviceKey: deviceKey,
|
||||
deviceName: deviceDisplayName,
|
||||
batteryPercent: percent,
|
||||
threshold: lowestNewlyCrossed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _checkManualAddContacts() async {
|
||||
// If manual add contacts is enabled, set auto add config and other params.
|
||||
// and disable it after
|
||||
@@ -7383,7 +7463,12 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}
|
||||
|
||||
final label = channelName ?? _channelDisplayName(channelIndex);
|
||||
if (_appSettingsService!.isChannelMuted(label)) return;
|
||||
final notificationMode = _appSettingsService!.getChannelNotificationMode(
|
||||
label,
|
||||
);
|
||||
|
||||
// Check if channel is muted
|
||||
if (notificationMode == ChannelNotificationMode.muted) return;
|
||||
|
||||
// Reuse translation result only if completed and non-empty; else use original text
|
||||
final resolvedText =
|
||||
@@ -7392,6 +7477,14 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
translationResult.translatedText.trim().isNotEmpty)
|
||||
? translationResult.translatedText.trim()
|
||||
: message.text.trim();
|
||||
|
||||
// Mentions are matched on the untranslated text.
|
||||
if (notificationMode == ChannelNotificationMode.mentionsOnly) {
|
||||
if (!textMentionsName(message.originalText ?? message.text, _selfName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unawaited(() async {
|
||||
await _notificationService.showChannelMessageNotification(
|
||||
channelName: label,
|
||||
@@ -7404,6 +7497,22 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}());
|
||||
}
|
||||
|
||||
/// Whether [text] mentions [name], case-insensitively, as either
|
||||
/// `@[name]` (the reply/mention prefix the app sends) or a plain `@name`.
|
||||
/// The plain form needs a word boundary on both sides, so `@bobby` does
|
||||
/// not mention `bob` and `x@bob.com` is not a mention. Names containing
|
||||
/// spaces must be written out in full.
|
||||
@visibleForTesting
|
||||
static bool textMentionsName(String text, String? name) {
|
||||
if (name == null || name.isEmpty) return false;
|
||||
final escaped = RegExp.escape(name);
|
||||
return RegExp(
|
||||
'@\\[$escaped\\]|(?<![\\p{L}\\p{N}_])@$escaped(?![\\p{L}\\p{N}_])',
|
||||
caseSensitive: false,
|
||||
unicode: true,
|
||||
).hasMatch(text);
|
||||
}
|
||||
|
||||
/// Handles RESP_CODE_CHANNEL_DATA_RECV (GRP_DATA). Frames whose dataType is
|
||||
/// not 0xAE1C — or that arrive before an [ImageChunkTransport] is installed —
|
||||
/// are ignored without disturbing any other behaviour.
|
||||
@@ -8598,6 +8707,18 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
_hasReceivedDeviceInfo = false;
|
||||
_batteryMillivolts = null;
|
||||
_batteryRequested = false;
|
||||
final alertDeviceKey = _lowBatteryAlertDeviceKey;
|
||||
if (alertDeviceKey != null && _batteryAlertedThresholds.isNotEmpty) {
|
||||
unawaited(
|
||||
_notificationService.clearLowBatteryNotifications(
|
||||
alertDeviceKey,
|
||||
_batteryAlertedThresholds.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
_batteryAlertedThresholds.clear();
|
||||
_lowBatteryAlertDeviceKey = null;
|
||||
_lowBatteryReadingStreak = 0;
|
||||
_pathHashByteWidth = 1;
|
||||
_maxContacts = _defaultMaxContacts;
|
||||
_maxChannels = _defaultMaxChannels;
|
||||
|
||||
Reference in new issue
Block a user