diff --git a/desktop/MainWindow.xaml.cs b/desktop/MainWindow.xaml.cs
index f500ab5..984d32a 100644
--- a/desktop/MainWindow.xaml.cs
+++ b/desktop/MainWindow.xaml.cs
@@ -1117,7 +1117,29 @@ public partial class MainWindow : Window
// 查询命中扫码记录 → **自动**校验回放(不用用户点按钮):
// 真的去录像机拉一下,确认这段时间有没有录像,再决定是否显示预览/下载。
- if (_currentQuery is { Streams.Count: > 0 } query) _ = ValidatePlaybackAsync(query);
+ if (_currentQuery is { Streams.Count: > 0 } query)
+ {
+ // 不能直接 fire-and-forget:方法内部有 await ConfigureAwait(false),
+ // 异常进不了任何 try,界面会静默停在第一句提示上(现场表现为“卡住”)。
+ _ = RunValidatePlaybackAsync(query);
+ }
+ }
+
+ private async Task RunValidatePlaybackAsync(PackQuery query)
+ {
+ try
+ {
+ await ValidatePlaybackAsync(query).ConfigureAwait(false);
+ }
+ catch (OperationCanceledException)
+ {
+ // 新查询覆盖旧查询:正常
+ }
+ catch (Exception ex)
+ {
+ AppLog.Write($"[playback] 自动校验异常({query.Code}):{ex}");
+ ShowPlayback($"校验回放失败:{ex.Message}");
+ }
}
// ---------------- 回放:校验 / 下载 ----------------
@@ -1180,10 +1202,33 @@ public partial class MainWindow : Window
private void ShowPlayback(string text)
{
+ // 校验流程里有 await ConfigureAwait(false),到这里可能已在线程池线程上,
+ // 直接写控件会抛“调用线程无法访问此对象”。统一切回 UI 线程。
+ if (!Dispatcher.CheckAccess())
+ {
+ Dispatcher.Invoke(() => ShowPlayback(text));
+ return;
+ }
+
PlaybackText.Text = text;
PlaybackPanel.Visibility = Visibility.Visible;
}
+ /// 预览/下载按钮的显隐同样可能来自线程池线程,统一在这里切回 UI 线程。
+ private void SetRouteButtons(bool showPreview, bool showDownload)
+ {
+ if (!Dispatcher.CheckAccess())
+ {
+ Dispatcher.Invoke(() => SetRouteButtons(showPreview, showDownload));
+ return;
+ }
+
+ PreviewButton.Visibility = showPreview ? Visibility.Visible : Visibility.Collapsed;
+ DownloadButton.Visibility = showDownload ? Visibility.Visible : Visibility.Collapsed;
+ PreviewButton.IsEnabled = showPreview;
+ DownloadButton.IsEnabled = showDownload;
+ }
+
///
/// 自动校验回放:**真的去录像机拉一下**这段时间有没有录像
///
@@ -1259,9 +1304,7 @@ public partial class MainWindow : Window
_validatedStreams = hasVideo ? streams : Array.Empty();
// 跨网只给下载:预览要实时拉流,云端中转成本高且体验差
- PreviewButton.Visibility = Visibility.Collapsed;
- DownloadButton.Visibility = hasVideo ? Visibility.Visible : Visibility.Collapsed;
- DownloadButton.IsEnabled = hasVideo;
+ SetRouteButtons(showPreview: false, showDownload: hasVideo);
AppLog.Write($"[route] {query.Code} 云端校验:hasVideo={hasVideo}"
+ $"({cloud.ScannerSn},{cloud.Frames} 帧)→ 跨网只给下载");
@@ -1276,8 +1319,7 @@ public partial class MainWindow : Window
if (cloud is { State: "no-plan" })
{
_validatedStreams = Array.Empty();
- PreviewButton.Visibility = Visibility.Collapsed;
- DownloadButton.Visibility = Visibility.Collapsed;
+ SetRouteButtons(showPreview: false, showDownload: false);
AppLog.Write($"[route] {query.Code} 云端判定无回放计划 → 不给按钮");
lines[0] = "这个运单算不出回放计划(扫码时该通道没绑定工作台)";
@@ -1377,10 +1419,7 @@ public partial class MainWindow : Window
lines[0] = checkedStreams >= streams.Count
? $"校验完成:{valid.Count}/{streams.Count} 路有录像,可以预览或下载"
: $"校验完成:{valid[0].DisplayName} 有录像(其余 {streams.Count - checkedStreams} 路未检查),可以预览或下载";
- PreviewButton.Visibility = Visibility.Visible;
- DownloadButton.Visibility = Visibility.Visible;
- PreviewButton.IsEnabled = true;
- DownloadButton.IsEnabled = true;
+ SetRouteButtons(showPreview: true, showDownload: true);
}
else
{
diff --git a/desktop/Program.cs b/desktop/Program.cs
index 7ed97cf..798b796 100644
--- a/desktop/Program.cs
+++ b/desktop/Program.cs
@@ -74,6 +74,46 @@ public static class Program
app.Run();
}
+ ///
+ /// 自愈时间戳。内置 Administrator 这类没有 UAC 分离令牌的账户,重启出来仍然是提权,
+ /// 会无限自我重启(窗口永远出不来),所以 30 秒内只允许自愈一次。
+ ///
+ private static string RelaunchStampFile => System.IO.Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+ "YuncangTrace", "elevated-relaunch.stamp");
+
+ /// 刚自愈过就又提权启动 → 说明这台机器没有标准令牌可用,别再重启了。
+ private static bool HasJustRelaunched()
+ {
+ try
+ {
+ var file = RelaunchStampFile;
+ if (!System.IO.File.Exists(file)) return false;
+
+ var age = DateTime.UtcNow - System.IO.File.GetLastWriteTimeUtc(file);
+ System.IO.File.Delete(file);
+ return age < TimeSpan.FromSeconds(30);
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ private static void MarkRelaunched()
+ {
+ try
+ {
+ var file = RelaunchStampFile;
+ System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file)!);
+ System.IO.File.WriteAllText(file, DateTime.UtcNow.ToString("O"));
+ }
+ catch
+ {
+ // 只是防抖标记,写不进去也不影响主流程
+ }
+ }
+
///
/// 以标准权限重新启动自己。
///
@@ -85,6 +125,12 @@ public static class Program
{
try
{
+ if (HasJustRelaunched())
+ {
+ AppLog.Write("[app] 重新以标准权限启动后仍是管理员(该账户没有 UAC 分离令牌),跳过自愈,继续以管理员运行");
+ return false;
+ }
+
var exe = Environment.ProcessPath;
if (string.IsNullOrEmpty(exe)) return false;
@@ -96,6 +142,7 @@ public static class Program
WindowStyle = ProcessWindowStyle.Hidden,
});
+ MarkRelaunched();
AppLog.Write("[app] 检测到以管理员权限运行(旧版本升级继承),已用标准权限重新启动");
return true;
}
diff --git a/desktop/YuncangTrace.LocalService.csproj b/desktop/YuncangTrace.LocalService.csproj
index 5ecd8c6..fdec01f 100644
--- a/desktop/YuncangTrace.LocalService.csproj
+++ b/desktop/YuncangTrace.LocalService.csproj
@@ -1,61 +1,61 @@
-
+
WinExe
-
+
net8.0-windows
true
-
+
true
enable
latest
disable
Assets\app.ico
-
+
YuncangTrace.LocalService
YuncangTrace.LocalService
app.manifest
$(NoWarn);WFAC010
Development
Production
http://127.0.0.1:7300
https://packs.example.com
- 1.0.105
- 云仓视频溯源软件
- 云仓
- 云仓视频溯源软件(本机服务)
+ 1.0.106
+ 浜戜粨瑙嗛婧簮杞欢
+ 浜戜粨
+ 浜戜粨瑙嗛婧簮杞欢锛堟湰鏈烘湇鍔★級
zh-CN
YuncangTrace.LocalService.Program
-
+
<_Parameter1>AppEnvironment
@@ -68,28 +68,28 @@
PreserveNewest
PreserveNewest
true
PreserveNewest
@@ -98,10 +98,10 @@
extension\%(RecursiveDir)%(Filename)%(Extension)