using System.Windows; using System.Windows.Shapes; using TeamsISO.App.Services; using TeamsISO.App.ViewModels; namespace TeamsISO.App; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); StateChanged += OnWindowStateChanged; SourceInitialized += OnSourceInitialized; Closing += OnClosing; } public MainWindow(MainViewModel viewModel) : this() { DataContext = viewModel; } /// /// Restore the window's previous placement after the HWND is created (so /// SetWindowPos / WindowState transitions actually take effect). Falls /// silently back to the XAML-default startup location if no snapshot exists. /// private void OnSourceInitialized(object? sender, EventArgs e) { WindowStateStore.TryApply(this); } /// Persist the placement on close so next launch lands in the same spot. private void OnClosing(object? sender, System.ComponentModel.CancelEventArgs e) { WindowStateStore.Save(this); } /// Custom min button — chrome'd window has no system caption buttons. private void OnMinimize(object sender, RoutedEventArgs e) => WindowState = WindowState.Minimized; /// Toggles maximize/restore. Bound to the maximize button + double-click on the drag region. private void OnMaximizeRestore(object sender, RoutedEventArgs e) => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; /// Custom close button. private void OnClose(object sender, RoutedEventArgs e) => Close(); /// Opens the About dialog — version, NDI runtime, build SHA. private void OnAboutClick(object sender, RoutedEventArgs e) { var about = new AboutWindow { Owner = this }; about.ShowDialog(); } /// /// Toggle behavior: if Teams is already running, ask to stop it; otherwise /// launch via TeamsLauncher's fallback chain. First step toward the /// Embedded-Teams roadmap (Phase E.1). /// private void OnLaunchTeamsClick(object sender, RoutedEventArgs e) { if (TeamsLauncher.IsRunning()) { var confirm = MessageBox.Show( "Microsoft Teams is currently running.\n\nClose all Teams windows now?", "TeamsISO — Stop Teams", MessageBoxButton.YesNo, MessageBoxImage.Question); if (confirm != MessageBoxResult.Yes) return; var asked = TeamsLauncher.StopAll(); if (TeamsLauncher.IsRunning()) { MessageBox.Show( asked == 0 ? "No Teams windows responded to close." : $"Sent close to {asked} Teams window(s); some may still be exiting.", "TeamsISO — Stop Teams", MessageBoxButton.OK, MessageBoxImage.Information); } return; } if (!TeamsLauncher.TryLaunch(out var error)) { MessageBox.Show( $"Could not launch Microsoft Teams.\n\n{error}", "TeamsISO — Launch Teams", MessageBoxButton.OK, MessageBoxImage.Warning); } } /// /// Swap the maximize-button glyph between the "single rectangle" (when normal) and the /// "two-overlapping-rectangles" (when maximized) variants, matching the Windows 11 /// caption-button conventions. /// private void OnWindowStateChanged(object? sender, EventArgs e) { if (FindName("MaximizeIcon") is not Path icon) return; icon.Data = WindowState == WindowState.Maximized // Two-rectangle "restore" glyph ? System.Windows.Media.Geometry.Parse("M 2,0 L 10,0 L 10,8 M 0,2 L 8,2 L 8,10 L 0,10 Z") // Single-rectangle "maximize" glyph : System.Windows.Media.Geometry.Parse("M 0,0 L 10,0 L 10,10 L 0,10 Z"); } }