60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using Microsoft.UI.Windowing;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using System;
|
|
using System.IO;
|
|
|
|
// To learn more about WinUI, the WinUI project structure,
|
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
|
|
|
namespace AmiReel_WinUI;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public sealed partial class MainWindow : Window
|
|
{
|
|
private bool _exitConfirmed;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
ExtendsContentIntoTitleBar = true;
|
|
SetTitleBar(AppTitleBar);
|
|
|
|
string? executablePath = Environment.ProcessPath;
|
|
if (!string.IsNullOrWhiteSpace(executablePath) && File.Exists(executablePath))
|
|
AppWindow.SetIcon(executablePath);
|
|
|
|
// Navigate the root frame to the main page on startup.
|
|
RootFrame.Navigate(typeof(MainPage));
|
|
|
|
AppWindow.Closing += AppWindow_Closing;
|
|
}
|
|
|
|
private async void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
|
|
{
|
|
if (_exitConfirmed) return;
|
|
args.Cancel = true;
|
|
|
|
ContentDialog dialog = new()
|
|
{
|
|
Title = "Exit AmiReel?",
|
|
Content = "Are you sure you want to close the application?",
|
|
PrimaryButtonText = "Exit",
|
|
CloseButtonText = "Cancel",
|
|
DefaultButton = ContentDialogButton.Close,
|
|
XamlRoot = RootFrame.XamlRoot
|
|
};
|
|
|
|
ContentDialogResult result = await dialog.ShowAsync();
|
|
if (result != ContentDialogResult.Primary) return;
|
|
|
|
_exitConfirmed = true;
|
|
Close();
|
|
}
|
|
}
|