mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-04-20 23:22:07 +00:00
This commit improves memory management, reduces redundant interpreter instantiation, and standardizes service usage patterns. - Add `dispose()` to `ExtensionService` interface and implement it across Dart, JS, LNReader, and Mihon services. - Replace repeated interpreter creation in `DartExtensionService` with a persistent `_interpreter` instance initialized once in the constructor. - Add disposal logic for JS DOM selector and Cheerio instances to prevent memory leaks. - Introduce `withExtensionService()` helper to ensure services are always disposed after use. - Update call sites across the codebase to use `withExtensionService()` or manual try/finally disposal. - Improve isolate service message handling by extracting `responsePort` earlier. - Ensure safer defaults (e.g., returning empty lists, const lists) when service calls fail.
38 lines
1 KiB
Dart
38 lines
1 KiB
Dart
import 'dart:convert';
|
|
import 'package:mangayomi/eval/javascript/http.dart';
|
|
import 'package:mangayomi/eval/lib.dart';
|
|
import 'package:mangayomi/services/http/m_client.dart';
|
|
import 'package:mangayomi/utils/utils.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
part 'headers.g.dart';
|
|
|
|
@riverpod
|
|
Map<String, String> headers(
|
|
Ref ref, {
|
|
required String source,
|
|
required String lang,
|
|
required int? sourceId,
|
|
String androidProxyServer = "",
|
|
}) {
|
|
final mSource = getSource(lang, source, sourceId);
|
|
|
|
Map<String, String> headers = {};
|
|
|
|
if (mSource != null) {
|
|
final fromSource = mSource.headers;
|
|
|
|
if (fromSource != null && fromSource.isNotEmpty) {
|
|
headers.addAll((jsonDecode(fromSource) as Map).toMapStringString!);
|
|
}
|
|
final service = getExtensionService(mSource, androidProxyServer);
|
|
try {
|
|
headers.addAll(service.getHeaders());
|
|
} finally {
|
|
service.dispose();
|
|
}
|
|
headers.addAll(MClient.getCookiesPref(mSource.baseUrl!));
|
|
}
|
|
|
|
return headers;
|
|
}
|