11using Flow . Launcher . Infrastructure ;
2+ using Flow . Launcher . Infrastructure . Logger ;
23using Microsoft . Toolkit . Uwp . Notifications ;
34using System ;
45using System . IO ;
6+ using System . Windows ;
57using Windows . Data . Xml . Dom ;
68using 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 )
0 commit comments