From c68ec63e914bb32ef3a15c9850aecd3afa90ecdb Mon Sep 17 00:00:00 2001 From: liufumingren Date: Tue, 20 Oct 2026 00:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E7=AB=AF=EF=BC=9A=E6=89=98?= =?UTF-8?q?=E7=9B=98=E9=80=80=E5=87=BA=E5=8A=A0=E7=A1=AE=E8=AE=A4=20+=20?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=9C=8D=E5=8A=A1=20.NET=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=85=9C=E5=BA=95=EF=BC=881.0.75=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 托盘「退出」改为 ConfirmExitFromTray:弹「退出确认」,默认按钮为取消; 文案按状态区分(服务模式提示后台 Windows 服务仍会继续扫码,普通模式提示扫码与查询都会停)。 登录取消等内部路径仍直接退出,不弹框 - ServiceInstaller: - StartCore 启动前调用 EnsureServiceDotnetEnvironment(框架依赖版服务写 DOTNET_ROOT, 自包含版自动清理),避免 LocalSystem 找不到用户目录里的 .NET 8 而表现为「后台服务启动超时」 - 用 RuntimeEnvironment.GetRuntimeDirectory() 取运行时目录,消除单文件发布下的 IL3000 警告 (typeof(object).Assembly.Location 在单文件里恒为空) --- desktop/App.xaml.cs | 34 ++++++++++++++++++++-- desktop/Services/Agent/ServiceInstaller.cs | 6 ++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/desktop/App.xaml.cs b/desktop/App.xaml.cs index e979ca6..4925d81 100644 --- a/desktop/App.xaml.cs +++ b/desktop/App.xaml.cs @@ -152,7 +152,7 @@ public partial class App : Application _tray = new TrayIconService(version); _tray.ShowRequested += ShowAppWindow; _tray.RestartRequested += RestartApplication; - _tray.ExitRequested += ExitApplication; + _tray.ExitRequested += ConfirmExitFromTray; UpdateTrayStatus(); AppLog.Write($"本机服务:{_server.BaseUrl}({(_server.IsRunning ? "运行中" : "未启动")})"); @@ -674,7 +674,37 @@ public partial class App : Application } } - /// 真正退出(托盘菜单 / 登录取消 / 退出登录后取消登录) + /// + /// 托盘菜单「退出」→ 先确认再退。 + /// + /// 退出不是“关窗口”:本机 HTTP/WS 服务、扫码中控都会停,网页也查不了东西—— + /// 用户常把托盘退出当成“隐藏图标”误点,所以必须弹一次确认。 + /// (登录取消 / 退出登录后取消登录 等内部路径仍用 ,不弹框) + /// + private void ConfirmExitFromTray() + { + if (_exiting) return; + + var consequence = _settings.DeviceServiceEnabled + ? (AgentPaths.MachineMode + ? "本机服务(网页查询/预览)会停止;后台扫码服务是独立 Windows 服务,仍会继续运行。" + : "本机服务(网页查询/预览)与扫码上报都会停止。") + : "本机服务(网页查询/预览)会停止,网页将无法再通过本机软件操作。"; + + var answer = MessageBox.Show( + $"确定要退出「云仓视频溯源软件」吗?\n\n{consequence}\n\n如需继续使用,请从开始菜单或桌面重新打开。", + "退出确认", + MessageBoxButton.OKCancel, + MessageBoxImage.Question, + MessageBoxResult.Cancel); + + if (answer != MessageBoxResult.OK) return; + + AppLog.Write("用户从托盘菜单确认退出"); + ExitApplication(); + } + + /// 真正退出(登录取消 / 退出登录后取消登录 / 确认后的托盘退出) private void ExitApplication() { if (_exiting) return; diff --git a/desktop/Services/Agent/ServiceInstaller.cs b/desktop/Services/Agent/ServiceInstaller.cs index ad55200..c5e09c4 100644 --- a/desktop/Services/Agent/ServiceInstaller.cs +++ b/desktop/Services/Agent/ServiceInstaller.cs @@ -300,8 +300,10 @@ public static class ServiceInstaller return; } - var runtimeDir = Path.GetDirectoryName(typeof(object).Assembly.Location); // ...\shared\Microsoft.NETCore.App\8.0.x - if (runtimeDir is null) return; + // ⚠️ 不要用 typeof(object).Assembly.Location:单文件发布里它恒为空(IL3000), + // RuntimeEnvironment.GetRuntimeDirectory() 在框架依赖时才是真实的 \shared\Microsoft.NETCore.App\8.0.x\ + var runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); + if (string.IsNullOrWhiteSpace(runtimeDir)) return; var dotnetRoot = Path.GetFullPath(Path.Combine(runtimeDir, "..", "..")); if (!File.Exists(Path.Combine(dotnetRoot, "dotnet.exe"))) return;