client: Windows 客户端(WinUI3 壳 + agent-core;调试用 Electron 壳存档);localserver token 改为常数时间比较
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.System;
|
||||
using EveryPublish.Client.Services;
|
||||
|
||||
namespace EveryPublish.Client.Pages;
|
||||
|
||||
public sealed partial class StatusPage : Page
|
||||
{
|
||||
private ClientContext _ctx = null!;
|
||||
private DispatcherTimer? _timer;
|
||||
|
||||
public StatusPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
_timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
|
||||
_timer.Tick += async (s, e) => await RefreshAsync();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
_ctx = (ClientContext)e.Parameter;
|
||||
_ctx.Core.ReloadLocalJson();
|
||||
_timer?.Start();
|
||||
_ = RefreshAsync();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
_timer?.Stop();
|
||||
}
|
||||
|
||||
private async Task RefreshAsync()
|
||||
{
|
||||
_ctx.Core.ReloadLocalJson();
|
||||
var status = await _ctx.Core.GetStatusAsync();
|
||||
if (status == null)
|
||||
{
|
||||
OnlineText.Text = "核心进程未就绪";
|
||||
OnlineDot.Fill = new SolidColorBrush(Microsoft.UI.Colors.Gray);
|
||||
return;
|
||||
}
|
||||
ServerText.Text = status.Server;
|
||||
DeviceText.Text = status.DeviceId > 0 ? "#" + status.DeviceId + "(" + status.Name + ")" : "未配对";
|
||||
SessionText.Text = status.Session;
|
||||
if (status.Online)
|
||||
{
|
||||
OnlineText.Text = "在线";
|
||||
OnlineDot.Fill = new SolidColorBrush(Microsoft.UI.Colors.LimeGreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnlineText.Text = status.DeviceId > 0 ? "离线(自动重连中)" : "未配对";
|
||||
OnlineDot.Fill = new SolidColorBrush(Microsoft.UI.Colors.Orange);
|
||||
}
|
||||
}
|
||||
|
||||
private async void OpenWeb_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var status = await _ctx.Core.GetStatusAsync();
|
||||
var url = status?.Server ?? "http://127.0.0.1:8090";
|
||||
await Launcher.LaunchUriAsync(new Uri(url));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user