using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; using System.Reflection; using System.Runtime.InteropServices.WindowsRuntime; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using Windows.Foundation; using Windows.Foundation.Collections; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace APIToolkit { public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); this.ExtendsContentIntoTitleBar = true; // Set the apps titlebar to be defined in MainWindow.xaml this.SetTitleBar(AppTitleBar); ContentArea.Navigate(typeof(URLShortener)); // Set default page GlobalMethods.WebRequest.BaseAddress = new Uri("https://enstrayed.com/api/"); // Set base address for web requests being made GlobalMethods.WebRequest.DefaultRequestHeaders.UserAgent.ParseAdd($"DotNet/{Environment.Version} APIToolkit/{GlobalMethods.Version}"); // Set user agent of client } private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) { if (args.IsSettingsInvoked) { ContentArea.Navigate(typeof(Settings)); } else { // If the page set in MainWindow.xaml does not exist (is null), then show an error message if (Type.GetType($"APIToolkit.{args.InvokedItemContainer.Tag}") == null) { UIFunctions.ShowError(MainWindow_MainGrid.XamlRoot, "Requested page is not implemented (Destination returned null)"); } else // Otherwise, navigate to page based on tag set in MainWindow.xaml { ContentArea.Navigate(Type.GetType($"APIToolkit.{args.InvokedItemContainer.Tag}")); } } } } public static class GlobalMethods { public static HttpClient WebRequest = new(); public static string Version = "1.0"; } }