using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using WinRT.Interop; namespace ClipForge { public partial class App : Application { public MainWindow? MainWindow { get; private set; } public static DispatcherQueue? MainQueue { get; private set; } public TrayIconService? TrayIcon { get; private set; } public App() { this.InitializeComponent(); } protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { MainQueue = DispatcherQueue.GetForCurrentThread(); MainWindow = new MainWindow(); MainWindow.Activate(); var hwnd = WindowNative.GetWindowHandle(MainWindow); TrayIcon = new TrayIconService(); TrayIcon.Initialize( hwnd, showWindow: () => { MainQueue?.TryEnqueue(() => { MainWindow?.AppWindow.Show(); MainWindow?.Activate(); }); }, exitApp: () => { MainQueue?.TryEnqueue(() => { TrayIcon?.Dispose(); Microsoft.UI.Xaml.Application.Current.Exit(); }); }); } } }