bug fixes

This commit is contained in:
2dust
2023-04-13 11:08:50 +08:00
parent e41dc25969
commit d1a2ad612c
2 changed files with 14 additions and 8 deletions

View File

@@ -78,6 +78,7 @@ namespace ClashN.Handler
private void CoreRestart(ProfileItem item) private void CoreRestart(ProfileItem item)
{ {
CoreStop(); CoreStop();
Thread.Sleep(1000);
CoreStart(item); CoreStart(item);
} }

View File

@@ -205,11 +205,11 @@ namespace ClashN.Handler
{ {
for (var i = 0; i < 5; i++) for (var i = 0; i < 5; i++)
{ {
var url = $"{Global.httpProtocol}{Global.Loopback}:{config.ApiPort}/proxies"; var url = $"{GetApiUrl()}/proxies";
var result = await HttpClientHelper.GetInstance().TryGetAsync(url); var result = await HttpClientHelper.GetInstance().TryGetAsync(url);
var clashProxies = Utils.FromJson<ClashProxies>(result); var clashProxies = Utils.FromJson<ClashProxies>(result);
var url2 = $"{Global.httpProtocol}{Global.Loopback}:{config.ApiPort}/providers/proxies"; var url2 = $"{GetApiUrl()}/providers/proxies";
var result2 = await HttpClientHelper.GetInstance().TryGetAsync(url2); var result2 = await HttpClientHelper.GetInstance().TryGetAsync(url2);
var clashProviders = Utils.FromJson<ClashProviders>(result2); var clashProviders = Utils.FromJson<ClashProviders>(result2);
@@ -261,7 +261,7 @@ namespace ClashN.Handler
{ {
return; return;
} }
var urlBase = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/proxies"; var urlBase = $"{GetApiUrl()}/proxies";
urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.Config.ConstItem.speedPingTestUrl; urlBase += @"/{0}/delay?timeout=10000&url=" + LazyConfig.Instance.Config.ConstItem.speedPingTestUrl;
List<Task> tasks = new List<Task>(); List<Task> tasks = new List<Task>();
@@ -320,7 +320,7 @@ namespace ClashN.Handler
{ {
try try
{ {
var url = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/proxies/{name}"; var url = $"{GetApiUrl()}/proxies/";
Dictionary<string, string> headers = new Dictionary<string, string>(); Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("name", nameNode); headers.Add("name", nameNode);
await HttpClientHelper.GetInstance().PutAsync(url, headers); await HttpClientHelper.GetInstance().PutAsync(url, headers);
@@ -341,7 +341,7 @@ namespace ClashN.Handler
return; return;
} }
var urlBase = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/configs"; var urlBase = $"{GetApiUrl()}/configs";
await HttpClientHelper.GetInstance().PatchAsync(urlBase, headers); await HttpClientHelper.GetInstance().PatchAsync(urlBase, headers);
}); });
@@ -352,7 +352,7 @@ namespace ClashN.Handler
ClashConnectionClose(""); ClashConnectionClose("");
try try
{ {
var url = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/configs?force=true"; var url = $"{GetApiUrl()}/configs?force=true";
Dictionary<string, string> headers = new Dictionary<string, string>(); Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("path", filePath); headers.Add("path", filePath);
await HttpClientHelper.GetInstance().PutAsync(url, headers); await HttpClientHelper.GetInstance().PutAsync(url, headers);
@@ -371,7 +371,7 @@ namespace ClashN.Handler
{ {
try try
{ {
var url = $"{Global.httpProtocol}{Global.Loopback}:{config.ApiPort}/connections"; var url = $"{GetApiUrl()}/connections";
var result = await HttpClientHelper.GetInstance().TryGetAsync(url); var result = await HttpClientHelper.GetInstance().TryGetAsync(url);
var clashConnections = Utils.FromJson<ClashConnections>(result); var clashConnections = Utils.FromJson<ClashConnections>(result);
@@ -387,7 +387,7 @@ namespace ClashN.Handler
{ {
try try
{ {
var url = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/connections/{id}"; var url = $"{GetApiUrl()}/connections/";
await HttpClientHelper.GetInstance().DeleteAsync(url); await HttpClientHelper.GetInstance().DeleteAsync(url);
} }
catch (Exception ex) catch (Exception ex)
@@ -395,5 +395,10 @@ namespace ClashN.Handler
Utils.SaveLog(ex.Message, ex); Utils.SaveLog(ex.Message, ex);
} }
} }
private string GetApiUrl()
{
return $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}";
}
} }
} }