using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using KronaStaffTerminal.Services; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace KronaStaffTerminal; /// /// Provides application-specific behavior to supplement the default Application class. /// public partial class App : Application { private TrayService? _trayService; /// /// The main application window. Use App.Window from any class that needs /// the window reference (for dialogs, pickers, interop, etc.). /// public static Window Window { get; private set; } = null!; /// /// The UI thread dispatcher. Use App.DispatcherQueue to marshal calls /// to the UI thread. Fully qualified to avoid CS0104 ambiguity with /// . /// public static Microsoft.UI.Dispatching.DispatcherQueue DispatcherQueue { get; private set; } = null!; /// /// The native window handle (HWND). Use for file pickers, /// DataTransferManager, and any WinRT interop that requires /// InitializeWithWindow. /// public static nint WindowHandle => WinRT.Interop.WindowNative.GetWindowHandle(Window); /// /// Initializes the singleton application object. /// public App() { InitializeComponent(); } /// /// Invoked when the application is launched. /// /// Details about the launch request and process. protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { Window = new MainWindow(); DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); _trayService = new TrayService(ShowWindow, RequestExit); Window.Activate(); } public void NotifyMinimizedToTray() => _trayService?.ShowRunningBalloon(); private static void ShowWindow() { if (Window is MainWindow mainWindow) { mainWindow.ShowWindow(); } } private static void RequestExit() { if (Window is MainWindow mainWindow) { mainWindow.ShowWindow(); _ = mainWindow.RequestExitAsync(); } } public void CompleteExit() { _trayService?.Dispose(); _trayService = null; if (Window is MainWindow mainWindow) { mainWindow.ExitApplication(); } } }