mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-04-19 22:22:05 +00:00
- to prevent old entries (before sourceId was introduced) from accidentally using conflicting sources with the same name even if they are not installed
28 lines
853 B
Dart
28 lines
853 B
Dart
import 'package:isar_community/isar.dart';
|
|
import 'package:mangayomi/main.dart';
|
|
import 'package:mangayomi/models/source.dart';
|
|
|
|
Source? getSource(
|
|
String lang,
|
|
String name,
|
|
int? sourceId, {
|
|
bool installedOnly = false,
|
|
}) {
|
|
try {
|
|
var sourcesFilter = isar.sources.filter().idIsNotNull();
|
|
if (installedOnly) {
|
|
sourcesFilter = sourcesFilter.isActiveEqualTo(true).isAddedEqualTo(true);
|
|
}
|
|
final sourcesList = sourcesFilter.findAllSync();
|
|
return sourcesList.firstWhere(
|
|
(element) => sourceId != null
|
|
? element.id == sourceId && element.sourceCode != null
|
|
: element.name!.toLowerCase() == name.toLowerCase() &&
|
|
element.lang == lang &&
|
|
element.sourceCode != null,
|
|
orElse: () => throw ("Error when getting source"),
|
|
);
|
|
} catch (_) {
|
|
return null;
|
|
}
|
|
}
|