Skip to content

Commit 2d3ad97

Browse files
committed
Update
1 parent 841efd1 commit 2d3ad97

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

app/src/main/java/com/tool/tree/ActionPage.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.net.Uri
66
import android.os.Bundle
77
import android.os.Handler
88
import android.os.Looper
9+
import android.text.SpannableString
910
import android.view.Menu
1011
import android.view.MenuItem
1112
import android.view.View
@@ -349,12 +350,15 @@ class ActionPage : AppCompatActivity() {
349350
val extraParams = hashMapOf("state" to menuOption.key, "menu_id" to menuOption.key)
350351

351352
lifecycleScope.launch(Dispatchers.IO) {
352-
ScriptEnvironmen.executeResultRoot(this@ActionPage, config.pageHandlerSh, config, extraParams)
353+
val output = ScriptEnvironmen.executeResultRoot(this@ActionPage, config.pageHandlerSh, config, extraParams)
353354

354355
if (!isActive) return@launch
355356

356357
withContext(Dispatchers.Main) {
357358
if (isFinishing || isDestroyed) return@withContext
359+
if (!output.isNullOrBlank()) {
360+
SilentShellOutputHandler(this@ActionPage).processOutput(output)
361+
}
358362
when {
359363
menuOption.autoFinish -> finish()
360364
menuOption.reloadPage -> recreate()
@@ -368,6 +372,27 @@ class ActionPage : AppCompatActivity() {
368372
}
369373
}
370374

375+
private class SilentShellOutputHandler(context: android.content.Context) : ShellHandlerBase(context) {
376+
override fun onProgress(current: Int, total: Int) {
377+
// Chạy ẩn không có UI để hiển thị tiến trình -> bỏ qua có chủ đích.
378+
}
379+
380+
override fun onStart(msg: Any?) {}
381+
override fun onStart(forceStop: Runnable?) {}
382+
override fun onExit(msg: Any?) {}
383+
override fun updateLog(msg: SpannableString?) {
384+
// Chạy ẩn không có log view -> bỏ qua có chủ đích.
385+
}
386+
387+
fun processOutput(output: String) {
388+
output.lineSequence().forEach { line ->
389+
if (line.isNotBlank()) {
390+
onReaderMsg(line)
391+
}
392+
}
393+
}
394+
}
395+
371396
private fun loadPageConfig(showLoading: Boolean = true) {
372397
val config = currentPageConfig ?: return
373398

0 commit comments

Comments
 (0)