reload config with api

This commit is contained in:
2dust
2022-08-11 20:17:23 +08:00
parent 2b6e4cd474
commit f42bec58fa
2 changed files with 29 additions and 6 deletions

View File

@@ -44,7 +44,8 @@ namespace clashN.Handler
return; return;
} }
SetCore(config, item);
SetCore(config, item, out bool blChanged);
string fileName = Utils.GetPath(coreConfigRes); string fileName = Utils.GetPath(coreConfigRes);
if (CoreConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0) if (CoreConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0)
{ {
@@ -54,7 +55,15 @@ namespace clashN.Handler
else else
{ {
ShowMsg(true, msg); ShowMsg(true, msg);
CoreRestart(item);
if (_process != null && !blChanged)
{
MainFormHandler.Instance.ClashConfigReload(fileName);
}
else
{
CoreRestart(item);
}
} }
} }
} }
@@ -261,17 +270,21 @@ namespace clashN.Handler
} }
} }
private int SetCore(Config config, ProfileItem item) private int SetCore(Config config, ProfileItem item, out bool blChanged)
{ {
blChanged = true;
if (item == null) if (item == null)
{ {
return -1; return -1;
} }
var coreType = LazyConfig.Instance.GetCoreType(item); var coreType = LazyConfig.Instance.GetCoreType(item);
var tempInfo = LazyConfig.Instance.GetCoreInfo(coreType);
if (tempInfo != null && coreInfo != null && tempInfo.coreType == coreInfo.coreType)
{
blChanged = false;
}
coreInfo = tempInfo;
coreInfo = LazyConfig.Instance.GetCoreInfo(coreType);
if (coreInfo == null) if (coreInfo == null)
{ {
return -1; return -1;

View File

@@ -357,5 +357,15 @@ namespace clashN.Handler
await HttpClientHelper.GetInstance().PatchAsync(urlBase, headers); await HttpClientHelper.GetInstance().PatchAsync(urlBase, headers);
}); });
} }
public async void ClashConfigReload( string filePath)
{
var url = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.GetConfig().APIPort}/configs";
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("path", filePath);
await HttpClientHelper.GetInstance().PutAsync(url, headers);
}
} }
} }