diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index 2efce43..b9b0acf 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -296,7 +296,7 @@ public partial class MainWin : Window HoldButtonTimer.Tick += MihomoButtonHoldTimer_Tick; HoldButtonTimer.Start(); } - private void MihomoButtonHoldTimer_Tick(object? sender, EventArgs e) + private async void MihomoButtonHoldTimer_Tick(object? sender, EventArgs e) { HoldButtonTimer?.Stop(); @@ -312,9 +312,11 @@ public partial class MainWin : Window if (!File.Exists(confPath)) File.Create(confPath).Dispose(); + string extraConfs = File.ReadAllText(confPath); + Dictionary mihomoConfs = new DeserializerBuilder() .WithNamingConvention(HyphenatedNamingConvention.Instance) - .Build().Deserialize>(File.ReadAllText(confPath)) ?? []; ; + .Build().Deserialize>(extraConfs) ?? []; ; mihomoConfs["mixed-port"] = 7880; mihomoConfs["ipv6"] = true; @@ -344,6 +346,20 @@ public partial class MainWin : Window new MihomoProc().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "-d ."); + while (true) + try + { + await Http.GetAsync("http://localhost:7880", MainClient); + break; + } + catch (HttpRequestException ex) when (ex.InnerException is SocketException innerEx) + { + if (innerEx.SocketErrorCode != SocketError.ConnectionRefused) + break; + } + + File.WriteAllText(confPath, extraConfs); + if (sender == null) Application.Current.Dispatcher.InvokeShutdown(); }