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;