From 6167624443914924a501cc7007b665040f36b136 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Fri, 6 Feb 2026 13:50:47 +0800
Subject: [PATCH] Rename ProfileItems to ProfileModels and refactor
---
v2rayN/ServiceLib/Handler/ConfigHandler.cs | 7 +++---
v2rayN/ServiceLib/Helper/DownloaderHelper.cs | 2 +-
v2rayN/ServiceLib/Manager/AppManager.cs | 13 ++++++++---
v2rayN/ServiceLib/Models/ConfigItems.cs | 2 +-
v2rayN/ServiceLib/Models/ProfileItem.cs | 16 ++++++-------
v2rayN/ServiceLib/Models/ProfileItemModel.cs | 23 +++++++++++++++++--
.../ViewModels/AddServerViewModel.cs | 3 +++
.../ViewModels/ProfilesSelectViewModel.cs | 2 +-
.../ViewModels/ProfilesViewModel.cs | 4 ++--
.../ViewModels/StatusBarViewModel.cs | 4 ++--
10 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
index 0ea515ec..37176608 100644
--- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs
+++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
@@ -844,7 +844,7 @@ public static class ConfigHandler
/// 0 if successful, -1 if failed
public static async Task SortServers(Config config, string subId, string colName, bool asc)
{
- var lstModel = await AppManager.Instance.ProfileItems(subId, "");
+ var lstModel = await AppManager.Instance.ProfileModels(subId, "");
if (lstModel.Count <= 0)
{
return -1;
@@ -1213,7 +1213,8 @@ public static class ConfigHandler
}
var extraItem = new ProtocolExtraItem
{
- ChildItems = childProfileIndexId, MultipleLoad = multipleLoad,
+ ChildItems = childProfileIndexId,
+ MultipleLoad = multipleLoad,
};
profile.SetProtocolExtra(extraItem);
var ret = await AddServerCommon(config, profile, true);
@@ -1277,7 +1278,7 @@ public static class ConfigHandler
/// Number of removed servers or -1 if failed
public static async Task RemoveInvalidServerResult(Config config, string subid)
{
- var lstModel = await AppManager.Instance.ProfileItems(subid, "");
+ var lstModel = await AppManager.Instance.ProfileModels(subid, "");
if (lstModel is { Count: <= 0 })
{
return -1;
diff --git a/v2rayN/ServiceLib/Helper/DownloaderHelper.cs b/v2rayN/ServiceLib/Helper/DownloaderHelper.cs
index 907d416f..f4a7ae7f 100644
--- a/v2rayN/ServiceLib/Helper/DownloaderHelper.cs
+++ b/v2rayN/ServiceLib/Helper/DownloaderHelper.cs
@@ -85,7 +85,7 @@ public class DownloaderHelper
{
maxSpeed = value.BytesPerSecondSpeed;
}
-
+
var ts = DateTime.Now - lastUpdateTime;
if (ts.TotalMilliseconds >= 1000)
{
diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs
index 83633c0f..0e471568 100644
--- a/v2rayN/ServiceLib/Manager/AppManager.cs
+++ b/v2rayN/ServiceLib/Manager/AppManager.cs
@@ -191,10 +191,17 @@ public sealed class AppManager
return (await ProfileItems(subid))?.Select(t => t.IndexId)?.ToList();
}
- public async Task?> ProfileItems(string subid, string filter)
+ public async Task?> ProfileModels(string subid, string filter)
{
- var sql = @$"select a.*
- ,b.remarks subRemarks
+ var sql = @$"select a.IndexId
+ ,a.ConfigType
+ ,a.Remarks
+ ,a.Address
+ ,a.Port
+ ,a.Network
+ ,a.StreamSecurity
+ ,a.Subid
+ ,b.remarks as subRemarks
from ProfileItem a
left join SubItem b on a.subid = b.id
where 1=1 ";
diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs
index 46297e40..46caee85 100644
--- a/v2rayN/ServiceLib/Models/ConfigItems.cs
+++ b/v2rayN/ServiceLib/Models/ConfigItems.cs
@@ -99,7 +99,7 @@ public class UIItem
public bool EnableDragDropSort { get; set; }
public bool DoubleClick2Activate { get; set; }
public bool AutoHideStartup { get; set; }
- public bool Hide2TrayWhenClose { get; set; }
+ public bool Hide2TrayWhenClose { get; set; }
public bool MacOSShowInDock { get; set; }
public List MainColumnItem { get; set; }
public List WindowSizeItem { get; set; }
diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs
index a43b6d18..6e9d2a30 100644
--- a/v2rayN/ServiceLib/Models/ProfileItem.cs
+++ b/v2rayN/ServiceLib/Models/ProfileItem.cs
@@ -1,7 +1,7 @@
namespace ServiceLib.Models;
[Serializable]
-public class ProfileItem : ReactiveObject
+public class ProfileItem
{
private ProtocolExtraItem? _protocolExtraCache;
@@ -10,6 +10,7 @@ public class ProfileItem : ReactiveObject
IndexId = string.Empty;
ConfigType = EConfigType.VMess;
ConfigVersion = 3;
+ Subid = string.Empty;
Address = string.Empty;
Port = 0;
Password = string.Empty;
@@ -21,7 +22,6 @@ public class ProfileItem : ReactiveObject
Path = string.Empty;
StreamSecurity = string.Empty;
AllowInsecure = string.Empty;
- Subid = string.Empty;
}
#region function
@@ -148,26 +148,26 @@ public class ProfileItem : ReactiveObject
public string IndexId { get; set; }
public EConfigType ConfigType { get; set; }
+ public ECoreType? CoreType { get; set; }
public int ConfigVersion { get; set; }
+ public string Subid { get; set; }
+ public bool IsSub { get; set; } = true;
+ public int? PreSocksPort { get; set; }
+ public bool DisplayLog { get; set; } = true;
+ public string Remarks { get; set; }
public string Address { get; set; }
public int Port { get; set; }
public string Password { get; set; }
public string Username { get; set; }
public string Network { get; set; }
- public string Remarks { get; set; }
public string HeaderType { get; set; }
public string RequestHost { get; set; }
public string Path { get; set; }
public string StreamSecurity { get; set; }
public string AllowInsecure { get; set; }
- public string Subid { get; set; }
- public bool IsSub { get; set; } = true;
public string Sni { get; set; }
public string Alpn { get; set; } = string.Empty;
- public ECoreType? CoreType { get; set; }
- public int? PreSocksPort { get; set; }
public string Fingerprint { get; set; }
- public bool DisplayLog { get; set; } = true;
public string PublicKey { get; set; }
public string ShortId { get; set; }
public string SpiderX { get; set; }
diff --git a/v2rayN/ServiceLib/Models/ProfileItemModel.cs b/v2rayN/ServiceLib/Models/ProfileItemModel.cs
index b4d72119..53170f17 100644
--- a/v2rayN/ServiceLib/Models/ProfileItemModel.cs
+++ b/v2rayN/ServiceLib/Models/ProfileItemModel.cs
@@ -1,16 +1,24 @@
namespace ServiceLib.Models;
[Serializable]
-public class ProfileItemModel : ProfileItem
+public class ProfileItemModel : ReactiveObject
{
public bool IsActive { get; set; }
+ public string IndexId { get; set; }
+ public EConfigType ConfigType { get; set; }
+ public string Remarks { get; set; }
+ public string Address { get; set; }
+ public int Port { get; set; }
+ public string Network { get; set; }
+ public string StreamSecurity { get; set; }
+ public string Subid { get; set; }
public string SubRemarks { get; set; }
+ public int Sort { get; set; }
[Reactive]
public int Delay { get; set; }
public decimal Speed { get; set; }
- public int Sort { get; set; }
[Reactive]
public string DelayVal { get; set; }
@@ -29,4 +37,15 @@ public class ProfileItemModel : ProfileItem
[Reactive]
public string TotalDown { get; set; }
+
+ public string GetSummary()
+ {
+ var summary = $"[{ConfigType}] {Remarks}";
+ if (!ConfigType.IsComplexType())
+ {
+ summary += $"({Address}:{Port})";
+ }
+
+ return summary;
+ }
}
diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs
index 914705c8..ba698c20 100644
--- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs
@@ -49,12 +49,15 @@ public class AddServerViewModel : MyReactiveObject
[Reactive]
public string WgPublicKey { get; set; }
+
//[Reactive]
//public string WgPresharedKey { get; set; }
[Reactive]
public string WgInterfaceAddress { get; set; }
+
[Reactive]
public string WgReserved { get; set; }
+
[Reactive]
public int WgMtu { get; set; }
diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs
index ca065d5d..ce349cb4 100644
--- a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs
@@ -200,7 +200,7 @@ public class ProfilesSelectViewModel : MyReactiveObject
private async Task?> GetProfileItemsEx(string subid, string filter)
{
- var lstModel = await AppManager.Instance.ProfileItems(_subIndexId, filter);
+ var lstModel = await AppManager.Instance.ProfileModels(_subIndexId, filter);
lstModel = (from t in lstModel
select new ProfileItemModel
{
diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
index 7bd4cb98..2d838189 100644
--- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
@@ -56,7 +56,7 @@ public class ProfilesViewModel : MyReactiveObject
public ReactiveCommand MoveUpCmd { get; }
public ReactiveCommand MoveDownCmd { get; }
- public ReactiveCommand MoveBottomCmd { get; }
+ public ReactiveCommand MoveBottomCmd { get; }
public ReactiveCommand MoveToGroupCmd { get; }
//servers ping
@@ -428,7 +428,7 @@ public class ProfilesViewModel : MyReactiveObject
private async Task?> GetProfileItemsEx(string subid, string filter)
{
- var lstModel = await AppManager.Instance.ProfileItems(_config.SubIndexId, filter);
+ var lstModel = await AppManager.Instance.ProfileModels(_config.SubIndexId, filter);
await ConfigHandler.SetDefaultServer(_config, lstModel);
diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
index b8cd142e..9269851d 100644
--- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs
@@ -303,7 +303,7 @@ public class StatusBarViewModel : MyReactiveObject
private async Task RefreshServersMenu()
{
- var lstModel = await AppManager.Instance.ProfileItems(_config.SubIndexId, "");
+ var lstModel = await AppManager.Instance.ProfileModels(_config.SubIndexId, "");
Servers.Clear();
if (lstModel.Count > _config.GuiItem.TrayMenuServersLimit)
@@ -315,7 +315,7 @@ public class StatusBarViewModel : MyReactiveObject
BlServers = true;
for (var k = 0; k < lstModel.Count; k++)
{
- ProfileItem it = lstModel[k];
+ var it = lstModel[k];
var name = it.GetSummary();
var item = new ComboItem() { ID = it.IndexId, Text = name };