Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Apr 13, 2023
1 parent e41dc25 commit d1a2ad6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions clashN/clashN/Handler/CoreHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void LoadCore(Config config)
private void CoreRestart(ProfileItem item)
{
CoreStop();
Thread.Sleep(1000);
CoreStart(item);
}

Expand Down
21 changes: 13 additions & 8 deletions clashN/clashN/Handler/MainFormHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ private async Task GetClashProxiesAsync(Config config, Action<ClashProxies, Clas
{
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 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 clashProviders = Utils.FromJson<ClashProviders>(result2);

Expand Down Expand Up @@ -261,7 +261,7 @@ public void ClashProxiesDelayTest(bool blAll, List<ProxyModel> lstProxy, Action<
{
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;

List<Task> tasks = new List<Task>();
Expand Down Expand Up @@ -320,7 +320,7 @@ public async void ClashSetActiveProxy(string name, string nameNode)
{
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>();
headers.Add("name", nameNode);
await HttpClientHelper.GetInstance().PutAsync(url, headers);
Expand All @@ -341,7 +341,7 @@ public void ClashConfigUpdate(Dictionary<string, string> headers)
return;
}

var urlBase = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/configs";
var urlBase = $"{GetApiUrl()}/configs";

await HttpClientHelper.GetInstance().PatchAsync(urlBase, headers);
});
Expand All @@ -352,7 +352,7 @@ public async void ClashConfigReload(string filePath)
ClashConnectionClose("");
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>();
headers.Add("path", filePath);
await HttpClientHelper.GetInstance().PutAsync(url, headers);
Expand All @@ -371,7 +371,7 @@ private async Task GetClashConnectionsAsync(Config config, Action<ClashConnectio
{
try
{
var url = $"{Global.httpProtocol}{Global.Loopback}:{config.ApiPort}/connections";
var url = $"{GetApiUrl()}/connections";
var result = await HttpClientHelper.GetInstance().TryGetAsync(url);
var clashConnections = Utils.FromJson<ClashConnections>(result);

Expand All @@ -387,13 +387,18 @@ public async void ClashConnectionClose(string id)
{
try
{
var url = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}/connections/{id}";
var url = $"{GetApiUrl()}/connections/";
await HttpClientHelper.GetInstance().DeleteAsync(url);
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
}

private string GetApiUrl()
{
return $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.Config.ApiPort}";
}
}
}

0 comments on commit d1a2ad6

Please sign in to comment.