89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// Provides application-specific behavior to supplement the default Application class.
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
private TrayService? _trayService;
|
|
/// <summary>
|
|
/// The main application window. Use <c>App.Window</c> from any class that needs
|
|
/// the window reference (for dialogs, pickers, interop, etc.).
|
|
/// </summary>
|
|
public static Window Window { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// The UI thread dispatcher. Use <c>App.DispatcherQueue</c> to marshal calls
|
|
/// to the UI thread. Fully qualified to avoid CS0104 ambiguity with
|
|
/// <see cref="Windows.System.DispatcherQueue"/>.
|
|
/// </summary>
|
|
public static Microsoft.UI.Dispatching.DispatcherQueue DispatcherQueue { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// The native window handle (HWND). Use for file pickers,
|
|
/// <c>DataTransferManager</c>, and any WinRT interop that requires
|
|
/// <c>InitializeWithWindow</c>.
|
|
/// </summary>
|
|
public static nint WindowHandle =>
|
|
WinRT.Interop.WindowNative.GetWindowHandle(Window);
|
|
|
|
/// <summary>
|
|
/// Initializes the singleton application object.
|
|
/// </summary>
|
|
public App()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when the application is launched.
|
|
/// </summary>
|
|
/// <param name="args">Details about the launch request and process.</param>
|
|
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();
|
|
}
|
|
}
|
|
}
|