Files
ThreadPilot/Views/SettingsWindow.xaml.cs
T
Kool 27e7b04913 Harden persistence, monitoring, and shutdown reliability (#46)
Addresses the audit findings across persistent-rule recovery, settings merge behavior, CPU identity, monitoring lifecycle, notifications, autostart, tray updates, and shutdown disposal. Includes regression coverage and the corrected disabled-monitoring view. CI DevSecOps and CodeQL pass.
2026-08-12 01:00:17 +02:00

78 lines
2.4 KiB
C#

namespace ThreadPilot.Views
{
using System;
using System.ComponentModel;
using System.Windows;
using ThreadPilot.ViewModels;
public partial class SettingsWindow : Window
{
private readonly SettingsViewModel viewModel;
private bool isClosingAfterUnsavedPrompt;
public SettingsWindow(SettingsViewModel viewModel)
{
this.InitializeComponent();
this.viewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel));
this.SettingsViewControl.DataContext = this.viewModel;
}
protected override void OnClosing(CancelEventArgs e)
{
// Check for unsaved changes
if (!this.isClosingAfterUnsavedPrompt && !this.viewModel.CanClose())
{
e.Cancel = true;
this.UnsavedSettingsOverlay.Visibility = Visibility.Visible;
return;
}
base.OnClosing(e);
}
private async void UnsavedSettingsSave_Click(object sender, RoutedEventArgs e)
{
try
{
var saved = await this.viewModel.SaveIfDirtyAsync();
if (saved)
{
this.CloseAfterUnsavedPrompt();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Failed to save settings from the unsaved-changes prompt: {ex.Message}");
}
}
private async void UnsavedSettingsDiscard_Click(object sender, RoutedEventArgs e)
{
try
{
await this.viewModel.DiscardPendingChangesAsync();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Failed to discard pending settings: {ex.Message}");
}
this.CloseAfterUnsavedPrompt();
}
private void UnsavedSettingsCancel_Click(object sender, RoutedEventArgs e)
{
this.UnsavedSettingsOverlay.Visibility = Visibility.Collapsed;
}
private void CloseAfterUnsavedPrompt()
{
this.isClosingAfterUnsavedPrompt = true;
this.UnsavedSettingsOverlay.Visibility = Visibility.Collapsed;
this.Close();
}
}
}