mirror of
https://github.com/netchx/netch.git
synced 2026-04-09 20:10:34 +08:00
Refactor Check settings change
Refactor Check Detection Tick value Fix sometimes Detection Tick not update
This commit is contained in:
@@ -629,10 +629,12 @@ namespace Netch.Forms
|
||||
|
||||
private void SettingsButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var oldSettings = Global.Settings.Clone();
|
||||
|
||||
Hide();
|
||||
new SettingForm().ShowDialog();
|
||||
|
||||
if (i18N.LangCode != Global.Settings.Language)
|
||||
if (oldSettings.Language != Global.Settings.Language)
|
||||
{
|
||||
i18N.Load(Global.Settings.Language);
|
||||
InitText();
|
||||
@@ -640,10 +642,10 @@ namespace Netch.Forms
|
||||
InitProfile();
|
||||
}
|
||||
|
||||
if (ServerHelper.DelayTestHelper.Interval != Global.Settings.DetectionTick)
|
||||
if (oldSettings.DetectionTick != Global.Settings.DetectionTick)
|
||||
ServerHelper.DelayTestHelper.UpdateInterval();
|
||||
|
||||
if (ProfileButtons.Count != Global.Settings.ProfileCount)
|
||||
if (oldSettings.ProfileCount != Global.Settings.ProfileCount)
|
||||
InitProfile();
|
||||
|
||||
Show();
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Netch.Forms
|
||||
i => Global.Settings.ProfileCount = i,
|
||||
Global.Settings.ProfileCount);
|
||||
BindTextBox<int>(DetectionTickTextBox,
|
||||
i => i >= 0,
|
||||
i => ServerHelper.DelayTestHelper.Range.InRange(i),
|
||||
i => Global.Settings.DetectionTick = i,
|
||||
Global.Settings.DetectionTick);
|
||||
BindTextBox<int>(StartedPingIntervalTextBox,
|
||||
|
||||
20
Netch/Models/Range.cs
Normal file
20
Netch/Models/Range.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Netch.Models
|
||||
{
|
||||
public readonly struct Range
|
||||
{
|
||||
public int Start { get; }
|
||||
|
||||
public int End { get; }
|
||||
|
||||
public Range(int start, int end)
|
||||
{
|
||||
Start = start;
|
||||
End = end;
|
||||
}
|
||||
|
||||
public bool InRange(int num)
|
||||
{
|
||||
return Start <= num && num <= End;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,5 +286,9 @@ namespace Netch.Models
|
||||
public bool UseProxyToUpdateSubscription = false;
|
||||
|
||||
public V2rayConfig V2RayConfig = new();
|
||||
public Setting Clone()
|
||||
{
|
||||
return (Setting) MemberwiseClone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using Netch.Models;
|
||||
|
||||
namespace Netch.Utils
|
||||
{
|
||||
@@ -65,7 +66,6 @@ namespace Netch.Utils
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 指定类型的端口是否已经被使用了
|
||||
/// </summary>
|
||||
@@ -151,24 +151,6 @@ namespace Netch.Utils
|
||||
}
|
||||
}
|
||||
|
||||
internal readonly struct Range
|
||||
{
|
||||
public int Start { get; }
|
||||
|
||||
public int End { get; }
|
||||
|
||||
public Range(int start, int end)
|
||||
{
|
||||
Start = start;
|
||||
End = end;
|
||||
}
|
||||
|
||||
public bool InRange(int num)
|
||||
{
|
||||
return Start <= num && num <= End;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查端口类型
|
||||
/// </summary>
|
||||
|
||||
@@ -23,13 +23,14 @@ namespace Netch.Utils
|
||||
{
|
||||
private static readonly Timer Timer;
|
||||
private static bool _mux;
|
||||
|
||||
public static readonly Range Range = new(0, int.MaxValue / 1000);
|
||||
static DelayTestHelper()
|
||||
{
|
||||
Timer = new Timer
|
||||
{
|
||||
Interval = 10000,
|
||||
AutoReset = true,
|
||||
Enabled = false
|
||||
AutoReset = true
|
||||
};
|
||||
|
||||
Timer.Elapsed += (_, _) => TestAllDelay();
|
||||
@@ -64,17 +65,14 @@ namespace Netch.Utils
|
||||
|
||||
public static void UpdateInterval()
|
||||
{
|
||||
var enabled = Enabled;
|
||||
Timer.Stop();
|
||||
if (Global.Settings.DetectionTick <= 0)
|
||||
|
||||
if (Global.Settings.DetectionTick == 0 || !Range.InRange(Global.Settings.DetectionTick))
|
||||
return;
|
||||
|
||||
Timer.Interval = Global.Settings.DetectionTick * 1000;
|
||||
if (enabled)
|
||||
{
|
||||
Task.Run(TestAllDelay);
|
||||
Timer.Start();
|
||||
}
|
||||
Task.Run(TestAllDelay);
|
||||
Timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user