Skip to content

Commit 6167624

Browse files
committed
Rename ProfileItems to ProfileModels and refactor
1 parent 7a58e78 commit 6167624

10 files changed

Lines changed: 53 additions & 23 deletions

File tree

v2rayN/ServiceLib/Handler/ConfigHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ public static async Task<int> AddAnytlsServer(Config config, ProfileItem profile
844844
/// <returns>0 if successful, -1 if failed</returns>
845845
public static async Task<int> SortServers(Config config, string subId, string colName, bool asc)
846846
{
847-
var lstModel = await AppManager.Instance.ProfileItems(subId, "");
847+
var lstModel = await AppManager.Instance.ProfileModels(subId, "");
848848
if (lstModel.Count <= 0)
849849
{
850850
return -1;
@@ -1213,7 +1213,8 @@ public static async Task<RetResult> AddGroupServer4Multiple(Config config, List<
12131213
}
12141214
var extraItem = new ProtocolExtraItem
12151215
{
1216-
ChildItems = childProfileIndexId, MultipleLoad = multipleLoad,
1216+
ChildItems = childProfileIndexId,
1217+
MultipleLoad = multipleLoad,
12171218
};
12181219
profile.SetProtocolExtra(extraItem);
12191220
var ret = await AddServerCommon(config, profile, true);
@@ -1277,7 +1278,7 @@ public static async Task<RetResult> AddGroupServer4Multiple(Config config, List<
12771278
/// <returns>Number of removed servers or -1 if failed</returns>
12781279
public static async Task<int> RemoveInvalidServerResult(Config config, string subid)
12791280
{
1280-
var lstModel = await AppManager.Instance.ProfileItems(subid, "");
1281+
var lstModel = await AppManager.Instance.ProfileModels(subid, "");
12811282
if (lstModel is { Count: <= 0 })
12821283
{
12831284
return -1;

v2rayN/ServiceLib/Helper/DownloaderHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task DownloadDataAsync4Speed(IWebProxy webProxy, string url, IProgr
8585
{
8686
maxSpeed = value.BytesPerSecondSpeed;
8787
}
88-
88+
8989
var ts = DateTime.Now - lastUpdateTime;
9090
if (ts.TotalMilliseconds >= 1000)
9191
{

v2rayN/ServiceLib/Manager/AppManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,17 @@ public int GetLocalPort(EInboundProtocol protocol)
191191
return (await ProfileItems(subid))?.Select(t => t.IndexId)?.ToList();
192192
}
193193

194-
public async Task<List<ProfileItemModel>?> ProfileItems(string subid, string filter)
194+
public async Task<List<ProfileItemModel>?> ProfileModels(string subid, string filter)
195195
{
196-
var sql = @$"select a.*
197-
,b.remarks subRemarks
196+
var sql = @$"select a.IndexId
197+
,a.ConfigType
198+
,a.Remarks
199+
,a.Address
200+
,a.Port
201+
,a.Network
202+
,a.StreamSecurity
203+
,a.Subid
204+
,b.remarks as subRemarks
198205
from ProfileItem a
199206
left join SubItem b on a.subid = b.id
200207
where 1=1 ";

v2rayN/ServiceLib/Models/ConfigItems.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class UIItem
9999
public bool EnableDragDropSort { get; set; }
100100
public bool DoubleClick2Activate { get; set; }
101101
public bool AutoHideStartup { get; set; }
102-
public bool Hide2TrayWhenClose { get; set; }
102+
public bool Hide2TrayWhenClose { get; set; }
103103
public bool MacOSShowInDock { get; set; }
104104
public List<ColumnItem> MainColumnItem { get; set; }
105105
public List<WindowSizeItem> WindowSizeItem { get; set; }

v2rayN/ServiceLib/Models/ProfileItem.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ServiceLib.Models;
22

33
[Serializable]
4-
public class ProfileItem : ReactiveObject
4+
public class ProfileItem
55
{
66
private ProtocolExtraItem? _protocolExtraCache;
77

@@ -10,6 +10,7 @@ public ProfileItem()
1010
IndexId = string.Empty;
1111
ConfigType = EConfigType.VMess;
1212
ConfigVersion = 3;
13+
Subid = string.Empty;
1314
Address = string.Empty;
1415
Port = 0;
1516
Password = string.Empty;
@@ -21,7 +22,6 @@ public ProfileItem()
2122
Path = string.Empty;
2223
StreamSecurity = string.Empty;
2324
AllowInsecure = string.Empty;
24-
Subid = string.Empty;
2525
}
2626

2727
#region function
@@ -148,26 +148,26 @@ public ProtocolExtraItem GetProtocolExtra()
148148
public string IndexId { get; set; }
149149

150150
public EConfigType ConfigType { get; set; }
151+
public ECoreType? CoreType { get; set; }
151152
public int ConfigVersion { get; set; }
153+
public string Subid { get; set; }
154+
public bool IsSub { get; set; } = true;
155+
public int? PreSocksPort { get; set; }
156+
public bool DisplayLog { get; set; } = true;
157+
public string Remarks { get; set; }
152158
public string Address { get; set; }
153159
public int Port { get; set; }
154160
public string Password { get; set; }
155161
public string Username { get; set; }
156162
public string Network { get; set; }
157-
public string Remarks { get; set; }
158163
public string HeaderType { get; set; }
159164
public string RequestHost { get; set; }
160165
public string Path { get; set; }
161166
public string StreamSecurity { get; set; }
162167
public string AllowInsecure { get; set; }
163-
public string Subid { get; set; }
164-
public bool IsSub { get; set; } = true;
165168
public string Sni { get; set; }
166169
public string Alpn { get; set; } = string.Empty;
167-
public ECoreType? CoreType { get; set; }
168-
public int? PreSocksPort { get; set; }
169170
public string Fingerprint { get; set; }
170-
public bool DisplayLog { get; set; } = true;
171171
public string PublicKey { get; set; }
172172
public string ShortId { get; set; }
173173
public string SpiderX { get; set; }

v2rayN/ServiceLib/Models/ProfileItemModel.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
namespace ServiceLib.Models;
22

33
[Serializable]
4-
public class ProfileItemModel : ProfileItem
4+
public class ProfileItemModel : ReactiveObject
55
{
66
public bool IsActive { get; set; }
7+
public string IndexId { get; set; }
8+
public EConfigType ConfigType { get; set; }
9+
public string Remarks { get; set; }
10+
public string Address { get; set; }
11+
public int Port { get; set; }
12+
public string Network { get; set; }
13+
public string StreamSecurity { get; set; }
14+
public string Subid { get; set; }
715
public string SubRemarks { get; set; }
16+
public int Sort { get; set; }
817

918
[Reactive]
1019
public int Delay { get; set; }
1120

1221
public decimal Speed { get; set; }
13-
public int Sort { get; set; }
1422

1523
[Reactive]
1624
public string DelayVal { get; set; }
@@ -29,4 +37,15 @@ public class ProfileItemModel : ProfileItem
2937

3038
[Reactive]
3139
public string TotalDown { get; set; }
40+
41+
public string GetSummary()
42+
{
43+
var summary = $"[{ConfigType}] {Remarks}";
44+
if (!ConfigType.IsComplexType())
45+
{
46+
summary += $"({Address}:{Port})";
47+
}
48+
49+
return summary;
50+
}
3251
}

v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ public class AddServerViewModel : MyReactiveObject
4949

5050
[Reactive]
5151
public string WgPublicKey { get; set; }
52+
5253
//[Reactive]
5354
//public string WgPresharedKey { get; set; }
5455
[Reactive]
5556
public string WgInterfaceAddress { get; set; }
57+
5658
[Reactive]
5759
public string WgReserved { get; set; }
60+
5861
[Reactive]
5962
public int WgMtu { get; set; }
6063

v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public async Task RefreshSubscriptions()
200200

201201
private async Task<List<ProfileItemModel>?> GetProfileItemsEx(string subid, string filter)
202202
{
203-
var lstModel = await AppManager.Instance.ProfileItems(_subIndexId, filter);
203+
var lstModel = await AppManager.Instance.ProfileModels(_subIndexId, filter);
204204
lstModel = (from t in lstModel
205205
select new ProfileItemModel
206206
{

v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class ProfilesViewModel : MyReactiveObject
5656

5757
public ReactiveCommand<Unit, Unit> MoveUpCmd { get; }
5858
public ReactiveCommand<Unit, Unit> MoveDownCmd { get; }
59-
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }
59+
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }
6060
public ReactiveCommand<SubItem, Unit> MoveToGroupCmd { get; }
6161

6262
//servers ping
@@ -428,7 +428,7 @@ private async Task RefreshSubscriptions()
428428

429429
private async Task<List<ProfileItemModel>?> GetProfileItemsEx(string subid, string filter)
430430
{
431-
var lstModel = await AppManager.Instance.ProfileItems(_config.SubIndexId, filter);
431+
var lstModel = await AppManager.Instance.ProfileModels(_config.SubIndexId, filter);
432432

433433
await ConfigHandler.SetDefaultServer(_config, lstModel);
434434

v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private async Task RefreshServersBiz()
303303

304304
private async Task RefreshServersMenu()
305305
{
306-
var lstModel = await AppManager.Instance.ProfileItems(_config.SubIndexId, "");
306+
var lstModel = await AppManager.Instance.ProfileModels(_config.SubIndexId, "");
307307

308308
Servers.Clear();
309309
if (lstModel.Count > _config.GuiItem.TrayMenuServersLimit)
@@ -315,7 +315,7 @@ private async Task RefreshServersMenu()
315315
BlServers = true;
316316
for (var k = 0; k < lstModel.Count; k++)
317317
{
318-
ProfileItem it = lstModel[k];
318+
var it = lstModel[k];
319319
var name = it.GetSummary();
320320

321321
var item = new ComboItem() { ID = it.IndexId, Text = name };

0 commit comments

Comments
 (0)