feat(desktop): 主界面增加 工具 / 服务 / 帮助 菜单

- 工具:测试查询(聚焦输入框)、清理更新缓存(删 %TEMP%\YuncangTraceUpdate)
- 服务:服务状态(只读,随启停实时刷新)、重启软件
- 帮助:检查更新(复用启动时的检查流程)、关于(版本/环境/服务状态)
- 重启/检查更新通过事件交给 App,避免 MainWindow 直接碰进程与更新逻辑
- 保持界面不出现服务地址 / 协议 / 停止服务 等内部信息
This commit is contained in:
liufumingren 2026-10-17 18:03:59 +08:00
parent 2ab3ad35e5
commit 7fdbe5afc1
4 changed files with 80 additions and 3 deletions

View File

@ -281,6 +281,8 @@ public partial class App : Application
_main = new MainWindow(server, _settings, session);
_main.LogoutRequested += OnLogoutRequested;
_main.HiddenToTray += OnHiddenToTray;
_main.RestartRequested += RestartApplication;
_main.CheckUpdateRequested += () => _ = CheckUpdatesAsync();
}
ShowAppWindow();

View File

@ -10,13 +10,35 @@
FontSize="13">
<Grid Margin="18">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- 菜单 -->
<Menu Grid.Row="0" Margin="-6,0,0,8" Background="Transparent" BorderThickness="0">
<MenuItem Header="工具(_T)">
<MenuItem Header="测试查询" Click="FocusQuery_Click" />
<Separator />
<MenuItem Header="清理更新缓存" Click="ClearUpdateCache_Click" />
</MenuItem>
<MenuItem Header="服务(_S)">
<MenuItem x:Name="MenuServiceStatus" Header="服务状态" IsEnabled="False" />
<Separator />
<MenuItem Header="重启软件" Click="Restart_Click" />
</MenuItem>
<MenuItem Header="帮助(_H)">
<MenuItem Header="检查更新" Click="CheckUpdate_Click" />
<Separator />
<MenuItem Header="关于" Click="About_Click" />
</MenuItem>
</Menu>
<!-- ① 标题 + 运行状态 + 当前登录用户 -->
<DockPanel Grid.Row="0" Margin="0,0,0,14">
<DockPanel Grid.Row="1" Margin="0,0,0,14">
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock x:Name="UserText" Text="未登录" Foreground="{StaticResource MutedBrush}"
VerticalAlignment="Center" Margin="0,0,10,0" />
@ -32,7 +54,7 @@
</DockPanel>
<!-- ② 查询测试 -->
<Border Grid.Row="1" Background="White" BorderBrush="{StaticResource LineBrush}"
<Border Grid.Row="2" Background="White" BorderBrush="{StaticResource LineBrush}"
BorderThickness="1" CornerRadius="8" Padding="12,10" Margin="0,0,0,10">
<StackPanel>
<DockPanel>
@ -50,7 +72,7 @@
</Border>
<!-- ③ 日志 -->
<Grid Grid.Row="2">
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
@ -29,6 +30,12 @@ public partial class MainWindow : Window
/// <summary>窗口被隐藏到托盘(用来弹一次气泡提示)</summary>
public event Action? HiddenToTray;
/// <summary>菜单「帮助 → 检查更新」(交给 App 处理,复用启动时的检查逻辑)</summary>
public event Action? CheckUpdateRequested;
/// <summary>菜单「服务 → 重启软件」(交给 App 处理:先退出再延迟拉起)</summary>
public event Action? RestartRequested;
public MainWindow(LocalHttpServer server, AppSettings settings, Session session)
{
InitializeComponent();
@ -82,6 +89,47 @@ public partial class MainWindow : Window
StatusText.Text = running ? $"运行中 · {_server.BaseUrl}" : "未启动";
StatusDot.Fill = (Brush)FindResource(running ? "OkBrush" : "BadBrush");
MenuServiceStatus.Header = running ? "服务状态:运行中" : "服务状态:未启动";
}
// ---------------- 菜单 ----------------
private void FocusQuery_Click(object sender, RoutedEventArgs e)
{
QueryBox.Focus();
QueryBox.SelectAll();
}
private void ClearUpdateCache_Click(object sender, RoutedEventArgs e)
{
var dir = Path.Combine(Path.GetTempPath(), "YuncangTraceUpdate");
try
{
if (Directory.Exists(dir)) Directory.Delete(dir, recursive: true);
AppLog.Write($"已清理更新缓存:{dir}");
}
catch (Exception ex)
{
AppLog.Write($"清理更新缓存失败:{ex.Message}");
}
}
private void Restart_Click(object sender, RoutedEventArgs e) => RestartRequested?.Invoke();
private void CheckUpdate_Click(object sender, RoutedEventArgs e) => CheckUpdateRequested?.Invoke();
private void About_Click(object sender, RoutedEventArgs e)
{
var version = GetType().Assembly.GetName().Version?.ToString() ?? "1.0.0";
MessageBox.Show(this,
$"云仓视频溯源软件(本机服务)\n\n" +
$"版本:{version}\n" +
$"环境:{BuildInfo.EnvironmentLabel}\n" +
$"服务:{(_server.IsRunning ? "运行中" : "未启动")}",
"关于",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
// ---------------- 查询 ----------------

View File

@ -51,6 +51,11 @@ desktop/
> 主界面**没有「停止服务 / 启动服务」**:本机服务跟随程序生命周期(启动即开、退出即停)。
> 留个停止按钮只会让用户误点后网页再也叫不醒软件(显示内容与「未安装」一模一样)。
> 也**没有「复制唤醒地址」**:唤醒地址由插件生成,不需要在界面上手测。
>
> 主界面顶部菜单:
> - **工具**:测试查询(聚焦输入框)、清理更新缓存(`%TEMP%\YuncangTraceUpdate`)
> - **服务**:服务状态(只读)、重启软件
> - **帮助**:检查更新、关于(版本 / 环境 / 运行状态)
## 环境配置(开发 / 生产)