781flyingdutchman / background_downloader

Flutter plugin for file downloads and uploads
Other
157 stars 73 forks source link

Receive status update in background #341

Closed tomasweigenast closed 2 months ago

tomasweigenast commented 3 months ago

If the package is able to record events that happened when the app was in background or terminated and resume them using

await _uploader.trackTasks();
await _uploader.resumeFromBackground();

Why we can't setup callbacks to directly receive those events on Dart, executing another Isolate obviously. Something like Firebase Messaging does for background notifications, which allows you to setup a callback that gets called although the app is in background/terminated state.

781flyingdutchman commented 3 months ago

Fair question. It would be possible to set it up that way, but if you wake up the app for every background event of the downloader (typically including progress updates that happen very frequently) then the app isn't really running in the background anymore, which is the whole point of background downloading.

Can you elaborate on the use case you'd have for this (other than avoiding a few extra lines on wakeup)?

Let me look into if it's possible to configure a wakeup for final state - but even then you'd still have to process what happened when the app was truly in the background.

tomasweigenast commented 3 months ago

I saw the source code and the package does nothing when the app is terminated (because it saves the state to SharedPreferences, on Android, I did not see code to awake the app when WorkManager fires events), correct me if I'm wrong.

I don't mean to awake the app for every possible event (could be left to the developer). In my use case, the app must receive an event when a background upload is finished, even if the app was terminated because it needs to call an HTTP endpoint.

Currently, I'll try to solve that requirement using the background_fetch package (https://pub.dev/packages/background_fetch) which runs a callback every 15 min. approx and then check if the task was completed or not.

781flyingdutchman commented 3 months ago

Correct, right now the plugin does not wake up the app. What I was suggesting is that perhaps I could add an option to do that only for a final state. That would presumably solve your issue, but I have to think about this a bit.

tomasweigenast commented 3 months ago

Yes, I think implementing that for a final state is good. I don't know if you can set up "hooks" for WorkManager or JobManager to call a function when the upload/download finishes even if the app is terminated.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 7 days since being marked as stale.