mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-18 05:25: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>
|
/// <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);
|
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>
|
/// <summary>
|
||||||
/// The main context with TunProtectSsPort/ProxyRelaySsPort merged in from the
|
/// The main context with TunProtectSsPort/ProxyRelaySsPort merged in from the
|
||||||
/// pre-socks result (if any). Pass this to the core runner.
|
/// pre-socks result (if any). Pass this to the core runner.
|
||||||
|
|
|
||||||
|
|
@ -38,4 +38,25 @@ public class NoticeManager
|
||||||
Enqueue(msg);
|
Enqueue(msg);
|
||||||
SendMessage(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;
|
return;
|
||||||
}
|
}
|
||||||
var allResult = await CoreConfigContextBuilder.BuildAll(_config, profileItem);
|
var allResult = await CoreConfigContextBuilder.BuildAll(_config, profileItem);
|
||||||
var msgs = new List<string>([.. allResult.MainResult.ValidatorResult.Errors, .. allResult.MainResult.ValidatorResult.Warnings]);
|
if (NoticeManager.Instance.NotifyValidatorResult(allResult.CombinedValidatorResult) && !allResult.Success)
|
||||||
if (allResult.PreSocksResult is not null)
|
|
||||||
{
|
{
|
||||||
msgs.AddRange(allResult.PreSocksResult.ValidatorResult.Errors);
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
|
|
|
||||||
|
|
@ -789,18 +789,9 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
|
|
||||||
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
|
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
|
||||||
var msgs = new List<string>([..validatorResult.Errors, ..validatorResult.Warnings]);
|
if (NoticeManager.Instance.NotifyValidatorResult(validatorResult) && !validatorResult.Success)
|
||||||
if (msgs.Count > 0)
|
|
||||||
{
|
{
|
||||||
foreach (var msg in msgs)
|
return;
|
||||||
{
|
|
||||||
NoticeManager.Instance.SendMessage(msg);
|
|
||||||
}
|
|
||||||
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
|
|
||||||
if (!validatorResult.Success)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blClipboard)
|
if (blClipboard)
|
||||||
|
|
@ -829,18 +820,9 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
|
var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, item);
|
||||||
var msgs = new List<string>([..validatorResult.Errors, ..validatorResult.Warnings]);
|
if (NoticeManager.Instance.NotifyValidatorResult(validatorResult) && !validatorResult.Success)
|
||||||
if (msgs.Count > 0)
|
|
||||||
{
|
{
|
||||||
foreach (var msg in msgs)
|
return;
|
||||||
{
|
|
||||||
NoticeManager.Instance.SendMessage(msg);
|
|
||||||
}
|
|
||||||
NoticeManager.Instance.Enqueue(Utils.List2String(msgs.Take(10).ToList(), true));
|
|
||||||
if (!validatorResult.Success)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var result = await CoreConfigHandler.GenerateClientConfig(context, fileName);
|
var result = await CoreConfigHandler.GenerateClientConfig(context, fileName);
|
||||||
if (result.Success != true)
|
if (result.Success != true)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue