mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Open-source Flutter client for MeshCore LoRa mesh networking devices. Features: - BLE device scanning and connection - Nordic UART Service (NUS) integration - Material 3 design with system theme support - Provider-based state management - Placeholder screens for chat, contacts, and settings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
101 lines
3.2 KiB
Dart
101 lines
3.2 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../models/app_settings.dart';
|
|
|
|
class AppSettingsService extends ChangeNotifier {
|
|
static const String _settingsKey = 'app_settings';
|
|
|
|
AppSettings _settings = AppSettings();
|
|
|
|
AppSettings get settings => _settings;
|
|
|
|
String batteryChemistryForDevice(String deviceId) {
|
|
final stored = _settings.batteryChemistryByDeviceId[deviceId];
|
|
if (stored == 'liion') return 'nmc';
|
|
return stored ?? 'nmc';
|
|
}
|
|
|
|
Future<void> loadSettings() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final jsonStr = prefs.getString(_settingsKey);
|
|
|
|
if (jsonStr != null) {
|
|
try {
|
|
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
|
|
_settings = AppSettings.fromJson(json);
|
|
notifyListeners();
|
|
} catch (e) {
|
|
// If parsing fails, use defaults
|
|
_settings = AppSettings();
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> updateSettings(AppSettings newSettings) async {
|
|
_settings = newSettings;
|
|
notifyListeners();
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final jsonStr = jsonEncode(_settings.toJson());
|
|
await prefs.setString(_settingsKey, jsonStr);
|
|
}
|
|
|
|
Future<void> setClearPathOnMaxRetry(bool value) async {
|
|
await updateSettings(_settings.copyWith(clearPathOnMaxRetry: value));
|
|
}
|
|
|
|
Future<void> setMapShowRepeaters(bool value) async {
|
|
await updateSettings(_settings.copyWith(mapShowRepeaters: value));
|
|
}
|
|
|
|
Future<void> setMapShowChatNodes(bool value) async {
|
|
await updateSettings(_settings.copyWith(mapShowChatNodes: value));
|
|
}
|
|
|
|
Future<void> setMapShowOtherNodes(bool value) async {
|
|
await updateSettings(_settings.copyWith(mapShowOtherNodes: value));
|
|
}
|
|
|
|
Future<void> setMapTimeFilterHours(double value) async {
|
|
await updateSettings(_settings.copyWith(mapTimeFilterHours: value));
|
|
}
|
|
|
|
Future<void> setMapKeyPrefixEnabled(bool value) async {
|
|
await updateSettings(_settings.copyWith(mapKeyPrefixEnabled: value));
|
|
}
|
|
|
|
Future<void> setMapKeyPrefix(String value) async {
|
|
await updateSettings(_settings.copyWith(mapKeyPrefix: value));
|
|
}
|
|
|
|
Future<void> setMapShowMarkers(bool value) async {
|
|
await updateSettings(_settings.copyWith(mapShowMarkers: value));
|
|
}
|
|
|
|
Future<void> setNotificationsEnabled(bool value) async {
|
|
await updateSettings(_settings.copyWith(notificationsEnabled: value));
|
|
}
|
|
|
|
Future<void> setNotifyOnNewMessage(bool value) async {
|
|
await updateSettings(_settings.copyWith(notifyOnNewMessage: value));
|
|
}
|
|
|
|
Future<void> setNotifyOnNewAdvert(bool value) async {
|
|
await updateSettings(_settings.copyWith(notifyOnNewAdvert: value));
|
|
}
|
|
|
|
Future<void> setAutoRouteRotationEnabled(bool value) async {
|
|
await updateSettings(_settings.copyWith(autoRouteRotationEnabled: value));
|
|
}
|
|
|
|
Future<void> setThemeMode(String value) async {
|
|
await updateSettings(_settings.copyWith(themeMode: value));
|
|
}
|
|
|
|
Future<void> setBatteryChemistryForDevice(String deviceId, String chemistry) async {
|
|
final updated = Map<String, String>.from(_settings.batteryChemistryByDeviceId);
|
|
updated[deviceId] = chemistry;
|
|
await updateSettings(_settings.copyWith(batteryChemistryByDeviceId: updated));
|
|
}
|
|
}
|