fix:一言API设置重复写入

This commit is contained in:
2026-04-05 09:25:53 +08:00
parent b62055e705
commit dfc23b4428
4 changed files with 26 additions and 8 deletions
+1 -1
View File
@@ -1441,7 +1441,7 @@
FontSize="14" Margin="0,0,0,6" />
<ikw:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<ComboBox Name="ComboBoxChickenSoupSource" FontFamily="Microsoft YaHei UI"
SelectedIndex="1" Width="240"
Width="240"
SelectionChanged="ComboBoxChickenSoupSource_SelectionChanged">
<ComboBoxItem Content="{i18n:I18n Key=Theme_QuoteSource_OsuQuotes}" FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="{i18n:I18n Key=Theme_QuoteSource_Mottos}" FontFamily="Microsoft YaHei UI" />
+1
View File
@@ -1165,6 +1165,7 @@ namespace Ink_Canvas
public static Settings Settings = new Settings();
public static string settingsFileName = Path.Combine("Configs", "Settings.json");
private bool isLoaded;
private bool _suppressChickenSoupSourceSelectionChanged;
private bool forcePointEraser;
/// <summary>
+3
View File
@@ -1261,8 +1261,11 @@ namespace Ink_Canvas
/// </remarks>
private async void ComboBoxChickenSoupSource_SelectionChanged(object sender, RoutedEventArgs e)
{
if (_suppressChickenSoupSourceSelectionChanged) return;
if (!isLoaded) return;
int idx = ComboBoxChickenSoupSource.SelectedIndex;
if (idx < 0) return;
if (Settings.Appearance.ChickenSoupSource == idx) return;
Settings.Appearance.ChickenSoupSource = idx;
+20 -6
View File
@@ -440,7 +440,17 @@ namespace Ink_Canvas
// 设置主题下拉框
ComboBoxTheme.SelectedIndex = Settings.Appearance.Theme;
_suppressChickenSoupSourceSelectionChanged = true;
try
{
ComboBoxChickenSoupSource.SelectedIndex = Settings.Appearance.ChickenSoupSource;
}
finally
{
Dispatcher.BeginInvoke(
(Action)(() => { _suppressChickenSoupSourceSelectionChanged = false; }),
DispatcherPriority.ContextIdle);
}
// 初始化自定义按钮的可见性(仅在选择API时显示)
if (BtnHitokotoCustomize != null)
@@ -450,11 +460,6 @@ namespace Ink_Canvas
: Visibility.Collapsed;
}
// 初始化HitokotoCategories,如果为空则默认全选
if (Settings.Appearance.HitokotoCategories == null || Settings.Appearance.HitokotoCategories.Count == 0)
{
Settings.Appearance.HitokotoCategories = new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" };
}
ToggleSwitchEnableQuickPanel.IsOn = Settings.Appearance.IsShowQuickPanel;
@@ -869,6 +874,8 @@ namespace Ink_Canvas
ToggleSwitchClearCanvasAlsoClearImages.IsOn = Settings.Canvas.ClearCanvasAlsoClearImages;
ToggleSwitchShowCircleCenter.IsOn = Settings.Canvas.ShowCircleCenter;
ApplyWhiteboardBoothToolbarFromSettings();
switch (Settings.Canvas.EraserShapeType)
{
case 0:
@@ -1494,7 +1501,7 @@ namespace Ink_Canvas
Settings defaultSettings = new Settings();
// 将默认配置和用户配置都序列化为JObject
JObject defaultConfigObj = JObject.FromObject(defaultSettings);
JObject defaultConfigObj = JObject.FromObject(defaultSettings); EnsureDefaultConfigSchemaIncludesIgnoredNullKeys(defaultConfigObj);
JObject userConfigObj = JObject.Parse(userConfigJson);
// 记录是否有清理操作
@@ -1535,6 +1542,13 @@ namespace Ink_Canvas
/// 7. 删除标记的键
/// 8. 设置变更标志
/// </remarks>
private static void EnsureDefaultConfigSchemaIncludesIgnoredNullKeys(JObject defaultConfigObj)
{
if (defaultConfigObj == null) return;
if (defaultConfigObj["appearance"] is JObject appearance && !appearance.ContainsKey("hitokotoCategories"))
appearance["hitokotoCategories"] = JValue.CreateNull();
}
private void RemoveObsoleteProperties(JObject userObj, JObject defaultObj, ref bool hasChanges)
{
if (userObj == null || defaultObj == null)