Skip to content

Commit

Permalink
Add notification type and wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBiellik committed Nov 3, 2019
1 parent 72937b1 commit 7932277
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 11 deletions.
22 changes: 22 additions & 0 deletions Notifications.Client/NotificationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using JetBrains.Annotations;
using NFive.Notifications.Shared;
using NFive.SDK.Client.Communications;

namespace NFive.Notifications.Client
{
[PublicAPI]
public class NotificationManager
{
private readonly ICommunicationManager comms;

public NotificationManager(ICommunicationManager comms)
{
this.comms = comms;
}

public void Show(Notification notification)
{
this.comms.Event(NotificationsEvents.ShowNotification).ToClient().Emit(notification);
}
}
}
1 change: 1 addition & 0 deletions Notifications.Client/Notifications.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="NotificationManager.cs" />
<Compile Include="Overlays\NotificationsOverlay.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NotificationsService.cs" />
Expand Down
9 changes: 4 additions & 5 deletions Notifications.Client/NotificationsService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;
using NFive.Notifications.Client.Overlays;
Expand Down Expand Up @@ -30,15 +29,15 @@ public override async Task Started()
this.overlay = new NotificationsOverlay(this.OverlayManager, this.config);

// Listen to server notifications
this.Comms.Event(NotificationsEvents.ShowNotification).FromServer().On<string, string, TimeSpan?>((e, text, type, timeout) =>
this.Comms.Event(NotificationsEvents.ShowNotification).FromServer().On<Notification>((e, notification) =>
{
this.overlay.Notify(text, type, timeout);
this.overlay.Notify(notification);
});

// Listen to client notifications
this.Comms.Event(NotificationsEvents.ShowNotification).FromClient().On<string, string, TimeSpan?>((e, text, type, timeout) =>
this.Comms.Event(NotificationsEvents.ShowNotification).FromClient().On<Notification>((e, notification) =>
{
this.overlay.Notify(text, type, timeout);
this.overlay.Notify(notification);
});
}
}
Expand Down
9 changes: 4 additions & 5 deletions Notifications.Client/Overlays/NotificationsOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using NFive.Notifications.Shared;
using NFive.SDK.Client.Interface;

Expand All @@ -24,13 +23,13 @@ public NotificationsOverlay(IOverlayManager manager, Configuration configuration
timeout = this.config.DefaultTimeout.TotalMilliseconds
};

public void Notify(string text, string type = null, TimeSpan? timeout = null)
public void Notify(Notification notification)
{
Emit("notify", new
{
text,
type,
timeout?.TotalMilliseconds
text = notification.Text,
type = notification.Type,
timeout = notification.Timeout?.TotalMilliseconds
});
}
}
Expand Down
13 changes: 13 additions & 0 deletions Notifications.Shared/Notification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace NFive.Notifications.Shared
{
public class Notification
{
public string Text { get; set; }

public string Type { get; set; }

public TimeSpan? Timeout { get; set; }
}
}
1 change: 1 addition & 0 deletions Notifications.Shared/Notifications.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Notification.cs" />
<Compile Include="NotificationsEvents.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion nfive.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: NFive/plugin-notifications
version: 0.1.0
version: 0.2.0
description: Simple client notifications
author: NFive
license: LGPL-3.0-or-later
Expand Down

0 comments on commit 7932277

Please sign in to comment.