apla / me.apla.cordova.app-preferences

App preferences plugin for cordova
Apache License 2.0
201 stars 209 forks source link

Event on update #37

Open micky2be opened 9 years ago

micky2be commented 9 years ago

Could be nice to receive an event when a property has been modified. It would allow us to react based on it.

apla commented 9 years ago

Don't have a time to add this feature, but you can send me a pull request -)

Can you provide little more details for a use case?

Using iOS, you can change preference using Settings.app, but for most cases application will be suspended by iOS after switch to Settings.app. Except applications with background execution and background app refresh. Workaround: if you have regular app, just reread preferences after application became active. Platform itself have support to notify about preference change.

HowTo iOS

Android seems cannot allow to change preferences outside of the app (i can be wrong). In this case make sure you have singleton to access preferences. Platform itself have support to notify about preference change.

HowTo Android

Windows Phone 7-8.0 doesn't have such functionality at all.

Windows Store Apps (WP 8.1+, Windows 8+) have DataChanged event for ApplicationData (not LocalSettings)

micky2be commented 9 years ago

Right I forgot about the suspension. I guess that something we will have to develop on app side then (on resume) I was hoping to have something automatic. Instead of having to read all properties individually.

Can we get easily the list of available properties? Can we get the value of all of them in one request?

apla commented 9 years ago

There is no way to bring crossplatform fetching of all properties. That's easy on Android — you have just plain key-value list. On iOS and Windows platforms you'll have to deal with dictionaries. Also, for my apps I'm storing more preferences that I can change via Settings.app on iOS. Probably best way to handle this situation is read json with all properties that can be changed externally and reread only those values on resume.

(Oh, my! split screen!) probably this feature is important even for iOS.

apla commented 9 years ago

Just added this as alpha version: no tests, no guarantees, just code for iOS, Android and localStorage fallback. Usage example:

plugins.appPreferences.watch();
document.addEventListener ('preferencesChanged', function (evt) {
    // with some platforms can give you details what is changed
    if (evt.key) {
        // handle key change
    } else if (evt.all) {
        // after clearAll
    }
});

Please try and share your thoughts.

micky2be commented 9 years ago

Oh! Thank you. I'm a bit busy on other projects at the moment, I'll come back to you as soon as I have tried this out.

duydao commented 8 years ago

I'm trying to run the watcher on android, but the events won't fire. The implementation for Android seems to pause when the preferences activity is shown and resumed when the preferences are closed. In the meantime, the preferences were changed, without the web view knowing about it.

Is there a way to return a result from the activity to mark the dirty preferences or something like that?

apla commented 8 years ago

@duydao implementation is strange, I'll take a look closer when I have time