Skip to content

Commit 0b823ea

Browse files
committed
Handle errors displaying app and close window automatically on focus change
1 parent 54d176c commit 0b823ea

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.Globalization;
89
using System.IO;
910
using System.Text.Json;
@@ -59,7 +60,7 @@ public MainWindow()
5960
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
6061
#endif
6162

62-
Activated += OnLauched;
63+
Activated += Window_Activated;
6364

6465
SettingsUtils settingsUtils = new();
6566

@@ -70,8 +71,13 @@ public MainWindow()
7071
}
7172
}
7273

73-
private void OnLauched(object sender, WindowActivatedEventArgs e)
74+
private void Window_Activated(object sender, WindowActivatedEventArgs e)
7475
{
76+
if (e.WindowActivationState == WindowActivationState.Deactivated)
77+
{
78+
Environment.Exit(0);
79+
}
80+
7581
if (!_setPosition)
7682
{
7783
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);

src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/ShortcutView.xaml.cs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,53 @@ public ShortcutView()
3030

3131
int i = -1;
3232

33-
CategorySelector.Items.Add(new SelectorBarItem() { Text = "Overview", Name = i.ToString(CultureInfo.InvariantCulture) });
33+
try
34+
{
35+
CategorySelector.Items.Add(new SelectorBarItem() { Text = "Overview", Name = i.ToString(CultureInfo.InvariantCulture) });
3436

35-
i++;
37+
i++;
3638

37-
foreach (var category in shortcutList.Shortcuts)
38-
{
39-
switch (category.SectionName)
39+
foreach (var category in shortcutList.Shortcuts)
4040
{
41-
case string name when name.StartsWith("<TASKBAR1-9>", StringComparison.Ordinal):
42-
// Todo: Implement GetTaskbarIconPositions
43-
break;
44-
case string name when name.StartsWith('<') && name.EndsWith('>'):
45-
break;
46-
default:
47-
CategorySelector.Items.Add(new SelectorBarItem() { Text = category.SectionName, Name = i.ToString(CultureInfo.InvariantCulture) });
48-
break;
41+
switch (category.SectionName)
42+
{
43+
case string name when name.StartsWith("<TASKBAR1-9>", StringComparison.Ordinal):
44+
// Todo: Implement GetTaskbarIconPositions
45+
break;
46+
case string name when name.StartsWith('<') && name.EndsWith('>'):
47+
break;
48+
default:
49+
CategorySelector.Items.Add(new SelectorBarItem() { Text = category.SectionName, Name = i.ToString(CultureInfo.InvariantCulture) });
50+
break;
51+
}
52+
53+
i++;
4954
}
5055

51-
i++;
52-
}
56+
CategorySelector.SelectedItem = CategorySelector.Items[0];
57+
CategorySelector.SelectionChanged += CategorySelector_SelectionChanged;
5358

54-
CategorySelector.SelectedItem = CategorySelector.Items[0];
55-
CategorySelector.SelectionChanged += CategorySelector_SelectionChanged;
59+
foreach (var shortcut in shortcutList.Shortcuts[0].Properties)
60+
{
61+
ShortcutListElement.Items.Add((ShortcutTemplateDataObject)shortcut);
62+
}
5663

57-
foreach (var shortcut in shortcutList.Shortcuts[0].Properties)
58-
{
59-
ShortcutListElement.Items.Add((ShortcutTemplateDataObject)shortcut);
60-
}
64+
ShortcutPageParameters.FrameHeight.FrameHeightChanged += ContentHeightChanged;
65+
ShortcutPageParameters.SearchFilter.FilterChanged += SearchFilter_FilterChanged;
6166

62-
ShortcutPageParameters.FrameHeight.FrameHeightChanged += ContentHeightChanged;
63-
ShortcutPageParameters.SearchFilter.FilterChanged += SearchFilter_FilterChanged;
67+
if (!ShortcutPageParameters.PinnedShortcuts.TryGetValue(ShortcutPageParameters.CurrentPageName, out var _))
68+
{
69+
ShortcutPageParameters.PinnedShortcuts.Add(ShortcutPageParameters.CurrentPageName, []);
70+
}
6471

65-
if (!ShortcutPageParameters.PinnedShortcuts.TryGetValue(ShortcutPageParameters.CurrentPageName, out var _))
72+
OpenOverview();
73+
}
74+
catch (Exception)
6675
{
67-
ShortcutPageParameters.PinnedShortcuts.Add(ShortcutPageParameters.CurrentPageName, []);
76+
OverviewStackPanel.Visibility = Visibility.Collapsed;
77+
ErrorMessage.Visibility = Visibility.Visible;
78+
ErrorMessage.Text = "Error displaying the applications shortcuts";
6879
}
69-
70-
OpenOverview();
7180
}
7281

7382
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)

0 commit comments

Comments
 (0)