From 61de890fda2186eadf3264fb19d2da7b4d91125c Mon Sep 17 00:00:00 2001 From: ByAyzen <189399597+ByAyzen@users.noreply.github.com> Date: Sat, 29 Aug 2026 05:17:05 +0300 Subject: [PATCH 1/4] Small bugfix: Cancel and clear downloads. --- .../cloudstream3/utils/downloader/DownloadQueueManager.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt index f3866408833..855d65c0016 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt @@ -198,8 +198,9 @@ object DownloadQueueManager { } } - /** Removes all queued items */ + /** Removes all queued items and cancels active downloads */ fun removeAllFromQueue() { + downloadInstances.value.forEach { it.cancelDownload() } removeAll().forEach { wrapper -> setQueueStatus(wrapper.id, VideoDownloadManager.DownloadType.IsStopped) } From 14c36607221e3f4f10ac019fd26ab9ca6b21e0f9 Mon Sep 17 00:00:00 2001 From: ByAyzen <189399597+ByAyzen@users.noreply.github.com> Date: Tue, 8 Sep 2026 00:52:09 +0300 Subject: [PATCH 2/4] Small change. --- .../cloudstream3/utils/downloader/DownloadQueueManager.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt index 855d65c0016..cf2a039dfdb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadQueueManager.kt @@ -198,9 +198,11 @@ object DownloadQueueManager { } } - /** Removes all queued items and cancels active downloads */ + /** /** Removes all inactive downloads */ */ fun removeAllFromQueue() { - downloadInstances.value.forEach { it.cancelDownload() } + downloadInstances.value + .filter { downloadStatus[it.downloadQueueWrapper.id] != VideoDownloadManager.DownloadType.IsDownloading } + .forEach { it.cancelDownload() } removeAll().forEach { wrapper -> setQueueStatus(wrapper.id, VideoDownloadManager.DownloadType.IsStopped) } From a10741308ef72e232f892eed889fce56bd66ee14 Mon Sep 17 00:00:00 2001 From: ByAyzen <189399597+ByAyzen@users.noreply.github.com> Date: Tue, 8 Sep 2026 03:37:08 +0300 Subject: [PATCH 3/4] Fix: Auto-remove stuck download instances from queue on completion/failure/cancel --- .../cloudstream3/services/DownloadQueueService.kt | 7 +++++++ .../cloudstream3/utils/downloader/DownloadManager.kt | 3 +++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt b/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt index e07747a860c..6dfecbe4fdf 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt @@ -71,6 +71,12 @@ class DownloadQueueService : Service() { val downloadInstances: StateFlow> = _downloadInstances + fun removeDownloadInstance(id: Int) { + _downloadInstances.update { list -> + list.filterNot { it.downloadQueueWrapper.id == id } + } + } + private val totalDownloadFlow = downloadInstances.combine(DownloadQueueManager.queue) { instances, queue -> instances to queue @@ -262,6 +268,7 @@ class DownloadQueueService : Service() { Log.d(TAG, "Download queue service stopped.") downloadEvent -= downloadEventListener isRunning = false + _downloadInstances.update { emptyList() } super.onDestroy() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt index adefedd2053..379178485ac 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt @@ -33,6 +33,7 @@ import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.safe +import com.lagradost.cloudstream3.services.DownloadQueueService import com.lagradost.cloudstream3.services.VideoDownloadService import com.lagradost.cloudstream3.sortUrls import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO @@ -1691,6 +1692,7 @@ object VideoDownloadManager { // Force refresh the queue when completed. // May lead to some redundant calls, but ensures that the queue is always up to date. DownloadQueueManager.forceRefreshQueue() + DownloadQueueService.removeDownloadInstance(downloadQueueWrapper.id) } } @@ -1725,6 +1727,7 @@ object VideoDownloadManager { // Force refresh the queue when failed. // May lead to some redundant calls, but ensures that the queue is always up to date. DownloadQueueManager.forceRefreshQueue() + DownloadQueueService.removeDownloadInstance(id) } var isCancelled = false From c685bceef3067812bf45232148dcad61a71053cc Mon Sep 17 00:00:00 2001 From: ByAyzen <189399597+ByAyzen@users.noreply.github.com> Date: Tue, 8 Sep 2026 04:35:32 +0300 Subject: [PATCH 4/4] Reverting last commit. I am reverting these changes because i thought the issue was solved but it didnt fully fix it. Prerelease already had no problem. --- .../cloudstream3/services/DownloadQueueService.kt | 7 ------- .../cloudstream3/utils/downloader/DownloadManager.kt | 3 --- 2 files changed, 10 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt b/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt index 6dfecbe4fdf..e07747a860c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/services/DownloadQueueService.kt @@ -71,12 +71,6 @@ class DownloadQueueService : Service() { val downloadInstances: StateFlow> = _downloadInstances - fun removeDownloadInstance(id: Int) { - _downloadInstances.update { list -> - list.filterNot { it.downloadQueueWrapper.id == id } - } - } - private val totalDownloadFlow = downloadInstances.combine(DownloadQueueManager.queue) { instances, queue -> instances to queue @@ -268,7 +262,6 @@ class DownloadQueueService : Service() { Log.d(TAG, "Download queue service stopped.") downloadEvent -= downloadEventListener isRunning = false - _downloadInstances.update { emptyList() } super.onDestroy() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt index 379178485ac..adefedd2053 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/downloader/DownloadManager.kt @@ -33,7 +33,6 @@ import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.safe -import com.lagradost.cloudstream3.services.DownloadQueueService import com.lagradost.cloudstream3.services.VideoDownloadService import com.lagradost.cloudstream3.sortUrls import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO @@ -1692,7 +1691,6 @@ object VideoDownloadManager { // Force refresh the queue when completed. // May lead to some redundant calls, but ensures that the queue is always up to date. DownloadQueueManager.forceRefreshQueue() - DownloadQueueService.removeDownloadInstance(downloadQueueWrapper.id) } } @@ -1727,7 +1725,6 @@ object VideoDownloadManager { // Force refresh the queue when failed. // May lead to some redundant calls, but ensures that the queue is always up to date. DownloadQueueManager.forceRefreshQueue() - DownloadQueueService.removeDownloadInstance(id) } var isCancelled = false