mirror of
https://github.com/2dust/v2rayN.git
synced 2026-02-18 08:13:02 +00:00
Rename ProfileItems to ProfileModels and refactor
This commit is contained in:
parent
7a58e78381
commit
6167624443
10 changed files with 53 additions and 23 deletions
|
|
@ -844,7 +844,7 @@ public static class ConfigHandler
|
||||||
/// <returns>0 if successful, -1 if failed</returns>
|
/// <returns>0 if successful, -1 if failed</returns>
|
||||||
public static async Task<int> SortServers(Config config, string subId, string colName, bool asc)
|
public static async Task<int> 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)
|
if (lstModel.Count <= 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -1213,7 +1213,8 @@ public static class ConfigHandler
|
||||||
}
|
}
|
||||||
var extraItem = new ProtocolExtraItem
|
var extraItem = new ProtocolExtraItem
|
||||||
{
|
{
|
||||||
ChildItems = childProfileIndexId, MultipleLoad = multipleLoad,
|
ChildItems = childProfileIndexId,
|
||||||
|
MultipleLoad = multipleLoad,
|
||||||
};
|
};
|
||||||
profile.SetProtocolExtra(extraItem);
|
profile.SetProtocolExtra(extraItem);
|
||||||
var ret = await AddServerCommon(config, profile, true);
|
var ret = await AddServerCommon(config, profile, true);
|
||||||
|
|
@ -1277,7 +1278,7 @@ public static class ConfigHandler
|
||||||
/// <returns>Number of removed servers or -1 if failed</returns>
|
/// <returns>Number of removed servers or -1 if failed</returns>
|
||||||
public static async Task<int> RemoveInvalidServerResult(Config config, string subid)
|
public static async Task<int> RemoveInvalidServerResult(Config config, string subid)
|
||||||
{
|
{
|
||||||
var lstModel = await AppManager.Instance.ProfileItems(subid, "");
|
var lstModel = await AppManager.Instance.ProfileModels(subid, "");
|
||||||
if (lstModel is { Count: <= 0 })
|
if (lstModel is { Count: <= 0 })
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -191,10 +191,17 @@ public sealed class AppManager
|
||||||
return (await ProfileItems(subid))?.Select(t => t.IndexId)?.ToList();
|
return (await ProfileItems(subid))?.Select(t => t.IndexId)?.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<ProfileItemModel>?> ProfileItems(string subid, string filter)
|
public async Task<List<ProfileItemModel>?> ProfileModels(string subid, string filter)
|
||||||
{
|
{
|
||||||
var sql = @$"select a.*
|
var sql = @$"select a.IndexId
|
||||||
,b.remarks subRemarks
|
,a.ConfigType
|
||||||
|
,a.Remarks
|
||||||
|
,a.Address
|
||||||
|
,a.Port
|
||||||
|
,a.Network
|
||||||
|
,a.StreamSecurity
|
||||||
|
,a.Subid
|
||||||
|
,b.remarks as subRemarks
|
||||||
from ProfileItem a
|
from ProfileItem a
|
||||||
left join SubItem b on a.subid = b.id
|
left join SubItem b on a.subid = b.id
|
||||||
where 1=1 ";
|
where 1=1 ";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
namespace ServiceLib.Models;
|
namespace ServiceLib.Models;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ProfileItem : ReactiveObject
|
public class ProfileItem
|
||||||
{
|
{
|
||||||
private ProtocolExtraItem? _protocolExtraCache;
|
private ProtocolExtraItem? _protocolExtraCache;
|
||||||
|
|
||||||
|
|
@ -10,6 +10,7 @@ public class ProfileItem : ReactiveObject
|
||||||
IndexId = string.Empty;
|
IndexId = string.Empty;
|
||||||
ConfigType = EConfigType.VMess;
|
ConfigType = EConfigType.VMess;
|
||||||
ConfigVersion = 3;
|
ConfigVersion = 3;
|
||||||
|
Subid = string.Empty;
|
||||||
Address = string.Empty;
|
Address = string.Empty;
|
||||||
Port = 0;
|
Port = 0;
|
||||||
Password = string.Empty;
|
Password = string.Empty;
|
||||||
|
|
@ -21,7 +22,6 @@ public class ProfileItem : ReactiveObject
|
||||||
Path = string.Empty;
|
Path = string.Empty;
|
||||||
StreamSecurity = string.Empty;
|
StreamSecurity = string.Empty;
|
||||||
AllowInsecure = string.Empty;
|
AllowInsecure = string.Empty;
|
||||||
Subid = string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region function
|
#region function
|
||||||
|
|
@ -148,26 +148,26 @@ public class ProfileItem : ReactiveObject
|
||||||
public string IndexId { get; set; }
|
public string IndexId { get; set; }
|
||||||
|
|
||||||
public EConfigType ConfigType { get; set; }
|
public EConfigType ConfigType { get; set; }
|
||||||
|
public ECoreType? CoreType { get; set; }
|
||||||
public int ConfigVersion { 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 string Address { get; set; }
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string Network { get; set; }
|
public string Network { get; set; }
|
||||||
public string Remarks { get; set; }
|
|
||||||
public string HeaderType { get; set; }
|
public string HeaderType { get; set; }
|
||||||
public string RequestHost { get; set; }
|
public string RequestHost { get; set; }
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
public string StreamSecurity { get; set; }
|
public string StreamSecurity { get; set; }
|
||||||
public string AllowInsecure { 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 Sni { get; set; }
|
||||||
public string Alpn { get; set; } = string.Empty;
|
public string Alpn { get; set; } = string.Empty;
|
||||||
public ECoreType? CoreType { get; set; }
|
|
||||||
public int? PreSocksPort { get; set; }
|
|
||||||
public string Fingerprint { get; set; }
|
public string Fingerprint { get; set; }
|
||||||
public bool DisplayLog { get; set; } = true;
|
|
||||||
public string PublicKey { get; set; }
|
public string PublicKey { get; set; }
|
||||||
public string ShortId { get; set; }
|
public string ShortId { get; set; }
|
||||||
public string SpiderX { get; set; }
|
public string SpiderX { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,24 @@
|
||||||
namespace ServiceLib.Models;
|
namespace ServiceLib.Models;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ProfileItemModel : ProfileItem
|
public class ProfileItemModel : ReactiveObject
|
||||||
{
|
{
|
||||||
public bool IsActive { get; set; }
|
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 string SubRemarks { get; set; }
|
||||||
|
public int Sort { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public int Delay { get; set; }
|
public int Delay { get; set; }
|
||||||
|
|
||||||
public decimal Speed { get; set; }
|
public decimal Speed { get; set; }
|
||||||
public int Sort { get; set; }
|
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string DelayVal { get; set; }
|
public string DelayVal { get; set; }
|
||||||
|
|
@ -29,4 +37,15 @@ public class ProfileItemModel : ProfileItem
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string TotalDown { get; set; }
|
public string TotalDown { get; set; }
|
||||||
|
|
||||||
|
public string GetSummary()
|
||||||
|
{
|
||||||
|
var summary = $"[{ConfigType}] {Remarks}";
|
||||||
|
if (!ConfigType.IsComplexType())
|
||||||
|
{
|
||||||
|
summary += $"({Address}:{Port})";
|
||||||
|
}
|
||||||
|
|
||||||
|
return summary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,15 @@ public class AddServerViewModel : MyReactiveObject
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string WgPublicKey { get; set; }
|
public string WgPublicKey { get; set; }
|
||||||
|
|
||||||
//[Reactive]
|
//[Reactive]
|
||||||
//public string WgPresharedKey { get; set; }
|
//public string WgPresharedKey { get; set; }
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string WgInterfaceAddress { get; set; }
|
public string WgInterfaceAddress { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public string WgReserved { get; set; }
|
public string WgReserved { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public int WgMtu { get; set; }
|
public int WgMtu { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ public class ProfilesSelectViewModel : MyReactiveObject
|
||||||
|
|
||||||
private async Task<List<ProfileItemModel>?> GetProfileItemsEx(string subid, string filter)
|
private async Task<List<ProfileItemModel>?> 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
|
lstModel = (from t in lstModel
|
||||||
select new ProfileItemModel
|
select new ProfileItemModel
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -428,7 +428,7 @@ public class ProfilesViewModel : MyReactiveObject
|
||||||
|
|
||||||
private async Task<List<ProfileItemModel>?> GetProfileItemsEx(string subid, string filter)
|
private async Task<List<ProfileItemModel>?> 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);
|
await ConfigHandler.SetDefaultServer(_config, lstModel);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -303,7 +303,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
|
|
||||||
private async Task RefreshServersMenu()
|
private async Task RefreshServersMenu()
|
||||||
{
|
{
|
||||||
var lstModel = await AppManager.Instance.ProfileItems(_config.SubIndexId, "");
|
var lstModel = await AppManager.Instance.ProfileModels(_config.SubIndexId, "");
|
||||||
|
|
||||||
Servers.Clear();
|
Servers.Clear();
|
||||||
if (lstModel.Count > _config.GuiItem.TrayMenuServersLimit)
|
if (lstModel.Count > _config.GuiItem.TrayMenuServersLimit)
|
||||||
|
|
@ -315,7 +315,7 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
BlServers = true;
|
BlServers = true;
|
||||||
for (var k = 0; k < lstModel.Count; k++)
|
for (var k = 0; k < lstModel.Count; k++)
|
||||||
{
|
{
|
||||||
ProfileItem it = lstModel[k];
|
var it = lstModel[k];
|
||||||
var name = it.GetSummary();
|
var name = it.GetSummary();
|
||||||
|
|
||||||
var item = new ComboItem() { ID = it.IndexId, Text = name };
|
var item = new ComboItem() { ID = it.IndexId, Text = name };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue