diff --git a/v2rayN/ServiceLib/Enums/EViewAction.cs b/v2rayN/ServiceLib/Enums/EViewAction.cs
index d62943c6..18065310 100644
--- a/v2rayN/ServiceLib/Enums/EViewAction.cs
+++ b/v2rayN/ServiceLib/Enums/EViewAction.cs
@@ -7,7 +7,6 @@
SaveFileDialog,
AddBatchRoutingRulesYesNo,
AdjustMainLvColWidth,
- UpdateSysProxy,
SetClipboardData,
AddServerViaClipboard,
ImportRulesFromClipboard,
diff --git a/v2rayN/ServiceLib/GlobalUsings.cs b/v2rayN/ServiceLib/GlobalUsings.cs
index 23d2a064..a4bf3ccd 100644
--- a/v2rayN/ServiceLib/GlobalUsings.cs
+++ b/v2rayN/ServiceLib/GlobalUsings.cs
@@ -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;
\ No newline at end of file
+global using ServiceLib.Resx;
+global using ServiceLib.Handler.SysProxy;
\ No newline at end of file
diff --git a/v2rayN/v2rayN.Desktop/Common/ProxySettingLinux.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs
similarity index 99%
rename from v2rayN/v2rayN.Desktop/Common/ProxySettingLinux.cs
rename to v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs
index abde3751..a06d329b 100644
--- a/v2rayN/v2rayN.Desktop/Common/ProxySettingLinux.cs
+++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs
@@ -1,4 +1,4 @@
-namespace v2rayN.Desktop.Common
+namespace ServiceLib.Handler.SysProxy
{
public class ProxySettingLinux
{
diff --git a/v2rayN/v2rayN.Desktop/Common/ProxySettingOSX.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs
similarity index 82%
rename from v2rayN/v2rayN.Desktop/Common/ProxySettingOSX.cs
rename to v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs
index fbe05894..e2eb4e26 100644
--- a/v2rayN/v2rayN.Desktop/Common/ProxySettingOSX.cs
+++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs
@@ -1,4 +1,4 @@
-namespace v2rayN.Desktop.Common
+namespace ServiceLib.Handler.SysProxy
{
public class ProxySettingOSX
{
diff --git a/v2rayN/PacLib/ProxySettingWindows.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs
similarity index 98%
rename from v2rayN/PacLib/ProxySettingWindows.cs
rename to v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs
index bbcb3775..112e759c 100644
--- a/v2rayN/PacLib/ProxySettingWindows.cs
+++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs
@@ -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);
diff --git a/v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs
similarity index 82%
rename from v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs
rename to v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs
index 26163db2..98220cc0 100644
--- a/v2rayN/v2rayN.Desktop/Handler/SysProxyHandler.cs
+++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs
@@ -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)
{
diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj
index d9b47d73..26187ec7 100644
--- a/v2rayN/ServiceLib/ServiceLib.csproj
+++ b/v2rayN/ServiceLib/ServiceLib.csproj
@@ -43,6 +43,7 @@
+
diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
index 084e0f86..bf00f0d4 100644
--- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
@@ -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()?.TestServerAvailability();
+ await SysProxyHandler.UpdateSysProxy(_config, false);
_updateView?.Invoke(EViewAction.DispatcherReload, null);
}
public void ReloadResult()
{
- //ChangeSystemProxyStatusAsync(_config.systemProxyItem.sysProxyType, false);
+ //Locator.Current.GetService()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
BlReloadEnabled = true;
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
if (ShowClashUI)
diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
index a93500bc..315e7ebf 100644
--- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
@@ -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);
diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs
index 2fc63d8e..7e337452 100644
--- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs
+++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs
@@ -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(() =>
diff --git a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
index 2ed2ee1b..5319c903 100644
--- a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
+++ b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj
@@ -33,7 +33,6 @@
-
diff --git a/v2rayN/v2rayN/Handler/SysProxyHandler.cs b/v2rayN/v2rayN/Handler/SysProxyHandler.cs
deleted file mode 100644
index b61f0317..00000000
--- a/v2rayN/v2rayN/Handler/SysProxyHandler.cs
+++ /dev/null
@@ -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 = $";{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;
- }
- }
-}
\ No newline at end of file
diff --git a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs
index f1e8c09a..ea53a556 100644
--- a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs
+++ b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs
@@ -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);
}
diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj
index 66d3e499..274ea8b8 100644
--- a/v2rayN/v2rayN/v2rayN.csproj
+++ b/v2rayN/v2rayN/v2rayN.csproj
@@ -36,7 +36,6 @@
-