Skip to content

Commit b1ebbc1

Browse files
committed
主题设置页面
1 parent 5de16c6 commit b1ebbc1

18 files changed

Lines changed: 942 additions & 21 deletions
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
using Avalonia.Media;
4+
5+
namespace SecRandom.Core.Abstraction;
6+
7+
public class ColorJsonConverter : JsonConverter<Color>
8+
{
9+
public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
10+
{
11+
if (reader.TokenType == JsonTokenType.String)
12+
{
13+
var value = reader.GetString();
14+
if (string.IsNullOrEmpty(value))
15+
{
16+
return Colors.White;
17+
}
18+
19+
try
20+
{
21+
return Color.Parse(value);
22+
}
23+
catch
24+
{
25+
return Colors.White;
26+
}
27+
}
28+
29+
if (reader.TokenType == JsonTokenType.Number)
30+
{
31+
return Color.FromUInt32(reader.GetUInt32());
32+
}
33+
34+
return Colors.White;
35+
}
36+
37+
public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options)
38+
{
39+
writer.WriteStringValue(value.ToString());
40+
}
41+
}

SecRandom.Core/Abstraction/ConfigServiceBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text.Json;
1+
using System.Text.Json;
22

33
namespace SecRandom.Core.Abstraction;
44

@@ -7,7 +7,8 @@ public abstract class ConfigServiceBase
77
protected readonly JsonSerializerOptions JsonOptions = new()
88
{
99
WriteIndented = true,
10-
PropertyNameCaseInsensitive = true
10+
PropertyNameCaseInsensitive = true,
11+
Converters = { new ColorJsonConverter() }
1112
};
1213

1314
public abstract T LoadConfig<T>(T fallback) where T : ConfigBase;

SecRandom.Core/SecRandom.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>

SecRandom/App.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
<Application.Styles>
1212
<StyleInclude Source="/Styles.axaml"/>
13-
1413
<Style Selector=":is(Window)">
1514
<Setter Property="Icon" Value="/Assets/AppLogo.png"/>
1615
</Style>

SecRandom/App.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private static void InitializeLanguages(CultureInfo cultureInfo)
251251
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
252252
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
253253
Langs.Common.Resources.Culture = cultureInfo;
254-
Langs.Pages.RollCallPage.Resources.Culture = cultureInfo;
254+
Langs.MainPages.RollCallPage.Resources.Culture = cultureInfo;
255255
Langs.SettingsPages.BasicSettingsPage.Resources.Culture = cultureInfo;
256256
Langs.SettingsPages.DrawSettingsPage.Resources.Culture = cultureInfo;
257257
}

SecRandom/Langs/Pages/RollCallPage/Resources.Designer.cs renamed to SecRandom/Langs/MainPages/RollCallPage/Resources.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SecRandom/Langs/Pages/RollCallPage/Resources.en-us.resx renamed to SecRandom/Langs/MainPages/RollCallPage/Resources.en-us.resx

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)