mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-16 12:35:46 +00:00
Notify validator result
This commit is contained in:
parent
624728dbe7
commit
8b486f9f50
4 changed files with 35 additions and 38 deletions
|
|
@ -16,6 +16,14 @@ public record CoreConfigContextBuilderAllResult(
|
|||
/// <summary>True only when both the main result and (if present) the pre-socks result succeeded.</summary>
|
||||
public bool Success => MainResult.Success && (PreSocksResult?.Success ?? true);
|
||||
|
||||
/// <summary>
|
||||
/// Merges all errors and warnings from the main result and the optional pre-socks result
|
||||
/// into a single <see cref="NodeValidatorResult"/> for unified notification.
|
||||
/// </summary>
|
||||
public NodeValidatorResult CombinedValidatorResult => new(
|
||||
[.. MainResult.ValidatorResult.Errors, .. PreSocksResult?.ValidatorResult.Errors ?? []],
|
||||
[.. MainResult.ValidatorResult.Warnings, .. PreSocksResult?.ValidatorResult.Warnings ?? []]);
|
||||
|
||||
/// <summary>
|
||||
/// The main context with TunProtectSsPort/ProxyRelaySsPort merged in from the
|
||||
/// pre-socks result (if any). Pass this to the core runner.
|
||||
|
|
|
|||
|
|
@ -38,4 +38,25 @@ public class NoticeManager
|
|||
Enqueue(msg);
|
||||
SendMessage(msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends each error and warning in <paramref name="validatorResult"/> to the message panel
|
||||
/// and enqueues a summary snack notification (capped at 10 messages).
|
||||
/// Returns <c>true</c> when there were any messages so the caller can decide on early-return
|
||||
/// based on <see cref="NodeValidatorResult.Success"/>.
|
||||
/// </summary>
|
||||
public bool NotifyValidatorResult(NodeValidatorResult validatorResult)
|
||||
{
|
||||
var msgs = new List<string>([.. 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -547,23 +547,9 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
return;
|
||||
}
|
||||
var allResult = await CoreConfigContextBuilder.BuildAll(_config, profileItem);
|
||||
var msgs = new List<string>([.. 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 () =>
|
||||
|
|
|
|||
|
|
@ -789,18 +789,9 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
}
|
||||
|
||||
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
|
||||
var msgs = new List<string>([..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<string>([..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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue