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

View File

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

View File

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