mirror of https://github.com/2dust/v2rayN
Improve and refactor the code
parent
5a81441351
commit
0f4884d9d8
|
@ -197,6 +197,15 @@ namespace v2rayN.Handler
|
|||
}
|
||||
config.clashUIItem ??= new();
|
||||
|
||||
if (config.systemProxyItem == null)
|
||||
{
|
||||
config.systemProxyItem = new()
|
||||
{
|
||||
systemProxyExceptions = config.systemProxyExceptions,
|
||||
systemProxyAdvancedProtocol = config.systemProxyAdvancedProtocol,
|
||||
};
|
||||
}
|
||||
|
||||
LazyConfig.Instance.SetConfig(config);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace v2rayN.Handler
|
|||
{
|
||||
try
|
||||
{
|
||||
int index = (int)config.sysProxyType;
|
||||
int index = (int)config.systemProxyItem.sysProxyType;
|
||||
|
||||
//Load from routing setting
|
||||
var createdIcon = GetNotifyIcon4Routing(config);
|
||||
|
@ -56,7 +56,7 @@ namespace v2rayN.Handler
|
|||
public System.Windows.Media.ImageSource GetAppIcon(Config config)
|
||||
{
|
||||
int index = 1;
|
||||
switch (config.sysProxyType)
|
||||
switch (config.systemProxyItem.sysProxyType)
|
||||
{
|
||||
case ESysProxyType.ForcedClear:
|
||||
index = 1;
|
||||
|
@ -90,7 +90,7 @@ namespace v2rayN.Handler
|
|||
}
|
||||
|
||||
Color color = ColorTranslator.FromHtml("#3399CC");
|
||||
int index = (int)config.sysProxyType;
|
||||
int index = (int)config.systemProxyItem.sysProxyType;
|
||||
if (index > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
var type = config.sysProxyType;
|
||||
var type = config.systemProxyItem.sysProxyType;
|
||||
|
||||
if (forceDisable && type != ESysProxyType.Unchanged)
|
||||
{
|
||||
|
@ -30,19 +30,19 @@ namespace v2rayN.Handler
|
|||
if (type == ESysProxyType.ForcedChange)
|
||||
{
|
||||
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;
|
||||
if (Utils.IsNullOrEmpty(config.systemProxyAdvancedProtocol))
|
||||
if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol))
|
||||
{
|
||||
strProxy = $"{Global.Loopback}:{port}";
|
||||
}
|
||||
else
|
||||
{
|
||||
strProxy = config.systemProxyAdvancedProtocol
|
||||
strProxy = config.systemProxyItem.systemProxyAdvancedProtocol
|
||||
.Replace("{ip}", Global.Loopback)
|
||||
.Replace("{http_port}", port.ToString())
|
||||
.Replace("{socks_port}", portSocks.ToString());
|
||||
|
|
|
@ -12,9 +12,7 @@ namespace v2rayN.Models
|
|||
|
||||
public string indexId { get; set; }
|
||||
public string subIndexId { get; set; }
|
||||
public ESysProxyType sysProxyType { get; set; }
|
||||
public string systemProxyExceptions { get; set; }
|
||||
public bool notProxyLocalAddress { get; set; } = true;
|
||||
public string systemProxyAdvancedProtocol { get; set; }
|
||||
|
||||
public ECoreType runningCoreType { get; set; }
|
||||
|
@ -48,6 +46,7 @@ namespace v2rayN.Models
|
|||
public Mux4SboxItem mux4SboxItem { get; set; }
|
||||
public HysteriaItem hysteriaItem { get; set; }
|
||||
public ClashUIItem clashUIItem { get; set; }
|
||||
public SystemProxyItem systemProxyItem { get; set; }
|
||||
public List<InItem> inbound { get; set; }
|
||||
public List<KeyEventItem> globalHotkeys { get; set; }
|
||||
public List<CoreTypeItem> coreTypeItem { get; set; }
|
||||
|
|
|
@ -227,4 +227,13 @@ namespace v2rayN.Models
|
|||
public bool connectionsAutoRefresh { get; set; }
|
||||
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())
|
||||
.Subscribe(c => ServerSelectedChanged(c));
|
||||
|
||||
SystemProxySelected = (int)_config.sysProxyType;
|
||||
SystemProxySelected = (int)_config.systemProxyItem.sysProxyType;
|
||||
this.WhenAnyValue(
|
||||
x => x.SystemProxySelected,
|
||||
y => y >= 0)
|
||||
|
@ -429,7 +429,7 @@ namespace v2rayN.ViewModels
|
|||
//RefreshServers();
|
||||
|
||||
Reload();
|
||||
ChangeSystemProxyStatus(_config.sysProxyType, true);
|
||||
ChangeSystemProxyStatus(_config.systemProxyItem.sysProxyType, true);
|
||||
}
|
||||
|
||||
private void OnProgramStarted(object state, bool timeout)
|
||||
|
@ -936,7 +936,7 @@ namespace v2rayN.ViewModels
|
|||
|
||||
//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)
|
||||
{
|
||||
if (_config.sysProxyType == type)
|
||||
if (_config.systemProxyItem.sysProxyType == type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_config.sysProxyType = type;
|
||||
_config.systemProxyItem.sysProxyType = type;
|
||||
ChangeSystemProxyStatus(type, true);
|
||||
|
||||
SystemProxySelected = (int)_config.sysProxyType;
|
||||
SystemProxySelected = (int)_config.systemProxyItem.sysProxyType;
|
||||
ConfigHandler.SaveConfig(_config, false);
|
||||
}
|
||||
|
||||
private void ChangeSystemProxyStatus(ESysProxyType type, bool blChange)
|
||||
{
|
||||
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)(() =>
|
||||
{
|
||||
|
@ -1046,7 +1046,7 @@ namespace v2rayN.ViewModels
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (_config.sysProxyType == (ESysProxyType)SystemProxySelected)
|
||||
if (_config.systemProxyItem.sysProxyType == (ESysProxyType)SystemProxySelected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1223,7 +1223,7 @@ namespace v2rayN.ViewModels
|
|||
StringBuilder sb = new();
|
||||
sb.Append($"[{EInboundProtocol.socks}:{LazyConfig.Instance.GetLocalPort(EInboundProtocol.socks)}]");
|
||||
sb.Append(" | ");
|
||||
//if (_config.sysProxyType == ESysProxyType.ForcedChange)
|
||||
//if (_config.systemProxyItem.sysProxyType == ESysProxyType.ForcedChange)
|
||||
//{
|
||||
// sb.Append($"[{Global.InboundHttp}({ResUI.SystemProxy}):{LazyConfig.Instance.GetLocalPort(Global.InboundHttp)}]");
|
||||
//}
|
||||
|
@ -1293,4 +1293,4 @@ namespace v2rayN.ViewModels
|
|||
|
||||
#endregion UI
|
||||
}
|
||||
}
|
||||
}
|
|
@ -179,9 +179,9 @@ namespace v2rayN.ViewModels
|
|||
|
||||
#region System proxy
|
||||
|
||||
notProxyLocalAddress = _config.notProxyLocalAddress;
|
||||
systemProxyAdvancedProtocol = _config.systemProxyAdvancedProtocol;
|
||||
systemProxyExceptions = _config.systemProxyExceptions;
|
||||
notProxyLocalAddress = _config.systemProxyItem.notProxyLocalAddress;
|
||||
systemProxyAdvancedProtocol = _config.systemProxyItem.systemProxyAdvancedProtocol;
|
||||
systemProxyExceptions = _config.systemProxyItem.systemProxyExceptions;
|
||||
|
||||
#endregion System proxy
|
||||
|
||||
|
@ -340,9 +340,9 @@ namespace v2rayN.ViewModels
|
|||
_config.uiItem.mainGirdOrientation = (EGirdOrientation)MainGirdOrientation;
|
||||
|
||||
//systemProxy
|
||||
_config.systemProxyExceptions = systemProxyExceptions;
|
||||
_config.notProxyLocalAddress = notProxyLocalAddress;
|
||||
_config.systemProxyAdvancedProtocol = systemProxyAdvancedProtocol;
|
||||
_config.systemProxyItem.systemProxyExceptions = systemProxyExceptions;
|
||||
_config.systemProxyItem.notProxyLocalAddress = notProxyLocalAddress;
|
||||
_config.systemProxyItem.systemProxyAdvancedProtocol = systemProxyAdvancedProtocol;
|
||||
|
||||
//tun mode
|
||||
_config.tunModeItem.strictRoute = TunStrictRoute;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<PackageReference Include="ReactiveUI.Validation" Version="4.0.9" />
|
||||
<PackageReference Include="ReactiveUI.WPF" Version="20.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>
|
||||
|
|
Loading…
Reference in New Issue