diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs index f54d5601e5..c0440cb735 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Text.Json; @@ -59,7 +60,7 @@ namespace ShortcutGuide SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); #endif - Activated += OnLauched; + Activated += Window_Activated; SettingsUtils settingsUtils = new(); @@ -70,8 +71,13 @@ namespace ShortcutGuide } } - private void OnLauched(object sender, WindowActivatedEventArgs e) + private void Window_Activated(object sender, WindowActivatedEventArgs e) { + if (e.WindowActivationState == WindowActivationState.Deactivated) + { + Environment.Exit(0); + } + if (!_setPosition) { var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this); diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/ShortcutView.xaml.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/ShortcutView.xaml.cs index a111ca97bd..ffbd507880 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/ShortcutView.xaml.cs +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/ShortcutView.xaml.cs @@ -30,44 +30,53 @@ namespace ShortcutGuide int i = -1; - CategorySelector.Items.Add(new SelectorBarItem() { Text = "Overview", Name = i.ToString(CultureInfo.InvariantCulture) }); - - i++; - - foreach (var category in shortcutList.Shortcuts) + try { - switch (category.SectionName) - { - case string name when name.StartsWith("", StringComparison.Ordinal): - // Todo: Implement GetTaskbarIconPositions - break; - case string name when name.StartsWith('<') && name.EndsWith('>'): - break; - default: - CategorySelector.Items.Add(new SelectorBarItem() { Text = category.SectionName, Name = i.ToString(CultureInfo.InvariantCulture) }); - break; - } + CategorySelector.Items.Add(new SelectorBarItem() { Text = "Overview", Name = i.ToString(CultureInfo.InvariantCulture) }); i++; + + foreach (var category in shortcutList.Shortcuts) + { + switch (category.SectionName) + { + case string name when name.StartsWith("", StringComparison.Ordinal): + // Todo: Implement GetTaskbarIconPositions + break; + case string name when name.StartsWith('<') && name.EndsWith('>'): + break; + default: + CategorySelector.Items.Add(new SelectorBarItem() { Text = category.SectionName, Name = i.ToString(CultureInfo.InvariantCulture) }); + break; + } + + i++; + } + + CategorySelector.SelectedItem = CategorySelector.Items[0]; + CategorySelector.SelectionChanged += CategorySelector_SelectionChanged; + + foreach (var shortcut in shortcutList.Shortcuts[0].Properties) + { + ShortcutListElement.Items.Add((ShortcutTemplateDataObject)shortcut); + } + + ShortcutPageParameters.FrameHeight.FrameHeightChanged += ContentHeightChanged; + ShortcutPageParameters.SearchFilter.FilterChanged += SearchFilter_FilterChanged; + + if (!ShortcutPageParameters.PinnedShortcuts.TryGetValue(ShortcutPageParameters.CurrentPageName, out var _)) + { + ShortcutPageParameters.PinnedShortcuts.Add(ShortcutPageParameters.CurrentPageName, []); + } + + OpenOverview(); } - - CategorySelector.SelectedItem = CategorySelector.Items[0]; - CategorySelector.SelectionChanged += CategorySelector_SelectionChanged; - - foreach (var shortcut in shortcutList.Shortcuts[0].Properties) + catch (Exception) { - ShortcutListElement.Items.Add((ShortcutTemplateDataObject)shortcut); + OverviewStackPanel.Visibility = Visibility.Collapsed; + ErrorMessage.Visibility = Visibility.Visible; + ErrorMessage.Text = "Error displaying the applications shortcuts"; } - - ShortcutPageParameters.FrameHeight.FrameHeightChanged += ContentHeightChanged; - ShortcutPageParameters.SearchFilter.FilterChanged += SearchFilter_FilterChanged; - - if (!ShortcutPageParameters.PinnedShortcuts.TryGetValue(ShortcutPageParameters.CurrentPageName, out var _)) - { - ShortcutPageParameters.PinnedShortcuts.Add(ShortcutPageParameters.CurrentPageName, []); - } - - OpenOverview(); } private void OnPropertyChanged([CallerMemberName] string? propertyName = null)