Refactor ProfileItem protocol extra handling

This commit is contained in:
2dust 2026-01-21 20:59:10 +08:00 committed by DHR60
parent 323bf70474
commit 3b826e3e36
2 changed files with 15 additions and 8 deletions

View file

@ -1102,6 +1102,7 @@ public static class ConfigHandler
if (toFile) if (toFile)
{ {
profileItem.SetProtocolExtra();
await SQLiteHelper.Instance.ReplaceAsync(profileItem); await SQLiteHelper.Instance.ReplaceAsync(profileItem);
} }
return 0; return 0;

View file

@ -3,7 +3,7 @@ namespace ServiceLib.Models;
[Serializable] [Serializable]
public class ProfileItem : ReactiveObject public class ProfileItem : ReactiveObject
{ {
private ProtocolExtraItem _protocolExtraItem = new(); private ProtocolExtraItem? _protocolExtraCache;
public ProfileItem() public ProfileItem()
{ {
@ -129,12 +129,18 @@ public class ProfileItem : ReactiveObject
public void SetProtocolExtra(ProtocolExtraItem extraItem) public void SetProtocolExtra(ProtocolExtraItem extraItem)
{ {
_protocolExtraItem = extraItem; _protocolExtraCache = extraItem;
ProtoExtra = JsonUtils.Serialize(extraItem, false);
}
public void SetProtocolExtra()
{
ProtoExtra = JsonUtils.Serialize(_protocolExtraCache, false);
} }
public ProtocolExtraItem GetProtocolExtra() public ProtocolExtraItem GetProtocolExtra()
{ {
return _protocolExtraItem; return _protocolExtraCache ??= JsonUtils.Deserialize<ProtocolExtraItem>(ProtoExtra) ?? new ProtocolExtraItem();
} }
#endregion function #endregion function
@ -173,20 +179,20 @@ public class ProfileItem : ReactiveObject
public string EchConfigList { get; set; } public string EchConfigList { get; set; }
public string EchForceQuery { get; set; } public string EchForceQuery { get; set; }
public string ProtoExtra public string ProtoExtra { get; set; }
{
get => JsonUtils.Serialize(_protocolExtraItem, false);
set => _protocolExtraItem = JsonUtils.Deserialize<ProtocolExtraItem>(value);
}
[Obsolete("Use ProtocolExtraItem.Ports instead.")] [Obsolete("Use ProtocolExtraItem.Ports instead.")]
public string Ports { get; set; } public string Ports { get; set; }
[Obsolete("Use ProtocolExtraItem.AlterId instead.")] [Obsolete("Use ProtocolExtraItem.AlterId instead.")]
public int AlterId { get; set; } public int AlterId { get; set; }
[Obsolete("Use ProtocolExtraItem.Flow instead.")] [Obsolete("Use ProtocolExtraItem.Flow instead.")]
public string Flow { get; set; } public string Flow { get; set; }
[Obsolete("Use ProfileItem.Password instead.")] [Obsolete("Use ProfileItem.Password instead.")]
public string Id { get; set; } public string Id { get; set; }
[Obsolete("Use ProtocolExtraItem.xxx instead.")] [Obsolete("Use ProtocolExtraItem.xxx instead.")]
public string Security { get; set; } public string Security { get; set; }
} }