增加IsShuttingDownFromTray标志位

This commit is contained in:
ww-rm
2025-09-30 08:45:28 +08:00
parent bb2862ed4f
commit 0b3db0fd0d
3 changed files with 17 additions and 3 deletions

View File

@@ -29,6 +29,12 @@ namespace SpineViewer.ViewModels.MainWindow
public string Title => $"SpineViewer - v{App.Version}"; public string Title => $"SpineViewer - v{App.Version}";
/// <summary>
/// 指示是否通过托盘图标进行退出
/// </summary>
public bool IsShuttingDownFromTray => _isShuttingDownFromTray;
private bool _isShuttingDownFromTray;
public bool? CloseToTray public bool? CloseToTray
{ {
get => _closeToTray; get => _closeToTray;
@@ -101,8 +107,13 @@ namespace SpineViewer.ViewModels.MainWindow
}); });
private RelayCommand _cmd_SwitchWallpaperView; private RelayCommand _cmd_SwitchWallpaperView;
public RelayCommand Cmd_Exit => _cmd_Exit ??= new(App.Current.Shutdown); public RelayCommand Cmd_ExitFromTray => _cmd_ExitFromTray ??= new(() =>
private RelayCommand? _cmd_Exit; {
_isShuttingDownFromTray = true;
OnPropertyChanged(nameof(IsShuttingDownFromTray));
App.Current.Shutdown();
});
private RelayCommand? _cmd_ExitFromTray;
/// <summary> /// <summary>
/// 打开工作区 /// 打开工作区

View File

@@ -942,7 +942,7 @@
<ContextMenu> <ContextMenu>
<MenuItem Header="{DynamicResource Str_WallpaperView}" Command="{Binding Cmd_SwitchWallpaperView}" IsChecked="{Binding PreferenceViewModel.WallpaperView}"/> <MenuItem Header="{DynamicResource Str_WallpaperView}" Command="{Binding Cmd_SwitchWallpaperView}" IsChecked="{Binding PreferenceViewModel.WallpaperView}"/>
<Separator/> <Separator/>
<MenuItem Header="{DynamicResource Str_Exit}" Command="{Binding Cmd_Exit}"/> <MenuItem Header="{DynamicResource Str_Exit}" Command="{Binding Cmd_ExitFromTray}"/>
</ContextMenu> </ContextMenu>
</hc:NotifyIcon.ContextMenu> </hc:NotifyIcon.ContextMenu>
</hc:NotifyIcon> </hc:NotifyIcon>

View File

@@ -226,6 +226,9 @@ public partial class MainWindow : Window
private void MainWindow_Closing(object? sender, CancelEventArgs e) private void MainWindow_Closing(object? sender, CancelEventArgs e)
{ {
if (_vm.IsShuttingDownFromTray)
return;
if (_vm.CloseToTray is null) if (_vm.CloseToTray is null)
{ {
_vm.PreferenceViewModel.CloseToTray = MessagePopupService.YesNo(AppResource.Str_CloseToTrayQuest); _vm.PreferenceViewModel.CloseToTray = MessagePopupService.YesNo(AppResource.Str_CloseToTrayQuest);