Skip to content

Commit f7e5311

Browse files
committed
fix: crash if repo link is invalid
1 parent 727a5ee commit f7e5311

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

lib/Functions/GetExtensions.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ class Extensions {
2020
static final novelRepo = ''.obs;
2121

2222
static Future<void> init() async {
23-
animeRepo.value = loadCustomData('animeRepo') ?? '';
24-
mangaRepo.value = loadCustomData('mangaRepo') ?? '';
25-
novelRepo.value = loadCustomData('novelRepo') ?? '';
23+
try {
24+
animeRepo.value = loadCustomData('animeRepo') ?? '';
25+
mangaRepo.value = loadCustomData('mangaRepo') ?? '';
26+
novelRepo.value = loadCustomData('novelRepo') ?? '';
2627

27-
await Future.wait([
28-
if (animeRepo.value.isNotEmpty)
29-
_provider.read(
30-
fetchAnimeSourcesListProvider(id: null, reFresh: false).future),
31-
if (mangaRepo.value.isNotEmpty)
32-
_provider.read(
33-
fetchMangaSourcesListProvider(id: null, reFresh: false).future),
34-
if (novelRepo.value.isNotEmpty)
35-
_provider.read(
36-
fetchNovelSourcesListProvider(id: null, reFresh: false).future),
37-
]);
28+
await Future.wait([
29+
if (animeRepo.value.isNotEmpty)
30+
_provider.read(
31+
fetchAnimeSourcesListProvider(id: null, reFresh: false).future),
32+
if (mangaRepo.value.isNotEmpty)
33+
_provider.read(
34+
fetchMangaSourcesListProvider(id: null, reFresh: false).future),
35+
if (novelRepo.value.isNotEmpty)
36+
_provider.read(
37+
fetchNovelSourcesListProvider(id: null, reFresh: false).future),
38+
]);
39+
} catch (_) {}
3840
}
3941

4042
static Future<void> refresh(ItemType itemType) async {
@@ -68,6 +70,7 @@ class Extensions {
6870
}
6971

7072
static Future<void> setRepo(ItemType itemType, String repo) async {
73+
7174
if (itemType == ItemType.manga) {
7275
mangaRepo.value = repo;
7376
saveCustomData('mangaRepo', repo);

lib/api/Extensions/ExtensionsQueries/GetMediaDetails.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension on ExtensionsQueries {
44
Future<Media?> _mediaDetails(Media media) async {
55
final source = isar.sources.getSync(media.sourceData!.id!);
66

7-
if (source == null) {
7+
if (source == null || source.sourceCode == null || source.isAdded == false) {
88
snackString('Source not found did you remove it?');
99
Get.back();
1010
return null;

lib/api/Sources/Extensions/GetSourceList.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Future<void> fetchSourcesList(
1717
required Ref ref,
1818
required ItemType itemType}) async {
1919
final http = MClient.init(reqcopyWith: {'useDartHttpClient': true});
20-
final req = await http.get(Uri.parse(sourcesIndexUrl));
20+
final req = await http.get(Uri.parse(sourcesIndexUrl.trim()));
2121

2222
final sourceList =
2323
(jsonDecode(req.body) as List).map((e) => Source.fromJson(e)).toList();

0 commit comments

Comments
 (0)