From 7930120e0b62c325add5fc64286bc552682f45a4 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Tue, 24 Sep 2024 17:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20ResetProxySettings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProxySettingsWindowViewModel.cs | 20 +++++++++++-------- .../Abstractions/SettingsPropertyBase.cs | 2 +- .../SettingsStructPropertyBase.cs | 4 ++-- .../Infrastructure/SettingsProperty.cs | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/ProxySettingsWindowViewModel.cs b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/ProxySettingsWindowViewModel.cs index 2c95bc40cfe..8b116b070f8 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/ProxySettingsWindowViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator/UI/ViewModels/ProxySettingsWindowViewModel.cs @@ -47,13 +47,17 @@ public ProxySettingsWindowViewModel() public void ResetSettings() { - ProxySettings.SystemProxyIp.Reset(); - ProxySettings.ProxyMasterDns.Reset(); - ProxySettings.SystemProxyPortId.Reset(); - ProxySettings.ProgramStartupRunProxy.Reset(); - ProxySettings.EnableHttpProxyToHttps.Reset(); - ProxySettings.UseDoh.Reset(); - ProxySettings.CustomDohAddres2.Reset(); - ProxySettings.OnlyEnableProxyScript.Reset(); + // 更改多个设置项不立即保存 + ProxySettings.SystemProxyIp.Reset(save: false); + ProxySettings.ProxyMasterDns.Reset(save: false); + ProxySettings.SystemProxyPortId.Reset(save: false); + ProxySettings.ProgramStartupRunProxy.Reset(save: false); + ProxySettings.EnableHttpProxyToHttps.Reset(save: false); + ProxySettings.UseDoh.Reset(save: false); + ProxySettings.CustomDohAddres2.Reset(save: false); + ProxySettings.OnlyEnableProxyScript.Reset(save: false); + + // 更改完成后保存一次 + ProxySettings.OnlyEnableProxyScript.Save(); } } \ No newline at end of file diff --git a/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsPropertyBase.cs b/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsPropertyBase.cs index afb5990a67f..a5626c22af9 100644 --- a/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsPropertyBase.cs +++ b/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsPropertyBase.cs @@ -12,7 +12,7 @@ public abstract class SettingsPropertyBase public abstract void RaiseValueChanged(bool notSave = false); - public abstract void Reset(); + public abstract void Reset(bool save = true); static readonly Dictionary> SettingsProperties = new(); static readonly Dictionary<(Type SettingsType, string PropertyName), bool?> SaveNameStatus = new(); diff --git a/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsStructPropertyBase.cs b/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsStructPropertyBase.cs index eb9acf7ba7c..375a154e887 100644 --- a/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsStructPropertyBase.cs +++ b/src/BD.WTTS.Client/Settings/Infrastructure/Abstractions/SettingsStructPropertyBase.cs @@ -89,7 +89,7 @@ public override void RaiseValueChanged(bool notSave = false) } } - public override void Reset() + public override void Reset(bool save = true) { var oldValue = value; value = Default; // 赋值当前字段 @@ -97,7 +97,7 @@ public override void Reset() OnValueChanged(oldValue, value); // 调用变更事件 - if (AutoSave) // 自动保存 + if (save && AutoSave) // 自动保存 { Save(); } diff --git a/src/BD.WTTS.Client/Settings/Infrastructure/SettingsProperty.cs b/src/BD.WTTS.Client/Settings/Infrastructure/SettingsProperty.cs index 08a7c30a88e..e33e1a243eb 100644 --- a/src/BD.WTTS.Client/Settings/Infrastructure/SettingsProperty.cs +++ b/src/BD.WTTS.Client/Settings/Infrastructure/SettingsProperty.cs @@ -136,7 +136,7 @@ public override void RaiseValueChanged(bool notSave = false) } } - public override void Reset() + public override void Reset(bool save = true) { var oldValue = value; value = Default; // 赋值当前字段 @@ -144,7 +144,7 @@ public override void Reset() OnValueChanged(oldValue, value); // 调用变更事件 - if (AutoSave) // 自动保存 + if (save && AutoSave) // 自动保存 { Save(); }