Compare commits

..

No commits in common. "d3a0b44247ca1745158c16d6bb668a3ea3af3063" and "f685682214c7873ffaf9e19606afb7f36b123139" have entirely different histories.

6 changed files with 17 additions and 23 deletions

View file

@ -27,7 +27,7 @@
get
{
_statePort2 ??= Utils.GetFreePort(GetLocalPort(EInboundProtocol.api2));
return _statePort2.Value + (_config.TunModeItem.EnableTun ? 1 : 0);
return _statePort2.Value;
}
}
@ -79,13 +79,6 @@
return true;
}
public bool Reset()
{
_statePort = null;
_statePort2 = null;
return true;
}
#endregion Init
#region Config

View file

@ -97,12 +97,12 @@ namespace ServiceLib.Handler
{
if (_process != null)
{
_process = await KillProcess(_process);
await KillProcess(_process);
}
if (_processPre != null)
{
_processPre = await KillProcess(_processPre);
await KillProcess(_processPre);
}
if (_linuxSudoPid > 0)
@ -321,18 +321,17 @@ namespace ServiceLib.Handler
}
}
private async Task<Process?> KillProcess(Process? proc)
private async Task KillProcess(Process? proc)
{
if (proc is null)
{
return null;
return;
}
try { proc?.Kill(true); } catch { }
try { proc?.Close(); } catch { }
try { proc?.Dispose(); } catch { }
proc = null;
await Task.Delay(100);
return null;
}
#endregion Process
@ -395,7 +394,7 @@ namespace ServiceLib.Handler
private async Task<string> CreateLinuxShellFile(string cmdLine, string fileName)
{
//Shell scripts
var shFilePath = Utils.GetBinPath(AppHandler.Instance.IsAdministrator ? "root_" + fileName : fileName);
var shFilePath = Utils.GetBinPath(fileName);
File.Delete(shFilePath);
var sb = new StringBuilder();
sb.AppendLine("#!/bin/sh");

View file

@ -66,10 +66,10 @@
private static void GetWindowsProxyString(Config config, int port, int portSocks, out string strProxy, out string strExceptions)
{
strExceptions = $"{config.ConstItem.DefIEProxyExceptions};{config.SystemProxyItem.SystemProxyExceptions}";
strExceptions = "";
if (config.SystemProxyItem.NotProxyLocalAddress)
{
strExceptions = $"<local>;{strExceptions}";
strExceptions = $"<local>;{config.ConstItem.DefIEProxyExceptions};{config.SystemProxyItem.SystemProxyExceptions}";
}
strProxy = string.Empty;

View file

@ -8,9 +8,9 @@ namespace ServiceLib.Services.Statistics
private Config _config;
private bool _exitFlag;
private ClientWebSocket? webSocket;
private string url = string.Empty;
private Action<ServerSpeedItem>? _updateFunc;
private string Url => $"ws://{Global.Loopback}:{AppHandler.Instance.StatePort2}/traffic";
public StatisticsSingboxService(Config config, Action<ServerSpeedItem> updateFunc)
{
_config = config;
@ -26,10 +26,12 @@ namespace ServiceLib.Services.Statistics
try
{
url = $"ws://{Global.Loopback}:{AppHandler.Instance.StatePort2}/traffic";
if (webSocket == null)
{
webSocket = new ClientWebSocket();
await webSocket.ConnectAsync(new Uri(Url), CancellationToken.None);
await webSocket.ConnectAsync(new Uri(url), CancellationToken.None);
}
}
catch { }

View file

@ -3,17 +3,18 @@
public class StatisticsXrayService
{
private const long linkBase = 1024;
private string _url;
private ServerSpeedItem _serverSpeedItem = new();
private Config _config;
private bool _exitFlag;
private Action<ServerSpeedItem>? _updateFunc;
private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}/debug/vars";
public StatisticsXrayService(Config config, Action<ServerSpeedItem> updateFunc)
{
_config = config;
_updateFunc = updateFunc;
_exitFlag = false;
_url = $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}/debug/vars";
Task.Run(Run);
}
@ -35,7 +36,7 @@
continue;
}
var result = await HttpClientHelper.Instance.TryGetAsync(Url);
var result = await HttpClientHelper.Instance.TryGetAsync(_url);
if (result != null)
{
var server = ParseOutput(result) ?? new ServerSpeedItem();

View file

@ -356,7 +356,6 @@ namespace ServiceLib.ViewModels
if (await ConfigHandler.SaveConfig(_config) == 0)
{
await AutoStartupHandler.UpdateTask(_config);
AppHandler.Instance.Reset();
NoticeHandler.Instance.Enqueue(needReboot ? ResUI.NeedRebootTips : ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow, null);