api: spawn CallbackList use UiThreadHandler::runAndWait executor (#2096)

![jsexception](https://github.com/user-attachments/assets/e8a4744d-bd0a-40bf-869c-def915b66075)

Because the exit callback in js cleans up the ChildProcess, when the
last callback of stdout is executed after the exit callback, an error
like “emitData ReferenceError: spawn_callback_1727358276092_68 is not
defined” will occur.
This commit is contained in:
Whale Choi 2024-09-29 13:31:06 +08:00 committed by GitHub
parent ac20b76eaf
commit f65aaff4e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,6 +14,7 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import com.topjohnwu.superuser.CallbackList
import com.topjohnwu.superuser.ShellUtils
import com.topjohnwu.superuser.internal.UiThreadHandler
import me.weishu.kernelsu.ui.util.listModules
import me.weishu.kernelsu.ui.util.createRootShell
import me.weishu.kernelsu.ui.util.withNewRootShell
@ -110,13 +111,13 @@ class WebViewInterface(val context: Context, private val webView: WebView, priva
}
}
val stdout = object : CallbackList<String>() {
val stdout = object : CallbackList<String>(UiThreadHandler::runAndWait) {
override fun onAddElement(s: String) {
emitData("stdout", s)
}
}
val stderr = object : CallbackList<String>() {
val stderr = object : CallbackList<String>(UiThreadHandler::runAndWait) {
override fun onAddElement(s: String) {
emitData("stderr", s)
}