mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-26 18:24:43 +00:00
Compare commits
2 commits
8ac9499d8c
...
ce438d8f18
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce438d8f18 | ||
|
|
d44459eb2f |
32 changed files with 399 additions and 436 deletions
|
|
@ -20,11 +20,11 @@
|
|||
<PackageVersion Include="ReactiveUI.WPF" Version="20.4.1" />
|
||||
<PackageVersion Include="Semi.Avalonia" Version="11.2.1.10" />
|
||||
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.2.1.10" />
|
||||
<PackageVersion Include="Splat.NLog" Version="17.0.1" />
|
||||
<PackageVersion Include="Splat.NLog" Version="16.2.1" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
<PackageVersion Include="TaskScheduler" Version="2.12.2" />
|
||||
<PackageVersion Include="WebDav.Client" Version="2.9.0" />
|
||||
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
|
||||
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
@ -6,22 +6,16 @@ namespace ServiceLib.Handler;
|
|||
public static class AppEvents
|
||||
{
|
||||
public static readonly Subject<Unit> ProfilesRefreshRequested = new();
|
||||
public static readonly Subject<Unit> SubscriptionsRefreshRequested = new();
|
||||
public static readonly Subject<Unit> ProxiesReloadRequested = new();
|
||||
public static readonly Subject<ServerSpeedItem> DispatcherStatisticsRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendSnackMsgRequested = new();
|
||||
|
||||
public static readonly Subject<string> SendMsgViewRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> AppExitRequested = new();
|
||||
|
||||
public static readonly Subject<bool> ShutdownRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> AdjustMainLvColWidthRequested = new();
|
||||
|
||||
public static readonly Subject<string> SetDefaultServerRequested = new();
|
||||
|
||||
public static readonly Subject<Unit> RoutingsMenuRefreshRequested = new();
|
||||
public static readonly Subject<Unit> TestServerRequested = new();
|
||||
public static readonly Subject<Unit> InboundDisplayRequested = new();
|
||||
public static readonly Subject<ESysProxyType> SysProxyChangeRequested = new();
|
||||
public static readonly Subject<ServerSpeedItem> DispatcherStatisticsRequested = new();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1251,7 +1251,7 @@ public static class ConfigHandler
|
|||
public static async Task<ProfileItem?> GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
|
||||
{
|
||||
ProfileItem? itemSocks = null;
|
||||
if (node.ConfigType != EConfigType.Custom && coreType != ECoreType.sing_box && config.TunModeItem.EnableTun)
|
||||
if (node.ConfigType != EConfigType.Custom && node.ConfigType < EConfigType.Group && coreType != ECoreType.sing_box && config.TunModeItem.EnableTun)
|
||||
{
|
||||
itemSocks = new ProfileItem()
|
||||
{
|
||||
|
|
@ -1262,7 +1262,7 @@ public static class ConfigHandler
|
|||
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||
};
|
||||
}
|
||||
else if (node.ConfigType == EConfigType.Custom && node.PreSocksPort > 0)
|
||||
else if (node.ConfigType == EConfigType.Custom && node.ConfigType < EConfigType.Group && node.PreSocksPort > 0)
|
||||
{
|
||||
var preCoreType = config.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
|
||||
itemSocks = new ProfileItem()
|
||||
|
|
|
|||
|
|
@ -32,19 +32,19 @@ public class ProfileItem : ReactiveObject
|
|||
public string GetSummary()
|
||||
{
|
||||
var summary = $"[{(ConfigType).ToString()}] ";
|
||||
if (IsComplex())
|
||||
var arrAddr = Address.Contains(':') ? Address.Split(':') : Address.Split('.');
|
||||
var addr = arrAddr.Length switch
|
||||
{
|
||||
> 2 => $"{arrAddr.First()}***{arrAddr.Last()}",
|
||||
> 1 => $"***{arrAddr.Last()}",
|
||||
_ => Address
|
||||
};
|
||||
if (ConfigType is EConfigType.Custom or > EConfigType.Group)
|
||||
{
|
||||
summary += $"[{CoreType.ToString()}]{Remarks}";
|
||||
}
|
||||
else
|
||||
{
|
||||
var arrAddr = Address.Contains(':') ? Address.Split(':') : Address.Split('.');
|
||||
var addr = arrAddr.Length switch
|
||||
{
|
||||
> 2 => $"{arrAddr.First()}***{arrAddr.Last()}",
|
||||
> 1 => $"***{arrAddr.Last()}",
|
||||
_ => Address
|
||||
};
|
||||
summary += $"{Remarks}({addr}:{Port})";
|
||||
}
|
||||
return summary;
|
||||
|
|
@ -64,51 +64,6 @@ public class ProfileItem : ReactiveObject
|
|||
return Network.TrimEx();
|
||||
}
|
||||
|
||||
public bool IsComplex()
|
||||
{
|
||||
return ConfigType is EConfigType.Custom or > EConfigType.Group;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
if (IsComplex())
|
||||
return true;
|
||||
|
||||
if (Address.IsNullOrEmpty() || Port is <= 0 or >= 65536)
|
||||
return false;
|
||||
|
||||
switch (ConfigType)
|
||||
{
|
||||
case EConfigType.VMess:
|
||||
if (Id.IsNullOrEmpty() || !Utils.IsGuidByParse(Id))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case EConfigType.VLESS:
|
||||
if (Id.IsNullOrEmpty() || (!Utils.IsGuidByParse(Id) && Id.Length > 30))
|
||||
return false;
|
||||
if (!Global.Flows.Contains(Flow))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case EConfigType.Shadowsocks:
|
||||
if (Id.IsNullOrEmpty())
|
||||
return false;
|
||||
if (string.IsNullOrEmpty(Security) || !Global.SsSecuritiesInSingbox.Contains(Security))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ConfigType is EConfigType.VLESS or EConfigType.Trojan)
|
||||
&& StreamSecurity == Global.StreamSecurityReality
|
||||
&& PublicKey.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion function
|
||||
|
||||
[PrimaryKey]
|
||||
|
|
|
|||
18
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
18
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
|
@ -303,15 +303,6 @@ namespace ServiceLib.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 The group "{0}" cannot reference itself. 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string GroupSelfReference {
|
||||
get {
|
||||
return ResourceManager.GetString("GroupSelfReference", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 This is not the correct configuration, please check 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
@ -339,15 +330,6 @@ namespace ServiceLib.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 The {0} property is invalid, please check. 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string InvalidProperty {
|
||||
get {
|
||||
return ResourceManager.GetString("InvalidProperty", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Invalid address (URL) 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1587,10 +1587,4 @@
|
|||
<data name="GroupEmpty" xml:space="preserve">
|
||||
<value>Group '{0}' is empty. Please add at least one node.</value>
|
||||
</data>
|
||||
<data name="InvalidProperty" xml:space="preserve">
|
||||
<value>The {0} property is invalid, please check.</value>
|
||||
</data>
|
||||
<data name="GroupSelfReference" xml:space="preserve">
|
||||
<value>The group "{0}" cannot reference itself.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -1587,10 +1587,4 @@
|
|||
<data name="GroupEmpty" xml:space="preserve">
|
||||
<value>Group '{0}' is empty. Please add at least one node.</value>
|
||||
</data>
|
||||
<data name="InvalidProperty" xml:space="preserve">
|
||||
<value>The {0} property is invalid, please check.</value>
|
||||
</data>
|
||||
<data name="GroupSelfReference" xml:space="preserve">
|
||||
<value>The group "{0}" cannot reference itself.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -1587,10 +1587,4 @@
|
|||
<data name="GroupEmpty" xml:space="preserve">
|
||||
<value>Group '{0}' is empty. Please add at least one node.</value>
|
||||
</data>
|
||||
<data name="InvalidProperty" xml:space="preserve">
|
||||
<value>The {0} property is invalid, please check.</value>
|
||||
</data>
|
||||
<data name="GroupSelfReference" xml:space="preserve">
|
||||
<value>The group "{0}" cannot reference itself.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -1587,10 +1587,4 @@
|
|||
<data name="GroupEmpty" xml:space="preserve">
|
||||
<value>Group '{0}' is empty. Please add at least one node.</value>
|
||||
</data>
|
||||
<data name="InvalidProperty" xml:space="preserve">
|
||||
<value>The {0} property is invalid, please check.</value>
|
||||
</data>
|
||||
<data name="GroupSelfReference" xml:space="preserve">
|
||||
<value>The group "{0}" cannot reference itself.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -1584,10 +1584,4 @@
|
|||
<data name="GroupEmpty" xml:space="preserve">
|
||||
<value>组“{0}”为空。请至少添加一个节点。</value>
|
||||
</data>
|
||||
<data name="InvalidProperty" xml:space="preserve">
|
||||
<value>{0}属性无效,请检查</value>
|
||||
</data>
|
||||
<data name="GroupSelfReference" xml:space="preserve">
|
||||
<value>{0} 分组不能引用自身</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -1584,10 +1584,4 @@
|
|||
<data name="GroupEmpty" xml:space="preserve">
|
||||
<value>Group '{0}' is empty. Please add at least one node.</value>
|
||||
</data>
|
||||
<data name="InvalidProperty" xml:space="preserve">
|
||||
<value>The {0} property is invalid, please check.</value>
|
||||
</data>
|
||||
<data name="GroupSelfReference" xml:space="preserve">
|
||||
<value>The group "{0}" cannot reference itself.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -65,56 +65,6 @@ public class ActionPrecheckService(Config config)
|
|||
return errors;
|
||||
}
|
||||
|
||||
if (!item.IsComplex())
|
||||
{
|
||||
if (item.Address.IsNullOrEmpty())
|
||||
{
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Address"));
|
||||
return errors;
|
||||
}
|
||||
|
||||
if (item.Port is <= 0 or >= 65536)
|
||||
{
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Port"));
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
||||
switch (item.ConfigType)
|
||||
{
|
||||
case EConfigType.VMess:
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Id"));
|
||||
break;
|
||||
|
||||
case EConfigType.VLESS:
|
||||
if (item.Id.IsNullOrEmpty() || (!Utils.IsGuidByParse(item.Id) && item.Id.Length > 30))
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Id"));
|
||||
if (!Global.Flows.Contains(item.Flow))
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Flow"));
|
||||
break;
|
||||
|
||||
case EConfigType.Shadowsocks:
|
||||
if (item.Id.IsNullOrEmpty())
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Id"));
|
||||
if (string.IsNullOrEmpty(item.Security) || !Global.SsSecuritiesInSingbox.Contains(item.Security))
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "Security"));
|
||||
break;
|
||||
}
|
||||
|
||||
if ((item.ConfigType is EConfigType.VLESS or EConfigType.Trojan)
|
||||
&& item.StreamSecurity == Global.StreamSecurityReality
|
||||
&& item.PublicKey.IsNullOrEmpty())
|
||||
{
|
||||
errors.Add(string.Format(ResUI.InvalidProperty, "PublicKey"));
|
||||
}
|
||||
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
ProfileGroupItemManager.Instance.TryGet(item.IndexId, out var group);
|
||||
|
|
@ -126,7 +76,6 @@ public class ActionPrecheckService(Config config)
|
|||
|
||||
foreach (var child in Utils.String2List(group.ChildItems))
|
||||
{
|
||||
var childErrors = new List<string>();
|
||||
if (child.IsNullOrEmpty())
|
||||
{
|
||||
continue;
|
||||
|
|
@ -135,24 +84,11 @@ public class ActionPrecheckService(Config config)
|
|||
var childItem = await AppManager.Instance.GetProfileItem(child);
|
||||
if (childItem is null)
|
||||
{
|
||||
childErrors.Add(string.Format(ResUI.NodeTagNotExist, child));
|
||||
errors.Add(string.Format(ResUI.NodeTagNotExist, child));
|
||||
continue;
|
||||
}
|
||||
|
||||
// self-reference check
|
||||
if (childItem.IndexId == item.IndexId)
|
||||
{
|
||||
childErrors.Add(string.Format(ResUI.GroupSelfReference, childItem.Remarks));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (childItem.ConfigType is EConfigType.Custom or EConfigType.ProxyChain)
|
||||
{
|
||||
childErrors.Add(string.Format(ResUI.InvalidProperty, childItem.Remarks));
|
||||
continue;
|
||||
}
|
||||
|
||||
childErrors.AddRange(await ValidateNodeAndCoreSupport(childItem, coreType));
|
||||
|
||||
var childErrors = await ValidateNodeAndCoreSupport(childItem, coreType);
|
||||
errors.AddRange(childErrors);
|
||||
}
|
||||
return errors;
|
||||
|
|
@ -187,7 +123,7 @@ public class ActionPrecheckService(Config config)
|
|||
}
|
||||
}
|
||||
|
||||
return errors.Select(s => $"{item.Remarks}: {s}").ToList();
|
||||
return errors;
|
||||
}
|
||||
|
||||
private async Task<List<string>> ValidateRelatedNodesExistAndValid(ProfileItem? item)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,35 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
var ret = new RetResult();
|
||||
try
|
||||
{
|
||||
if (node?.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem == null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
)).Where(p => p != null).ToList();
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
}
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
return await GenerateClientMultipleLoadConfig(childProfiles, profileGroupItem.MultipleLoad);
|
||||
case EConfigType.ProxyChain:
|
||||
return await GenerateClientChainConfig(childProfiles);
|
||||
}
|
||||
}
|
||||
|
||||
if (node == null
|
||||
|| !node.IsValid())
|
||||
|| node.Port <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
|
|
@ -28,17 +55,6 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
}
|
||||
|
||||
ret.Msg = ResUI.InitialConfiguration;
|
||||
|
||||
if (node?.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
return await GenerateClientMultipleLoadConfig(node);
|
||||
case EConfigType.ProxyChain:
|
||||
return await GenerateClientChainConfig(node);
|
||||
}
|
||||
}
|
||||
|
||||
var result = EmbedUtils.GetEmbedText(Global.SingboxSampleClient);
|
||||
if (result.IsNullOrEmpty())
|
||||
|
|
@ -153,9 +169,12 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
continue;
|
||||
}
|
||||
var item = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
if (item is null || item.IsComplex() || !item.IsValid())
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
continue;
|
||||
if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//find unused port
|
||||
|
|
@ -195,6 +214,27 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
singboxConfig.inbounds.Add(inbound);
|
||||
|
||||
//outbound
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.Shadowsocks
|
||||
&& !Global.SsSecuritiesInSingbox.Contains(item.Security))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.VLESS
|
||||
&& !Global.Flows.Contains(item.Flow))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.ConfigType is EConfigType.VLESS or EConfigType.Trojan
|
||||
&& item.StreamSecurity == Global.StreamSecurityReality
|
||||
&& item.PublicKey.IsNullOrEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var server = await GenServer(item);
|
||||
if (server is null)
|
||||
{
|
||||
|
|
@ -253,8 +293,7 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
var ret = new RetResult();
|
||||
try
|
||||
{
|
||||
if (node == null
|
||||
|| !node.IsValid())
|
||||
if (node is not { Port: > 0 })
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
|
|
@ -332,7 +371,7 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<RetResult> GenerateClientMultipleLoadConfig(ProfileItem parentNode)
|
||||
public async Task<RetResult> GenerateClientMultipleLoadConfig(List<ProfileItem> selecteds, EMultipleLoad multipleLoad)
|
||||
{
|
||||
var ret = new RetResult();
|
||||
try
|
||||
|
|
@ -366,12 +405,53 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
await GenRouting(singboxConfig);
|
||||
await GenExperimental(singboxConfig);
|
||||
|
||||
var groupRet = await GenGroupOutbound(parentNode, singboxConfig);
|
||||
if (groupRet != 0)
|
||||
var proxyProfiles = new List<ProfileItem>();
|
||||
foreach (var it in selecteds)
|
||||
{
|
||||
if (it.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
var itemGroup = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
proxyProfiles.Add(itemGroup);
|
||||
}
|
||||
if (!Global.SingboxSupportConfigType.Contains(it.ConfigType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.Port <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item.ConfigType == EConfigType.Shadowsocks
|
||||
&& !Global.SsSecuritiesInSingbox.Contains(item.Security))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.VLESS && !Global.Flows.Contains(item.Flow))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//outbound
|
||||
proxyProfiles.Add(item);
|
||||
}
|
||||
if (proxyProfiles.Count <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||
return ret;
|
||||
}
|
||||
await GenOutboundsListWithChain(proxyProfiles, singboxConfig, multipleLoad);
|
||||
|
||||
await GenDns(null, singboxConfig);
|
||||
await ConvertGeo2Ruleset(singboxConfig);
|
||||
|
|
@ -389,7 +469,7 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<RetResult> GenerateClientChainConfig(ProfileItem parentNode)
|
||||
public async Task<RetResult> GenerateClientChainConfig(List<ProfileItem> selecteds)
|
||||
{
|
||||
var ret = new RetResult();
|
||||
try
|
||||
|
|
@ -423,12 +503,48 @@ public partial class CoreConfigSingboxService(Config config)
|
|||
await GenExperimental(singboxConfig);
|
||||
singboxConfig.outbounds.RemoveAt(0);
|
||||
|
||||
var groupRet = await GenGroupOutbound(parentNode, singboxConfig);
|
||||
if (groupRet != 0)
|
||||
var proxyProfiles = new List<ProfileItem>();
|
||||
foreach (var it in selecteds)
|
||||
{
|
||||
if (!Global.SingboxSupportConfigType.Contains(it.ConfigType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.Port <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item.ConfigType == EConfigType.Shadowsocks
|
||||
&& !Global.SsSecuritiesInSingbox.Contains(item.Security))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.VLESS && !Global.Flows.Contains(item.Flow))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//outbound
|
||||
proxyProfiles.Add(item);
|
||||
}
|
||||
if (proxyProfiles.Count <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||
return ret;
|
||||
}
|
||||
await GenChainOutboundsList(proxyProfiles, singboxConfig);
|
||||
|
||||
await GenDns(null, singboxConfig);
|
||||
await ConvertGeo2Ruleset(singboxConfig);
|
||||
|
|
|
|||
|
|
@ -204,67 +204,6 @@ public partial class CoreConfigSingboxService
|
|||
return await Task.FromResult<BaseServer4Sbox?>(null);
|
||||
}
|
||||
|
||||
private async Task<int> GenGroupOutbound(ProfileItem node, SingboxConfig singboxConfig, string baseTagName = Global.ProxyTag, bool ignoreOriginChain = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (node.ConfigType is not (EConfigType.PolicyGroup or EConfigType.ProxyChain))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem is null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// remove custom nodes
|
||||
// remove group nodes for proxy chain
|
||||
// avoid self-reference
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
))
|
||||
.Where(p =>
|
||||
p != null
|
||||
&& p.IsValid()
|
||||
&& p.ConfigType != EConfigType.Custom
|
||||
&& (node.ConfigType == EConfigType.PolicyGroup || p.ConfigType < EConfigType.Group)
|
||||
&& p.IndexId != node.IndexId
|
||||
)
|
||||
.ToList();
|
||||
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
if (ignoreOriginChain)
|
||||
{
|
||||
await GenOutboundsList(childProfiles, singboxConfig, profileGroupItem.MultipleLoad, baseTagName);
|
||||
}
|
||||
else
|
||||
{
|
||||
await GenOutboundsListWithChain(childProfiles, singboxConfig, profileGroupItem.MultipleLoad, baseTagName);
|
||||
}
|
||||
|
||||
break;
|
||||
case EConfigType.ProxyChain:
|
||||
await GenChainOutboundsList(childProfiles, singboxConfig, baseTagName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
private async Task<int> GenOutboundMux(ProfileItem node, Outbound4Sbox outbound)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -385,8 +385,29 @@ public partial class CoreConfigSingboxService
|
|||
|
||||
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem == null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return Global.ProxyTag;
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
)).Where(p => p != null).ToList();
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
return Global.ProxyTag;
|
||||
}
|
||||
var childBaseTagName = $"{Global.ProxyTag}-{node.IndexId}";
|
||||
var ret = await GenGroupOutbound(node, singboxConfig, childBaseTagName);
|
||||
var ret = node.ConfigType switch
|
||||
{
|
||||
EConfigType.PolicyGroup =>
|
||||
await GenOutboundsListWithChain(childProfiles, singboxConfig, profileGroupItem.MultipleLoad, childBaseTagName),
|
||||
EConfigType.ProxyChain =>
|
||||
await GenChainOutboundsList(childProfiles, singboxConfig, childBaseTagName),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
if (ret == 0)
|
||||
{
|
||||
return childBaseTagName;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,35 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
var ret = new RetResult();
|
||||
try
|
||||
{
|
||||
if (node?.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem == null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
)).Where(p => p != null).ToList();
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
}
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
return await GenerateClientMultipleLoadConfig(childProfiles, profileGroupItem.MultipleLoad);
|
||||
case EConfigType.ProxyChain:
|
||||
return await GenerateClientChainConfig(childProfiles);
|
||||
}
|
||||
}
|
||||
|
||||
if (node == null
|
||||
|| !node.IsValid())
|
||||
|| node.Port <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
|
|
@ -30,17 +57,6 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
|
||||
ret.Msg = ResUI.InitialConfiguration;
|
||||
|
||||
if (node?.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
return await GenerateClientMultipleLoadConfig(node);
|
||||
case EConfigType.ProxyChain:
|
||||
return await GenerateClientChainConfig(node);
|
||||
}
|
||||
}
|
||||
|
||||
var result = EmbedUtils.GetEmbedText(Global.V2raySampleClient);
|
||||
if (result.IsNullOrEmpty())
|
||||
{
|
||||
|
|
@ -82,7 +98,7 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<RetResult> GenerateClientMultipleLoadConfig(ProfileItem parentNode)
|
||||
public async Task<RetResult> GenerateClientMultipleLoadConfig(List<ProfileItem> selecteds, EMultipleLoad multipleLoad)
|
||||
{
|
||||
var ret = new RetResult();
|
||||
|
||||
|
|
@ -118,12 +134,57 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
await GenDns(null, v2rayConfig);
|
||||
await GenStatistic(v2rayConfig);
|
||||
|
||||
var groupRet = await GenGroupOutbound(parentNode, v2rayConfig);
|
||||
if (groupRet != 0)
|
||||
var proxyProfiles = new List<ProfileItem>();
|
||||
foreach (var it in selecteds)
|
||||
{
|
||||
if (it.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
var itemGroup = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
proxyProfiles.Add(itemGroup);
|
||||
}
|
||||
if (!Global.XraySupportConfigType.Contains(it.ConfigType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.Port <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item.ConfigType == EConfigType.Shadowsocks
|
||||
&& !Global.SsSecuritiesInSingbox.Contains(item.Security))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.VLESS && !Global.Flows.Contains(item.Flow))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//outbound
|
||||
proxyProfiles.Add(item);
|
||||
}
|
||||
if (proxyProfiles.Count <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||
return ret;
|
||||
}
|
||||
await GenOutboundsListWithChain(proxyProfiles, v2rayConfig);
|
||||
|
||||
//add balancers
|
||||
await GenObservatory(v2rayConfig, multipleLoad);
|
||||
await GenBalancer(v2rayConfig, multipleLoad);
|
||||
|
||||
var defaultBalancerTag = $"{Global.ProxyTag}{Global.BalancerTagSuffix}";
|
||||
|
||||
|
|
@ -187,7 +248,7 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<RetResult> GenerateClientChainConfig(ProfileItem parentNode)
|
||||
public async Task<RetResult> GenerateClientChainConfig(List<ProfileItem> selecteds)
|
||||
{
|
||||
var ret = new RetResult();
|
||||
|
||||
|
|
@ -223,12 +284,48 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
await GenStatistic(v2rayConfig);
|
||||
v2rayConfig.outbounds.RemoveAt(0);
|
||||
|
||||
var groupRet = await GenGroupOutbound(parentNode, v2rayConfig);
|
||||
if (groupRet != 0)
|
||||
var proxyProfiles = new List<ProfileItem>();
|
||||
foreach (var it in selecteds)
|
||||
{
|
||||
if (!Global.XraySupportConfigType.Contains(it.ConfigType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.Port <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var item = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
if (item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item.ConfigType == EConfigType.Shadowsocks
|
||||
&& !Global.SsSecuritiesInSingbox.Contains(item.Security))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.VLESS && !Global.Flows.Contains(item.Flow))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//outbound
|
||||
proxyProfiles.Add(item);
|
||||
}
|
||||
if (proxyProfiles.Count <= 0)
|
||||
{
|
||||
ret.Msg = ResUI.FailedGenDefaultConfiguration;
|
||||
return ret;
|
||||
}
|
||||
await GenChainOutboundsList(proxyProfiles, v2rayConfig);
|
||||
|
||||
ret.Success = true;
|
||||
|
||||
|
|
@ -301,9 +398,12 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
continue;
|
||||
}
|
||||
var item = await AppManager.Instance.GetProfileItem(it.IndexId);
|
||||
if (item is null || item.IsComplex() || !item.IsValid())
|
||||
if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
|
||||
{
|
||||
continue;
|
||||
if (item is null || item.Id.IsNullOrEmpty() || !Utils.IsGuidByParse(item.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//find unused port
|
||||
|
|
@ -332,6 +432,28 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
it.Port = port;
|
||||
it.AllowTest = true;
|
||||
|
||||
//outbound
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.Shadowsocks
|
||||
&& !Global.SsSecuritiesInXray.Contains(item.Security))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item.ConfigType == EConfigType.VLESS
|
||||
&& !Global.Flows.Contains(item.Flow))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (it.ConfigType is EConfigType.VLESS or EConfigType.Trojan
|
||||
&& item.StreamSecurity == Global.StreamSecurityReality
|
||||
&& item.PublicKey.IsNullOrEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//inbound
|
||||
Inbounds4Ray inbound = new()
|
||||
{
|
||||
|
|
@ -342,7 +464,6 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
inbound.tag = inbound.protocol + inbound.port.ToString();
|
||||
v2rayConfig.inbounds.Add(inbound);
|
||||
|
||||
//outbound
|
||||
var outbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound);
|
||||
await GenOutbound(item, outbound);
|
||||
outbound.tag = Global.ProxyTag + inbound.port.ToString();
|
||||
|
|
@ -376,8 +497,7 @@ public partial class CoreConfigV2rayService(Config config)
|
|||
var ret = new RetResult();
|
||||
try
|
||||
{
|
||||
if (node == null
|
||||
|| !node.IsValid())
|
||||
if (node is not { Port: > 0 })
|
||||
{
|
||||
ret.Msg = ResUI.CheckServerSettings;
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -480,69 +480,6 @@ public partial class CoreConfigV2rayService
|
|||
return 0;
|
||||
}
|
||||
|
||||
private async Task<int> GenGroupOutbound(ProfileItem node, V2rayConfig v2rayConfig, string baseTagName = Global.ProxyTag, bool ignoreOriginChain = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (node.ConfigType is not (EConfigType.PolicyGroup or EConfigType.ProxyChain))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem is null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// remove custom nodes
|
||||
// remove group nodes for proxy chain
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
))
|
||||
.Where(p =>
|
||||
p != null &&
|
||||
p.IsValid() &&
|
||||
p.ConfigType != EConfigType.Custom &&
|
||||
(node.ConfigType == EConfigType.PolicyGroup || p.ConfigType < EConfigType.Group)
|
||||
)
|
||||
.ToList();
|
||||
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
switch (node.ConfigType)
|
||||
{
|
||||
case EConfigType.PolicyGroup:
|
||||
if (ignoreOriginChain)
|
||||
{
|
||||
await GenOutboundsList(childProfiles, v2rayConfig, baseTagName);
|
||||
}
|
||||
else
|
||||
{
|
||||
await GenOutboundsListWithChain(childProfiles, v2rayConfig, baseTagName);
|
||||
}
|
||||
break;
|
||||
case EConfigType.ProxyChain:
|
||||
await GenChainOutboundsList(childProfiles, v2rayConfig, baseTagName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//add balancers
|
||||
await GenObservatory(v2rayConfig, profileGroupItem.MultipleLoad, baseTagName);
|
||||
await GenBalancer(v2rayConfig, profileGroupItem.MultipleLoad, baseTagName);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
return await Task.FromResult(0);
|
||||
}
|
||||
|
||||
private async Task<int> GenMoreOutbounds(ProfileItem node, V2rayConfig v2rayConfig)
|
||||
{
|
||||
//fragment proxy
|
||||
|
|
|
|||
|
|
@ -141,8 +141,33 @@ public partial class CoreConfigV2rayService
|
|||
|
||||
if (node.ConfigType is EConfigType.PolicyGroup or EConfigType.ProxyChain)
|
||||
{
|
||||
ProfileGroupItemManager.Instance.TryGet(node.IndexId, out var profileGroupItem);
|
||||
if (profileGroupItem == null || profileGroupItem.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return Global.ProxyTag;
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
Utils.String2List(profileGroupItem.ChildItems)
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
)).Where(p => p != null).ToList();
|
||||
if (childProfiles.Count <= 0)
|
||||
{
|
||||
return Global.ProxyTag;
|
||||
}
|
||||
var childBaseTagName = $"{Global.ProxyTag}-{node.IndexId}";
|
||||
var ret = await GenGroupOutbound(node, v2rayConfig, childBaseTagName);
|
||||
var ret = node.ConfigType switch
|
||||
{
|
||||
EConfigType.PolicyGroup =>
|
||||
await GenOutboundsListWithChain(childProfiles, v2rayConfig, childBaseTagName),
|
||||
EConfigType.ProxyChain =>
|
||||
await GenChainOutboundsList(childProfiles, v2rayConfig, childBaseTagName),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
if (node.ConfigType == EConfigType.PolicyGroup)
|
||||
{
|
||||
await GenBalancer(v2rayConfig, profileGroupItem.MultipleLoad, childBaseTagName);
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
return childBaseTagName;
|
||||
|
|
|
|||
|
|
@ -69,8 +69,6 @@ public class ClashProxiesViewModel : MyReactiveObject
|
|||
SortingSelected = _config.ClashUIItem.ProxiesSorting;
|
||||
RuleModeSelected = (int)_config.ClashUIItem.RuleMode;
|
||||
|
||||
#region WhenAnyValue && ReactiveCommand
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.SelectedGroup,
|
||||
y => y != null && y.Name.IsNotEmpty())
|
||||
|
|
@ -91,17 +89,6 @@ public class ClashProxiesViewModel : MyReactiveObject
|
|||
y => y == true)
|
||||
.Subscribe(c => { _config.ClashUIItem.ProxiesAutoRefresh = AutoRefresh; });
|
||||
|
||||
#endregion WhenAnyValue && ReactiveCommand
|
||||
|
||||
#region AppEvents
|
||||
|
||||
AppEvents.ProxiesReloadRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await ProxiesReload());
|
||||
|
||||
#endregion AppEvents
|
||||
|
||||
_ = Init();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System.Reactive;
|
|||
using System.Reactive.Concurrency;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Splat;
|
||||
|
||||
namespace ServiceLib.ViewModels;
|
||||
|
||||
|
|
@ -250,6 +251,7 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
BlReloadEnabled = true;
|
||||
await Reload();
|
||||
await AutoHideStartup();
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
}
|
||||
|
||||
#endregion Init
|
||||
|
|
@ -310,7 +312,7 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
|
||||
private void RefreshSubscriptions()
|
||||
{
|
||||
AppEvents.SubscriptionsRefreshRequested.OnNext(Unit.Default);
|
||||
Locator.Current.GetService<ProfilesViewModel>()?.RefreshSubscriptions();
|
||||
}
|
||||
|
||||
#endregion Servers && Groups
|
||||
|
|
@ -446,7 +448,7 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null);
|
||||
if (ret == true)
|
||||
{
|
||||
AppEvents.InboundDisplayRequested.OnNext(Unit.Default);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.InboundDisplayStatus();
|
||||
await Reload();
|
||||
}
|
||||
}
|
||||
|
|
@ -457,7 +459,7 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
if (ret == true)
|
||||
{
|
||||
await ConfigHandler.InitBuiltinRouting(_config);
|
||||
AppEvents.RoutingsMenuRefreshRequested.OnNext(Unit.Default);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
await Reload();
|
||||
}
|
||||
}
|
||||
|
|
@ -531,15 +533,9 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
await SysProxyHandler.UpdateSysProxy(_config, false);
|
||||
await Task.Delay(1000);
|
||||
});
|
||||
AppEvents.TestServerRequested.OnNext(Unit.Default);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.TestServerAvailability();
|
||||
|
||||
var showClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
||||
if (showClashUI)
|
||||
{
|
||||
AppEvents.ProxiesReloadRequested.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
RxApp.MainThreadScheduler.Schedule(() => ReloadResult(showClashUI));
|
||||
RxApp.MainThreadScheduler.Schedule(() => _ = ReloadResult());
|
||||
|
||||
BlReloadEnabled = true;
|
||||
if (_hasNextReloadJob)
|
||||
|
|
@ -549,11 +545,19 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
}
|
||||
}
|
||||
|
||||
private void ReloadResult(bool showClashUI)
|
||||
public async Task ReloadResult()
|
||||
{
|
||||
// BlReloadEnabled = true;
|
||||
ShowClashUI = showClashUI;
|
||||
TabMainSelectedIndex = showClashUI ? TabMainSelectedIndex : 0;
|
||||
//Locator.Current.GetService<StatusBarViewModel>()?.ChangeSystemProxyAsync(_config.systemProxyItem.sysProxyType, false);
|
||||
ShowClashUI = _config.IsRunningCore(ECoreType.sing_box);
|
||||
if (ShowClashUI)
|
||||
{
|
||||
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
|
||||
}
|
||||
else
|
||||
{
|
||||
TabMainSelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadCore()
|
||||
|
|
@ -585,7 +589,7 @@ public class MainWindowViewModel : MyReactiveObject
|
|||
{
|
||||
await ConfigHandler.ApplyRegionalPreset(_config, type);
|
||||
await ConfigHandler.InitRouting(_config);
|
||||
AppEvents.RoutingsMenuRefreshRequested.OnNext(Unit.Default);
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.RefreshRoutingsMenu();
|
||||
|
||||
await ConfigHandler.SaveConfig(_config);
|
||||
await new UpdateService().UpdateGeoFileAll(_config, UpdateTaskHandler);
|
||||
|
|
|
|||
|
|
@ -250,21 +250,11 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await RefreshServersBiz());
|
||||
|
||||
AppEvents.SubscriptionsRefreshRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await RefreshSubscriptions());
|
||||
|
||||
AppEvents.DispatcherStatisticsRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async result => await UpdateStatistics(result));
|
||||
|
||||
AppEvents.SetDefaultServerRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async indexId => await SetDefaultServer(indexId));
|
||||
|
||||
#endregion AppEvents
|
||||
|
||||
_ = Init();
|
||||
|
|
@ -400,7 +390,7 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
await _updateView?.Invoke(EViewAction.DispatcherRefreshServersBiz, null);
|
||||
}
|
||||
|
||||
private async Task RefreshSubscriptions()
|
||||
public async Task RefreshSubscriptions()
|
||||
{
|
||||
SubItems.Clear();
|
||||
|
||||
|
|
@ -589,7 +579,7 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
await SetDefaultServer(SelectedProfile.IndexId);
|
||||
}
|
||||
|
||||
private async Task SetDefaultServer(string? indexId)
|
||||
public async Task SetDefaultServer(string? indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ namespace ServiceLib.ViewModels;
|
|||
|
||||
public class StatusBarViewModel : MyReactiveObject
|
||||
{
|
||||
private static readonly Lazy<StatusBarViewModel> _instance = new(() => new(null));
|
||||
public static StatusBarViewModel Instance => _instance.Value;
|
||||
|
||||
#region ObservableCollection
|
||||
|
||||
public IObservableCollection<RoutingItem> RoutingItems { get; } = new ObservableCollectionExtended<RoutingItem>();
|
||||
|
|
@ -212,26 +209,6 @@ public class StatusBarViewModel : MyReactiveObject
|
|||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async result => await UpdateStatistics(result));
|
||||
|
||||
AppEvents.RoutingsMenuRefreshRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await RefreshRoutingsMenu());
|
||||
|
||||
AppEvents.TestServerRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await TestServerAvailability());
|
||||
|
||||
AppEvents.InboundDisplayRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async _ => await InboundDisplayStatus());
|
||||
|
||||
AppEvents.SysProxyChangeRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(async result => await SetListenerType(result));
|
||||
|
||||
#endregion AppEvents
|
||||
|
||||
_ = Init();
|
||||
|
|
@ -352,7 +329,7 @@ public class StatusBarViewModel : MyReactiveObject
|
|||
{
|
||||
return;
|
||||
}
|
||||
AppEvents.SetDefaultServerRequested.OnNext(SelectedServer.ID);
|
||||
Locator.Current.GetService<ProfilesViewModel>()?.SetDefaultServer(SelectedServer.ID);
|
||||
}
|
||||
|
||||
public async Task TestServerAvailability()
|
||||
|
|
@ -387,7 +364,7 @@ public class StatusBarViewModel : MyReactiveObject
|
|||
|
||||
#region System proxy and Routings
|
||||
|
||||
private async Task SetListenerType(ESysProxyType type)
|
||||
public async Task SetListenerType(ESysProxyType type)
|
||||
{
|
||||
if (_config.SystemProxyItem.SysProxyType == type)
|
||||
{
|
||||
|
|
@ -416,7 +393,7 @@ public class StatusBarViewModel : MyReactiveObject
|
|||
}
|
||||
}
|
||||
|
||||
private async Task RefreshRoutingsMenu()
|
||||
public async Task RefreshRoutingsMenu()
|
||||
{
|
||||
RoutingItems.Clear();
|
||||
|
||||
|
|
@ -524,7 +501,7 @@ public class StatusBarViewModel : MyReactiveObject
|
|||
|
||||
#region UI
|
||||
|
||||
private async Task InboundDisplayStatus()
|
||||
public async Task InboundDisplayStatus()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb.Append($"[{EInboundProtocol.mixed}:{AppManager.Instance.GetLocalPort(EInboundProtocol.socks)}");
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ public partial class App : Application
|
|||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
|
||||
|
||||
DataContext = StatusBarViewModel.Instance;
|
||||
var ViewModel = new StatusBarViewModel(null);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using Avalonia.Input;
|
|||
using Avalonia.ReactiveUI;
|
||||
using DynamicData;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
|
||||
namespace v2rayN.Desktop.Views;
|
||||
|
||||
|
|
@ -12,6 +13,7 @@ public partial class ClashProxiesView : ReactiveUserControl<ClashProxiesViewMode
|
|||
{
|
||||
InitializeComponent();
|
||||
ViewModel = new ClashProxiesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ClashProxiesViewModel));
|
||||
lstProxyDetails.DoubleTapped += LstProxyDetails_DoubleTapped;
|
||||
this.KeyDown += ClashProxiesView_KeyDown;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace v2rayN.Desktop.Views;
|
|||
public partial class MainWindow : WindowBase<MainWindowViewModel>
|
||||
{
|
||||
private static Config _config;
|
||||
private readonly WindowNotificationManager? _manager;
|
||||
private WindowNotificationManager? _manager;
|
||||
private CheckUpdateView? _checkUpdateView;
|
||||
private BackupAndRestoreView? _backupAndRestoreView;
|
||||
private bool _blCloseByUser = false;
|
||||
|
|
@ -266,7 +266,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
|
|||
case EGlobalHotkey.SystemProxySet:
|
||||
case EGlobalHotkey.SystemProxyUnchanged:
|
||||
case EGlobalHotkey.SystemProxyPac:
|
||||
AppEvents.SysProxyChangeRequested.OnNext((ESysProxyType)((int)e - 1));
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.SetListenerType((ESysProxyType)((int)e - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using Avalonia.Threading;
|
|||
using DialogHostAvalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Desktop.Common;
|
||||
|
||||
namespace v2rayN.Desktop.Views;
|
||||
|
|
@ -47,6 +48,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
|||
//}
|
||||
|
||||
ViewModel = new ProfilesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ProfilesViewModel));
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Avalonia.ReactiveUI;
|
|||
using Avalonia.Threading;
|
||||
using DialogHostAvalonia;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Desktop.Common;
|
||||
|
||||
namespace v2rayN.Desktop.Views;
|
||||
|
|
@ -19,8 +20,9 @@ public partial class StatusBarView : ReactiveUserControl<StatusBarViewModel>
|
|||
InitializeComponent();
|
||||
|
||||
_config = AppManager.Instance.Config;
|
||||
|
||||
ViewModel = StatusBarViewModel.Instance;
|
||||
//ViewModel = new StatusBarViewModel(UpdateViewHandler);
|
||||
//Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
ViewModel = Locator.Current.GetService<StatusBarViewModel>();
|
||||
ViewModel?.InitUpdateView(UpdateViewHandler);
|
||||
|
||||
txtRunningServerDisplay.Tapped += TxtRunningServerDisplay_Tapped;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ public partial class AddGroupServerWindow
|
|||
|
||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||
});
|
||||
WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme);
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Reactive.Disposables;
|
||||
using System.Windows.Input;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
|
||||
namespace v2rayN.Views;
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ public partial class ClashProxiesView
|
|||
{
|
||||
InitializeComponent();
|
||||
ViewModel = new ClashProxiesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ClashProxiesViewModel));
|
||||
lstProxyDetails.PreviewMouseDoubleClick += lstProxyDetails_PreviewMouseDoubleClick;
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ public partial class MainWindow
|
|||
case EGlobalHotkey.SystemProxySet:
|
||||
case EGlobalHotkey.SystemProxyUnchanged:
|
||||
case EGlobalHotkey.SystemProxyPac:
|
||||
AppEvents.SysProxyChangeRequested.OnNext((ESysProxyType)((int)e - 1));
|
||||
Locator.Current.GetService<StatusBarViewModel>()?.SetListenerType((ESysProxyType)((int)e - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -294,7 +294,11 @@ public partial class MainWindow
|
|||
var clipboardData = WindowsUtils.GetClipboardData();
|
||||
if (clipboardData.IsNotEmpty())
|
||||
{
|
||||
ViewModel?.AddServerViaClipboardAsync(clipboardData);
|
||||
var service = Locator.Current.GetService<MainWindowViewModel>();
|
||||
if (service != null)
|
||||
{
|
||||
_ = service.AddServerViaClipboardAsync(clipboardData);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Windows.Media;
|
|||
using System.Windows.Threading;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Base;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ public partial class ProfilesView
|
|||
}
|
||||
|
||||
ViewModel = new ProfilesViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(ProfilesViewModel));
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Windows;
|
|||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
using v2rayN.Manager;
|
||||
|
||||
namespace v2rayN.Views;
|
||||
|
|
@ -15,8 +16,8 @@ public partial class StatusBarView
|
|||
{
|
||||
InitializeComponent();
|
||||
_config = AppManager.Instance.Config;
|
||||
ViewModel = StatusBarViewModel.Instance;
|
||||
ViewModel?.InitUpdateView(UpdateViewHandler);
|
||||
ViewModel = new StatusBarViewModel(UpdateViewHandler);
|
||||
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
|
||||
|
||||
menuExit.Click += menuExit_Click;
|
||||
txtRunningServerDisplay.PreviewMouseDown += txtRunningInfoDisplay_MouseDoubleClick;
|
||||
|
|
|
|||
Loading…
Reference in a new issue