Skip to content

Commit b3212a0

Browse files
VictoriousRaptorjjw24
authored andcommitted
Fix Windows 11 notification error (#2073)
* Fix Windows 11 22H2 (22621) notification error * Fix main thread issue of LegacyShow() * Mark RestarApp() as deprecated
1 parent 25dec33 commit b3212a0

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

.github/actions/spelling/expect.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Google
2121
Customise
2222
UWP
2323
uwp
24+
Uwp
2425
Bokmal
2526
Bokm
2627
uninstallation
@@ -88,3 +89,8 @@ Noresult
8889
wpftk
8990
mkv
9091
flac
92+
IPublic
93+
keyevent
94+
KListener
95+
requery
96+
vkcode

.github/actions/spelling/patterns.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,6 @@
115115

116116
#http/https
117117
(?:\b(?:https?|ftp|file)://)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]
118+
119+
# UWP
120+
[Uu][Ww][Pp]

Flow.Launcher/Notification.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Flow.Launcher.Infrastructure;
2+
using Flow.Launcher.Infrastructure.Logger;
23
using Microsoft.Toolkit.Uwp.Notifications;
34
using System;
45
using System.IO;
6+
using System.Windows;
57
using Windows.Data.Xml.Dom;
68
using Windows.UI.Notifications;
79

@@ -17,8 +19,16 @@ internal static void Uninstall()
1719
ToastNotificationManagerCompat.Uninstall();
1820
}
1921

20-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
2122
public static void Show(string title, string subTitle, string iconPath = null)
23+
{
24+
Application.Current.Dispatcher.Invoke(() =>
25+
{
26+
ShowInternal(title, subTitle, iconPath);
27+
});
28+
}
29+
30+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
31+
private static void ShowInternal(string title, string subTitle, string iconPath = null)
2232
{
2333
// Handle notification for win7/8/early win10
2434
if (legacy)
@@ -32,11 +42,33 @@ public static void Show(string title, string subTitle, string iconPath = null)
3242
? Path.Combine(Constant.ProgramDirectory, "Images\\app.png")
3343
: iconPath;
3444

35-
new ToastContentBuilder()
36-
.AddText(title, hintMaxLines: 1)
37-
.AddText(subTitle)
38-
.AddAppLogoOverride(new Uri(Icon))
39-
.Show();
45+
try
46+
{
47+
new ToastContentBuilder()
48+
.AddText(title, hintMaxLines: 1)
49+
.AddText(subTitle)
50+
.AddAppLogoOverride(new Uri(Icon))
51+
.Show();
52+
}
53+
catch (InvalidOperationException e)
54+
{
55+
// Temporary fix for the Windows 11 notification issue
56+
// Possibly from 22621.1413 or 22621.1485, judging by post time of #2024
57+
Log.Exception("Flow.Launcher.Notification|Notification InvalidOperationException Error", e);
58+
if (Environment.OSVersion.Version.Build >= 22621)
59+
{
60+
return;
61+
}
62+
else
63+
{
64+
throw;
65+
}
66+
}
67+
catch (Exception e)
68+
{
69+
Log.Exception("Flow.Launcher.Notification|Notification Error", e);
70+
throw;
71+
}
4072
}
4173

4274
private static void LegacyShow(string title, string subTitle, string iconPath)

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void RestartApp()
6868
UpdateManager.RestartApp(Constant.ApplicationFileName);
6969
}
7070

71+
[Obsolete("Typo")]
7172
public void RestarApp() => RestartApp();
7273

7374
public void ShowMainWindow() => _mainVM.Show();
@@ -92,10 +93,7 @@ public void ShowMsg(string title, string subTitle = "", string iconPath = "") =>
9293

9394
public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true)
9495
{
95-
Application.Current.Dispatcher.Invoke(() =>
96-
{
97-
Notification.Show(title, subTitle, iconPath);
98-
});
96+
Notification.Show(title, subTitle, iconPath);
9997
}
10098

10199
public void OpenSettingDialog()

0 commit comments

Comments
 (0)