mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: add native OS notifications
This commit is contained in:
@@ -27,6 +27,7 @@ public sealed class AppOrchestrator : IDisposable
|
|||||||
private readonly ChatMessageManager _messageManager;
|
private readonly ChatMessageManager _messageManager;
|
||||||
private readonly CommandHandler _commandHandler;
|
private readonly CommandHandler _commandHandler;
|
||||||
private readonly NotificationSoundService _notificationSound;
|
private readonly NotificationSoundService _notificationSound;
|
||||||
|
private readonly OsNotificationService _osNotification;
|
||||||
private readonly AudioPlaybackService _audioPlayback = new();
|
private readonly AudioPlaybackService _audioPlayback = new();
|
||||||
private readonly UpdateChecker _updateService;
|
private readonly UpdateChecker _updateService;
|
||||||
private readonly ConnectionManager _conn = new();
|
private readonly ConnectionManager _conn = new();
|
||||||
@@ -65,6 +66,7 @@ public sealed class AppOrchestrator : IDisposable
|
|||||||
_mainWindow = new MainWindow(app, _messageManager);
|
_mainWindow = new MainWindow(app, _messageManager);
|
||||||
_commandHandler = new CommandHandler();
|
_commandHandler = new CommandHandler();
|
||||||
_notificationSound = new NotificationSoundService(config.Notifications);
|
_notificationSound = new NotificationSoundService(config.Notifications);
|
||||||
|
_osNotification = new OsNotificationService();
|
||||||
_updateService = new UpdateChecker(app);
|
_updateService = new UpdateChecker(app);
|
||||||
|
|
||||||
WireMainWindowEvents();
|
WireMainWindowEvents();
|
||||||
@@ -1105,6 +1107,9 @@ public sealed class AppOrchestrator : IDisposable
|
|||||||
&& message.Content.Contains($"@{_session.Username}", StringComparison.OrdinalIgnoreCase))
|
&& message.Content.Contains($"@{_session.Username}", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
_ = _notificationSound.PlayAsync();
|
_ = _notificationSound.PlayAsync();
|
||||||
|
string title = $"Mentioned by {message.SenderDisplayName ?? message.SenderUsername} in #{message.ChannelName}";
|
||||||
|
string body = message.Content.Length > 200 ? message.Content[..200] + "..." : message.Content;
|
||||||
|
_osNotification.Show(title, body);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.3" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.3" />
|
||||||
<PackageReference Include="NetCoreAudio" Version="2.0.1" />
|
<PackageReference Include="NetCoreAudio" Version="2.0.1" />
|
||||||
|
<PackageReference Include="OsNotifications" Version="1.1.5" />
|
||||||
<PackageReference Include="Serilog" Version="4.3.1" />
|
<PackageReference Include="Serilog" Version="4.3.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using OsNotifications;
|
||||||
|
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace EchoHub.Client.Services;
|
||||||
|
|
||||||
|
public sealed class OsNotificationService
|
||||||
|
{
|
||||||
|
static OsNotificationService()
|
||||||
|
{
|
||||||
|
Notifications.SetGuiApplication(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows an OS notification with the given title and optional body.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title"></param>
|
||||||
|
/// <param name="body"></param>
|
||||||
|
public void Show(string title, string? body = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Notifications.ShowNotification(title, body ?? string.Empty);
|
||||||
|
}
|
||||||
|
catch (PlatformNotSupportedException ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "OS notifications not supported on this platform");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Failed to show OS notification");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user