using System.ComponentModel; using System.Windows; using System.Windows.Input; using HC_APTBS.ViewModels.Dialogs; namespace HC_APTBS.Views.Dialogs { /// /// Non-modal window showing immobilizer unlock progress. /// Prevents user-initiated closing until the unlock sequence completes; /// programmatic close via always succeeds. /// Equivalent to the old WUnlocker window. /// public partial class UnlockProgressDialog : Window { private bool _forceClose; /// Creates the dialog and wires the ViewModel. public UnlockProgressDialog(UnlockProgressViewModel vm) { InitializeComponent(); DataContext = vm; vm.RequestClose += ForceClose; } /// Closes the window unconditionally (bypasses the completion guard). public void ForceClose() { _forceClose = true; Close(); } /// Allows dragging the borderless window by clicking anywhere. private void OnMouseDrag(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) DragMove(); } /// Prevents user-initiated closing while the unlock sequence is still running. private void OnWindowClosing(object? sender, CancelEventArgs e) { if (_forceClose) return; if (DataContext is UnlockProgressViewModel vm && !vm.IsComplete) e.Cancel = true; } } }