Skip to content

Commit

Permalink
Fix external repo info banner in ExtensionDetailsScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed Jan 7, 2024
1 parent 3dc2f9a commit 4b8fa05
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,7 +139,7 @@ fun ExtensionDetailsScreen(
private fun ExtensionDetails(
contentPadding: PaddingValues,
extension: Extension.Installed,
sources: List<ExtensionSourceItem>,
sources: ImmutableList<ExtensionSourceItem>,
onClickSourcePreferences: (sourceId: Long) -> Unit,
onClickUninstall: () -> Unit,
onClickSource: (sourceId: Long) -> Unit,
Expand All @@ -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)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal class ExtensionApi {
apkName = it.apk,
iconUrl = "$repoUrl/icon/${it.pkg}.png",
repoUrl = repoUrl,
isRepoSource = isRepoSource,
isFromExternalRepo = isRepoSource,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions i18n/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@
<string name="untrusted_extension">Untrusted extension</string>
<string name="untrusted_extension_message">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.</string>
<string name="obsolete_extension_message">This extension is no longer available. It may not function properly and can cause issues with the app. Uninstalling it is recommended.</string>
<string name="unofficial_extension_message">This extension is not from the official list.</string>
<string name="extension_api_error">Failed to get extensions list</string>
<string name="unofficial_extension_message">This extension is not from the official repo.</string>
<string name="extension_api_error">Failed to fetch available extensions</string>
<string name="ext_info_version">Version</string>
<string name="ext_info_language">Language</string>
<string name="ext_info_age_rating">Age rating</string>
Expand Down

0 comments on commit 4b8fa05

Please sign in to comment.