feat(ui): confirm main-window close when Mission Control sessions are open
Closing the main window used to silently kill every open Mission Control ConPTY session (App's ShutdownMode.OnMainWindowClose tears the process down without warning). Intercept Window.Closing, and when at least one pane is open, ask via the existing ConfirmAsync pattern before proceeding; cancelling leaves the window and sessions alive, confirming force-closes as before.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
using ClaudeDo.Ui.ViewModels;
|
||||
using ClaudeDo.Ui.ViewModels.Islands;
|
||||
using ClaudeDo.Ui.ViewModels.Modals;
|
||||
@@ -13,6 +16,8 @@ namespace ClaudeDo.Ui.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private bool _forceClose;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -21,6 +26,29 @@ public partial class MainWindow : Window
|
||||
UpdateMaxIcon();
|
||||
}
|
||||
|
||||
// Closing the main window kills every open Mission Control ConPTY session without
|
||||
// warning (App.axaml.cs: ShutdownMode.OnMainWindowClose). Ask first — never silently.
|
||||
protected override void OnClosing(WindowClosingEventArgs e)
|
||||
{
|
||||
if (!_forceClose
|
||||
&& DataContext is IslandsShellViewModel { Dialogs: { } dialogs } vm
|
||||
&& IslandsShellViewModel.RequiresCloseConfirmation(vm.OpenMissionControlSessionCount))
|
||||
{
|
||||
e.Cancel = true;
|
||||
_ = ConfirmCloseWithOpenSessionsAsync(dialogs, vm.OpenMissionControlSessionCount);
|
||||
return;
|
||||
}
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private async Task ConfirmCloseWithOpenSessionsAsync(IDialogService dialogs, int openSessionCount)
|
||||
{
|
||||
var confirmed = await dialogs.ConfirmAsync(Loc.T("vm.mainWindow.closeConfirm.message", openSessionCount));
|
||||
if (!confirmed) return;
|
||||
_forceClose = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
Reference in New Issue
Block a user