Refactor gui settings

pull/3301/head
2dust 2023-02-10 14:36:37 +08:00
parent 1ff1962425
commit 9b8181b72b
10 changed files with 83 additions and 100 deletions

View File

@ -44,10 +44,7 @@ namespace v2rayN.Handler
{ {
config = new Config config = new Config
{ {
enableStatistics = false,
statisticsFreshRate = 1,
enableRoutingAdvanced = true enableRoutingAdvanced = true
}; };
} }
@ -134,6 +131,14 @@ namespace v2rayN.Handler
mtu = 9000, mtu = 9000,
}; };
} }
if (config.guiItem == null)
{
config.guiItem = new()
{
enableStatistics = false,
statisticsFreshRate = 1,
};
}
if (config.uiItem == null) if (config.uiItem == null)
{ {
config.uiItem = new UIItem() config.uiItem = new UIItem()
@ -180,9 +185,9 @@ namespace v2rayN.Handler
config.speedTestItem.speedPingTestUrl = Global.SpeedPingTestUrl; config.speedTestItem.speedPingTestUrl = Global.SpeedPingTestUrl;
} }
if (config.statisticsFreshRate > 100 || config.statisticsFreshRate < 1) if (config.guiItem.statisticsFreshRate > 100 || config.guiItem.statisticsFreshRate < 1)
{ {
config.statisticsFreshRate = 1; config.guiItem.statisticsFreshRate = 1;
} }
if (config == null) if (config == null)
@ -758,7 +763,7 @@ namespace v2rayN.Handler
public static int DedupServerList(ref Config config, ref List<ProfileItem> lstProfile) public static int DedupServerList(ref Config config, ref List<ProfileItem> lstProfile)
{ {
List<ProfileItem> source = lstProfile; List<ProfileItem> source = lstProfile;
bool keepOlder = config.keepOlderDedupl; bool keepOlder = config.guiItem.keepOlderDedupl;
List<ProfileItem> list = new List<ProfileItem>(); List<ProfileItem> list = new List<ProfileItem>();
if (!keepOlder) source.Reverse(); // Remove the early items first if (!keepOlder) source.Reverse(); // Remove the early items first

View File

@ -825,7 +825,7 @@ namespace v2rayN.Handler
private static int statistic(Config config, ref V2rayConfig v2rayConfig) private static int statistic(Config config, ref V2rayConfig v2rayConfig)
{ {
if (config.enableStatistics) if (config.guiItem.enableStatistics)
{ {
string tag = Global.InboundAPITagName; string tag = Global.InboundAPITagName;
API apiObj = new API(); API apiObj = new API();

View File

@ -35,7 +35,7 @@ namespace v2rayN.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
var progress = new Progress<string>(); var progress = new Progress<string>();
progress.ProgressChanged += (sender, value) => progress.ProgressChanged += (sender, value) =>
@ -67,7 +67,7 @@ namespace v2rayN.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Downloading)); UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Downloading));
var progress = new Progress<double>(); var progress = new Progress<double>();
@ -101,7 +101,7 @@ namespace v2rayN.Handler
public async Task<string> UrlRedirectAsync(string url, bool blProxy) public async Task<string> UrlRedirectAsync(string url, bool blProxy)
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
var webRequestHandler = new SocketsHttpHandler var webRequestHandler = new SocketsHttpHandler
{ {
AllowAutoRedirect = false, AllowAutoRedirect = false,
@ -129,7 +129,7 @@ namespace v2rayN.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
var webProxy = GetWebProxy(blProxy); var webProxy = GetWebProxy(blProxy);
var result = await DownloaderHelper.Instance.DownloadStringAsync(webProxy, url, userAgent, 30); var result = await DownloaderHelper.Instance.DownloadStringAsync(webProxy, url, userAgent, 30);
@ -155,7 +155,7 @@ namespace v2rayN.Handler
{ {
try try
{ {
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
var client = new HttpClient(new SocketsHttpHandler() var client = new HttpClient(new SocketsHttpHandler()
{ {
Proxy = GetWebProxy(blProxy) Proxy = GetWebProxy(blProxy)

View File

@ -309,9 +309,9 @@ namespace v2rayN.Handler
{ {
var dtNow = DateTime.Now; var dtNow = DateTime.Now;
if (config.autoUpdateSubInterval > 0) if (config.guiItem.autoUpdateSubInterval > 0)
{ {
if ((dtNow - autoUpdateSubTime).Hours % config.autoUpdateSubInterval == 0) if ((dtNow - autoUpdateSubTime).Hours % config.guiItem.autoUpdateSubInterval == 0)
{ {
updateHandle.UpdateSubscriptionProcess(config, "", true, (bool success, string msg) => updateHandle.UpdateSubscriptionProcess(config, "", true, (bool success, string msg) =>
{ {
@ -324,9 +324,9 @@ namespace v2rayN.Handler
Thread.Sleep(60000); Thread.Sleep(60000);
} }
if (config.autoUpdateInterval > 0) if (config.guiItem.autoUpdateInterval > 0)
{ {
if ((dtNow - autoUpdateGeoTime).Hours % config.autoUpdateInterval == 0) if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0)
{ {
updateHandle.UpdateGeoFile("geosite", config, (bool success, string msg) => updateHandle.UpdateGeoFile("geosite", config, (bool success, string msg) =>
{ {

View File

@ -27,7 +27,7 @@ namespace v2rayN.Handler
public StatisticsHandler(Mode.Config config, Action<ServerSpeedItem> update) public StatisticsHandler(Mode.Config config, Action<ServerSpeedItem> update)
{ {
config_ = config; config_ = config;
Enable = config.enableStatistics; Enable = config.guiItem.enableStatistics;
updateFunc_ = update; updateFunc_ = update;
exitFlag_ = false; exitFlag_ = false;
@ -103,7 +103,7 @@ namespace v2rayN.Handler
} }
} }
} }
var sleep = config_.statisticsFreshRate < 1 ? 1 : config_.statisticsFreshRate; var sleep = config_.guiItem.statisticsFreshRate < 1 ? 1 : config_.guiItem.statisticsFreshRate;
Thread.Sleep(1000 * sleep); Thread.Sleep(1000 * sleep);
channel_.ConnectAsync(); channel_.ConnectAsync();
} }

View File

@ -7,15 +7,11 @@
public class Config public class Config
{ {
#region property #region property
public string indexId public string indexId
{ {
get; set; get; set;
} }
/// <summary> /// <summary>
/// ///
@ -23,33 +19,7 @@
public ESysProxyType sysProxyType public ESysProxyType sysProxyType
{ {
get; set; get; set;
} }
public bool autoRun { get; set; }
/// <summary>
/// 启用实时网速和流量统计
/// </summary>
public bool enableStatistics
{
get; set;
}
/// <summary>
/// 去重时优先保留较旧(顶部)节点
/// </summary>
public bool keepOlderDedupl
{
get; set;
}
/// <summary>
/// 视图刷新率
/// </summary>
public int statisticsFreshRate
{
get; set;
}
/// <summary> /// <summary>
/// 自定义远程DNS /// 自定义远程DNS
@ -65,9 +35,7 @@
public string domainStrategy4Freedom public string domainStrategy4Freedom
{ {
get; set; get; set;
} }
/// <summary> /// <summary>
/// 域名解析策略 /// 域名解析策略
@ -84,9 +52,7 @@
public bool enableRoutingAdvanced public bool enableRoutingAdvanced
{ {
get; set; get; set;
} }
public bool ignoreGeoUpdateCore { get; set; } = true;
/// <summary> /// <summary>
/// systemProxyExceptions /// systemProxyExceptions
@ -97,19 +63,6 @@
} }
public string systemProxyAdvancedProtocol { get; set; } public string systemProxyAdvancedProtocol { get; set; }
public int autoUpdateInterval { get; set; } = 10;
public int autoUpdateSubInterval { get; set; } = 10;
public bool checkPreReleaseUpdate { get; set; } = false;
public bool enableSecurityProtocolTls13
{
get; set;
}
public int trayMenuServersLimit { get; set; } = 20;
#endregion #endregion
#region other entities #region other entities
@ -118,6 +71,7 @@
public TunModeItem tunModeItem { get; set; } public TunModeItem tunModeItem { get; set; }
public KcpItem kcpItem { get; set; } public KcpItem kcpItem { get; set; }
public GrpcItem grpcItem { get; set; } public GrpcItem grpcItem { get; set; }
public GUIItem guiItem { get; set; }
public UIItem uiItem { get; set; } public UIItem uiItem { get; set; }
public ConstItem constItem { get; set; } public ConstItem constItem { get; set; }
public SpeedTestItem speedTestItem { get; set; } public SpeedTestItem speedTestItem { get; set; }

View File

@ -2,6 +2,7 @@
namespace v2rayN.Mode namespace v2rayN.Mode
{ {
[Serializable]
public class CoreBasicItem public class CoreBasicItem
{ {
/// <summary> /// <summary>
@ -32,7 +33,6 @@ namespace v2rayN.Mode
public string defUserAgent { get; set; } public string defUserAgent { get; set; }
} }
[Serializable] [Serializable]
public class InItem public class InItem
{ {
@ -82,6 +82,30 @@ namespace v2rayN.Mode
public int initial_windows_size { get; set; } public int initial_windows_size { get; set; }
} }
[Serializable]
public class GUIItem
{
public bool autoRun { get; set; }
public bool enableStatistics { get; set; }
public int statisticsFreshRate { get; set; }
public bool keepOlderDedupl { get; set; }
public bool ignoreGeoUpdateCore { get; set; } = true;
public int autoUpdateInterval { get; set; } = 10;
public int autoUpdateSubInterval { get; set; } = 10;
public bool checkPreReleaseUpdate { get; set; } = false;
public bool enableSecurityProtocolTls13 { get; set; }
public int trayMenuServersLimit { get; set; } = 20;
}
[Serializable] [Serializable]
public class UIItem public class UIItem
{ {

View File

@ -506,7 +506,7 @@ namespace v2rayN.ViewModels
//MainFormHandler.Instance.BackupGuiNConfig(_config, true); //MainFormHandler.Instance.BackupGuiNConfig(_config, true);
_coreHandler = new CoreHandler(UpdateHandler); _coreHandler = new CoreHandler(UpdateHandler);
if (_config.enableStatistics) if (_config.guiItem.enableStatistics)
{ {
_statistics = new StatisticsHandler(_config, UpdateStatisticsHandler); _statistics = new StatisticsHandler(_config, UpdateStatisticsHandler);
} }
@ -773,7 +773,7 @@ namespace v2rayN.ViewModels
private void RefreshServersMenu() private void RefreshServersMenu()
{ {
_servers.Clear(); _servers.Clear();
if (_lstProfile.Count > _config.trayMenuServersLimit) if (_lstProfile.Count > _config.guiItem.trayMenuServersLimit)
{ {
return; return;
} }
@ -1301,7 +1301,7 @@ namespace v2rayN.ViewModels
MyAppExit(false); MyAppExit(false);
} }
}; };
(new UpdateHandle()).CheckUpdateGuiN(_config, _updateUI, _config.checkPreReleaseUpdate); (new UpdateHandle()).CheckUpdateGuiN(_config, _updateUI, _config.guiItem.checkPreReleaseUpdate);
} }
private void CheckUpdateCore(ECoreType type) private void CheckUpdateCore(ECoreType type)
@ -1316,7 +1316,7 @@ namespace v2rayN.ViewModels
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg)); string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg));
string toPath = Utils.GetBinPath("", type); string toPath = Utils.GetBinPath("", type);
FileManager.ZipExtractToFile(fileName, toPath, _config.ignoreGeoUpdateCore ? "geo" : ""); FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : "");
_noticeHandler?.SendMessage(ResUI.MsgUpdateV2rayCoreSuccessfullyMore); _noticeHandler?.SendMessage(ResUI.MsgUpdateV2rayCoreSuccessfullyMore);
@ -1330,7 +1330,7 @@ namespace v2rayN.ViewModels
} }
} }
}; };
(new UpdateHandle()).CheckUpdateCore(type, _config, _updateUI, _config.checkPreReleaseUpdate); (new UpdateHandle()).CheckUpdateCore(type, _config, _updateUI, _config.guiItem.checkPreReleaseUpdate);
} }
private void CheckUpdateGeo() private void CheckUpdateGeo()

View File

@ -140,20 +140,20 @@ namespace v2rayN.ViewModels
#endregion #endregion
#region UI #region UI
AutoRun = _config.autoRun; AutoRun = _config.guiItem.autoRun;
EnableStatistics = _config.enableStatistics; EnableStatistics = _config.guiItem.enableStatistics;
StatisticsFreshRate = _config.statisticsFreshRate; StatisticsFreshRate = _config.guiItem.statisticsFreshRate;
KeepOlderDedupl = _config.keepOlderDedupl; KeepOlderDedupl = _config.guiItem.keepOlderDedupl;
IgnoreGeoUpdateCore = _config.ignoreGeoUpdateCore; IgnoreGeoUpdateCore = _config.guiItem.ignoreGeoUpdateCore;
EnableAutoAdjustMainLvColWidth = _config.uiItem.enableAutoAdjustMainLvColWidth; EnableAutoAdjustMainLvColWidth = _config.uiItem.enableAutoAdjustMainLvColWidth;
EnableSecurityProtocolTls13 = _config.enableSecurityProtocolTls13; EnableSecurityProtocolTls13 = _config.guiItem.enableSecurityProtocolTls13;
AutoHideStartup = _config.uiItem.autoHideStartup; AutoHideStartup = _config.uiItem.autoHideStartup;
EnableCheckPreReleaseUpdate = _config.checkPreReleaseUpdate; EnableCheckPreReleaseUpdate = _config.guiItem.checkPreReleaseUpdate;
EnableDragDropSort = _config.uiItem.enableDragDropSort; EnableDragDropSort = _config.uiItem.enableDragDropSort;
DoubleClick2Activate = _config.uiItem.doubleClick2Activate; DoubleClick2Activate = _config.uiItem.doubleClick2Activate;
autoUpdateInterval = _config.autoUpdateInterval; autoUpdateInterval = _config.guiItem.autoUpdateInterval;
autoUpdateSubInterval = _config.autoUpdateSubInterval; autoUpdateSubInterval = _config.guiItem.autoUpdateSubInterval;
trayMenuServersLimit = _config.trayMenuServersLimit; trayMenuServersLimit = _config.guiItem.trayMenuServersLimit;
currentFontFamily = _config.uiItem.currentFontFamily; currentFontFamily = _config.uiItem.currentFontFamily;
SpeedTestTimeout = _config.speedTestItem.speedTestTimeout; SpeedTestTimeout = _config.speedTestItem.speedTestTimeout;
SpeedTestUrl = _config.speedTestItem.speedTestUrl; SpeedTestUrl = _config.speedTestItem.speedTestUrl;
@ -312,24 +312,24 @@ namespace v2rayN.ViewModels
//UI //UI
Utils.SetAutoRun(AutoRun); Utils.SetAutoRun(AutoRun);
_config.autoRun = AutoRun; _config.guiItem.autoRun = AutoRun;
_config.enableStatistics = EnableStatistics; _config.guiItem.enableStatistics = EnableStatistics;
_config.statisticsFreshRate = StatisticsFreshRate; _config.guiItem.statisticsFreshRate = StatisticsFreshRate;
if (_config.statisticsFreshRate > 100 || _config.statisticsFreshRate < 1) if (_config.guiItem.statisticsFreshRate > 100 || _config.guiItem.statisticsFreshRate < 1)
{ {
_config.statisticsFreshRate = 1; _config.guiItem.statisticsFreshRate = 1;
} }
_config.keepOlderDedupl = KeepOlderDedupl; _config.guiItem.keepOlderDedupl = KeepOlderDedupl;
_config.ignoreGeoUpdateCore = IgnoreGeoUpdateCore; _config.guiItem.ignoreGeoUpdateCore = IgnoreGeoUpdateCore;
_config.uiItem.enableAutoAdjustMainLvColWidth = EnableAutoAdjustMainLvColWidth; _config.uiItem.enableAutoAdjustMainLvColWidth = EnableAutoAdjustMainLvColWidth;
_config.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13; _config.guiItem.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13;
_config.uiItem.autoHideStartup = AutoHideStartup; _config.uiItem.autoHideStartup = AutoHideStartup;
_config.autoUpdateInterval = autoUpdateInterval; _config.guiItem.autoUpdateInterval = autoUpdateInterval;
_config.autoUpdateSubInterval = autoUpdateSubInterval; _config.guiItem.autoUpdateSubInterval = autoUpdateSubInterval;
_config.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate; _config.guiItem.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate;
_config.uiItem.enableDragDropSort = EnableDragDropSort; _config.uiItem.enableDragDropSort = EnableDragDropSort;
_config.uiItem.doubleClick2Activate = DoubleClick2Activate; _config.uiItem.doubleClick2Activate = DoubleClick2Activate;
_config.trayMenuServersLimit = trayMenuServersLimit; _config.guiItem.trayMenuServersLimit = trayMenuServersLimit;
_config.uiItem.currentFontFamily = currentFontFamily; _config.uiItem.currentFontFamily = currentFontFamily;
_config.speedTestItem.speedTestTimeout = SpeedTestTimeout; _config.speedTestItem.speedTestTimeout = SpeedTestTimeout;
_config.speedTestItem.speedTestUrl = SpeedTestUrl; _config.speedTestItem.speedTestUrl = SpeedTestUrl;

View File

@ -434,7 +434,7 @@ namespace v2rayN.Views
var width = ConfigHandler.GetformMainLvColWidth(ref _config, ((EServerColName)k).ToString(), Convert.ToInt32(lstProfiles.Columns[k].Width.Value)); var width = ConfigHandler.GetformMainLvColWidth(ref _config, ((EServerColName)k).ToString(), Convert.ToInt32(lstProfiles.Columns[k].Width.Value));
lstProfiles.Columns[k].Width = width; lstProfiles.Columns[k].Width = width;
} }
if (!_config.enableStatistics) if (!_config.guiItem.enableStatistics)
{ {
colTodayUp.Visibility = Visibility.Hidden; colTodayUp.Visibility = Visibility.Hidden;
colTodayDown.Visibility = Visibility.Hidden; colTodayDown.Visibility = Visibility.Hidden;