Scratch-Client-4 / itchy-ionic

📱 A mobile app for Scratch
https://itchy.micahlindley.com
23 stars 4 forks source link

[feat] Background notifications #56

Open micahlt opened 2 years ago

micahlt commented 2 years ago

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.

moeenio commented 2 years ago

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.

micahlt commented 2 years ago

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 commented 2 years ago

@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 🤩

moeenio commented 2 years ago

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 commented 2 years ago

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

moeenio commented 2 years ago

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.

micahlt commented 2 years ago

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 commented 2 years ago

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

moeenio commented 2 years ago

Great

micahlt commented 2 years ago

I appreciate your help on this issue! Thanks again!

micahlt commented 2 years ago

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

moeenio commented 2 years ago

I will this week

micahlt commented 2 years ago

Awesome! Thanks again!

micahlt commented 2 years ago

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

micahlt commented 2 years ago

Bump - @locness3 any updates?