using Microsoft.UI.Xaml; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace KronaStaffTerminal; /// /// The application window. This hosts a Frame that displays pages. Add your /// UI and logic to MainPage.xaml / MainPage.xaml.cs instead of here so you /// can use Page features such as navigation events and the Loaded lifecycle. /// public sealed partial class MainWindow : Window { private bool _allowClose; public MainWindow() { InitializeComponent(); ExtendsContentIntoTitleBar = true; SetTitleBar(AppTitleBar); AppWindow.SetIcon("Assets/AppIcon.ico"); AppWindow.Resize(new Windows.Graphics.SizeInt32(1120, 760)); AppWindow.Closing += AppWindow_Closing; AppWindow.Changed += AppWindow_Changed; // Navigate the root frame to the main page on startup. RootFrame.Navigate(typeof(MainPage)); } private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args) { if (_allowClose) return; args.Cancel = true; if (RootFrame.Content is MainPage page) page.LockAdminSession(); AppWindow.Hide(); ((App)Application.Current).NotifyMinimizedToTray(); } private void AppWindow_Changed(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowChangedEventArgs args) { if (!args.DidPresenterChange || sender.Presenter is not Microsoft.UI.Windowing.OverlappedPresenter presenter || presenter.State != Microsoft.UI.Windowing.OverlappedPresenterState.Minimized) { return; } if (RootFrame.Content is MainPage page) page.LockAdminSession(); } public void ShowWindow() { AppWindow.Show(); Activate(); } public void HideToTray() { if (RootFrame.Content is MainPage page) page.LockAdminSession(); AppWindow.Hide(); } public async Task RequestExitAsync() { if (RootFrame.Content is MainPage page && await page.AuthorizeExitAsync()) { ((App)Application.Current).CompleteExit(); } } public void ExitApplication() { _allowClose = true; Close(); } }