@@ -193,35 +193,41 @@ class ActionPage : AppCompatActivity() {
193193 private fun refreshCheckboxMenuStates () {
194194 val config = currentPageConfig ? : return
195195
196- // Lọc danh sách checkbox dựa trên ID duy nhất
196+ // Lọc danh sách các checkbox hợp lệ
197197 val checkboxOptions = menuOptions?.filter { option ->
198198 val uniqueItemId = option.key.hashCode()
199199 option.type == " checkbox" && option.checkedSh.isNotEmpty() && ! justClickedItemIds.contains(uniqueItemId)
200200 }
201-
201+
202202 if (checkboxOptions.isNullOrEmpty() || menuCheckboxRefreshing) return
203203 menuCheckboxRefreshing = true
204-
204+
205205 lifecycleScope.launch(Dispatchers .IO ) {
206- val results = checkboxOptions.map { option ->
207- val result = ScriptEnvironmen .executeResultRoot(this @ActionPage, option.checkedSh, config)?.trim()
208- option to result
206+ // TỐI ƯU SONG SONG: Sử dụng async để phát TẤT CẢ các lệnh getprop đi CÙNG MỘT LÚC
207+ val deferredResults = checkboxOptions.map { option ->
208+ async {
209+ val result = ScriptEnvironmen .executeResultRoot(this @ActionPage, option.checkedSh, config)?.trim()
210+ option to result
211+ }
209212 }
210-
213+
214+ // Đợi tất cả các ô trả về kết quả đầy đủ rồi mới xử lý tiếp
215+ val results = deferredResults.awaitAll()
216+
211217 withContext(Dispatchers .Main ) {
212218 menuCheckboxRefreshing = false
213219 var changed = false
214220
215221 results.forEach { (option, result) ->
216222 val uniqueItemId = option.key.hashCode()
217- // Khớp chính xác ID để tránh đè dữ liệu cũ trong khi lệnh shell click đang thực thi
218223 if (! justClickedItemIds.contains(uniqueItemId)) {
219224 val newChecked = result == " 1" || result?.lowercase() == " true"
220225 if (option.checked != newChecked) changed = true
221226 option.checked = newChecked
222227 }
223228 }
224229
230+ // Chỉ vẽ lại và kích hoạt luồng reload khi TẤT CẢ dữ liệu đã sẵn sàng
225231 if (changed && ! isFinishing) {
226232 invalidateOptionsMenu()
227233 }
0 commit comments