Files
SpotiFLAC-Mobile/lib/services/native_log_source.dart
T
zarzet f502edd1f2 feat(desktop): route the backend channel through Rust FFI on desktop
Introduce BackendChannel with a MethodChannel implementation for Android
and iOS and a dart:ffi implementation for desktop builds. PlatformBridge
and NativeLogSource select the backend through isDesktopPlatform; mobile
keeps the same channels and call sites. The desktop library loads lazily,
so a missing library fails calls with backend_unavailable instead of
crashing at startup.
2026-10-20 13:38:13 +07:00

37 lines
1.2 KiB
Dart

import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:mornye/services/backend/backend_channel.dart';
import 'package:mornye/services/backend/method_channel_backend.dart';
/// Logging transport is independent of the bridge whose calls it records.
class NativeLogSource {
/// Uses [channel] when given, otherwise the platform's backend.
const NativeLogSource({MethodChannel? channel}) : _channel = channel;
final MethodChannel? _channel;
BackendChannel get _backend {
final channel = _channel;
return channel == null ? backendChannel : MethodChannelBackend(channel);
}
Future<Map<String, dynamic>> getSince(int index) async {
final result = await _backend.invokeMethod<Object?>('getLogsSince', {
'index': index,
});
final decoded = result is String
? (result.isEmpty ? null : jsonDecode(result))
: result;
if (decoded is Map) return decoded.cast<String, dynamic>();
throw FormatException(
'Expected map result from getLogsSince, got ${decoded.runtimeType}',
);
}
Future<void> setLoggingEnabled(bool enabled) =>
_backend.invokeMethod<void>('setLoggingEnabled', {'enabled': enabled});
Future<void> clear() => _backend.invokeMethod<void>('clearLogs');
}