From 6a39c8fc13821a3b6d8f0efd738254154f4b7148 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 28 Nov 2021 18:29:22 -0500 Subject: [PATCH] Avoid loading available extensions list if it seems too small --- .../eu/kanade/tachiyomi/extension/ExtensionManager.kt | 6 +++++- .../tachiyomi/extension/api/ExtensionGithubApi.kt | 10 +++++++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 985dcaca22..de917dd312 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.extension import android.content.Context import android.graphics.drawable.Drawable import com.jakewharton.rxrelay.BehaviorRelay +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.plusAssign import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi @@ -15,8 +16,10 @@ import eu.kanade.tachiyomi.extension.util.ExtensionLoader import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.util.lang.launchNow +import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.async +import logcat.LogPriority import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -160,7 +163,8 @@ class ExtensionManager( val extensions: List = try { api.findExtensions() } catch (e: Exception) { - context.toast(e.message) + logcat(LogPriority.ERROR, e) + context.toast(R.string.extension_api_error) emptyList() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index 308b3782d6..87e85a4dda 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -22,11 +22,19 @@ internal class ExtensionGithubApi { suspend fun findExtensions(): List { return withIOContext { - networkService.client + val extensions = networkService.client .newCall(GET("${REPO_URL_PREFIX}index.min.json")) .await() .parseAs>() .toExtensions() + + // Sanity check - a small number of extensions probably means something broke + // with the repo generator + if (extensions.size < 100) { + throw Exception() + } + + extensions } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a6ff4ad9b8..6154b5aef5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -261,6 +261,7 @@ This extension was signed with an untrusted certificate and wasn\'t activated.\n\nA malicious extension could read any login credentials stored in Tachiyomi or execute arbitrary code.\n\nBy trusting this certificate you accept these risks. This extension is no longer available. This extension is not from the official Tachiyomi extensions list. + Failed to get extensions list Version: %1$s Language: %1$s 18+