mirror of https://github.com/2dust/v2rayN
Refactor system proxy
parent
35e5475255
commit
74f980aab1
|
@ -7,7 +7,6 @@
|
|||
SaveFileDialog,
|
||||
AddBatchRoutingRulesYesNo,
|
||||
AdjustMainLvColWidth,
|
||||
UpdateSysProxy,
|
||||
SetClipboardData,
|
||||
AddServerViaClipboard,
|
||||
ImportRulesFromClipboard,
|
||||
|
|
|
@ -7,4 +7,5 @@ global using ServiceLib.Services;
|
|||
global using ServiceLib.Services.Statistics;
|
||||
global using ServiceLib.Services.CoreConfig;
|
||||
global using ServiceLib.Models;
|
||||
global using ServiceLib.Resx;
|
||||
global using ServiceLib.Resx;
|
||||
global using ServiceLib.Handler.SysProxy;
|
|
@ -1,4 +1,4 @@
|
|||
namespace v2rayN.Desktop.Common
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
public class ProxySettingLinux
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace v2rayN.Desktop.Common
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
public class ProxySettingOSX
|
||||
{
|
|
@ -1,10 +1,10 @@
|
|||
using Microsoft.Win32;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using static PacLib.ProxySettingWindows.InternetConnectionOption;
|
||||
using static ServiceLib.Handler.SysProxy.ProxySettingWindows.InternetConnectionOption;
|
||||
|
||||
namespace PacLib
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
public class ProxySettingWindows
|
||||
{
|
||||
|
@ -362,10 +362,10 @@ namespace PacLib
|
|||
|
||||
private static void RegWriteValue(string path, string name, object value)
|
||||
{
|
||||
RegistryKey? regKey = null;
|
||||
Microsoft.Win32.RegistryKey? regKey = null;
|
||||
try
|
||||
{
|
||||
regKey = Registry.CurrentUser.CreateSubKey(path);
|
||||
regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(path);
|
||||
if (string.IsNullOrEmpty(value.ToString()))
|
||||
{
|
||||
regKey?.DeleteValue(name, false);
|
|
@ -1,7 +1,6 @@
|
|||
using PacLib;
|
||||
using v2rayN.Desktop.Common;
|
||||
|
||||
namespace v2rayN.Desktop.Handler
|
||||
namespace ServiceLib.Handler.SysProxy
|
||||
{
|
||||
public static class SysProxyHandler
|
||||
{
|
||||
|
@ -16,9 +15,9 @@ namespace v2rayN.Desktop.Handler
|
|||
|
||||
try
|
||||
{
|
||||
int port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
int portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
int portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
|
||||
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
var portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
var portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
|
||||
if (port <= 0)
|
||||
{
|
||||
return false;
|
||||
|
@ -73,12 +72,15 @@ namespace v2rayN.Desktop.Handler
|
|||
}
|
||||
else if (type == ESysProxyType.Pac)
|
||||
{
|
||||
PacHandler.Start(Utils.GetConfigPath(), port, portPac);
|
||||
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
|
||||
ProxySettingWindows.SetProxy(strProxy, "", 4);
|
||||
}
|
||||
|
||||
//if (type != ESysProxyType.Pac)
|
||||
//{
|
||||
// PacHandler.Stop();
|
||||
//}
|
||||
if (type != ESysProxyType.Pac)
|
||||
{
|
||||
PacHandler.Stop();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PacLib\PacLib.csproj" />
|
||||
<ProjectReference Include="..\ProtosLib\ProtosLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
Logging.SaveLog("MyAppExit Begin");
|
||||
//if (blWindowsShutDown)
|
||||
await _updateView?.Invoke(EViewAction.UpdateSysProxy, true);
|
||||
await SysProxyHandler.UpdateSysProxy(_config, true);
|
||||
|
||||
ConfigHandler.SaveConfig(_config);
|
||||
ProfileExHandler.Instance.SaveTo();
|
||||
|
@ -492,12 +492,13 @@ namespace ServiceLib.ViewModels
|
|||
|
||||
await LoadCore();
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.TestServerAvailability();
|
||||
await SysProxyHandler.UpdateSysProxy(_config, false);
|
||||
_updateView?.Invoke(EViewAction.DispatcherReload, null);
|
||||
}
|
||||
|
||||
public void ReloadResult()
|
||||
{
|
||||
//ChangeSystemProxyStatusAsync(_config.systemProxyItem.sysProxyType, false);
|
||||
//Locator.Current.GetService<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
|
||||
BlReloadEnabled = true;
|
||||
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
||||
if (ShowClashUI)
|
||||
|
|
|
@ -3,7 +3,6 @@ using ReactiveUI;
|
|||
using ReactiveUI.Fody.Helpers;
|
||||
using Splat;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceLib.ViewModels
|
||||
|
@ -318,10 +317,9 @@ namespace ServiceLib.ViewModels
|
|||
ConfigHandler.SaveConfig(_config, false);
|
||||
}
|
||||
|
||||
private async Task ChangeSystemProxyAsync(ESysProxyType type, bool blChange)
|
||||
public async Task ChangeSystemProxyAsync(ESysProxyType type, bool blChange)
|
||||
{
|
||||
//await _updateView?.Invoke(EViewAction.UpdateSysProxy, _config.tunModeItem.enableTun ? true : false);
|
||||
_updateView?.Invoke(EViewAction.UpdateSysProxy, false);
|
||||
await SysProxyHandler.UpdateSysProxy(_config, false);
|
||||
|
||||
BlSystemProxyClear = (type == ESysProxyType.ForcedClear);
|
||||
BlSystemProxySet = (type == ESysProxyType.ForcedChange);
|
||||
|
|
|
@ -6,7 +6,6 @@ using ReactiveUI;
|
|||
using Splat;
|
||||
using System.Reactive.Disposables;
|
||||
using v2rayN.Desktop.Common;
|
||||
using v2rayN.Desktop.Handler;
|
||||
|
||||
namespace v2rayN.Desktop.Views
|
||||
{
|
||||
|
@ -91,11 +90,6 @@ namespace v2rayN.Desktop.Views
|
|||
{
|
||||
switch (action)
|
||||
{
|
||||
case EViewAction.UpdateSysProxy:
|
||||
if (obj is null) return false;
|
||||
await SysProxyHandler.UpdateSysProxy(_config, (bool)obj);
|
||||
break;
|
||||
|
||||
case EViewAction.DispatcherServerAvailability:
|
||||
if (obj is null) return false;
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PacLib\PacLib.csproj" />
|
||||
<ProjectReference Include="..\ServiceLib\ServiceLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
using PacLib;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
{
|
||||
public static class SysProxyHandler
|
||||
{
|
||||
public static bool UpdateSysProxy(Config config, bool forceDisable)
|
||||
{
|
||||
var type = config.systemProxyItem.sysProxyType;
|
||||
|
||||
if (forceDisable && type != ESysProxyType.Unchanged)
|
||||
{
|
||||
type = ESysProxyType.ForcedClear;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http);
|
||||
int portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
|
||||
int portPac = AppHandler.Instance.GetLocalPort(EInboundProtocol.pac);
|
||||
if (port <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (type == ESysProxyType.ForcedChange)
|
||||
{
|
||||
var strExceptions = "";
|
||||
if (config.systemProxyItem.notProxyLocalAddress)
|
||||
{
|
||||
strExceptions = $"<local>;{config.constItem.defIEProxyExceptions};{config.systemProxyItem.systemProxyExceptions}";
|
||||
}
|
||||
|
||||
var strProxy = string.Empty;
|
||||
if (Utils.IsNullOrEmpty(config.systemProxyItem.systemProxyAdvancedProtocol))
|
||||
{
|
||||
strProxy = $"{Global.Loopback}:{port}";
|
||||
}
|
||||
else
|
||||
{
|
||||
strProxy = config.systemProxyItem.systemProxyAdvancedProtocol
|
||||
.Replace("{ip}", Global.Loopback)
|
||||
.Replace("{http_port}", port.ToString())
|
||||
.Replace("{socks_port}", portSocks.ToString());
|
||||
}
|
||||
ProxySettingWindows.SetProxy(strProxy, strExceptions, 2);
|
||||
}
|
||||
else if (type == ESysProxyType.ForcedClear)
|
||||
{
|
||||
ProxySettingWindows.UnsetProxy();
|
||||
}
|
||||
else if (type == ESysProxyType.Unchanged)
|
||||
{
|
||||
}
|
||||
else if (type == ESysProxyType.Pac)
|
||||
{
|
||||
PacHandler.Start(Utils.GetConfigPath(), port, portPac);
|
||||
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
|
||||
ProxySettingWindows.SetProxy(strProxy, "", 4);
|
||||
}
|
||||
|
||||
if (type != ESysProxyType.Pac)
|
||||
{
|
||||
PacHandler.Stop();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(ex.Message, ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -96,11 +96,6 @@ namespace v2rayN.Views
|
|||
Application.Current.MainWindow.Icon = WindowsHandler.Instance.GetAppIcon(_config);
|
||||
}), DispatcherPriority.Normal);
|
||||
break;
|
||||
|
||||
case EViewAction.UpdateSysProxy:
|
||||
if (obj is null) return false;
|
||||
SysProxyHandler.UpdateSysProxy(_config, (bool)obj);
|
||||
break;
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PacLib\PacLib.csproj" />
|
||||
<ProjectReference Include="..\ServiceLib\ServiceLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Reference in New Issue