diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt index 61a46f2aca00..2ba822b24bb4 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt @@ -150,6 +150,7 @@ private fun ModuleList( val changelogText = stringResource(R.string.module_changelog) val downloadingText = stringResource(R.string.module_downloading) val startDownloadingText = stringResource(R.string.module_start_downloading) + val fetchChangeLogFailed = stringResource(R.string.module_changelog_failed) val dialogHost = LocalDialogHost.current val snackBarHost = LocalSnackbarHost.current @@ -161,36 +162,48 @@ private fun ModuleList( downloadUrl: String, fileName: String ) { - val changelog = dialogHost.withLoading { + val changelogResult = dialogHost.withLoading { withContext(Dispatchers.IO) { - OkHttpClient().newCall( - okhttp3.Request.Builder().url(changelogUrl).build() - ).execute().body!!.string() + runCatching { + OkHttpClient().newCall( + okhttp3.Request.Builder().url(changelogUrl).build() + ).execute().body!!.string() + } } } - if (changelog.isNotEmpty()) { - // changelog is not empty, show it and wait for confirm - val confirmResult = dialogHost.showConfirm( - changelogText, - content = changelog, - markdown = true, - confirm = updateText, - ) - - if (confirmResult != ConfirmResult.Confirmed) { - return + val showToast: suspend (String) -> Unit = {msg-> + withContext(Dispatchers.Main) { + Toast.makeText( + context, + msg, + Toast.LENGTH_SHORT + ).show() } } - withContext(Dispatchers.Main) { - Toast.makeText( - context, - startDownloadingText.format(module.name), - Toast.LENGTH_SHORT - ).show() + val changelog = changelogResult.getOrElse { + showToast(fetchChangeLogFailed.format(it.message)) + return + }.ifBlank { + showToast(fetchChangeLogFailed.format(module.name)) + return + } + + // changelog is not empty, show it and wait for confirm + val confirmResult = dialogHost.showConfirm( + changelogText, + content = changelog, + markdown = true, + confirm = updateText, + ) + + if (confirmResult != ConfirmResult.Confirmed) { + return } + showToast(startDownloadingText.format(module.name)) + val downloading = downloadingText.format(module.name) withContext(Dispatchers.IO) { download( diff --git a/manager/app/src/main/res/values-zh-rCN/strings.xml b/manager/app/src/main/res/values-zh-rCN/strings.xml index d9676d269455..cbf0fa7d7416 100644 --- a/manager/app/src/main/res/values-zh-rCN/strings.xml +++ b/manager/app/src/main/res/values-zh-rCN/strings.xml @@ -101,4 +101,5 @@ 同步在线规则 模版保存失败! 剪切板为空! + 获取更新日志失败:%s \ No newline at end of file diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index a42e5af098f7..3f7adb82d8b8 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -103,4 +103,5 @@ Sync online templates Failed to save template Clipboard is empty! + Fetch changelog failed: %s