jamesmontemagno / SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows
MIT License
324 stars 80 forks source link

Add roaming settings for UWP (and WinRT) #25

Closed limefrogyank closed 7 years ago

limefrogyank commented 8 years ago

Feature Request:

I really would like roaming settings that come with UWP/WinRT apps. In addition to using ApplicationData.Current.LocalSettings, also allow ApplicationData.Current.RoamingSettings.

In fact, I've already implemented it in a forked project: https://github.com/limefrogyank/SettingsPlugin

I didn't want to break any of your current code, so I simply wrote a second file in the WP81 project called RoamingSettings.cs where I changed only LocalSettings to RoamingSettings. (Then linked it to UWP)

I modified CrossSettings's CreateSettings method to accept an enum for Local or Roaming with a default of Local.

I then modified CrossSettings to add a second property called CurrentRoaming that gets a second Lazy reference to an ISettings type called roamingSettings. This version is instantiated with CreateSettings(SettingsType.Roaming)

It seems to work fine on my end. The preprocessor symbols in the IF THEN statements need to be updated to include the other WinRT projects... I'm only using UWP so I didn't care.

jamesmontemagno commented 8 years ago

So, I think that this is probably doable in the next version I am about to release. I am adding in a "FileName" for the next version that is optional.

If no folder is specified then it will use:

If you pass in a folder it will then, create a new folder/suite for iOS/Android. In Windows I was just creating a new data container, but I could specify Roaming:

    ApplicationDataContainer GetAppSettings(string fileName = null)
        {
            if (string.IsNullOrWhiteSpace(fileName))
                return ApplicationData.Current.LocalSettings;

            if (!ApplicationData.Current.RoamingSettings.Containers.ContainsKey(fileName))
                ApplicationData.Current.RoamingSettings.CreateContainer(fileName, ApplicationDataCreateDisposition.Always);

            return ApplicationData.Current.RoamingSettings.Containers[fileName];
        }

However, Perhaps I could do a new structure for the setting:

public struct SettingInfo
{
   public string FileName {get;set;} = string.Empty;
   public bool Roaming {get;set;} = false;
}

The question becomes..... what is the equivalent on iOS/Android to roaming settings in UWP?

limefrogyank commented 8 years ago

This sounds good. I don't believe there is an equivalent in Android. I was actually looking for that when I was wondering how to alter your code. As for iOS, I have no clue. Probably none either.

Do you have a deadline for this release? I borked the Android portion when editing your code (PCL vs shared issues) and was wondering if I should just wait. Thanks!

limefrogyank commented 8 years ago

Looks like iOS iCloud syncing is done manually: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/UserDefaults/StoringPreferenceDatainiCloud/StoringPreferenceDatainiCloud.html

jamesmontemagno commented 8 years ago

This is a very important package so I most likely will not add it for a bit to be honest. I am still attempting to finalize containers on Windows moving to roaming would make some sense as NSUserDefaults could be shared with other apps. I have to investigate a bit more.

Android can work as it is private as long as the user id of apps is the same.

jamesmontemagno commented 8 years ago

UWP roaming isn't synced at all between profiles is it? What is the purpose?

jamesmontemagno commented 8 years ago

Ahhh reading now, let me think about it: https://msdn.microsoft.com/windows/uwp/app-settings/store-and-retrieve-app-data#roaming-data

limefrogyank commented 8 years ago

No problem, I'll just have to fix my hack then.

AndreasLuebbers commented 7 years ago

Is this implemented meanwhile and if it was, how could I use it? I love the Roaming feature and want to use your tool with Xamarin with roaming.

jamesmontemagno commented 7 years ago

It's in the 2.6.0 beta

varyamereon commented 7 years ago

Using the beta version, have seen that it is possible to change the filename but it is still stored in local settings? What method should be used to store it in roaming settings or is this not implemented yet?

jamesmontemagno commented 7 years ago

I do not support roaming settings on UWP actually. I am thinking a larger idea here for settings as the roaming settings don't work well with the filename idea.

My plan long term is to introduce additional containers inside that you can use for settings. However, they are not part of it today.