Handle errors displaying app and close window automatically on focus change

This commit is contained in:
Aaron Junker
2025-06-11 15:41:39 +02:00
parent 54d176c4c4
commit 0b823ea8bd
2 changed files with 49 additions and 34 deletions

View File

@@ -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);

View File

@@ -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("<TASKBAR1-9>", 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("<TASKBAR1-9>", 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)