Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Dec 16, 2024
1 parent 1a33c59 commit c49ba73
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions v2rayN/ServiceLib/ViewModels/MsgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class MsgViewModel : MyReactiveObject
{
private ConcurrentQueue<string> _queueMsg = new();
private int _numMaxMsg = 500;
private string _lastMsgFilter = string.Empty;
private bool _lastMsgFilterNotAvailable;
private bool _blLockShow = false;

Expand All @@ -28,7 +27,7 @@ public MsgViewModel(Func<EViewAction, object?, Task<bool>>? updateView)

this.WhenAnyValue(
x => x.MsgFilter)
.Subscribe(c => _config.MsgUIItem.MainMsgFilter = MsgFilter);
.Subscribe(c => DoMsgFilter());

this.WhenAnyValue(
x => x.AutoRefresh,
Expand Down Expand Up @@ -77,8 +76,7 @@ private async Task AppendQueueMsg(string msg)
private async Task EnqueueQueueMsg(string msg)
{
//filter msg
if (MsgFilter != _lastMsgFilter) _lastMsgFilterNotAvailable = false;
if (Utils.IsNotEmpty(MsgFilter) && !_lastMsgFilterNotAvailable)
if (MsgFilter.IsNotEmpty() && !_lastMsgFilterNotAvailable)
{
try
{
Expand All @@ -87,12 +85,12 @@ private async Task EnqueueQueueMsg(string msg)
return;
}
}
catch (Exception)
catch (Exception ex)
{
_queueMsg.Enqueue(ex.Message);
_lastMsgFilterNotAvailable = true;
}
}
_lastMsgFilter = MsgFilter;

//Enqueue
if (_queueMsg.Count > _numMaxMsg)
Expand All @@ -113,5 +111,11 @@ public void ClearMsg()
{
_queueMsg.Clear();
}

private void DoMsgFilter()
{
_config.MsgUIItem.MainMsgFilter = MsgFilter;
_lastMsgFilterNotAvailable = false;
}
}
}

0 comments on commit c49ba73

Please sign in to comment.