mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
- Rewrite UsbScreen to mirror ScannerScreen patterns (status bar, tap-to-connect port list, bottom FABs, SnackBar errors) - Extract MeshCoreUsbManager from MeshCoreConnector for cleaner USB transport ownership - Add debug logging throughout USB connection flow (connector, manager, web/native services) - Print debug logs to console in debug mode even when app debug log setting is disabled - Localize remaining hardcoded strings (Web Serial Device fallback label, USB status bar keys, companion firmware timeout hint) - Fix Swedish misspelling in translations (stöderliga → stödda) - Guard Linux notification init against missing D-Bus session bus - Fix SNRIndicator hit-test error by adding minimum size constraints - Update USB flow tests for new UI patterns
97 lines
2.3 KiB
Dart
97 lines
2.3 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
enum AppDebugLogLevel { info, warning, error }
|
|
|
|
class AppDebugLogEntry {
|
|
final DateTime timestamp;
|
|
final AppDebugLogLevel level;
|
|
final String tag;
|
|
final String message;
|
|
|
|
AppDebugLogEntry({
|
|
required this.timestamp,
|
|
required this.level,
|
|
required this.tag,
|
|
required this.message,
|
|
});
|
|
|
|
String get levelLabel {
|
|
switch (level) {
|
|
case AppDebugLogLevel.info:
|
|
return 'INFO';
|
|
case AppDebugLogLevel.warning:
|
|
return 'WARN';
|
|
case AppDebugLogLevel.error:
|
|
return 'ERROR';
|
|
}
|
|
}
|
|
|
|
String get formattedTime {
|
|
return '${timestamp.hour.toString().padLeft(2, '0')}:'
|
|
'${timestamp.minute.toString().padLeft(2, '0')}:'
|
|
'${timestamp.second.toString().padLeft(2, '0')}.'
|
|
'${timestamp.millisecond.toString().padLeft(3, '0')}';
|
|
}
|
|
}
|
|
|
|
class AppDebugLogService extends ChangeNotifier {
|
|
static const int maxEntries = 1000;
|
|
final List<AppDebugLogEntry> _entries = [];
|
|
bool _enabled = false;
|
|
|
|
List<AppDebugLogEntry> get entries => List.unmodifiable(_entries);
|
|
bool get enabled => _enabled;
|
|
|
|
void setEnabled(bool value) {
|
|
_enabled = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
void log(
|
|
String message, {
|
|
String tag = 'App',
|
|
AppDebugLogLevel level = AppDebugLogLevel.info,
|
|
}) {
|
|
if (!_enabled && !kDebugMode) return;
|
|
if (!_enabled) {
|
|
// In debug mode, still print to console but don't store entries.
|
|
debugPrint('[$tag] $message');
|
|
return;
|
|
}
|
|
|
|
_entries.add(
|
|
AppDebugLogEntry(
|
|
timestamp: DateTime.now(),
|
|
level: level,
|
|
tag: tag,
|
|
message: message,
|
|
),
|
|
);
|
|
|
|
if (_entries.length > maxEntries) {
|
|
_entries.removeRange(0, _entries.length - maxEntries);
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
// Also print to console for development
|
|
debugPrint('[$tag] $message');
|
|
}
|
|
|
|
void info(String message, {String tag = 'App'}) {
|
|
log(message, tag: tag, level: AppDebugLogLevel.info);
|
|
}
|
|
|
|
void warn(String message, {String tag = 'App'}) {
|
|
log(message, tag: tag, level: AppDebugLogLevel.warning);
|
|
}
|
|
|
|
void error(String message, {String tag = 'App'}) {
|
|
log(message, tag: tag, level: AppDebugLogLevel.error);
|
|
}
|
|
|
|
void clear() {
|
|
_entries.clear();
|
|
notifyListeners();
|
|
}
|
|
}
|