mangayomi/lib/services/supports_latest.dart
2024-02-03 17:58:11 +01:00

28 lines
922 B
Dart

import 'package:mangayomi/eval/bridge/m_source.dart';
import 'package:mangayomi/eval/compiler/compiler.dart';
import 'package:mangayomi/eval/model/m_provider.dart';
import 'package:mangayomi/models/source.dart';
import 'package:mangayomi/eval/runtime/runtime.dart';
import 'package:mangayomi/sources/source_test.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'supports_latest.g.dart';
@riverpod
bool supportsLatest(SupportsLatestRef ref, {required Source source}) {
bool? supportsLatest;
try {
final bytecode =
compilerEval(useTestSourceCode ? testSourceCode : source.sourceCode!);
final runtime = runtimeEval(bytecode);
var res = runtime.executeLib('package:mangayomi/main.dart', 'main',
[$MSource.wrap(source.toMSource())]);
supportsLatest = (res as MProvider).supportsLatest;
} catch (e) {
supportsLatest = true;
}
return supportsLatest;
}