Skip to content

Commit

Permalink
🐛 ResetProxySettings
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Sep 24, 2024
1 parent aa44b13 commit 7930120
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, List<string>> SettingsProperties = new();
static readonly Dictionary<(Type SettingsType, string PropertyName), bool?> SaveNameStatus = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public override void RaiseValueChanged(bool notSave = false)
}
}

public override void Reset()
public override void Reset(bool save = true)
{
var oldValue = value;
value = Default; // 赋值当前字段
setter(monitor.CurrentValue, default); // 赋值模型类属性

OnValueChanged(oldValue, value); // 调用变更事件

if (AutoSave) // 自动保存
if (save && AutoSave) // 自动保存
{
Save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ public override void RaiseValueChanged(bool notSave = false)
}
}

public override void Reset()
public override void Reset(bool save = true)
{
var oldValue = value;
value = Default; // 赋值当前字段
SetModelValue(default); // 赋值模型类属性

OnValueChanged(oldValue, value); // 调用变更事件

if (AutoSave) // 自动保存
if (save && AutoSave) // 自动保存
{
Save();
}
Expand Down

0 comments on commit 7930120

Please sign in to comment.