mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-10-20 14:37:33 +02:00
refactor(logging): rename Go-era log names to native
The log buffer polls the native backend, so isFromGo, the Go log polling methods and their private state now use native names. Comments that still described the backend as Go are reworded. No string literals changed.
This commit is contained in:
1 parent
4887172926
commit
019257541b
8 files changed
+55
-55
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/// Canonical service / provider identifiers shared across the app.
|
||||
///
|
||||
/// These values must stay in sync with the provider ids reported by the Go
|
||||
/// These values must stay in sync with the provider ids reported by the native
|
||||
/// backend and by extensions; use them instead of raw string literals when
|
||||
/// comparing or dispatching on a service id.
|
||||
abstract final class MusicServices {
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ void main() {
|
||||
_startupBenchmark = _StartupBenchmark();
|
||||
}
|
||||
// Catch uncaught Dart errors so a failing async path is logged, not fatal.
|
||||
// Native (Go) crashes still can't be caught here.
|
||||
// Native backend crashes still can't be caught here.
|
||||
runZonedGuarded(
|
||||
() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@@ -594,7 +594,7 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
|
||||
_log.e('Failed to flush expired iOS queue: $error');
|
||||
}),
|
||||
);
|
||||
// The native expiration callback cancels Go synchronously before this
|
||||
// The native expiration callback cancels the download synchronously before this
|
||||
// asynchronous event reaches Dart. If foregrounding won that race, still
|
||||
// requeue the cancelled item, then immediately let the running queue loop
|
||||
// continue instead of misclassifying it as a skipped download.
|
||||
|
||||
@@ -43,13 +43,13 @@ class _LogScreenState extends State<LogScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
LogBuffer().addListener(_onLogUpdate);
|
||||
LogBuffer().startGoLogPolling();
|
||||
LogBuffer().startNativeLogPolling();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
LogBuffer().removeListener(_onLogUpdate);
|
||||
LogBuffer().stopGoLogPolling();
|
||||
LogBuffer().stopNativeLogPolling();
|
||||
_scrollController.dispose();
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
@@ -624,7 +624,7 @@ class _LogEntryTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (entry.isFromGo) ...[
|
||||
if (entry.isFromNative) ...[
|
||||
const SizedBox(width: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
|
||||
@@ -2334,7 +2334,7 @@ class PlatformBridge {
|
||||
}
|
||||
|
||||
/// Streaming-platform links for a track, keyed by song.link platform ID.
|
||||
/// Served from the Go-side memory cache; throws when the lookup fails.
|
||||
/// Served from the native backend's memory cache; throws when the lookup fails.
|
||||
static Future<Map<String, String>> getTrackPlatformLinks({
|
||||
String spotifyId = '',
|
||||
String isrc = '',
|
||||
@@ -2847,7 +2847,7 @@ class PlatformBridge {
|
||||
});
|
||||
if (result['success'] != true) return result;
|
||||
|
||||
// The Go/Rust result uses new_file_path; the queue consumes file_path.
|
||||
// The native result uses new_file_path; the queue consumes file_path.
|
||||
// SAF publishes back to its document URI after processing a temporary file.
|
||||
final uri = result['new_file_uri'];
|
||||
final path = result['new_file_path'];
|
||||
|
||||
+39
-39
@@ -80,7 +80,7 @@ class LogEntry {
|
||||
final String tag;
|
||||
final String message;
|
||||
final String? error;
|
||||
final bool isFromGo;
|
||||
final bool isFromNative;
|
||||
|
||||
LogEntry({
|
||||
required this.timestamp,
|
||||
@@ -88,7 +88,7 @@ class LogEntry {
|
||||
required this.tag,
|
||||
required this.message,
|
||||
this.error,
|
||||
this.isFromGo = false,
|
||||
this.isFromNative = false,
|
||||
});
|
||||
|
||||
String get formattedTime {
|
||||
@@ -106,7 +106,7 @@ class LogEntry {
|
||||
@override
|
||||
String toString() {
|
||||
final errorPart = error != null ? ' | $error' : '';
|
||||
final nativePart = isFromGo ? ' [Native]' : '';
|
||||
final nativePart = isFromNative ? ' [Native]' : '';
|
||||
return '[$formattedTime] [$level]$nativePart [$tag] $message$errorPart';
|
||||
}
|
||||
}
|
||||
@@ -122,13 +122,13 @@ class LogBuffer extends ChangeNotifier {
|
||||
|
||||
static const int maxEntries = 500;
|
||||
static const _nativeLogs = NativeLogSource();
|
||||
static const Duration _goLogPollingInterval = Duration(milliseconds: 800);
|
||||
static const Duration _nativeLogPollingInterval = Duration(milliseconds: 800);
|
||||
final Queue<LogEntry> _entries = Queue<LogEntry>();
|
||||
Timer? _goLogTimer;
|
||||
int _lastGoLogIndex = 0;
|
||||
bool _isFetchingGoLogs = false;
|
||||
int _goLogGeneration = 0;
|
||||
Future<void>? _pendingGoLogClear;
|
||||
Timer? _nativeLogTimer;
|
||||
int _lastNativeLogIndex = 0;
|
||||
bool _isFetchingNativeLogs = false;
|
||||
int _nativeLogGeneration = 0;
|
||||
Future<void>? _pendingNativeLogClear;
|
||||
|
||||
static bool _loggingEnabled = false;
|
||||
static bool get loggingEnabled => _loggingEnabled;
|
||||
@@ -177,7 +177,7 @@ class LogBuffer extends ChangeNotifier {
|
||||
tag: entry.tag,
|
||||
message: sanitizedMessage,
|
||||
error: sanitizedError,
|
||||
isFromGo: entry.isFromGo,
|
||||
isFromNative: entry.isFromNative,
|
||||
);
|
||||
|
||||
if (_entries.length >= maxEntries) {
|
||||
@@ -187,36 +187,36 @@ class LogBuffer extends ChangeNotifier {
|
||||
return true;
|
||||
}
|
||||
|
||||
void startGoLogPolling() {
|
||||
_goLogTimer?.cancel();
|
||||
_goLogGeneration++;
|
||||
_goLogTimer = Timer.periodic(_goLogPollingInterval, (_) async {
|
||||
if (_isFetchingGoLogs) return;
|
||||
_isFetchingGoLogs = true;
|
||||
void startNativeLogPolling() {
|
||||
_nativeLogTimer?.cancel();
|
||||
_nativeLogGeneration++;
|
||||
_nativeLogTimer = Timer.periodic(_nativeLogPollingInterval, (_) async {
|
||||
if (_isFetchingNativeLogs) return;
|
||||
_isFetchingNativeLogs = true;
|
||||
try {
|
||||
await _fetchGoLogs(_goLogGeneration);
|
||||
await _fetchNativeLogs(_nativeLogGeneration);
|
||||
} finally {
|
||||
_isFetchingGoLogs = false;
|
||||
_isFetchingNativeLogs = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void stopGoLogPolling() {
|
||||
_goLogTimer?.cancel();
|
||||
_goLogTimer = null;
|
||||
_goLogGeneration++;
|
||||
void stopNativeLogPolling() {
|
||||
_nativeLogTimer?.cancel();
|
||||
_nativeLogTimer = null;
|
||||
_nativeLogGeneration++;
|
||||
// The stopped poll still owns the in-flight slot until its call completes.
|
||||
}
|
||||
|
||||
Future<void> _fetchGoLogs(int generation) async {
|
||||
Future<void> _fetchNativeLogs(int generation) async {
|
||||
try {
|
||||
final clearing = _pendingGoLogClear;
|
||||
final clearing = _pendingNativeLogClear;
|
||||
if (clearing != null) await clearing;
|
||||
if (generation != _goLogGeneration) return;
|
||||
final result = await _nativeLogs.getSince(_lastGoLogIndex);
|
||||
if (generation != _goLogGeneration) return;
|
||||
if (generation != _nativeLogGeneration) return;
|
||||
final result = await _nativeLogs.getSince(_lastNativeLogIndex);
|
||||
if (generation != _nativeLogGeneration) return;
|
||||
final logs = result['logs'] as List<dynamic>? ?? [];
|
||||
final nextIndex = result['next_index'] as int? ?? _lastGoLogIndex;
|
||||
final nextIndex = result['next_index'] as int? ?? _lastNativeLogIndex;
|
||||
final keepNonErrorLogs = _loggingEnabled;
|
||||
final entries = <LogEntry>[];
|
||||
|
||||
@@ -256,13 +256,13 @@ class LogBuffer extends ChangeNotifier {
|
||||
level: level,
|
||||
tag: tag,
|
||||
message: message,
|
||||
isFromGo: true,
|
||||
isFromNative: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
addAll(entries);
|
||||
if (generation == _goLogGeneration) _lastGoLogIndex = nextIndex;
|
||||
if (generation == _nativeLogGeneration) _lastNativeLogIndex = nextIndex;
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
debugPrint('Failed to fetch native backend logs: $e');
|
||||
@@ -272,19 +272,19 @@ class LogBuffer extends ChangeNotifier {
|
||||
|
||||
void clear() {
|
||||
_entries.clear();
|
||||
_lastGoLogIndex = 0;
|
||||
_goLogGeneration++;
|
||||
_lastNativeLogIndex = 0;
|
||||
_nativeLogGeneration++;
|
||||
late final Future<void> clearing;
|
||||
clearing =
|
||||
(_pendingGoLogClear?.then((_) => _nativeLogs.clear()) ??
|
||||
(_pendingNativeLogClear?.then((_) => _nativeLogs.clear()) ??
|
||||
_nativeLogs.clear())
|
||||
.catchError((_) {})
|
||||
.whenComplete(() {
|
||||
if (identical(_pendingGoLogClear, clearing)) {
|
||||
_pendingGoLogClear = null;
|
||||
if (identical(_pendingNativeLogClear, clearing)) {
|
||||
_pendingNativeLogClear = null;
|
||||
}
|
||||
});
|
||||
_pendingGoLogClear = clearing;
|
||||
_pendingNativeLogClear = clearing;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ class LogBuffer extends ChangeNotifier {
|
||||
int warnCount = 0;
|
||||
int infoCount = 0;
|
||||
int debugCount = 0;
|
||||
int goCount = 0;
|
||||
int nativeCount = 0;
|
||||
|
||||
for (final entry in _entries) {
|
||||
switch (entry.level) {
|
||||
@@ -377,14 +377,14 @@ class LogBuffer extends ChangeNotifier {
|
||||
debugCount++;
|
||||
break;
|
||||
}
|
||||
if (entry.isFromGo) goCount++;
|
||||
if (entry.isFromNative) nativeCount++;
|
||||
}
|
||||
|
||||
buffer.writeln('Errors: $errorCount');
|
||||
buffer.writeln('Warnings: $warnCount');
|
||||
buffer.writeln('Info: $infoCount');
|
||||
buffer.writeln('Debug: $debugCount');
|
||||
buffer.writeln('From Native Backend: $goCount');
|
||||
buffer.writeln('From Native Backend: $nativeCount');
|
||||
buffer.writeln();
|
||||
|
||||
buffer.writeln('=' * 60);
|
||||
|
||||
@@ -52,7 +52,7 @@ void main() {
|
||||
tag: 'Download',
|
||||
message: 'second',
|
||||
error: 'failed',
|
||||
isFromGo: true,
|
||||
isFromNative: true,
|
||||
),
|
||||
];
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ void main() {
|
||||
const interval = Duration(milliseconds: 800);
|
||||
|
||||
tearDown(() {
|
||||
buffer.stopGoLogPolling();
|
||||
buffer.stopNativeLogPolling();
|
||||
messenger.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
@@ -39,12 +39,12 @@ void main() {
|
||||
buffer.clear();
|
||||
await tester.pump();
|
||||
|
||||
buffer.startGoLogPolling();
|
||||
buffer.startNativeLogPolling();
|
||||
await tester.pump(interval);
|
||||
expect(indexes, [0]);
|
||||
|
||||
buffer.stopGoLogPolling();
|
||||
buffer.startGoLogPolling();
|
||||
buffer.stopNativeLogPolling();
|
||||
buffer.startNativeLogPolling();
|
||||
await tester.pump(interval);
|
||||
expect(indexes, [0]);
|
||||
|
||||
@@ -58,7 +58,7 @@ void main() {
|
||||
|
||||
await tester.pump(interval);
|
||||
expect(indexes, [0, 0, 4]);
|
||||
buffer.stopGoLogPolling();
|
||||
buffer.stopNativeLogPolling();
|
||||
});
|
||||
|
||||
testWidgets('clear rejects old logs and waits for native cursor reset', (
|
||||
@@ -81,7 +81,7 @@ void main() {
|
||||
buffer.clear();
|
||||
await tester.pump();
|
||||
|
||||
buffer.startGoLogPolling();
|
||||
buffer.startNativeLogPolling();
|
||||
await tester.pump(interval);
|
||||
expect(indexes, [0]);
|
||||
|
||||
@@ -102,6 +102,6 @@ void main() {
|
||||
|
||||
await tester.pump(interval);
|
||||
expect(indexes, [0, 0, 1]);
|
||||
buffer.stopGoLogPolling();
|
||||
buffer.stopNativeLogPolling();
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user