[AOT]Clean up some AOT build issues in PowerAccent.Core (#36264)
* init * Use AotCompatibility instead * Replace typeof(Lanaguge) with GetValues<Language> * Create new folder to place source generation context file. --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
This commit is contained in:
Родитель
a665975460
Коммит
aa9f3bb540
|
@ -57,7 +57,7 @@ namespace PowerAccent.Core
|
||||||
{
|
{
|
||||||
public static string[] GetDefaultLetterKey(LetterKey letter, Language[] langs)
|
public static string[] GetDefaultLetterKey(LetterKey letter, Language[] langs)
|
||||||
{
|
{
|
||||||
if (langs.Length == Enum.GetValues(typeof(Language)).Length)
|
if (langs.Length == Enum.GetValues<Language>().Length)
|
||||||
{
|
{
|
||||||
return GetDefaultLetterKeyALL(letter);
|
return GetDefaultLetterKeyALL(letter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||||
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
|
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
|
||||||
<Import Project="..\..\..\Common.SelfContained.props" />
|
<Import Project="..\..\..\Common.SelfContained.props" />
|
||||||
|
<Import Project="..\..\..\Common.Dotnet.AotCompatibility.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
|
|
@ -14,7 +14,7 @@ using PowerToys.PowerAccentKeyboardService;
|
||||||
|
|
||||||
namespace PowerAccent.Core;
|
namespace PowerAccent.Core;
|
||||||
|
|
||||||
public class PowerAccent : IDisposable
|
public partial class PowerAccent : IDisposable
|
||||||
{
|
{
|
||||||
private readonly SettingsService _settingService;
|
private readonly SettingsService _settingService;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// 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.Text.Json.Serialization;
|
||||||
|
using PowerAccent.Core.Services;
|
||||||
|
|
||||||
|
namespace PowerAccent.Core.SerializationContext;
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(SettingsService))]
|
||||||
|
public partial class SourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ using ManagedCommon;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
|
using PowerAccent.Core.SerializationContext;
|
||||||
using PowerToys.PowerAccentKeyboardService;
|
using PowerToys.PowerAccentKeyboardService;
|
||||||
|
|
||||||
namespace PowerAccent.Core.Services;
|
namespace PowerAccent.Core.Services;
|
||||||
|
@ -29,11 +30,6 @@ public class SettingsService
|
||||||
_watcher = Helper.GetFileWatcher(PowerAccentModuleName, "settings.json", () => { ReadSettings(); });
|
_watcher = Helper.GetFileWatcher(PowerAccentModuleName, "settings.json", () => { ReadSettings(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
private void ReadSettings()
|
private void ReadSettings()
|
||||||
{
|
{
|
||||||
// TODO this IO call should by Async, update GetFileWatcher helper to support async
|
// TODO this IO call should by Async, update GetFileWatcher helper to support async
|
||||||
|
@ -46,9 +42,8 @@ public class SettingsService
|
||||||
{
|
{
|
||||||
Logger.LogInfo("QuickAccent settings.json was missing, creating a new one");
|
Logger.LogInfo("QuickAccent settings.json was missing, creating a new one");
|
||||||
var defaultSettings = new PowerAccentSettings();
|
var defaultSettings = new PowerAccentSettings();
|
||||||
var options = _serializerOptions;
|
|
||||||
|
|
||||||
_settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), PowerAccentModuleName);
|
_settingsUtils.SaveSettings(JsonSerializer.Serialize(this, SourceGenerationContext.Default.SettingsService), PowerAccentModuleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
var settings = _settingsUtils.GetSettingsOrDefault<PowerAccentSettings>(PowerAccentModuleName);
|
var settings = _settingsUtils.GetSettingsOrDefault<PowerAccentSettings>(PowerAccentModuleName);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче