桌面端:托盘退出加确认 + 后台服务 .NET 环境兜底(1.0.75)
- 托盘「退出」改为 ConfirmExitFromTray:弹「退出确认」,默认按钮为取消;
文案按状态区分(服务模式提示后台 Windows 服务仍会继续扫码,普通模式提示扫码与查询都会停)。
登录取消等内部路径仍直接退出,不弹框
- ServiceInstaller:
- StartCore 启动前调用 EnsureServiceDotnetEnvironment(框架依赖版服务写 DOTNET_ROOT,
自包含版自动清理),避免 LocalSystem 找不到用户目录里的 .NET 8 而表现为「后台服务启动超时」
- 用 RuntimeEnvironment.GetRuntimeDirectory() 取运行时目录,消除单文件发布下的 IL3000 警告
(typeof(object).Assembly.Location 在单文件里恒为空)
This commit is contained in:
parent
bca8f7270c
commit
c68ec63e91
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>真正退出(托盘菜单 / 登录取消 / 退出登录后取消登录)</summary>
|
||||
/// <summary>
|
||||
/// 托盘菜单「退出」→ 先确认再退。
|
||||
///
|
||||
/// 退出不是“关窗口”:本机 HTTP/WS 服务、扫码中控都会停,网页也查不了东西——
|
||||
/// 用户常把托盘退出当成“隐藏图标”误点,所以必须弹一次确认。
|
||||
/// (登录取消 / 退出登录后取消登录 等内部路径仍用 <see cref="ExitApplication"/>,不弹框)
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>真正退出(登录取消 / 退出登录后取消登录 / 确认后的托盘退出)</summary>
|
||||
private void ExitApplication()
|
||||
{
|
||||
if (_exiting) return;
|
||||
|
||||
@ -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() 在框架依赖时才是真实的 <root>\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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user