Skip to content

Commit

Permalink
fix: 处理签名全部失败的情况,添加错误信息提示和复制功能
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiaoyong committed Mar 8, 2024
1 parent 158cbb8 commit 92b5056
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/main/kotlin/io/github/jixiaoyong/pages/signapp/SignApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import java.awt.Desktop
import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.StringSelection
import java.awt.dnd.DnDConstants
import java.awt.dnd.DropTarget
import java.awt.dnd.DropTargetAdapter
Expand Down Expand Up @@ -374,22 +376,31 @@ fun PageSignApp(
val mergedResult = mergeCommandResult(signResult, currentApkFilePath)
signApkResult = mergedResult
val firstSuccessSignedApk =
signResult.firstOrNull { it is CommandResult.Success<*> } as CommandResult.Success<*>
signResult.firstOrNull { it is CommandResult.Success<*> } as CommandResult.Success<*>?

if (mergedResult is CommandResult.Success<*> && !firstSuccessSignedApk.result?.toString()
if (mergedResult is CommandResult.Success<*> && !firstSuccessSignedApk?.result?.toString()
.isNullOrBlank()
) {
val result = scaffoldState.snackbarHostState.showSnackbar(
"签名成功,是否打开签名后的文件?",
"打开",
SnackbarDuration.Long
)
val file = File(firstSuccessSignedApk.result?.toString() ?: "")
val file = File(firstSuccessSignedApk?.result?.toString() ?: "")
if (SnackbarResult.ActionPerformed == result && file.exists()) {
Desktop.getDesktop().open(file.parentFile)
}
} else if (mergedResult is CommandResult.Error<*>) {
showToast("签名失败:${mergedResult.message}")
val result = scaffoldState.snackbarHostState.showSnackbar(
"签名失败,:${mergedResult.message}",
"复制错误信息",
SnackbarDuration.Indefinite
)
if (SnackbarResult.ActionPerformed == result) {
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
val stringSelection = StringSelection("${mergedResult.message}")
clipboard.setContents(stringSelection, null)
}
}

signApkResult = CommandResult.NOT_EXECUT
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/github/jixiaoyong/utils/ApkSigner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ object ApkSigner {

// 读取输出流并打印到控制台
var line: String? = null
var totalResult =StringBuffer()
while (reader.readLine().also {
if (null != it) {
line = it
Expand All @@ -225,6 +226,7 @@ object ApkSigner {
line?.let {
Logger.info(it)
onProgress(it)
totalResult.append(it)
}
}

Expand All @@ -234,7 +236,7 @@ object ApkSigner {
return if (0 == exitCode) {
CommandResult.Success(outPutFilePath)
} else {
CommandResult.Error("$line")
CommandResult.Error(totalResult.toString())
}
} catch (e: Exception) {
Logger.error("签名失败", e)
Expand Down

0 comments on commit 92b5056

Please sign in to comment.