This commit is contained in:
RMBGAME
2022-06-23 13:56:20 +08:00
parent c033e853d6
commit 24fd562475
3 changed files with 23 additions and 7 deletions
@@ -1,13 +1,16 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using DynamicData.Binding;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Avalonia;
using ReactiveUI;
using System.Application.Models;
using System.Application.Services;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace System.Application.UI.Views.Pages
@@ -69,7 +72,21 @@ namespace System.Application.UI.Views.Pages
chart.YAxes = new Axis[] { new Axis { Labeler = YFormatter, MinLimit = 0 } };
}
FlushFlowChartAsync();
var cancellation = new CancellationTokenSource();
ProxyService.Current.WhenValueChanged(x => x.ProxyStatus, false)
.Subscribe(x =>
{
if (x)
{
cancellation.TryReset();
FlushFlowChartAsync(cancellation.Token);
}
else
{
cancellation.Cancel();
}
});
}
private void InitializeComponent()
@@ -92,15 +109,13 @@ namespace System.Application.UI.Views.Pages
}
}
private async void FlushFlowChartAsync()
private async void FlushFlowChartAsync(CancellationToken token)
{
while (true)
while (!token.IsCancellationRequested)
{
try
{
if (!ProxyService.Current.ProxyStatus) continue;
var flowStatistics = await IHttpService.Instance.GetAsync<FlowStatistics>("https://localhost/flowStatistics");
var flowStatistics = await IHttpService.Instance.GetAsync<FlowStatistics>("https://localhost/flowStatistics", cancellationToken: token);
if (flowStatistics == null)
{
continue;
@@ -28,6 +28,7 @@ namespace System.Application.Services
void InitCloudManageMain(int appid);
void InitTaskBarWindowViewModel();
void DispoeTaskBarWindowViewModel();
/// <summary>
@@ -91,7 +91,7 @@ namespace System.Application.Services.Implementation
{
try
{
if (OperatingSystem2.IsWindows() && StartupOptions.Value.HasNotifyIcon && taskbarWindow == null)
if (OperatingSystem2.IsWindows() && StartupOptions.Value.HasNotifyIcon && taskbarWindow == null && mMainWindow != null)
{
taskbarWindow = new TaskBarWindowViewModel(mMainWindow);
}