-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Application.Properties obsolete and fix implementation #2158
Conversation
On Windows, use LocalApplication folder with a file, on iOS/MacCatalyst store the serialized blob into NSUserDefaults, on Android use the cache directory from essentials to store the file.
Fixes #1920 |
This sort of resolves #22. Though the original spec calls for simply removing the feature altogether (and telling folks to use Essentials). |
@@ -94,6 +94,7 @@ public Page MainPage | |||
} | |||
} | |||
|
|||
[Obsolete("Properties API is obsolete, use Essentials.Preferences instead.")] | |||
public IDictionary<string, object> Properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EditorBrowsable.Never?
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix usage on COntrolGallery
"D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj" (default target) (15:6) ->
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue2104.cs(47,6): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue2104.cs(52,7): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue2104.cs(58,7): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue2104.cs(75,6): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue3541.cs(65,4): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue3541.cs(66,10): error CS0618: 'Application.SavePropertiesAsync()' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue3541.cs(80,8): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Issue3541.cs(81,12): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(51,21): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(60,33): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(64,27): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(68,32): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(70,5): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(71,5): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(72,5): error CS0618: 'Application.Properties' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(82,10): error CS0618: 'Application.SavePropertiesAsync()' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
D:\agent\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\Bugzilla28709.cs(88,10): error CS0618: 'Application.SavePropertiesAsync()' is obsolete: 'Properties API is obsolete, use Essentials.Preferences instead.' [D:\agent\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]
@@ -11,37 +12,35 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Android | |||
{ | |||
internal class Deserializer : IDeserializer | |||
{ | |||
const string PropertyStoreFile = "PropertyStore.forms"; | |||
const string PropertyStoreFile = "PropertyStore.maui"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since no compatibility with Xamarin.Forms
is expected, would it be better to use System.Json
for serialization and deserialization? It is at least more space efficient if not faster too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is because it is a separate dependency we have to bring in. Also, this feature is very obsolete and bringing in a dependency for a feature we basically want to delete is not worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that System.Json
is part of net6.0
and hence net6.0-android
. Never mind then 😅. I agree, it's not worth it.
First of all, mark
Application.Properties
andApplication.SavePropertiesAsync
as obsolete and suggestEssentials.Preferences
instead.Next, the current implementation is broken/throwing on some platforms, and on at least MacCatalyst saving to a file is causing a native permission dialog to popup when the app exits the first time (since the properties get saved on exit).
So, switch to using more normal System.IO API's to do the work:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Essentials.FileSystem.CacheDirectory
Note: I avoided using Essentials.Preferences as the implementation for the existing api for a couple of reasons:
Preferences.Set(..)
on every platform, except.... Android has issues with larger data being stored with SharedPreferences (which is what Preferences API uses), so serializing many MB of data could cause it to break on some android devices.