Merge remote-tracking branch 'origin/dev' into fix/ui-issues

# Conflicts:
#	untranslated.json
This commit is contained in:
zjs81 committed 2026-10-24 21:13:02 -07:00
commit 7c2f481520
52 files changed
+1397 -111

No files matched your search

+18 -11
View File
@@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart';
import '../models/app_settings.dart';
import '../models/image_codec_support.dart';
import '../models/translation_support.dart';
export '../models/app_settings.dart' show ChannelNotificationMode;
import '../storage/prefs_manager.dart';
import '../utils/app_logger.dart';
import '../helpers/cyr2lat.dart';
@@ -286,19 +288,24 @@ class AppSettingsService extends ChangeNotifier {
await updateSettings(_settings.copyWith(unitSystem: value));
}
bool isChannelMuted(String channelName) {
return _settings.mutedChannels.contains(channelName);
ChannelNotificationMode getChannelNotificationMode(String channelName) {
return _settings.channelNotificationModes[channelName] ??
ChannelNotificationMode.all;
}
Future<void> muteChannel(String channelName) async {
final updated = Set<String>.from(_settings.mutedChannels)..add(channelName);
await updateSettings(_settings.copyWith(mutedChannels: updated));
}
Future<void> unmuteChannel(String channelName) async {
final updated = Set<String>.from(_settings.mutedChannels)
..remove(channelName);
await updateSettings(_settings.copyWith(mutedChannels: updated));
Future<void> setChannelNotificationMode(
String channelName,
ChannelNotificationMode mode,
) async {
final updated = Map<String, ChannelNotificationMode>.from(
_settings.channelNotificationModes,
);
if (mode == ChannelNotificationMode.all) {
updated.remove(channelName);
} else {
updated[channelName] = mode;
}
await updateSettings(_settings.copyWith(channelNotificationModes: updated));
}
Future<void> setTcpServerAddress(String value) async {
+68
View File
@@ -612,6 +612,54 @@ class NotificationService {
}
}
/// Posts a low-battery alert for the connected device.
///
/// Uses a per-device, per-threshold notification id so each alert level
/// updates its own notification instead of stacking, and alerts for
/// different radios don't overwrite each other. Bypasses the rate-limit
/// queue, which only handles message and advert notifications.
Future<void> showLowBatteryNotification({
required String deviceKey,
required String deviceName,
required int batteryPercent,
required int threshold,
}) async {
if (!await _ensureCanNotify()) return;
const androidDetails = AndroidNotificationDetails(
'low_battery',
'Low Battery',
channelDescription: 'Low battery alerts for the connected device',
importance: Importance.high,
priority: Priority.high,
icon: '@mipmap/ic_launcher',
);
const darwinDetails = DarwinNotificationDetails(
presentAlert: true,
presentBadge: false,
presentSound: true,
);
const notificationDetails = NotificationDetails(
android: androidDetails,
iOS: darwinDetails,
macOS: darwinDetails,
);
try {
await _notifications.show(
id: _lowBatteryNotificationId(deviceKey, threshold),
title: _l10n.notification_lowBatteryTitle,
body: _l10n.notification_lowBatteryBody(deviceName, batteryPercent),
notificationDetails: notificationDetails,
payload: 'low_battery',
);
} catch (e) {
debugPrint('Failed to show low battery notification: $e');
}
}
/// Returns a privacy-safe identifier for debug logging.
/// - advert: shows device name (body contains contactName)
/// - message: shows "from: sender" (avoids logging message content)
@@ -668,6 +716,26 @@ class NotificationService {
await _updateBadge(totalUnreadCount);
}
static int _lowBatteryNotificationId(String deviceKey, int threshold) =>
'low_battery:$deviceKey:$threshold'.hashCode;
/// Cancel a device's low-battery notifications for the given thresholds.
Future<void> clearLowBatteryNotifications(
String deviceKey,
Iterable<int> thresholds,
) async {
if (!await _ensureInitialized()) return;
for (final threshold in thresholds) {
try {
await _notifications.cancel(
id: _lowBatteryNotificationId(deviceKey, threshold),
);
} catch (e) {
debugPrint('Failed to clear low battery notification: $e');
}
}
}
/// Cancel advert notifications for the given contact public key hexes.
Future<void> clearAdvertNotifications(List<String> contactIds) async {
if (!await _ensureInitialized()) return;