From ac486a47232b3b4bd3d6838a1a39c7009afe1d67 Mon Sep 17 00:00:00 2001 From: Magesh K <47920326+mahee96@users.noreply.github.com> Date: Sun, 2 Feb 2025 04:38:46 +0530 Subject: [PATCH] [DisableIdleTimeout]: Fix: account for concurrency --- AltStore/Managing Apps/AppManager.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index 13a5927f..8081bc26 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -1231,8 +1231,11 @@ private extension AppManager } else { - DispatchQueue.main.schedule { - UIApplication.shared.isIdleTimerDisabled = UserDefaults.standard.isIdleTimeoutDisableEnabled + // Disable the idleTimeout + if !UIApplication.shared.isIdleTimerDisabled { // accept only once if concurrent + DispatchQueue.main.schedule { + UIApplication.shared.isIdleTimerDisabled = UserDefaults.standard.isIdleTimeoutDisableEnabled + } } performAppOperations() // Moved to self.finish() @@ -2099,9 +2102,14 @@ private extension AppManager func finish(_ operation: AppOperation, result: Result, group: RefreshGroup, progress: Progress?) { - // remove disableIdleTimeout - DispatchQueue.main.schedule { - UIApplication.shared.isIdleTimerDisabled = false + // Remove disableIdleTimeout + // TODO: This should disable for the last finish() request not the first though for batches + // probably if we are in batch mode, we can count expected no of finishes() to arrive + // and schedule disabling only on last request by matching it with count. + if UIApplication.shared.isIdleTimerDisabled { // accept only once if concurrent + DispatchQueue.main.schedule { + UIApplication.shared.isIdleTimerDisabled = false + } } // Must remove before saving installedApp.