Winify – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
11 | office | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Drawing; |
||
5 | using System.Linq; |
||
6 | using System.Threading; |
||
7 | using System.Threading.Tasks; |
||
8 | using System.Windows.Forms; |
||
9 | using Microsoft.Win32; |
||
10 | using Winify.Gotify; |
||
12 | office | 11 | using Winify.Properties; |
11 | office | 12 | |
13 | namespace Winify |
||
14 | { |
||
15 | public class NotificationManager : IDisposable |
||
16 | { |
||
17 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
18 | |||
19 | private readonly TaskScheduler _uiScheduler; |
||
20 | |||
21 | private List<NotificationForm> _notificationList; |
||
22 | |||
23 | private Rectangle _screenWorkingArea; |
||
24 | |||
25 | #endregion |
||
26 | |||
27 | #region Constructors, Destructors and Finalizers |
||
28 | |||
29 | public NotificationManager(TaskScheduler uiScheduler) : this() |
||
30 | { |
||
31 | _uiScheduler = uiScheduler; |
||
32 | } |
||
33 | |||
34 | private NotificationManager() |
||
35 | { |
||
36 | UpdateScreenResolution(); |
||
37 | |||
38 | SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; |
||
39 | } |
||
40 | |||
41 | public void Dispose() |
||
42 | { |
||
43 | SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; |
||
44 | } |
||
45 | |||
46 | #endregion |
||
47 | |||
48 | #region Event Handlers |
||
49 | |||
50 | private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) |
||
51 | { |
||
52 | UpdateScreenResolution(); |
||
53 | } |
||
54 | |||
55 | private void NotificationForm_Closing(object sender, CancelEventArgs e) |
||
56 | { |
||
57 | var notificationForm = (NotificationForm) sender; |
||
58 | notificationForm.Closing += NotificationForm_Closing; |
||
59 | _notificationList[notificationForm.Index] = null; |
||
60 | } |
||
61 | |||
62 | #endregion |
||
63 | |||
64 | #region Public Methods |
||
65 | |||
66 | public void UpdateScreenResolution() |
||
67 | { |
||
68 | _notificationList = new List<NotificationForm>(); |
||
69 | |||
70 | _screenWorkingArea = Screen.GetWorkingArea(new Point(0, 0)); |
||
71 | |||
72 | using (var notificationForm = new NotificationForm()) |
||
73 | { |
||
74 | var items = _screenWorkingArea.Bottom / notificationForm.Height; |
||
75 | foreach (var _ in Enumerable.Range(0, items)) |
||
76 | { |
||
77 | _notificationList.Add(null); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public void ShowNotification(GotifyNotificationEventArgs e) |
||
83 | { |
||
84 | Task.Factory.StartNew(() => |
||
85 | { |
||
86 | var i = _notificationList.FindIndex(item => item == null); |
||
87 | if (i == -1) |
||
88 | { |
||
89 | return; |
||
90 | } |
||
91 | |||
92 | var notificationForm = |
||
13 | office | 93 | new NotificationForm(i, e.Image, e.Notification.Title, |
12 | office | 94 | e.Notification.Message, 5000); |
11 | office | 95 | |
96 | _notificationList[i] = notificationForm; |
||
97 | |||
98 | var notificationX = _screenWorkingArea.Right - notificationForm.Width; |
||
99 | var notificationY = _screenWorkingArea.Bottom - (i + 1) * notificationForm.Height; |
||
100 | notificationForm.UpdateLocation(notificationX, notificationY); |
||
101 | |||
102 | notificationForm.Closing += NotificationForm_Closing; |
||
103 | notificationForm.Show(); |
||
104 | }, CancellationToken.None, TaskCreationOptions.None, _uiScheduler); |
||
105 | } |
||
106 | |||
107 | #endregion |
||
108 | } |
||
109 | } |