From 4b8fa059d5f9234176680d0c5c9e8e706ddd7e98 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 7 Jan 2024 16:35:25 -0500 Subject: [PATCH] Fix external repo info banner in ExtensionDetailsScreen --- .../source/interactor/CreateSourceRepo.kt | 2 +- .../browse/ExtensionDetailsScreen.kt | 23 ++++++++++++------- .../tachiyomi/extension/ExtensionManager.kt | 12 +++++++++- .../tachiyomi/extension/api/ExtensionApi.kt | 2 +- .../tachiyomi/extension/model/Extension.kt | 4 ++-- .../commonMain/resources/MR/base/strings.xml | 4 ++-- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/CreateSourceRepo.kt b/app/src/main/java/eu/kanade/domain/source/interactor/CreateSourceRepo.kt index e22d8980f7..f55532e120 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/CreateSourceRepo.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/CreateSourceRepo.kt @@ -11,7 +11,7 @@ class CreateSourceRepo(private val preferences: SourcePreferences) { return Result.InvalidUrl } - preferences.extensionRepos() += name.substringBeforeLast("/index.min.json") + preferences.extensionRepos() += name.removeSuffix("/index.min.json") return Result.Success } diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt index 3c4b8e2ca3..213fe9dd2c 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt @@ -53,6 +53,7 @@ import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionDetailsScreenModel import eu.kanade.tachiyomi.util.system.LocaleHelper +import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.ScrollbarLazyColumn @@ -138,7 +139,7 @@ fun ExtensionDetailsScreen( private fun ExtensionDetails( contentPadding: PaddingValues, extension: Extension.Installed, - sources: List, + sources: ImmutableList, onClickSourcePreferences: (sourceId: Long) -> Unit, onClickUninstall: () -> Unit, onClickSource: (sourceId: Long) -> Unit, @@ -150,18 +151,24 @@ private fun ExtensionDetails( contentPadding = contentPadding, ) { when { - extension.isRepoSource -> + extension.isFromExternalRepo -> item { val uriHandler = LocalUriHandler.current + val url = remember(extension) { + val regex = """https://raw.githubusercontent.com/(.+?)/(.+?)/.+""".toRegex() + regex.find(extension.repoUrl.orEmpty()) + ?.let { + val (user, repo) = it.destructured + "https://github.com/$user/$repo" + } + ?: extension.repoUrl + } + WarningBanner( MR.strings.repo_extension_message, modifier = Modifier.clickable { - extension.repoUrl ?: return@clickable - uriHandler.openUri( - extension.repoUrl - .replace("https://raw.githubusercontent.com", "https://github.com") - .removeSuffix("/repo/"), - ) + url ?: return@clickable + uriHandler.openUri(url) }, ) } 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 942e8f4a1c..156d881c8d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -185,7 +185,17 @@ class ExtensionManager( val hasUpdate = installedExt.updateExists(availableExt) if (installedExt.hasUpdate != hasUpdate) { - mutInstalledExtensions[index] = installedExt.copy(hasUpdate = hasUpdate) + mutInstalledExtensions[index] = installedExt.copy( + hasUpdate = hasUpdate, + isFromExternalRepo = availableExt.isFromExternalRepo, + repoUrl = availableExt.repoUrl, + ) + changed = true + } else if (availableExt.isFromExternalRepo) { + mutInstalledExtensions[index] = installedExt.copy( + isFromExternalRepo = true, + repoUrl = availableExt.repoUrl, + ) changed = true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionApi.kt index e885652b31..d0d493a97d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionApi.kt @@ -133,7 +133,7 @@ internal class ExtensionApi { apkName = it.apk, iconUrl = "$repoUrl/icon/${it.pkg}.png", repoUrl = repoUrl, - isRepoSource = isRepoSource, + isFromExternalRepo = isRepoSource, ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt index 4dbf09a265..4982ef6e3d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt @@ -30,7 +30,7 @@ sealed class Extension { val isUnofficial: Boolean = false, val isShared: Boolean, val repoUrl: String? = null, - val isRepoSource: Boolean = false, + val isFromExternalRepo: Boolean = false, ) : Extension() data class Available( @@ -45,7 +45,7 @@ sealed class Extension { val apkName: String, val iconUrl: String, val repoUrl: String, - val isRepoSource: Boolean, + val isFromExternalRepo: Boolean, ) : Extension() { data class Source( diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index d19e1f5439..5da0b3a548 100644 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -318,8 +318,8 @@ Untrusted extension This extension was signed by any unknown author and wasn\'t loaded.\n\nMalicious extensions can read any stored login credentials or execute arbitrary code.\n\nBy trusting this extension\'s certificate, you accept these risks. This extension is no longer available. It may not function properly and can cause issues with the app. Uninstalling it is recommended. - This extension is not from the official list. - Failed to get extensions list + This extension is not from the official repo. + Failed to fetch available extensions Version Language Age rating