@@ -241,7 +241,39 @@ class ActionPage : AppCompatActivity() {
241241 " killapp" -> killApp()
242242 " file" -> menuItemChooseFile(menuOption)
243243 else -> {
244- menuItemExecute(menuOption, hashMapOf(" state" to menuOption.key, " menu_id" to menuOption.key))
244+ if (menuOption.silent) {
245+ menuItemExecuteSilent(menuOption)
246+ } else {
247+ menuItemExecute(menuOption, hashMapOf(" state" to menuOption.key, " menu_id" to menuOption.key))
248+ }
249+ }
250+ }
251+ }
252+
253+ // Chạy script của menu item ở NỀN (IO thread), không hiện DialogLogFragment/không có output hiển thị.
254+ // Vẫn tôn trọng các cờ auto-finish/reload-page/auto-kill/auto-restart sau khi script chạy xong.
255+ private fun menuItemExecuteSilent (menuOption : PageMenuOption ) {
256+ val config = currentPageConfig ? : return
257+ val extraParams = hashMapOf(" state" to menuOption.key, " menu_id" to menuOption.key)
258+
259+ lifecycleScope.launch(Dispatchers .IO ) {
260+ ScriptEnvironmen .executeResultRoot(this @ActionPage, config.pageHandlerSh, config, extraParams)
261+
262+ if (! isActive) return @launch
263+
264+ withContext(Dispatchers .Main ) {
265+ if (isFinishing) return @withContext
266+ when {
267+ menuOption.autoFinish -> finish()
268+ menuOption.reloadPage -> recreate()
269+ menuOption.autoKill -> killApp()
270+ menuOption.autoRestart -> restartApp()
271+ }
272+ // Nếu là menu checkbox, cập nhật lại dấu tích ngay sau khi script chạy xong
273+ // (không cần đợi người dùng mở lại menu).
274+ if (menuOption.type == " checkbox" ) {
275+ refreshCheckboxMenuStates()
276+ }
245277 }
246278 }
247279 }
0 commit comments