Skip to content

Commit f42bec5

Browse files
committed
reload config with api
1 parent 2b6e4cd commit f42bec5

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

clashN/clashN/Handler/CoreHandler.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public void LoadCore(Config config)
4444
return;
4545
}
4646

47-
SetCore(config, item);
47+
48+
SetCore(config, item, out bool blChanged);
4849
string fileName = Utils.GetPath(coreConfigRes);
4950
if (CoreConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0)
5051
{
@@ -54,7 +55,15 @@ public void LoadCore(Config config)
5455
else
5556
{
5657
ShowMsg(true, msg);
57-
CoreRestart(item);
58+
59+
if (_process != null && !blChanged)
60+
{
61+
MainFormHandler.Instance.ClashConfigReload(fileName);
62+
}
63+
else
64+
{
65+
CoreRestart(item);
66+
}
5867
}
5968
}
6069
}
@@ -261,17 +270,21 @@ private void KillProcess(Process p)
261270
}
262271
}
263272

264-
private int SetCore(Config config, ProfileItem item)
273+
private int SetCore(Config config, ProfileItem item, out bool blChanged)
265274
{
275+
blChanged = true;
266276
if (item == null)
267277
{
268278
return -1;
269279
}
270280
var coreType = LazyConfig.Instance.GetCoreType(item);
281+
var tempInfo = LazyConfig.Instance.GetCoreInfo(coreType);
282+
if (tempInfo != null && coreInfo != null && tempInfo.coreType == coreInfo.coreType)
283+
{
284+
blChanged = false;
285+
}
271286

272-
273-
coreInfo = LazyConfig.Instance.GetCoreInfo(coreType);
274-
287+
coreInfo = tempInfo;
275288
if (coreInfo == null)
276289
{
277290
return -1;

clashN/clashN/Handler/MainFormHandler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,15 @@ public void ClashConfigUpdate(Dictionary<string, string> headers)
357357
await HttpClientHelper.GetInstance().PatchAsync(urlBase, headers);
358358
});
359359
}
360+
361+
public async void ClashConfigReload( string filePath)
362+
{
363+
var url = $"{Global.httpProtocol}{Global.Loopback}:{LazyConfig.Instance.GetConfig().APIPort}/configs";
364+
Dictionary<string, string> headers = new Dictionary<string, string>();
365+
headers.Add("path", filePath);
366+
await HttpClientHelper.GetInstance().PutAsync(url, headers);
367+
368+
}
369+
360370
}
361371
}

0 commit comments

Comments
 (0)