diff --git a/v2rayN/ProtosLib/ProtosLib.csproj b/v2rayN/ProtosLib/ProtosLib.csproj index 124ee2f9..6abd38c4 100644 --- a/v2rayN/ProtosLib/ProtosLib.csproj +++ b/v2rayN/ProtosLib/ProtosLib.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs index 8a30a4fa..7337d79f 100644 --- a/v2rayN/v2rayN/App.xaml.cs +++ b/v2rayN/v2rayN/App.xaml.cs @@ -65,10 +65,10 @@ namespace v2rayN Environment.Exit(0); return; } - if (RuntimeInformation.ProcessArchitecture != Architecture.X86 && RuntimeInformation.ProcessArchitecture != Architecture.X64) - { - _config.guiItem.enableStatistics = false; - } + //if (RuntimeInformation.ProcessArchitecture != Architecture.X86 && RuntimeInformation.ProcessArchitecture != Architecture.X64) + //{ + // _config.guiItem.enableStatistics = false; + //} } private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { diff --git a/v2rayN/v2rayN/Handler/StatisticsHandler.cs b/v2rayN/v2rayN/Handler/StatisticsHandler.cs index f548346e..23f18ba1 100644 --- a/v2rayN/v2rayN/Handler/StatisticsHandler.cs +++ b/v2rayN/v2rayN/Handler/StatisticsHandler.cs @@ -1,4 +1,5 @@ using Grpc.Core; +using Grpc.Net.Client; using ProtosLib.Statistics; using System.Net; using System.Net.Sockets; @@ -7,17 +8,17 @@ using v2rayN.Mode; namespace v2rayN.Handler { - class StatisticsHandler + internal class StatisticsHandler { private Mode.Config config_; - private Channel channel_; - private StatsService.StatsServiceClient client_; - private bool exitFlag_; + private GrpcChannel _channel; + private StatsService.StatsServiceClient _client; + private bool _exitFlag; private ServerStatItem? _serverStatItem; private List _lstServerStat; public List ServerStat => _lstServerStat; - Action updateFunc_; + private Action _updateFunc; public bool Enable { @@ -28,8 +29,8 @@ namespace v2rayN.Handler { config_ = config; Enable = config.guiItem.enableStatistics; - updateFunc_ = update; - exitFlag_ = false; + _updateFunc = update; + _exitFlag = false; Init(); GrpcInit(); @@ -39,13 +40,12 @@ namespace v2rayN.Handler private void GrpcInit() { - if (channel_ == null) + if (_channel == null) { Global.statePort = GetFreePort(); - channel_ = new Channel($"{Global.Loopback}:{Global.statePort}", ChannelCredentials.Insecure); - channel_.ConnectAsync(); - client_ = new StatsService.StatsServiceClient(channel_); + _channel = GrpcChannel.ForAddress($"{Global.httpProtocol}{Global.Loopback}:{Global.statePort}"); + _client = new StatsService.StatsServiceClient(_channel); } } @@ -53,8 +53,8 @@ namespace v2rayN.Handler { try { - exitFlag_ = true; - channel_.ShutdownAsync(); + _exitFlag = true; + //channel_.ShutdownAsync(); } catch (Exception ex) { @@ -62,18 +62,18 @@ namespace v2rayN.Handler } } - public void Run() + public async void Run() { - while (!exitFlag_) + while (!_exitFlag) { try { - if (Enable && channel_.State == ChannelState.Ready) + if (Enable && _channel.State == ConnectivityState.Ready) { QueryStatsResponse? res = null; try { - res = client_.QueryStats(new QueryStatsRequest() { Pattern = "", Reset = true }); + res = await _client.QueryStatsAsync(new QueryStatsRequest() { Pattern = "", Reset = true }); } catch (Exception ex) { @@ -99,13 +99,13 @@ namespace v2rayN.Handler server.todayDown = _serverStatItem.todayDown; server.totalUp = _serverStatItem.totalUp; server.totalDown = _serverStatItem.totalDown; - updateFunc_(server); + _updateFunc(server); } } } var sleep = config_.guiItem.statisticsFreshRate < 1 ? 1 : config_.guiItem.statisticsFreshRate; Thread.Sleep(1000 * sleep); - channel_.ConnectAsync(); + await _channel.ConnectAsync(); } catch { @@ -182,7 +182,6 @@ namespace v2rayN.Handler server = new(); try { - foreach (Stat stat in source) { string name = stat.Name; @@ -245,4 +244,4 @@ namespace v2rayN.Handler } } } -} +} \ No newline at end of file