File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments