Skip to content

Commit daad288

Browse files
committed
Upload file
1 parent 980ae55 commit daad288

2 files changed

Lines changed: 39 additions & 17 deletions

File tree

64 Bytes
Binary file not shown.

pio/src/main/java/com/projectkr/shell/SplashActivity.kt

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,34 +196,56 @@ class SplashActivity : AppCompatActivity() {
196196
}
197197

198198
private fun runBeforeStartSh(config: KrScriptConfig, hasRoot: Boolean) {
199-
lifecycleScope.launch(Dispatchers.IO) {
199+
200+
Thread {
201+
200202
try {
201203
val process = if (hasRoot)
202204
ShellExecutor.getSuperUserRuntime()
203205
else
204206
ShellExecutor.getRuntime()
205-
process?.let { proc ->
206-
readStreamAsync(proc.inputStream.bufferedReader())
207-
readStreamAsync(proc.errorStream.bufferedReader())
208-
DataOutputStream(proc.outputStream).use { os ->
209-
ScriptEnvironmen.executeShell(
210-
this@SplashActivity,
211-
os,
212-
config.beforeStartSh,
213-
config.variables,
214-
null,
215-
"pio-splash"
216-
)
217-
}
218-
proc.waitFor()
207+
208+
if (process != null) {
209+
210+
val outputStream = DataOutputStream(process.outputStream)
211+
212+
ScriptEnvironmen.executeShell(
213+
this@SplashActivity,
214+
outputStream,
215+
config.beforeStartSh,
216+
config.variables,
217+
null,
218+
"pio-splash"
219+
)
220+
221+
// Đọc stdout
222+
Thread {
223+
process.inputStream.bufferedReader().forEachLine { line ->
224+
runOnUiThread { onLogOutput(line) }
225+
}
226+
}.start()
227+
228+
// Đọc stderr
229+
Thread {
230+
process.errorStream.bufferedReader().forEachLine { line ->
231+
runOnUiThread { onLogOutput(line) }
232+
}
233+
}.start()
234+
235+
// Chờ shell kết thúc
236+
process.waitFor()
219237
}
238+
220239
} catch (e: Exception) {
221240
e.printStackTrace()
222241
}
223-
withContext(Dispatchers.Main) {
242+
243+
// Khi shell exit mới vào Home
244+
runOnUiThread {
224245
gotoHome()
225246
}
226-
}
247+
248+
}.start()
227249
}
228250

229251
// Buffer lưu 4 dòng cuối

0 commit comments

Comments
 (0)