/trunk/Winify/NotificationManager.cs |
@@ -7,6 +7,7 @@ |
using System.Threading.Tasks; |
using System.Windows.Forms; |
using Microsoft.Win32; |
using ToastNotifications; |
using Winify.Gotify; |
|
namespace Winify |
@@ -17,10 +18,6 @@ |
|
private readonly TaskScheduler _uiScheduler; |
|
private List<NotificationForm> _notificationList; |
|
private Rectangle _screenWorkingArea; |
|
#endregion |
|
#region Constructors, Destructors and Finalizers |
@@ -32,34 +29,14 @@ |
|
private NotificationManager() |
{ |
UpdateScreenResolution(); |
|
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; |
} |
|
public void Dispose() |
{ |
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; |
} |
|
#endregion |
|
#region Event Handlers |
|
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) |
{ |
UpdateScreenResolution(); |
} |
|
private void NotificationForm_Closing(object sender, CancelEventArgs e) |
{ |
var notificationForm = (NotificationForm) sender; |
notificationForm.Closing += NotificationForm_Closing; |
_notificationList[notificationForm.Index] = null; |
} |
|
#endregion |
|
#region Public Methods |
|
public void ShowNotification(GotifyNotificationEventArgs e, Announcements.Announcements notifications) |
@@ -66,64 +43,29 @@ |
{ |
Task.Factory.StartNew(() => |
{ |
var i = _notificationList.FindIndex(item => item == null); |
if (i == -1) |
{ |
return; |
} |
|
var settings = |
notifications.Announcement.FirstOrDefault( |
notification => notification.AppId == e.Notification.AppId); |
announcement => announcement.AppId == e.Notification.AppId); |
|
NotificationForm notificationForm; |
Notification notification; |
switch (settings == null) |
{ |
case true: |
notificationForm = |
new NotificationForm(i, e.Image, $"{e.Notification.Title} ({e.Notification.AppId})", |
e.Notification.Message, 5000); |
|
notification = new Notification($"{e.Notification.Title} ({e.Notification.AppId})", |
e.Notification.Message, 5000, e.Image, FormAnimator.AnimationMethod.Slide, |
FormAnimator.AnimationDirection.Up); |
break; |
default: |
notificationForm = |
new NotificationForm(i, e.Image, $"{e.Notification.Title} ({e.Notification.AppId})", |
e.Notification.Message, settings.LingerTime, settings.Speak); |
|
notification = new Notification($"{e.Notification.Title} ({e.Notification.AppId})", |
e.Notification.Message, settings.LingerTime, e.Image, FormAnimator.AnimationMethod.Slide, |
FormAnimator.AnimationDirection.Up); |
break; |
} |
|
_notificationList[i] = notificationForm; |
|
var notificationX = _screenWorkingArea.Right - notificationForm.Width; |
var notificationY = _screenWorkingArea.Bottom - (i + 1) * notificationForm.Height; |
notificationForm.UpdateLocation(notificationX, notificationY); |
|
notificationForm.Closing += NotificationForm_Closing; |
notificationForm.Show(); |
notification.Show(); |
}, CancellationToken.None, TaskCreationOptions.None, _uiScheduler); |
} |
|
#endregion |
|
#region Private Methods |
|
private void UpdateScreenResolution() |
{ |
_notificationList = new List<NotificationForm>(); |
|
_screenWorkingArea = Screen.GetWorkingArea(new Point(0, 0)); |
|
using (var notificationForm = new NotificationForm()) |
{ |
var items = _screenWorkingArea.Bottom / notificationForm.Height; |
foreach (var _ in Enumerable.Range(0, items)) |
{ |
_notificationList.Add(null); |
} |
} |
} |
|
#endregion |
} |
} |
/trunk/Winify/Winify.csproj |
@@ -1,6 +1,5 @@ |
<?xml version="1.0" encoding="utf-8"?> |
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<PropertyGroup> |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
@@ -97,12 +96,6 @@ |
<Compile Include="Gotify\GotifyNotificationEventArgs.cs" /> |
<Compile Include="Utilities\AES.cs" /> |
<Compile Include="Utilities\Natives.cs" /> |
<Compile Include="NotificationForm.cs"> |
<SubType>Form</SubType> |
</Compile> |
<Compile Include="NotificationForm.Designer.cs"> |
<DependentUpon>NotificationForm.cs</DependentUpon> |
</Compile> |
<Compile Include="Program.cs" /> |
<Compile Include="Properties\Annotations.cs" /> |
<Compile Include="Properties\AssemblyInfo.cs" /> |
@@ -125,9 +118,6 @@ |
<EmbeddedResource Include="Form1.resx"> |
<DependentUpon>Form1.cs</DependentUpon> |
</EmbeddedResource> |
<EmbeddedResource Include="NotificationForm.resx"> |
<DependentUpon>NotificationForm.cs</DependentUpon> |
</EmbeddedResource> |
<EmbeddedResource Include="Properties\Resources.resx"> |
<Generator>ResXFileCodeGenerator</Generator> |
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
@@ -157,8 +147,8 @@ |
<None Include="App.config" /> |
</ItemGroup> |
<ItemGroup> |
<ProjectReference Include="..\Notifications\Announcements.csproj"> |
<Project>{AEBB1E52-0676-406F-980B-708006EA36E0}</Project> |
<ProjectReference Include="..\Announcements\Announcements.csproj"> |
<Project>{aebb1e52-0676-406f-980b-708006ea36e0}</Project> |
<Name>Announcements</Name> |
</ProjectReference> |
<ProjectReference Include="..\Servers\Servers.csproj"> |
@@ -165,6 +155,10 @@ |
<Project>{ddab11f9-3308-4464-b864-4d75cba1acc8}</Project> |
<Name>Servers</Name> |
</ProjectReference> |
<ProjectReference Include="..\WindowsToastNotifications\ToastNotifications\ToastNotifications.csproj"> |
<Project>{380d8d88-386c-4c50-9a54-800f79fdf7d2}</Project> |
<Name>ToastNotifications</Name> |
</ProjectReference> |
</ItemGroup> |
<ItemGroup> |
<Content Include="Resources\about.png" /> |