13
13
********************************************************************/
14
14
15
15
using System ;
16
+ using System . Collections . Generic ;
16
17
using Serilog ;
17
18
18
19
namespace SoundSwitch . Framework . Banner
@@ -22,8 +23,9 @@ namespace SoundSwitch.Framework.Banner
22
23
/// </summary>
23
24
public class BannerManager
24
25
{
25
- private static System . Threading . SynchronizationContext syncContext ;
26
- private static BannerForm banner ;
26
+ private static System . Threading . SynchronizationContext _syncContext ;
27
+ private int _currentOffset = 0 ;
28
+ private readonly Dictionary < Guid , BannerForm > _bannerForms = new ( ) ;
27
29
28
30
/// <summary>
29
31
/// Show a banner notification with the given data
@@ -32,15 +34,21 @@ public class BannerManager
32
34
public void ShowNotification ( BannerData data )
33
35
{
34
36
// Execute the banner in the context of the UI thread
35
- syncContext . Send ( _ =>
37
+ _syncContext . Send ( _ =>
36
38
{
37
- if ( banner == null )
39
+ var banner = new BannerForm ( ) ;
40
+ banner . Disposed += ( s , e ) =>
38
41
{
39
- banner = new BannerForm ( ) ;
40
- banner . Disposed += ( s , e ) => banner = null ;
41
- }
42
-
43
- banner . SetData ( data ) ;
42
+ _currentOffset -= banner . Height ;
43
+ _bannerForms . Remove ( banner . Id ) ;
44
+ foreach ( var bannerForm in _bannerForms . Values )
45
+ {
46
+ bannerForm . UpdateLocation ( banner . Height ) ;
47
+ }
48
+ } ;
49
+ banner . SetData ( data , _currentOffset ) ;
50
+ _currentOffset += banner . Height ;
51
+ _bannerForms . Add ( banner . Id , banner ) ;
44
52
} , null ) ;
45
53
}
46
54
@@ -51,8 +59,8 @@ public void ShowNotification(BannerData data)
51
59
internal static void Setup ( )
52
60
{
53
61
// Grab the synchronization context of the UI thread!
54
- syncContext = System . Threading . SynchronizationContext . Current ;
55
- if ( ! ( syncContext is System . Windows . Forms . WindowsFormsSynchronizationContext ) )
62
+ _syncContext = System . Threading . SynchronizationContext . Current ;
63
+ if ( ! ( _syncContext is System . Windows . Forms . WindowsFormsSynchronizationContext ) )
56
64
throw new InvalidOperationException ( "BannerManager must be called in the context of the UI thread." ) ;
57
65
Log . Information ( "Banner manager initialized" ) ;
58
66
}
0 commit comments