Skip to content
Merged

Fix #8864

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions v2rayN/ServiceLib/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ public static async Task<RetResult> AddGroupServer4Multiple(Config config, List<
return itemSocks;
}

public static CoreConfigContext? GetPreSocksCoreConfigContext(CoreConfigContext nodeContext)
public static async Task<CoreConfigContextBuilderResult?> GetPreSocksCoreConfigContext(CoreConfigContext nodeContext)
{
var config = nodeContext.AppConfig;
var node = nodeContext.Node;
Expand All @@ -1260,7 +1260,15 @@ public static async Task<RetResult> AddGroupServer4Multiple(Config config, List<
var preSocksItem = GetPreSocksItem(config, node, coreType);
if (preSocksItem != null)
{
return nodeContext with { Node = preSocksItem, };
var preSocksResult = await CoreConfigContextBuilder.Build(nodeContext.AppConfig, preSocksItem);
// share protect domain
var protectDomainList = nodeContext.ProtectDomainList ?? [];
protectDomainList.UnionWith(preSocksResult.Context.ProtectDomainList ?? []);
preSocksResult = preSocksResult with
{
Context = preSocksResult.Context with { ProtectDomainList = protectDomainList, }
};
return preSocksResult;
}

if ((!nodeContext.IsTunEnabled)
Expand All @@ -1283,13 +1291,20 @@ public static async Task<RetResult> AddGroupServer4Multiple(Config config, List<
{
SsMethod = Global.None,
});
var preContext = nodeContext with
var preResult = await CoreConfigContextBuilder.Build(nodeContext.AppConfig, preItem);
// share protect domain
var protectDomainList2 = nodeContext.ProtectDomainList ?? [];
protectDomainList2.UnionWith(preResult.Context.ProtectDomainList ?? []);
preResult = preResult with
{
Node = preItem,
TunProtectSsPort = tunProtectSsPort,
ProxyRelaySsPort = proxyRelaySsPort,
Context = preResult.Context with
{
ProtectDomainList = protectDomainList2,
TunProtectSsPort = tunProtectSsPort,
ProxyRelaySsPort = proxyRelaySsPort,
}
};
return preContext;
return preResult;
}

/// <summary>
Expand Down
20 changes: 19 additions & 1 deletion v2rayN/ServiceLib/Manager/CoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,25 @@ public async Task LoadCore(CoreConfigContext? context)
var contextMod = context;
var node = contextMod.Node;
var fileName = Utils.GetBinConfigPath(Global.CoreConfigFileName);
var preContext = ConfigHandler.GetPreSocksCoreConfigContext(contextMod);
var preResult = await ConfigHandler.GetPreSocksCoreConfigContext(contextMod);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetPreSocksCoreConfigContext 是在这里获取的,
但是 var (context, validatorResult) = await CoreConfigContextBuilder.Build(_config, profileItem); 是在 MainWindowViewModel.Reload 获取 , 感觉有点不优雅了

if (preResult is not null)
{
var validatorResult = preResult.ValidatorResult;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

刚好这里也用到了,类似下面的代码,是否可以复用?

var msgs = new List<string>([..validatorResult.Errors, ..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 (!validatorResult.Success)
    {
        return;
    }
}

var msgs = new List<string>([.. validatorResult.Errors, .. validatorResult.Warnings]);
if (msgs.Count > 0)
{
foreach (var msg in msgs)
{
await UpdateFunc(false, msg);
}
await UpdateFunc(true, Utils.List2String(msgs.Take(10).ToList(), true));
if (!validatorResult.Success)
{
return;
}
}
}
var preContext = preResult?.Context;
if (preContext is not null)
{
contextMod = contextMod with
Expand Down