diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs index e5d5b594..7e90e6ca 100644 --- a/v2rayN/v2rayN/Handler/UpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs @@ -286,8 +286,8 @@ namespace v2rayN.Handler await UpdateGeoFile("geosite", _config, update); await UpdateGeoFile("geoip", _config, update); - await UpdateGeoFile4Singbox("geosite", _config, update); - await UpdateGeoFile4Singbox("geoip", _config, update); + await UpdateGeoFile4Singbox("geosite", _config, false, update); + await UpdateGeoFile4Singbox("geoip", _config, true, update); }); } @@ -602,7 +602,7 @@ namespace v2rayN.Handler await askToDownload(downloadHandle, url, false); } - private async Task UpdateGeoFile4Singbox(string geoName, Config config, Action update) + private async Task UpdateGeoFile4Singbox(string geoName, Config config, bool needStop, Action update) { _config = config; _updateFunc = update; @@ -614,9 +614,11 @@ namespace v2rayN.Handler if (args.Success) { _updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName)); + var coreHandler = Locator.Current.GetService(); try { + if (needStop) coreHandler?.CoreStop(); string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url)); if (File.Exists(fileName)) { @@ -625,6 +627,7 @@ namespace v2rayN.Handler File.Delete(fileName); } + if (needStop) coreHandler?.LoadCore(); } catch (Exception ex) { diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 3c4b3f8d..1e90d7aa 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -558,6 +558,7 @@ namespace v2rayN.ViewModels ConfigHandler.InitBuiltinRouting(ref _config); ConfigHandler.InitBuiltinDNS(_config); _coreHandler = new CoreHandler(_config, UpdateHandler); + Locator.CurrentMutable.RegisterLazySingleton(() => _coreHandler, typeof(CoreHandler)); if (_config.guiItem.enableStatistics) {