itchy-ionic icon indicating copy to clipboard operation
itchy-ionic copied to clipboard

[feat] Background notifications

Open micahlt opened this issue 3 years ago • 15 comments

At the moment, message notifications only fire when the app is open. This is because the request is being made with the Capacitor Local Notifications plugin which is controlled via JavaScript, which only runs when the app is in the foreground. The solution to this problem would be to write an Android Service to fetch messages periodically in the background, or even better a WorkManager since it's the new standard and is battery-efficient.

This really should be worked on before release to Google Play since the current experience is very unpolished. @locness3 do you have any experience with Java? I know you've mentioned creating a native app before.

micahlt avatar Mar 02 '22 15:03 micahlt

It seems relatively simple to set up a WorkManager. We might not even need to have it interact with the webview. Might look into sync adapters as well.

moeenio avatar Mar 06 '22 10:03 moeenio

Sync adapters look really interesting as well! You're right - we shouldn't need to directly interact with the webview, but we do have to store the current username somewhere that can be synced between the webview and the service/WorkManager/sync adapter.

micahlt avatar Mar 06 '22 23:03 micahlt

@locness3 So just from what I've tried, setting up a sync adapter lies beyond my marginal knowledge of Java. Would you be willing to add this feature and make a PR? That would be absolutely amazing 🤩

micahlt avatar Apr 01 '22 03:04 micahlt

we do have to store the current username somewhere that can be synced between the webview and the service/WorkManager/sync adapter.

I believe we're currently using localStorage? I think we should look into @capacitor/storage - whose doc page recommends against using the former :

Mobile OSs may periodically clear data set in window.localStorage, so this API should be used instead.

I believe @capacitor/storage fits as it uses Android's SharedPreferences which are easy to access from java code.

moeenio avatar Apr 01 '22 14:04 moeenio

Note to self : @capacitor/storage seems to use CapacitorStorage as the default name for the shared preferences file.

moeenio avatar Apr 01 '22 14:04 moeenio

Might look into sync adapters as well.

These look relatively complex to set up since it looks like you need to create an authenticator and a content provider - would stick with using WorkManager.

moeenio avatar Apr 01 '22 14:04 moeenio

Might look into sync adapters as well.

These look relatively complex to set up since it looks like you need to create an authenticator and a content provider - would stick with using WorkManager.

Been meaning to switch to Capacitor Storage for a while. I'll write the code sometime tonight and PR the changes into this repo so you can set up a WorkManager easily!

micahlt avatar Apr 01 '22 15:04 micahlt

@locness3 It's been done - the current signed-in username is stored with the key username. You should be good to go!

micahlt avatar Apr 01 '22 21:04 micahlt

Great

moeenio avatar Apr 02 '22 12:04 moeenio

I appreciate your help on this issue! Thanks again!

micahlt avatar Apr 02 '22 16:04 micahlt

@locness3 no hurry, but have you gotten any time to work on this issue?

micahlt avatar Apr 16 '22 23:04 micahlt

I will this week

moeenio avatar Apr 19 '22 14:04 moeenio

Awesome! Thanks again!

micahlt avatar Apr 19 '22 16:04 micahlt

Any updates on this @locness3? Again, no rush - just as you get to it 😊

micahlt avatar Jun 26 '22 21:06 micahlt

Bump - @locness3 any updates?

micahlt avatar Jul 13 '22 16:07 micahlt