mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
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.
37 lines
1.2 KiB
Dart
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');
|
|
}
|