diff --git a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs index 0139d3fe..c7606c0f 100644 --- a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs +++ b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs @@ -16,6 +16,14 @@ public record CoreConfigContextBuilderAllResult( /// True only when both the main result and (if present) the pre-socks result succeeded. public bool Success => MainResult.Success && (PreSocksResult?.Success ?? true); + /// + /// Merges all errors and warnings from the main result and the optional pre-socks result + /// into a single for unified notification. + /// + public NodeValidatorResult CombinedValidatorResult => new( + [.. MainResult.ValidatorResult.Errors, .. PreSocksResult?.ValidatorResult.Errors ?? []], + [.. MainResult.ValidatorResult.Warnings, .. PreSocksResult?.ValidatorResult.Warnings ?? []]); + /// /// The main context with TunProtectSsPort/ProxyRelaySsPort merged in from the /// pre-socks result (if any). Pass this to the core runner. diff --git a/v2rayN/ServiceLib/Manager/NoticeManager.cs b/v2rayN/ServiceLib/Manager/NoticeManager.cs index da034f02..184ef79c 100644 --- a/v2rayN/ServiceLib/Manager/NoticeManager.cs +++ b/v2rayN/ServiceLib/Manager/NoticeManager.cs @@ -38,4 +38,25 @@ public class NoticeManager Enqueue(msg); SendMessage(msg); } + + /// + /// Sends each error and warning in to the message panel + /// and enqueues a summary snack notification (capped at 10 messages). + /// Returns true when there were any messages so the caller can decide on early-return + /// based on . + /// + public bool NotifyValidatorResult(NodeValidatorResult validatorResult) + { + var msgs = new List([.. validatorResult.Errors, .. validatorResult.Warnings]); + if (msgs.Count == 0) + { + return false; + } + foreach (var msg in msgs) + { + SendMessage(msg); + } + Enqueue(Utils.List2String(msgs.Take(10).ToList(), true)); + return true; + } } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index fedfbe9d..0bd0c588 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -547,23 +547,9 @@ public class MainWindowViewModel : MyReactiveObject return; } var allResult = await CoreConfigContextBuilder.BuildAll(_config, profileItem); - var msgs = new List([.. allResult.MainResult.ValidatorResult.Errors, .. allResult.MainResult.ValidatorResult.Warnings]); - if (allResult.PreSocksResult is not null) + if (NoticeManager.Instance.NotifyValidatorResult(allResult.CombinedValidatorResult) && !allResult.Success) { - msgs.AddRange(allResult.PreSocksResult.ValidatorResult.Errors); - msgs.AddRange(allResult.PreSocksResult.ValidatorResult.Warnings); - } - if (msgs.Count > 0) - { - foreach (var msg in msgs) - { - NoticeManager.Instance.SendMessage(msg); - } - NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true)); - if (!allResult.Success) - { - return; - } + return; } await Task.Run(async () => diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 1cc6f46e..8284bb46 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -789,18 +789,9 @@ public class ProfilesViewModel : MyReactiveObject } var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item); - var msgs = new List([..validatorResult.Errors, ..validatorResult.Warnings]); - if (msgs.Count > 0) + if (NoticeManager.Instance.NotifyValidatorResult(validatorResult) && !validatorResult.Success) { - foreach (var msg in msgs) - { - NoticeManager.Instance.SendMessage(msg); - } - NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true)); - if (!validatorResult.Success) - { - return; - } + return; } if (blClipboard) @@ -829,18 +820,9 @@ public class ProfilesViewModel : MyReactiveObject return; } var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item); - var msgs = new List([..validatorResult.Errors, ..validatorResult.Warnings]); - if (msgs.Count > 0) + if (NoticeManager.Instance.NotifyValidatorResult(validatorResult) && !validatorResult.Success) { - foreach (var msg in msgs) - { - NoticeManager.Instance.SendMessage(msg); - } - NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true)); - if (!validatorResult.Success) - { - return; - } + return; } var result = await CoreConfigHandler.GenerateClientConfig(context, fileName); if (result.Success != true)