mirror of
https://github.com/2dust/v2rayN.git
synced 2025-07-05 14:32:09 +00:00
Improve and refactor the code
This commit is contained in:
parent
5a81441351
commit
0f4884d9d8
8 changed files with 44 additions and 27 deletions
|
@ -197,6 +197,15 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
config.clashUIItem ??= new();
|
config.clashUIItem ??= new();
|
||||||
|
|
||||||
|
if (config.systemProxyItem == null)
|
||||||
|
{
|
||||||
|
config.systemProxyItem = new()
|
||||||
|
{
|
||||||
|
systemProxyExceptions = config.systemProxyExceptions,
|
||||||
|
systemProxyAdvancedProtocol = config.systemProxyAdvancedProtocol,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
LazyConfig.Instance.SetConfig(config);
|
LazyConfig.Instance.SetConfig(config);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int index = (int)config.sysProxyType;
|
int index = (int)config.systemProxyItem.sysProxyType;
|
||||||
|
|
||||||
//Load from routing setting
|
//Load from routing setting
|
||||||
var createdIcon = GetNotifyIcon4Routing(config);
|
var createdIcon = GetNotifyIcon4Routing(config);
|
||||||
|
@ -56,7 +56,7 @@ namespace v2rayN.Handler
|
||||||
public System.Windows.Media.ImageSource GetAppIcon(Config config)
|
public System.Windows.Media.ImageSource GetAppIcon(Config config)
|
||||||
{
|
{
|
||||||
int index = 1;
|
int index = 1;
|
||||||
switch (config.sysProxyType)
|
switch (config.systemProxyItem.sysProxyType)
|
||||||
{
|
{
|
||||||
case ESysProxyType.ForcedClear:
|
case ESysProxyType.ForcedClear:
|
||||||
index = 1;
|
index = 1;
|
||||||
|
@ -90,7 +90,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
Color color = ColorTranslator.FromHtml("#3399CC");
|
Color color = ColorTranslator.FromHtml("#3399CC");
|
||||||
int index = (int)config.sysProxyType;
|
int index = (int)config.systemProxyItem.sysProxyType;
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
{
|
{
|
||||||
color = (new[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1];
|
color = (new[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1];
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public static bool UpdateSysProxy(Config config, bool forceDisable)
|
public static bool UpdateSysProxy(Config config, bool forceDisable)
|
||||||
{
|
{
|
||||||
var type = config.sysProxyType;
|
var type = config.systemProxyItem.sysProxyType;
|
||||||
|
|
||||||
if (forceDisable && type != ESysProxyType.Unchanged)
|
if (forceDisable && type != ESysProxyType.Unchanged)
|
||||||
{
|
{
|
||||||
|
@ -30,19 +30,19 @@ namespace v2rayN.Handler
|
||||||
if (type == ESysProxyType.ForcedChange)
|
if (type == ESysProxyType.ForcedChange)
|
||||||
{
|
{
|
||||||
var strExceptions = "";
|
var strExceptions = "";
|
||||||
if (config.notProxyLocalAddress)
|
if (config.systemProxyItem.notProxyLocalAddress)
|
||||||
{
|
{
|
||||||
strExceptions = $"<local>;{config.constItem.defIEProxyExceptions};{config.systemProxyExceptions}";
|
strExceptions = $"<local>;{config.constItem.defIEProxyExceptions};{config.systemProxyItem.systemProxyExceptions}";
|
||||||
}
|
}
|
||||||
|
|
||||||
var strProxy = string.Empty;
|
var strProxy = string.Empty;
|
||||||
if (Utils.IsNullOrEmpty(config.systemProxyAdvancedProtocol))
|
if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol))
|
||||||
{
|
{
|
||||||
strProxy = $"{Global.Loopback}:{port}";
|
strProxy = $"{Global.Loopback}:{port}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strProxy = config.systemProxyAdvancedProtocol
|
strProxy = config.systemProxyItem.systemProxyAdvancedProtocol
|
||||||
.Replace("{ip}", Global.Loopback)
|
.Replace("{ip}", Global.Loopback)
|
||||||
.Replace("{http_port}", port.ToString())
|
.Replace("{http_port}", port.ToString())
|
||||||
.Replace("{socks_port}", portSocks.ToString());
|
.Replace("{socks_port}", portSocks.ToString());
|
||||||
|
|
|
@ -12,9 +12,7 @@ namespace v2rayN.Models
|
||||||
|
|
||||||
public string indexId { get; set; }
|
public string indexId { get; set; }
|
||||||
public string subIndexId { get; set; }
|
public string subIndexId { get; set; }
|
||||||
public ESysProxyType sysProxyType { get; set; }
|
|
||||||
public string systemProxyExceptions { get; set; }
|
public string systemProxyExceptions { get; set; }
|
||||||
public bool notProxyLocalAddress { get; set; } = true;
|
|
||||||
public string systemProxyAdvancedProtocol { get; set; }
|
public string systemProxyAdvancedProtocol { get; set; }
|
||||||
|
|
||||||
public ECoreType runningCoreType { get; set; }
|
public ECoreType runningCoreType { get; set; }
|
||||||
|
@ -48,6 +46,7 @@ namespace v2rayN.Models
|
||||||
public Mux4SboxItem mux4SboxItem { get; set; }
|
public Mux4SboxItem mux4SboxItem { get; set; }
|
||||||
public HysteriaItem hysteriaItem { get; set; }
|
public HysteriaItem hysteriaItem { get; set; }
|
||||||
public ClashUIItem clashUIItem { get; set; }
|
public ClashUIItem clashUIItem { get; set; }
|
||||||
|
public SystemProxyItem systemProxyItem { get; set; }
|
||||||
public List<InItem> inbound { get; set; }
|
public List<InItem> inbound { get; set; }
|
||||||
public List<KeyEventItem> globalHotkeys { get; set; }
|
public List<KeyEventItem> globalHotkeys { get; set; }
|
||||||
public List<CoreTypeItem> coreTypeItem { get; set; }
|
public List<CoreTypeItem> coreTypeItem { get; set; }
|
||||||
|
|
|
@ -227,4 +227,13 @@ namespace v2rayN.Models
|
||||||
public bool connectionsAutoRefresh { get; set; }
|
public bool connectionsAutoRefresh { get; set; }
|
||||||
public int connectionsRefreshInterval { get; set; } = 2;
|
public int connectionsRefreshInterval { get; set; } = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class SystemProxyItem
|
||||||
|
{
|
||||||
|
public ESysProxyType sysProxyType { get; set; }
|
||||||
|
public string systemProxyExceptions { get; set; }
|
||||||
|
public bool notProxyLocalAddress { get; set; } = true;
|
||||||
|
public string systemProxyAdvancedProtocol { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -234,7 +234,7 @@ namespace v2rayN.ViewModels
|
||||||
y => y != null && !y.Text.IsNullOrEmpty())
|
y => y != null && !y.Text.IsNullOrEmpty())
|
||||||
.Subscribe(c => ServerSelectedChanged(c));
|
.Subscribe(c => ServerSelectedChanged(c));
|
||||||
|
|
||||||
SystemProxySelected = (int)_config.sysProxyType;
|
SystemProxySelected = (int)_config.systemProxyItem.sysProxyType;
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.SystemProxySelected,
|
x => x.SystemProxySelected,
|
||||||
y => y >= 0)
|
y => y >= 0)
|
||||||
|
@ -429,7 +429,7 @@ namespace v2rayN.ViewModels
|
||||||
//RefreshServers();
|
//RefreshServers();
|
||||||
|
|
||||||
Reload();
|
Reload();
|
||||||
ChangeSystemProxyStatus(_config.sysProxyType, true);
|
ChangeSystemProxyStatus(_config.systemProxyItem.sysProxyType, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnProgramStarted(object state, bool timeout)
|
private void OnProgramStarted(object state, bool timeout)
|
||||||
|
@ -936,7 +936,7 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
//ConfigHandler.SaveConfig(_config, false);
|
//ConfigHandler.SaveConfig(_config, false);
|
||||||
|
|
||||||
ChangeSystemProxyStatus(_config.sysProxyType, false);
|
ChangeSystemProxyStatus(_config.systemProxyItem.sysProxyType, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -955,21 +955,21 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
public void SetListenerType(ESysProxyType type)
|
public void SetListenerType(ESysProxyType type)
|
||||||
{
|
{
|
||||||
if (_config.sysProxyType == type)
|
if (_config.systemProxyItem.sysProxyType == type)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_config.sysProxyType = type;
|
_config.systemProxyItem.sysProxyType = type;
|
||||||
ChangeSystemProxyStatus(type, true);
|
ChangeSystemProxyStatus(type, true);
|
||||||
|
|
||||||
SystemProxySelected = (int)_config.sysProxyType;
|
SystemProxySelected = (int)_config.systemProxyItem.sysProxyType;
|
||||||
ConfigHandler.SaveConfig(_config, false);
|
ConfigHandler.SaveConfig(_config, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeSystemProxyStatus(ESysProxyType type, bool blChange)
|
private void ChangeSystemProxyStatus(ESysProxyType type, bool blChange)
|
||||||
{
|
{
|
||||||
SysProxyHandle.UpdateSysProxy(_config, _config.tunModeItem.enableTun ? true : false);
|
SysProxyHandle.UpdateSysProxy(_config, _config.tunModeItem.enableTun ? true : false);
|
||||||
_noticeHandler?.SendMessage($"{ResUI.TipChangeSystemProxy} - {_config.sysProxyType.ToString()}", true);
|
_noticeHandler?.SendMessage($"{ResUI.TipChangeSystemProxy} - {_config.systemProxyItem.sysProxyType.ToString()}", true);
|
||||||
|
|
||||||
Application.Current?.Dispatcher.Invoke((Action)(() =>
|
Application.Current?.Dispatcher.Invoke((Action)(() =>
|
||||||
{
|
{
|
||||||
|
@ -1046,7 +1046,7 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_config.sysProxyType == (ESysProxyType)SystemProxySelected)
|
if (_config.systemProxyItem.sysProxyType == (ESysProxyType)SystemProxySelected)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1223,7 +1223,7 @@ namespace v2rayN.ViewModels
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
sb.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]");
|
sb.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]");
|
||||||
sb.Append(" | ");
|
sb.Append(" | ");
|
||||||
//if (_config.sysProxyType == ESysProxyType.ForcedChange)
|
//if (_config.systemProxyItem.sysProxyType == ESysProxyType.ForcedChange)
|
||||||
//{
|
//{
|
||||||
// sb.Append($"[{Global.InboundHttp}({ResUI.SystemProxy}):{LazyConfig.Instance.GetLocalPort(Global.InboundHttp)}]");
|
// sb.Append($"[{Global.InboundHttp}({ResUI.SystemProxy}):{LazyConfig.Instance.GetLocalPort(Global.InboundHttp)}]");
|
||||||
//}
|
//}
|
||||||
|
|
|
@ -179,9 +179,9 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
#region System proxy
|
#region System proxy
|
||||||
|
|
||||||
notProxyLocalAddress = _config.notProxyLocalAddress;
|
notProxyLocalAddress = _config.systemProxyItem.notProxyLocalAddress;
|
||||||
systemProxyAdvancedProtocol = _config.systemProxyAdvancedProtocol;
|
systemProxyAdvancedProtocol = _config.systemProxyItem.systemProxyAdvancedProtocol;
|
||||||
systemProxyExceptions = _config.systemProxyExceptions;
|
systemProxyExceptions = _config.systemProxyItem.systemProxyExceptions;
|
||||||
|
|
||||||
#endregion System proxy
|
#endregion System proxy
|
||||||
|
|
||||||
|
@ -340,9 +340,9 @@ namespace v2rayN.ViewModels
|
||||||
_config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation;
|
_config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation;
|
||||||
|
|
||||||
//systemProxy
|
//systemProxy
|
||||||
_config.systemProxyExceptions = systemProxyExceptions;
|
_config.systemProxyItem.systemProxyExceptions = systemProxyExceptions;
|
||||||
_config.notProxyLocalAddress = notProxyLocalAddress;
|
_config.systemProxyItem.notProxyLocalAddress = notProxyLocalAddress;
|
||||||
_config.systemProxyAdvancedProtocol = systemProxyAdvancedProtocol;
|
_config.systemProxyItem.systemProxyAdvancedProtocol = systemProxyAdvancedProtocol;
|
||||||
|
|
||||||
//tun mode
|
//tun mode
|
||||||
_config.tunModeItem.strictRoute = TunStrictRoute;
|
_config.tunModeItem.strictRoute = TunStrictRoute;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<PackageReference Include="ReactiveUI.Validation" Version="4.0.9" />
|
<PackageReference Include="ReactiveUI.Validation" Version="4.0.9" />
|
||||||
<PackageReference Include="ReactiveUI.WPF" Version="20.1.1" />
|
<PackageReference Include="ReactiveUI.WPF" Version="20.1.1" />
|
||||||
<PackageReference Include="Splat.NLog" Version="15.1.1" />
|
<PackageReference Include="Splat.NLog" Version="15.1.1" />
|
||||||
<PackageReference Include="YamlDotNet" Version="15.3.0" />
|
<PackageReference Include="YamlDotNet" Version="16.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in a new issue