diff --git a/src/settings-ui/Settings.UI/Helpers/ActionMessage.cs b/src/settings-ui/Settings.UI/Helpers/ActionMessage.cs new file mode 100644 index 000000000000..ead3fb13d501 --- /dev/null +++ b/src/settings-ui/Settings.UI/Helpers/ActionMessage.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace Microsoft.PowerToys.Settings.UI.Helpers +{ + public sealed class ActionMessage + { + [JsonPropertyName("action")] + public SettingsAction Action { get; set; } + + public static ActionMessage Create(string actionName) + { + return new ActionMessage + { + Action = new SettingsAction + { + PublishedDate = new SettingsGeneral + { + ActionName = actionName, + }, + }, + }; + } + } + + [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Those are just a define for one simple struct")] + public sealed class SettingsAction + { + [JsonPropertyName("general")] + public SettingsGeneral PublishedDate { get; set; } + } + + [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Those are just a define for one simple struct")] + public sealed class SettingsGeneral + { + [JsonPropertyName("action_name")] + public string ActionName { get; set; } + } +} diff --git a/src/settings-ui/Settings.UI/Helpers/AsyncCommand.cs b/src/settings-ui/Settings.UI/Helpers/AsyncCommand.cs index 4c9be4706084..c44f34b6e5de 100644 --- a/src/settings-ui/Settings.UI/Helpers/AsyncCommand.cs +++ b/src/settings-ui/Settings.UI/Helpers/AsyncCommand.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers { - internal sealed class AsyncCommand : ICommand + internal sealed partial class AsyncCommand : ICommand { private readonly Func _execute; private readonly Func _canExecute; diff --git a/src/settings-ui/Settings.UI/Helpers/IndexedObservableCollection.cs b/src/settings-ui/Settings.UI/Helpers/IndexedObservableCollection.cs index c0cdebcdc7c1..491c06ef5a49 100644 --- a/src/settings-ui/Settings.UI/Helpers/IndexedObservableCollection.cs +++ b/src/settings-ui/Settings.UI/Helpers/IndexedObservableCollection.cs @@ -27,7 +27,7 @@ public IndexedItem(T item, int index) } #pragma warning disable SA1402 // File may only contain a single type - public class IndexedObservableCollection : ObservableCollection> + public partial class IndexedObservableCollection : ObservableCollection> #pragma warning restore SA1402 // File may only contain a single type { public IndexedObservableCollection(IEnumerable items) diff --git a/src/settings-ui/Settings.UI/Helpers/NativeKeyboardHelper.cs b/src/settings-ui/Settings.UI/Helpers/NativeKeyboardHelper.cs index 9d3961f907fa..b9d32e25d3db 100644 --- a/src/settings-ui/Settings.UI/Helpers/NativeKeyboardHelper.cs +++ b/src/settings-ui/Settings.UI/Helpers/NativeKeyboardHelper.cs @@ -18,7 +18,7 @@ internal struct INPUT internal static int Size { - get { return Marshal.SizeOf(typeof(INPUT)); } + get { return Marshal.SizeOf(); } } } diff --git a/src/settings-ui/Settings.UI/Helpers/PowerToysReleaseInfo.cs b/src/settings-ui/Settings.UI/Helpers/PowerToysReleaseInfo.cs new file mode 100644 index 000000000000..5805eac47a7c --- /dev/null +++ b/src/settings-ui/Settings.UI/Helpers/PowerToysReleaseInfo.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace Microsoft.PowerToys.Settings.UI.Helpers +{ + // Contains information for a release. Used to deserialize release JSON info from GitHub. + public sealed class PowerToysReleaseInfo + { + [JsonPropertyName("published_at")] + public DateTimeOffset PublishedDate { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("tag_name")] + public string TagName { get; set; } + + [JsonPropertyName("body")] + public string ReleaseNotes { get; set; } + } +} diff --git a/src/settings-ui/Settings.UI/Helpers/RelayCommand.cs b/src/settings-ui/Settings.UI/Helpers/RelayCommand.cs index 7bfcd8479f51..5d647f82cd94 100644 --- a/src/settings-ui/Settings.UI/Helpers/RelayCommand.cs +++ b/src/settings-ui/Settings.UI/Helpers/RelayCommand.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers { - public class RelayCommand : ICommand + public partial class RelayCommand : ICommand { private readonly Action _execute; private readonly Func _canExecute; @@ -33,7 +33,7 @@ public RelayCommand(Action execute, Func canExecute) } [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "abstract T and abstract")] - public class RelayCommand : ICommand + public partial class RelayCommand : ICommand { private readonly Action execute; diff --git a/src/settings-ui/Settings.UI/Helpers/WindowHelper.cs b/src/settings-ui/Settings.UI/Helpers/WindowHelper.cs index 489e2b9a4a80..9e9718074ced 100644 --- a/src/settings-ui/Settings.UI/Helpers/WindowHelper.cs +++ b/src/settings-ui/Settings.UI/Helpers/WindowHelper.cs @@ -6,7 +6,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Text.Json; - +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Microsoft.UI.Xaml; namespace Microsoft.PowerToys.Settings.UI.Helpers @@ -20,9 +20,9 @@ public static WINDOWPLACEMENT DeserializePlacementOrDefault(IntPtr handle) try { var json = File.ReadAllText(_placementPath); - var placement = JsonSerializer.Deserialize(json); + var placement = JsonSerializer.Deserialize(json, SourceGenerationContextContext.Default.WINDOWPLACEMENT); - placement.Length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); + placement.Length = Marshal.SizeOf(); placement.Flags = 0; placement.ShowCmd = (placement.ShowCmd == NativeMethods.SW_SHOWMAXIMIZED) ? NativeMethods.SW_SHOWMAXIMIZED : NativeMethods.SW_SHOWNORMAL; return placement; @@ -40,7 +40,7 @@ public static void SerializePlacement(IntPtr handle) _ = NativeMethods.GetWindowPlacement(handle, out var placement); try { - var json = JsonSerializer.Serialize(placement); + var json = JsonSerializer.Serialize(placement, SourceGenerationContextContext.Default.WINDOWPLACEMENT); File.WriteAllText(_placementPath, json); } catch (Exception) diff --git a/src/settings-ui/Settings.UI/SerializationContext/SourceGenerationContextContext.cs b/src/settings-ui/Settings.UI/SerializationContext/SourceGenerationContextContext.cs new file mode 100644 index 000000000000..8fd948fd862f --- /dev/null +++ b/src/settings-ui/Settings.UI/SerializationContext/SourceGenerationContextContext.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using Microsoft.PowerToys.Settings.UI.Helpers; +using Microsoft.PowerToys.Settings.UI.Library; + +namespace Microsoft.PowerToys.Settings.UI.SerializationContext; + +[JsonSerializable(typeof(WINDOWPLACEMENT))] +[JsonSerializable(typeof(AdvancedPasteSettings))] +[JsonSerializable(typeof(Dictionary>))] +[JsonSerializable(typeof(AlwaysOnTopSettings))] +[JsonSerializable(typeof(ColorPickerSettings))] +[JsonSerializable(typeof(CropAndLockSettings))] +[JsonSerializable(typeof(FileLocksmithSettings))] +[JsonSerializable(typeof(MeasureToolSettings))] +[JsonSerializable(typeof(MouseWithoutBordersSettings))] +[JsonSerializable(typeof(NewPlusSettings))] +[JsonSerializable(typeof(PeekSettings))] +[JsonSerializable(typeof(PowerLauncherSettings))] +[JsonSerializable(typeof(PowerOcrSettings))] +[JsonSerializable(typeof(RegistryPreviewSettings))] +[JsonSerializable(typeof(WorkspacesSettings))] +[JsonSerializable(typeof(IList))] +[JsonSerializable(typeof(ActionMessage))] +public sealed partial class SourceGenerationContextContext : JsonSerializerContext +{ +} diff --git a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs index 1fb40ce907d9..3a9570baa2a6 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs @@ -14,6 +14,7 @@ using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Microsoft.PowerToys.Settings.UI.Services; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.PowerToys.Telemetry; @@ -167,7 +168,7 @@ private void OnLaunchedToGetSetting(string[] cmdArgs) try { - var requestedSettings = JsonSerializer.Deserialize>>(File.ReadAllText(ipcFileName)); + var requestedSettings = JsonSerializer.Deserialize>>(File.ReadAllText(ipcFileName), SourceGenerationContextContext.Default.DictionaryStringListString); File.WriteAllText(ipcFileName, GetSettingCommandLineCommand.Execute(requestedSettings)); } catch (Exception ex) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeWhatsNew.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeWhatsNew.xaml.cs index ea0876913434..472b231e881c 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeWhatsNew.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeWhatsNew.xaml.cs @@ -20,6 +20,7 @@ using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.OOBE.Enums; using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.PowerToys.Telemetry; using Microsoft.UI.Xaml.Controls; @@ -29,22 +30,6 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views { public sealed partial class OobeWhatsNew : Page { - // Contains information for a release. Used to deserialize release JSON info from GitHub. - private sealed class PowerToysReleaseInfo - { - [JsonPropertyName("published_at")] - public DateTimeOffset PublishedDate { get; set; } - - [JsonPropertyName("name")] - public string Name { get; set; } - - [JsonPropertyName("tag_name")] - public string TagName { get; set; } - - [JsonPropertyName("body")] - public string ReleaseNotes { get; set; } - } - public OobePowerToysModule ViewModel { get; set; } public bool ShowDataDiagnosticsInfoBar => GetShowDataDiagnosticsInfoBar(); @@ -111,7 +96,7 @@ private static async Task GetReleaseNotesMarkdown() // https://docs.github.com/rest/overview/resources-in-the-rest-api#user-agent-required getReleaseInfoClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "PowerToys"); releaseNotesJSON = await getReleaseInfoClient.GetStringAsync("https://api.github.com/repos/microsoft/PowerToys/releases"); - IList releases = JsonSerializer.Deserialize>(releaseNotesJSON); + IList releases = JsonSerializer.Deserialize>(releaseNotesJSON, SourceGenerationContextContext.Default.IListPowerToysReleaseInfo); // Get the latest releases var latestReleases = releases.OrderByDescending(release => release.PublishedDate).Take(5); diff --git a/src/settings-ui/Settings.UI/ViewModels/AdvancedPasteViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/AdvancedPasteViewModel.cs index ac25973ba246..a84006a30544 100644 --- a/src/settings-ui/Settings.UI/ViewModels/AdvancedPasteViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/AdvancedPasteViewModel.cs @@ -18,12 +18,13 @@ using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Microsoft.Win32; using Windows.Security.Credentials; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class AdvancedPasteViewModel : Observable, IDisposable + public partial class AdvancedPasteViewModel : Observable, IDisposable { private static readonly HashSet WarnHotkeys = ["Ctrl + V", "Ctrl + Shift + V"]; @@ -387,7 +388,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", AdvancedPasteSettings.ModuleName, - JsonSerializer.Serialize(_advancedPasteSettings))); + JsonSerializer.Serialize(_advancedPasteSettings, SourceGenerationContextContext.Default.AdvancedPasteSettings))); } public void RefreshEnabledState() diff --git a/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs index f8787f763481..789ef92dfcfc 100644 --- a/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs @@ -12,10 +12,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class AlwaysOnTopViewModel : Observable + public partial class AlwaysOnTopViewModel : Observable { private ISettingsUtils SettingsUtils { get; set; } @@ -131,7 +132,7 @@ public HotkeySettings Hotkey CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", AlwaysOnTopSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.AlwaysOnTopSettings))); } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs index 9de0c269b62f..fef95137e7e7 100644 --- a/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/AwakeViewModel.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class AwakeViewModel : Observable + public partial class AwakeViewModel : Observable { public AwakeViewModel() { diff --git a/src/settings-ui/Settings.UI/ViewModels/CmdNotFoundViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/CmdNotFoundViewModel.cs index 37ad090abfb7..085e447c8e58 100644 --- a/src/settings-ui/Settings.UI/ViewModels/CmdNotFoundViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/CmdNotFoundViewModel.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class CmdNotFoundViewModel : Observable + public partial class CmdNotFoundViewModel : Observable { public ButtonClickCommand CheckRequirementsEventHandler => new ButtonClickCommand(CheckCommandNotFoundRequirements); @@ -39,10 +39,7 @@ public static string AssemblyDirectory { get { - string codeBase = Assembly.GetExecutingAssembly().Location; - UriBuilder uri = new UriBuilder(codeBase); - string path = Uri.UnescapeDataString(uri.Path); - return Path.GetDirectoryName(path); + return Path.TrimEndingDirectorySeparator(AppContext.BaseDirectory); } } diff --git a/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs index bf20e551f2bf..c851ebb90062 100644 --- a/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs @@ -16,10 +16,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Enumerations; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class ColorPickerViewModel : Observable, IDisposable + public partial class ColorPickerViewModel : Observable, IDisposable { private bool disposedValue; @@ -362,7 +363,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", ColorPickerSettings.ModuleName, - JsonSerializer.Serialize(_colorPickerSettings))); + JsonSerializer.Serialize(_colorPickerSettings, SourceGenerationContextContext.Default.ColorPickerSettings))); } public void RefreshEnabledState() diff --git a/src/settings-ui/Settings.UI/ViewModels/Commands/ButtonClickCommand.cs b/src/settings-ui/Settings.UI/ViewModels/Commands/ButtonClickCommand.cs index 8285a66c5abb..7d07eb3fd0f4 100644 --- a/src/settings-ui/Settings.UI/ViewModels/Commands/ButtonClickCommand.cs +++ b/src/settings-ui/Settings.UI/ViewModels/Commands/ButtonClickCommand.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Commands { - public class ButtonClickCommand : ICommand + public partial class ButtonClickCommand : ICommand { private readonly Action _execute; diff --git a/src/settings-ui/Settings.UI/ViewModels/CropAndLockViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/CropAndLockViewModel.cs index 9064cd905879..dc5f6846ef2c 100644 --- a/src/settings-ui/Settings.UI/ViewModels/CropAndLockViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/CropAndLockViewModel.cs @@ -12,10 +12,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class CropAndLockViewModel : Observable + public partial class CropAndLockViewModel : Observable { private ISettingsUtils SettingsUtils { get; set; } @@ -122,7 +123,7 @@ public HotkeySettings ReparentActivationShortcut CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", CropAndLockSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.CropAndLockSettings))); } } } @@ -153,7 +154,7 @@ public HotkeySettings ThumbnailActivationShortcut CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", CropAndLockSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.CropAndLockSettings))); } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/DashboardListItem.cs b/src/settings-ui/Settings.UI/ViewModels/DashboardListItem.cs index 03843a8d8ca8..70214f89c81f 100644 --- a/src/settings-ui/Settings.UI/ViewModels/DashboardListItem.cs +++ b/src/settings-ui/Settings.UI/ViewModels/DashboardListItem.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class DashboardListItem : INotifyPropertyChanged + public partial class DashboardListItem : INotifyPropertyChanged { private bool _visible; private bool _isEnabled; diff --git a/src/settings-ui/Settings.UI/ViewModels/DashboardModuleItem.cs b/src/settings-ui/Settings.UI/ViewModels/DashboardModuleItem.cs index fe029e661936..20132bff2062 100644 --- a/src/settings-ui/Settings.UI/ViewModels/DashboardModuleItem.cs +++ b/src/settings-ui/Settings.UI/ViewModels/DashboardModuleItem.cs @@ -14,11 +14,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { #pragma warning disable SA1402 // File may only contain a single type #pragma warning disable SA1649 // File name should match first type name - public class DashboardModuleTextItem : DashboardModuleItem + public partial class DashboardModuleTextItem : DashboardModuleItem { } - public class DashboardModuleButtonItem : DashboardModuleItem + public partial class DashboardModuleButtonItem : DashboardModuleItem { public string ButtonTitle { get; set; } @@ -31,12 +31,12 @@ public class DashboardModuleButtonItem : DashboardModuleItem public RoutedEventHandler ButtonClickHandler { get; set; } } - public class DashboardModuleShortcutItem : DashboardModuleItem + public partial class DashboardModuleShortcutItem : DashboardModuleItem { public List Shortcut { get; set; } } - public class DashboardModuleKBMItem : DashboardModuleItem + public partial class DashboardModuleKBMItem : DashboardModuleItem { private List _remapKeys = new List(); @@ -55,7 +55,7 @@ public List RemapShortcuts } } - public class DashboardModuleItem : INotifyPropertyChanged + public partial class DashboardModuleItem : INotifyPropertyChanged { public string Label { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/DashboardViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/DashboardViewModel.cs index e2b076228866..198575990d85 100644 --- a/src/settings-ui/Settings.UI/ViewModels/DashboardViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/DashboardViewModel.cs @@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class DashboardViewModel : Observable + public partial class DashboardViewModel : Observable { private const string JsonFileType = ".json"; private IFileSystemWatcher _watcher; @@ -55,7 +55,7 @@ public DashboardViewModel(ISettingsRepository settingsRepositor _allModules = new List(); - foreach (ModuleType moduleType in Enum.GetValues(typeof(ModuleType))) + foreach (ModuleType moduleType in Enum.GetValues()) { AddDashboardListItem(moduleType); } diff --git a/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs index 636d88d1cae1..e256278d003d 100644 --- a/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs @@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class EnvironmentVariablesViewModel : Observable + public partial class EnvironmentVariablesViewModel : Observable { private bool _isElevated; private GpoRuleConfigured _enabledGpoRuleConfiguration; diff --git a/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs index 50195b34ffab..cd8ace4703e8 100644 --- a/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class FancyZonesViewModel : Observable + public partial class FancyZonesViewModel : Observable { private SettingsUtils SettingsUtils { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/FileLocksmithViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/FileLocksmithViewModel.cs index 19175dba9af0..226d0c8b08ce 100644 --- a/src/settings-ui/Settings.UI/ViewModels/FileLocksmithViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/FileLocksmithViewModel.cs @@ -10,10 +10,11 @@ using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class FileLocksmithViewModel : Observable + public partial class FileLocksmithViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } @@ -134,7 +135,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", FileLocksmithSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.FileLocksmithSettings))); } private Func SendConfigMSG { get; } diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/AllAppsViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/AllAppsViewModel.cs index 58d1f4f9ce70..3239da678fd1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/Flyout/AllAppsViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/AllAppsViewModel.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class AllAppsViewModel : Observable + public partial class AllAppsViewModel : Observable { public ObservableCollection FlyoutMenuItems { get; set; } @@ -34,7 +34,7 @@ public AllAppsViewModel(ISettingsRepository settingsRepository, resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader; FlyoutMenuItems = new ObservableCollection(); - foreach (ModuleType moduleType in Enum.GetValues(typeof(ModuleType))) + foreach (ModuleType moduleType in Enum.GetValues()) { AddFlyoutMenuItem(moduleType); } diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs index 8493834f0f1a..3b38c425a351 100644 --- a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs +++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class FlyoutMenuItem : INotifyPropertyChanged + public partial class FlyoutMenuItem : INotifyPropertyChanged { private bool _visible; private bool _isEnabled; diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs index a8cb2474aa93..4a834d9d310a 100644 --- a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout { - public class FlyoutViewModel : IDisposable + public partial class FlyoutViewModel : IDisposable { private Timer _hideTimer; private bool _disposed; diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/LauncherViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/LauncherViewModel.cs index c1d820c0d7c9..0227a2e9db6c 100644 --- a/src/settings-ui/Settings.UI/ViewModels/Flyout/LauncherViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/LauncherViewModel.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class LauncherViewModel : Observable + public partial class LauncherViewModel : Observable { public bool IsUpdateAvailable { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 6a2340f8c6fb..4af8c50cccdc 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -12,6 +12,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Text.Json; +using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; using global::PowerToys.GPOWrapper; @@ -22,11 +23,12 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Microsoft.PowerToys.Telemetry; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class GeneralViewModel : Observable + public partial class GeneralViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } @@ -34,7 +36,7 @@ public class GeneralViewModel : Observable public ButtonClickCommand CheckForUpdatesEventHandler { get; set; } - public object ResourceLoader { get; set; } + public Windows.ApplicationModel.Resources.ResourceLoader ResourceLoader { get; set; } private Action HideBackupAndRestoreMessageAreaAction { get; set; } @@ -70,7 +72,7 @@ public class GeneralViewModel : Observable private SettingsBackupAndRestoreUtils settingsBackupAndRestoreUtils = SettingsBackupAndRestoreUtils.Instance; - public GeneralViewModel(ISettingsRepository settingsRepository, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func ipcMSGCallBackFunc, Func ipcMSGRestartAsAdminMSGCallBackFunc, Func ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "", Action dispatcherAction = null, Action hideBackupAndRestoreMessageAreaAction = null, Action doBackupAndRestoreDryRun = null, Func> pickSingleFolderDialog = null, object resourceLoader = null) + public GeneralViewModel(ISettingsRepository settingsRepository, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func ipcMSGCallBackFunc, Func ipcMSGRestartAsAdminMSGCallBackFunc, Func ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "", Action dispatcherAction = null, Action hideBackupAndRestoreMessageAreaAction = null, Action doBackupAndRestoreDryRun = null, Func> pickSingleFolderDialog = null, Windows.ApplicationModel.Resources.ResourceLoader resourceLoader = null) { CheckForUpdatesEventHandler = new ButtonClickCommand(CheckForUpdatesClick); RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated); @@ -1051,11 +1053,7 @@ public string GetResourceString(string resource) { if (ResourceLoader != null) { - var type = ResourceLoader.GetType(); - MethodInfo methodInfo = type.GetMethod("GetString"); - object classInstance = Activator.CreateInstance(type, null); - object[] parametersArray = new object[] { resource }; - var result = (string)methodInfo.Invoke(ResourceLoader, parametersArray); + var result = ResourceLoader.GetString(resource); if (string.IsNullOrEmpty(result)) { return resource.ToUpperInvariant() + "!!!"; @@ -1105,7 +1103,7 @@ public void Restart() GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings); var dataToSend = customaction.ToString(); - dataToSend = JsonSerializer.Serialize(new { action = new { general = new { action_name = "restart_maintain_elevation" } } }); + dataToSend = JsonSerializer.Serialize(ActionMessage.Create("restart_maintain_elevation"), SourceGenerationContextContext.Default.ActionMessage); SendRestartAsAdminConfigMSG(dataToSend); } diff --git a/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs index c15d8f9306cf..d2bfb989e77e 100644 --- a/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs @@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class HostsViewModel : Observable + public partial class HostsViewModel : Observable { private bool _isElevated; private GpoRuleConfigured _enabledGpoRuleConfiguration; diff --git a/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs index dcd8db95f19d..7edd08676830 100644 --- a/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/ImageResizerViewModel.cs @@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class ImageResizerViewModel : Observable + public partial class ImageResizerViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs index 822df0d6f1e2..fae2f82fc572 100644 --- a/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/KeyboardManagerViewModel.cs @@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class KeyboardManagerViewModel : Observable + public partial class KeyboardManagerViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/MeasureToolViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/MeasureToolViewModel.cs index 6c8ee5053549..ea66fd58dda4 100644 --- a/src/settings-ui/Settings.UI/ViewModels/MeasureToolViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/MeasureToolViewModel.cs @@ -11,10 +11,11 @@ using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class MeasureToolViewModel : Observable + public partial class MeasureToolViewModel : Observable { private ISettingsUtils SettingsUtils { get; set; } @@ -213,7 +214,7 @@ public HotkeySettings ActivationShortcut CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", MeasureToolSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.MeasureToolSettings))); } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/MouseWithoutBordersViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/MouseWithoutBordersViewModel.cs index 5cfc22d6445e..052ccea814c1 100644 --- a/src/settings-ui/Settings.UI/ViewModels/MouseWithoutBordersViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/MouseWithoutBordersViewModel.cs @@ -21,6 +21,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Microsoft.UI; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml.Media; @@ -29,7 +30,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class MouseWithoutBordersViewModel : Observable, IDisposable + public partial class MouseWithoutBordersViewModel : Observable, IDisposable { // These should be in the same order as the ComboBoxItems in MouseWithoutBordersPage.xaml switch machine shortcut options private readonly int[] _switchBetweenMachineShortcutOptions = @@ -260,7 +261,7 @@ public struct MachineSocketState private static VisualStudio.Threading.AsyncSemaphore _ipcSemaphore = new VisualStudio.Threading.AsyncSemaphore(1); - private sealed class SyncHelper : IDisposable + private sealed partial class SyncHelper : IDisposable { public SyncHelper(NamedPipeClientStream stream) { @@ -1083,7 +1084,7 @@ public bool BlockMouseAtScreenCorners private IndexedObservableCollection machineMatrixString; - public class DeviceViewModel : Observable + public partial class DeviceViewModel : Observable { public string Name { get; set; } @@ -1185,7 +1186,7 @@ private void NotifyModuleUpdatedSettings() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", MouseWithoutBordersSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.MouseWithoutBordersSettings))); } public void NotifyUpdatedSettings() diff --git a/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs index 73c8335e1209..36c356ce57f5 100644 --- a/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs @@ -12,12 +12,12 @@ using System.Windows; using global::PowerToys.GPOWrapper; using ManagedCommon; -using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Windows.ApplicationModel.VoiceCommands; using Windows.System; @@ -25,7 +25,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class NewPlusViewModel : Observable + public partial class NewPlusViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } @@ -189,7 +189,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.NewPlusSettings))); } private Func SendConfigMSG { get; } diff --git a/src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs index f6f6eac63be2..cfe0aa2fed9a 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs @@ -10,11 +10,12 @@ using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Settings.UI.Library; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PeekViewModel : Observable + public partial class PeekViewModel : Observable { private bool _isEnabled; @@ -224,7 +225,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PeekSettings.ModuleName, - JsonSerializer.Serialize(_peekSettings))); + JsonSerializer.Serialize(_peekSettings, SourceGenerationContextContext.Default.PeekSettings))); } private void SavePreviewSettings() diff --git a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs index c77d2c05967c..8f8e9b7b561d 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PluginAdditionalOptionViewModel : INotifyPropertyChanged + public partial class PluginAdditionalOptionViewModel : INotifyPropertyChanged { private PluginAdditionalOption _additionalOption; diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs index ca2bdabe072f..320f23c4aeb9 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PowerAccentViewModel : Observable + public partial class PowerAccentViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerLauncherPluginViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerLauncherPluginViewModel.cs index 1543ce727d2b..fd69c781a9be 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerLauncherPluginViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerLauncherPluginViewModel.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PowerLauncherPluginViewModel : INotifyPropertyChanged + public partial class PowerLauncherPluginViewModel : INotifyPropertyChanged { private readonly PowerLauncherPluginSettings settings; private readonly Func isDark; diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerLauncherViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerLauncherViewModel.cs index 67473e84e50a..8c02d5831938 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerLauncherViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerLauncherViewModel.cs @@ -17,10 +17,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PowerLauncherViewModel : Observable + public partial class PowerLauncherViewModel : Observable { private int _themeIndex; private int _monitorPositionIndex; @@ -74,7 +75,7 @@ public PowerLauncherViewModel( CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, - JsonSerializer.Serialize(s))); + JsonSerializer.Serialize(s, SourceGenerationContextContext.Default.PowerLauncherSettings))); }; switch (settings.Properties.Theme) @@ -103,7 +104,7 @@ public PowerLauncherViewModel( break; } - SearchPluginsCommand = new RelayCommand(SearchPlugins); + SearchPluginsCommand = new Library.ViewModels.Commands.RelayCommand(SearchPlugins); } private void InitializeEnabledValue() diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs index f7b81de07aa4..09aa682c397c 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs @@ -14,12 +14,13 @@ using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; +using Microsoft.PowerToys.Settings.UI.SerializationContext; using Windows.Globalization; using Windows.Media.Ocr; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PowerOcrViewModel : Observable, IDisposable + public partial class PowerOcrViewModel : Observable, IDisposable { private bool disposedValue; @@ -236,7 +237,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerOcrSettings.ModuleName, - JsonSerializer.Serialize(_powerOcrSettings))); + JsonSerializer.Serialize(_powerOcrSettings, SourceGenerationContextContext.Default.PowerOcrSettings))); } public void RefreshEnabledState() diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs index 05704aa70e3f..86089a2d5df4 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PowerPreviewViewModel : Observable + public partial class PowerPreviewViewModel : Observable { private const string ModuleName = PowerPreviewSettings.ModuleName; diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs index 00616bd678bb..e1dd68ed5fd0 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerRenameViewModel.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class PowerRenameViewModel : Observable + public partial class PowerRenameViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/RegistryPreviewViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/RegistryPreviewViewModel.cs index f6edc9952468..acd6f4012942 100644 --- a/src/settings-ui/Settings.UI/ViewModels/RegistryPreviewViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/RegistryPreviewViewModel.cs @@ -11,10 +11,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class RegistryPreviewViewModel : Observable + public partial class RegistryPreviewViewModel : Observable { private GeneralSettings GeneralSettingsConfig { get; set; } @@ -121,7 +122,7 @@ private void NotifySettingsChanged() CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", RegistryPreviewSettings.ModuleName, - JsonSerializer.Serialize(_settings))); + JsonSerializer.Serialize(_settings, SourceGenerationContextContext.Default.RegistryPreviewSettings))); } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs index c60963b28ee6..54e998785872 100644 --- a/src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class ShellViewModel : Observable + public partial class ShellViewModel : Observable { private readonly KeyboardAccelerator altLeftKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu); diff --git a/src/settings-ui/Settings.UI/ViewModels/ShortcutGuideViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ShortcutGuideViewModel.cs index e98b62dea455..6ae2dd0746d7 100644 --- a/src/settings-ui/Settings.UI/ViewModels/ShortcutGuideViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/ShortcutGuideViewModel.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class ShortcutGuideViewModel : Observable + public partial class ShortcutGuideViewModel : Observable { private ISettingsUtils SettingsUtils { get; set; } diff --git a/src/settings-ui/Settings.UI/ViewModels/WorkspacesViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/WorkspacesViewModel.cs index ff7ff1bf8824..e24b2ce59741 100644 --- a/src/settings-ui/Settings.UI/ViewModels/WorkspacesViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/WorkspacesViewModel.cs @@ -12,10 +12,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using Microsoft.PowerToys.Settings.UI.SerializationContext; namespace Microsoft.PowerToys.Settings.UI.ViewModels { - public class WorkspacesViewModel : Observable + public partial class WorkspacesViewModel : Observable { private ISettingsUtils SettingsUtils { get; set; } @@ -131,7 +132,7 @@ public HotkeySettings Hotkey CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", WorkspacesSettings.ModuleName, - JsonSerializer.Serialize(Settings))); + JsonSerializer.Serialize(Settings, SourceGenerationContextContext.Default.WorkspacesSettings))); } } }