From a3d34c1b74f9ba8919f3b3d0cfdbf769034dc12d Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 16 Jan 2023 10:06:39 -0500 Subject: [PATCH 1/2] Only generate Pages once instead of on the fly --- MainWindow.xaml.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index b97e625..b1b2543 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -78,6 +78,8 @@ public partial class MainWindow : Window private static string SingleOrMulti = "Single"; + public Collection Pages = new Collection (); + private static void LaunchScript(object sender, EventArgs e, string scriptPath, string args, string type, string inputType, string wait, string elevate, string hide) { string EXEPath; @@ -231,6 +233,7 @@ public static void LaunchExplorer(string path) public static Page GenerateCategoryPageFromXML(string name) { Page page = new Page(); + page.Name = name; //ResourceDictionary myResourceDictionary = new ResourceDictionary(); //myResourceDictionary.Source = new Uri("ResourceDictionary.xaml", UriKind.RelativeOrAbsolute); ////page.Resources.MergedDictionaries.Add(myResourceDictionary); @@ -623,6 +626,7 @@ public MainWindow() guiConfig = XDocument.Load(@"XML\Scripts.xml"); foreach (XElement item in from y in categoryConfig.Descendants("Item") select y) { + Pages.Add(GenerateCategoryPageFromXML(item.Attribute("category").Value)); //Add the page to a collection for later use MainNav.MenuItems.Add(GenerateCategoryNavigationViewItemFromXML(item.Attribute("category").Value, item.Attribute("icon").Value, item.Attribute("foreground").Value)); } @@ -727,7 +731,6 @@ private void MainNav_SelectionChanged(NavigationView sender, NavigationViewSelec Type _page = null; _page = typeof(Settings); contentFrame.Navigate(_page); - //TODO: Should we hide the machine input, terminal, and machine info pane here? If so ensure we show it once we navigate away below ContentSplitView.IsPaneOpen = false; MachineDetailsToggleButton.IsChecked = false; MachineInputs.Visibility = Visibility.Collapsed; @@ -748,9 +751,14 @@ private void MainNav_SelectionChanged(NavigationView sender, NavigationViewSelec } else { - Page _page = GenerateCategoryPageFromXML(args.SelectedItemContainer.Content.ToString()); + //Page _page = GenerateCategoryPageFromXML(args.SelectedItemContainer.Content.ToString()); + string PageName = args.SelectedItemContainer.Content.ToString(); + var _page = from Page in Pages + where Page.Name == PageName + select Page; + //MainNav.Header = args.SelectedItemContainer.Content.ToString(); - contentFrame.Content = _page; //TODO: This probably doesn't need to generate each time you click + contentFrame.Content = _page.FirstOrDefault(); MachineInputs.Visibility = Visibility.Visible; } } From 02cacf7c73316b1a7e463e97e854cd777daa0693 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 16 Jan 2023 12:36:48 -0500 Subject: [PATCH 2/2] Misc --- MainWindow.xaml | 6 +++++- MainWindow.xaml.cs | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/MainWindow.xaml b/MainWindow.xaml index 5684d4f..c9baa52 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -126,6 +126,11 @@ + + + + + @@ -142,7 +147,6 @@ - diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index b1b2543..0c41128 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -553,7 +553,7 @@ public void EnsureWindowsSystemDispatcherQueueController() } } - private void Window_Activated(object sender, WindowActivatedEventArgs args) + private void Window_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args) { m_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated; } @@ -631,6 +631,7 @@ public MainWindow() } //Select the first navigation item + //TODO: This will need to be adjusted once Dashboard and All Scripts are available, should this be a setting? MainNav.SelectedItem = MainNav.MenuItems[1]; //Index 1 because 0 is the "Categories" text header //We've got to check for updates in the main window due to a WinUI limitation that currently exists @@ -666,7 +667,7 @@ private async void CheckForUpdates() LoadingText.Text = "Downloading update..."; string scriptName = "Updater.ps1"; string scriptPath = Environment.CurrentDirectory + "\\" + scriptName; - LaunchScript(scriptPath, " -InstallPath \"" + Environment.CurrentDirectory + "\" -DownloadURL \"" + updateXMLData.Attribute("link").Value + "\"", "PS5", "None", "false", "true", "true"); //TODO: Should this be moved to run with the integrated host? Probably can't until elevation support is added to Windows App SDK with v1.1 + LaunchScript(scriptPath, " -InstallPath \"" + Environment.CurrentDirectory + "\" -DownloadURL \"" + updateXMLData.Attribute("link").Value + "\"", "PS5", "None", "false", "true", "true"); await Task.Run(() => Task.Delay(1000000)); //TODO: This needs fixed, for some reason WaitForExit() isn't working //TODO: Run LoadingPhrase() on a loop }