Skip to content

Commit

Permalink
Refactor the main interface
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jul 18, 2024
1 parent 355a424 commit bc35938
Show file tree
Hide file tree
Showing 9 changed files with 1,590 additions and 1,348 deletions.
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ internal class Global
public const string CommandClearMsg = "CommandClearMsg";
public const string CommandSendMsgView = "CommandSendMsgView";
public const string CommandStopSpeedTest = "CommandStopSpeedTest";
public const string CommandRefreshProfiles = "CommandRefreshProfiles";
public const string DelayUnit = "";
public const string SpeedUnit = "";
public const int MinFontSize = 10;
Expand Down
21 changes: 12 additions & 9 deletions v2rayN/v2rayN/Handler/Statistics/StatisticsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace v2rayN.Handler.Statistics
{
internal class StatisticsHandler
{
private static readonly Lazy<StatisticsHandler> instance = new(() => new());
public static StatisticsHandler Instance => instance.Value;

private Config _config;
private ServerStatItem? _serverStatItem;
private List<ServerStatItem> _lstServerStat;
Expand All @@ -12,20 +15,17 @@ internal class StatisticsHandler
private StatisticsSingbox? _statisticsSingbox;

public List<ServerStatItem> ServerStat => _lstServerStat;
public bool Enable { get; set; }

public StatisticsHandler(Config config, Action<ServerSpeedItem> update)
public void Init(Config config, Action<ServerSpeedItem> update)
{
_config = config;
Enable = config.guiItem.enableStatistics;
if (!Enable)
_updateFunc = update;
if (!config.guiItem.enableStatistics)
{
return;
}

_updateFunc = update;

Init();
InitData();

_statisticsV2Ray = new StatisticsV2ray(config, UpdateServerStat);
_statisticsSingbox = new StatisticsSingbox(config, UpdateServerStat);
Expand Down Expand Up @@ -55,15 +55,18 @@ public void SaveTo()
{
try
{
SQLiteHelper.Instance.UpdateAll(_lstServerStat);
if (_lstServerStat != null)
{
SQLiteHelper.Instance.UpdateAll(_lstServerStat);
}
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
}
}

private void Init()
private void InitData()
{
SQLiteHelper.Instance.Execute($"delete from ServerStatItem where indexId not in ( select indexId from ProfileItem )");

Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Models/ServerSpeedItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace v2rayN.Models
{
[Serializable]
internal class ServerSpeedItem : ServerStatItem
public class ServerSpeedItem : ServerStatItem
{
public long proxyUp
{
Expand Down
Loading

0 comments on commit bc35938

Please sign in to comment.