781flyingdutchman / background_downloader

Flutter plugin for file downloads and uploads
Other
165 stars 76 forks source link

Using group notifications combined with HoldingQueue leads to incorrect numTotal #420

Open 781flyingdutchman opened 3 days ago

781flyingdutchman commented 3 days ago

Discussed in https://github.com/781flyingdutchman/background_downloader/discussions/418

Originally posted by **philitell** November 26, 2024 Hi, i'm trying to use notifications for groups. I have a large number of DownloadTasks within a group (e.g. 80 tasks). Those tasks are all enqueued and i would like to show a notification that says e.g. "25 of 80" with a progress-indicator. The problem is that i'm seeing an notification that gets updated with every status update (when a Task is started and completed). So the notifications shows "0 of 1" - then gets updated to "1 of " - then when the next file is downloaded the notification is updated and shows "0 of 1" again. This happens for all 80 files. What i'm doing wrong? ``` // here is the general initialization/configuration await FileDownloader().ready; final configResult = await FileDownloader().configure( globalConfig: [ (Config.requestTimeout, const Duration(seconds: 100)), (Config.checkAvailableSpace, 500), // NOTE: queue and sets the constraints maxConcurrent to 3, maxConcurrentByHost to 2, // and maxConcurrentByGroup to 1. (Config.holdingQueue, (3, 2, 1)), ], androidConfig: [ (Config.useCacheDir, Config.whenAble), ], iOSConfig: [ (Config.localize, {"Cancel": S.current.stopIt}), ], ); // Register an event listener to process status and progress updates _ref.read(fileTransferTaskStatusUpdateProvider); repositoryLogger.info("Start persistent task tracking"); await FileDownloader().trackTasks(); repositoryLogger.info("Check for events that happened while the app was in the background"); await FileDownloader().resumeFromBackground(); .... // this is my notification configruation which is created right before the tasks of the current group are enqueued (i'm NOT using downloadBatch because is need to to persistent task tracking as well) FileDownloader().configureNotificationForGroup( groupIdentifier, running: const TaskNotification("{numFinished} von {numTotal}", "Fortschritt: {progress}"), complete: const TaskNotification("Abgeschlossen", "{numTotal} Dateien heruntergeladen"), error: const TaskNotification("Fehler", "{numFailed}/{numTotal} fehlgeschlagen"), progressBar: true, groupNotificationId: "notification_$groupIdentifier", ); ```
781flyingdutchman commented 3 days ago

Note to self, re Android:

Haven't checked iOS but suspect similar issue