Skip to content

Commit 0f3a3ea

Browse files
authored
Group preview (2dust#8760)
* Group Preview * Fix
1 parent 54608ab commit 0f3a3ea

14 files changed

Lines changed: 213 additions & 21 deletions

v2rayN/ServiceLib/Manager/GroupProfileManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static async Task<bool> HasCycle(string? indexId, ProtocolExtraItem? ext
7575
return (await GetChildProfileItemsByProtocolExtra(protocolExtra), protocolExtra);
7676
}
7777

78-
private static async Task<List<ProfileItem>> GetChildProfileItemsByProtocolExtra(ProtocolExtraItem? protocolExtra)
78+
public static async Task<List<ProfileItem>> GetChildProfileItemsByProtocolExtra(ProtocolExtraItem? protocolExtra)
7979
{
8080
if (protocolExtra == null)
8181
{

v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,4 +1668,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16681668
<data name="TbHopInt7" xml:space="preserve">
16691669
<value>Port hopping interval</value>
16701670
</data>
1671+
<data name="menuServerListPreview" xml:space="preserve">
1672+
<value>Configuration item preview</value>
1673+
</data>
16711674
</root>

v2rayN/ServiceLib/Resx/ResUI.fr.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,4 +1665,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16651665
<data name="TbHopInt7" xml:space="preserve">
16661666
<value>Port hopping interval</value>
16671667
</data>
1668+
<data name="menuServerListPreview" xml:space="preserve">
1669+
<value>Configuration item preview</value>
1670+
</data>
16681671
</root>

v2rayN/ServiceLib/Resx/ResUI.hu.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,4 +1668,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16681668
<data name="TbHopInt7" xml:space="preserve">
16691669
<value>Port hopping interval</value>
16701670
</data>
1671+
<data name="menuServerListPreview" xml:space="preserve">
1672+
<value>Configuration item preview</value>
1673+
</data>
16711674
</root>

v2rayN/ServiceLib/Resx/ResUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,4 +1668,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16681668
<data name="TbHopInt7" xml:space="preserve">
16691669
<value>Port hopping interval</value>
16701670
</data>
1671+
<data name="menuServerListPreview" xml:space="preserve">
1672+
<value>Configuration item preview</value>
1673+
</data>
16711674
</root>

v2rayN/ServiceLib/Resx/ResUI.ru.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,4 +1668,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
16681668
<data name="TbHopInt7" xml:space="preserve">
16691669
<value>Port hopping interval</value>
16701670
</data>
1671+
<data name="menuServerListPreview" xml:space="preserve">
1672+
<value>Configuration item preview</value>
1673+
</data>
16711674
</root>

v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,4 +1665,7 @@
16651665
<data name="TbHopInt7" xml:space="preserve">
16661666
<value>端口跳跃间隔</value>
16671667
</data>
1668+
<data name="menuServerListPreview" xml:space="preserve">
1669+
<value>子配置项预览</value>
1670+
</data>
16681671
</root>

v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,4 +1665,7 @@
16651665
<data name="TbHopInt7" xml:space="preserve">
16661666
<value>Port hopping interval</value>
16671667
</data>
1668+
<data name="menuServerListPreview" xml:space="preserve">
1669+
<value>Configuration item preview</value>
1670+
</data>
16681671
</root>

v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class AddGroupServerViewModel : MyReactiveObject
2727

2828
public IObservableCollection<ProfileItem> ChildItemsObs { get; } = new ObservableCollectionExtended<ProfileItem>();
2929

30+
public IObservableCollection<ProfileItem> AllProfilePreviewItemsObs { get; } = new ObservableCollectionExtended<ProfileItem>();
31+
3032
//public ReactiveCommand<Unit, Unit> AddCmd { get; }
3133
public ReactiveCommand<Unit, Unit> RemoveCmd { get; }
3234

@@ -182,6 +184,32 @@ public async Task MoveServer(EMove eMove)
182184
await Task.CompletedTask;
183185
}
184186

187+
private ProtocolExtraItem GetUpdatedProtocolExtra()
188+
{
189+
return SelectedSource.GetProtocolExtra() with
190+
{
191+
ChildItems =
192+
Utils.List2String(ChildItemsObs.Where(s => !s.IndexId.IsNullOrEmpty()).Select(s => s.IndexId).ToList()),
193+
MultipleLoad = PolicyGroupType switch
194+
{
195+
var s when s == ResUI.TbLeastPing => EMultipleLoad.LeastPing,
196+
var s when s == ResUI.TbFallback => EMultipleLoad.Fallback,
197+
var s when s == ResUI.TbRandom => EMultipleLoad.Random,
198+
var s when s == ResUI.TbRoundRobin => EMultipleLoad.RoundRobin,
199+
var s when s == ResUI.TbLeastLoad => EMultipleLoad.LeastLoad,
200+
_ => EMultipleLoad.LeastPing,
201+
},
202+
SubChildItems = SelectedSubItem?.Id,
203+
Filter = Filter,
204+
};
205+
}
206+
207+
public async Task UpdatePreviewList()
208+
{
209+
AllProfilePreviewItemsObs.Clear();
210+
AllProfilePreviewItemsObs.AddRange(await GroupProfileManager.GetChildProfileItemsByProtocolExtra(GetUpdatedProtocolExtra()));
211+
}
212+
185213
private async Task SaveServerAsync()
186214
{
187215
var remarks = SelectedSource.Remarks;
@@ -202,24 +230,11 @@ SelectedSource.ConfigType is not (EConfigType.ProxyChain or EConfigType.PolicyGr
202230
return;
203231
}
204232

205-
SelectedSource.SetProtocolExtra(SelectedSource.GetProtocolExtra() with
206-
{
207-
ChildItems =
208-
Utils.List2String(ChildItemsObs.Where(s => !s.IndexId.IsNullOrEmpty()).Select(s => s.IndexId).ToList()),
209-
MultipleLoad = PolicyGroupType switch
210-
{
211-
var s when s == ResUI.TbLeastPing => EMultipleLoad.LeastPing,
212-
var s when s == ResUI.TbFallback => EMultipleLoad.Fallback,
213-
var s when s == ResUI.TbRandom => EMultipleLoad.Random,
214-
var s when s == ResUI.TbRoundRobin => EMultipleLoad.RoundRobin,
215-
var s when s == ResUI.TbLeastLoad => EMultipleLoad.LeastLoad,
216-
_ => EMultipleLoad.LeastPing,
217-
},
218-
SubChildItems = SelectedSubItem?.Id,
219-
Filter = Filter,
220-
});
233+
var protocolExtra = GetUpdatedProtocolExtra();
234+
235+
SelectedSource.SetProtocolExtra(protocolExtra);
221236

222-
var hasCycle = await GroupProfileManager.HasCycle(SelectedSource.IndexId, SelectedSource.GetProtocolExtra());
237+
var hasCycle = await GroupProfileManager.HasCycle(SelectedSource.IndexId, protocolExtra);
223238
if (hasCycle)
224239
{
225240
NoticeManager.Instance.Enqueue(string.Format(ResUI.GroupSelfReference, remarks));

0 commit comments

Comments
 (0)