1
1
using Flow . Launcher . Infrastructure ;
2
+ using Flow . Launcher . Infrastructure . Logger ;
2
3
using Microsoft . Toolkit . Uwp . Notifications ;
3
4
using System ;
4
5
using System . IO ;
6
+ using System . Windows ;
5
7
using Windows . Data . Xml . Dom ;
6
8
using Windows . UI . Notifications ;
7
9
@@ -17,8 +19,16 @@ internal static void Uninstall()
17
19
ToastNotificationManagerCompat . Uninstall ( ) ;
18
20
}
19
21
20
- [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Interoperability" , "CA1416:Validate platform compatibility" , Justification = "<Pending>" ) ]
21
22
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 )
22
32
{
23
33
// Handle notification for win7/8/early win10
24
34
if ( legacy )
@@ -32,11 +42,33 @@ public static void Show(string title, string subTitle, string iconPath = null)
32
42
? Path . Combine ( Constant . ProgramDirectory , "Images\\ app.png" )
33
43
: iconPath ;
34
44
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
+ }
40
72
}
41
73
42
74
private static void LegacyShow ( string title , string subTitle , string iconPath )
0 commit comments