Fix Windows 11 notification error (#2073)

* Fix Windows 11 22H2 (22621) notification error

* Fix main thread issue of LegacyShow()

* Mark RestarApp() as deprecated
This commit is contained in:
VictoriousRaptor 2023-04-21 06:56:54 +08:00 committed by GitHub
parent c61d6f791c
commit 04cdfed901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 10 deletions

View file

@ -22,6 +22,7 @@ Google
Customise Customise
UWP UWP
uwp uwp
Uwp
Bokmal Bokmal
Bokm Bokm
uninstallation uninstallation
@ -89,3 +90,8 @@ Noresult
wpftk wpftk
mkv mkv
flac flac
IPublic
keyevent
KListener
requery
vkcode

View file

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

View file

@ -1,7 +1,9 @@
using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Microsoft.Toolkit.Uwp.Notifications; using Microsoft.Toolkit.Uwp.Notifications;
using System; using System;
using System.IO; using System.IO;
using System.Windows;
using Windows.Data.Xml.Dom; using Windows.Data.Xml.Dom;
using Windows.UI.Notifications; using Windows.UI.Notifications;
@ -17,8 +19,16 @@ namespace Flow.Launcher
ToastNotificationManagerCompat.Uninstall(); ToastNotificationManagerCompat.Uninstall();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
public static void Show(string title, string subTitle, string iconPath = null) public static void Show(string title, string subTitle, string iconPath = null)
{
Application.Current.Dispatcher.Invoke(() =>
{
ShowInternal(title, subTitle, iconPath);
});
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
private static void ShowInternal(string title, string subTitle, string iconPath = null)
{ {
// Handle notification for win7/8/early win10 // Handle notification for win7/8/early win10
if (legacy) if (legacy)
@ -32,11 +42,33 @@ namespace Flow.Launcher
? Path.Combine(Constant.ProgramDirectory, "Images\\app.png") ? Path.Combine(Constant.ProgramDirectory, "Images\\app.png")
: iconPath; : iconPath;
new ToastContentBuilder() try
.AddText(title, hintMaxLines: 1) {
.AddText(subTitle) new ToastContentBuilder()
.AddAppLogoOverride(new Uri(Icon)) .AddText(title, hintMaxLines: 1)
.Show(); .AddText(subTitle)
.AddAppLogoOverride(new Uri(Icon))
.Show();
}
catch (InvalidOperationException e)
{
// Temporary fix for the Windows 11 notification issue
// Possibly from 22621.1413 or 22621.1485, judging by post time of #2024
Log.Exception("Flow.Launcher.Notification|Notification InvalidOperationException Error", e);
if (Environment.OSVersion.Version.Build >= 22621)
{
return;
}
else
{
throw;
}
}
catch (Exception e)
{
Log.Exception("Flow.Launcher.Notification|Notification Error", e);
throw;
}
} }
private static void LegacyShow(string title, string subTitle, string iconPath) private static void LegacyShow(string title, string subTitle, string iconPath)

View file

@ -68,6 +68,7 @@ namespace Flow.Launcher
UpdateManager.RestartApp(Constant.ApplicationFileName); UpdateManager.RestartApp(Constant.ApplicationFileName);
} }
[Obsolete("Typo")]
public void RestarApp() => RestartApp(); public void RestarApp() => RestartApp();
public void ShowMainWindow() => _mainVM.Show(); public void ShowMainWindow() => _mainVM.Show();
@ -92,10 +93,7 @@ namespace Flow.Launcher
public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true) public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true)
{ {
Application.Current.Dispatcher.Invoke(() => Notification.Show(title, subTitle, iconPath);
{
Notification.Show(title, subTitle, iconPath);
});
} }
public void OpenSettingDialog() public void OpenSettingDialog()