fm-sys / snapdrop-android

Android client for local file sharing via https://snapdrop.net/ and https://pairdrop.net
https://play.google.com/store/apps/details?id=com.fmsys.snapdrop
GNU General Public License v3.0
837 stars 59 forks source link

Option to work in background (with popup notification if someone tries to share a file) #185

Open ghost opened 2 years ago

ghost commented 2 years ago

Describe the feature

Could you add option for the app to work in background?

I've been using it to send files between work profile and main profile, but since v1.9.1 if the app is not in foreground it disconnects from server so switching back and forth between apps does not work anymore.

Describe alternatives you've considered

Using older versions of the app or using from browser will work.

Additional context

No response

fm-sys commented 2 years ago

Yes, the problem is that android activities aren't designed to run in the background.

One solution might be to create a ViewModel/LiveData backed implementation and start a background service with the same webview instance as soon as the activity is paused. Not sure if this will really work though...

https://medium.com/@nicholas.rose/keeping-webview-state-across-configuration-changes-8e071ee9de86

https://medium.com/@oriharel/how-to-run-javascript-code-in-a-background-service-on-android-8ec1a12ebe92

ueen commented 2 years ago

Better would be a Foreground Service with a running notification* On the other hand i'm not really sure its worth it, you can just open the app like once and start sending files, which you would have to do anyway for accepting files.

If you actually do want to pursue this heres a start 1.) create foreground service with notification https://developer.android.com/guide/components/foreground-services 2.) include webview https://stackoverflow.com/questions/39038771/calling-javascript-from-service-android 3.) proabably best would be just to run the network.js and connect.js you can be inspired by my firefox addon which is basiclly doing the same (running a stripped down version for the background mode - checkout background.js) https://github.com/ueen/SnapdropFirefoxAddon if a file is send the app probably should be opened, but consider restrictions on starting activities https://developer.android.com/guide/components/activities/background-starts

fm-sys commented 1 month ago

Marking as won't fix, at least I won't work on it myself cause of potential battery drain and very difficult implementation.