Initial commit: ReminderOrganizer WPF app
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
50
Services/NotificationService.cs
Normal file
50
Services/NotificationService.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ReminderOrganizer.Services
|
||||
{
|
||||
public class NotificationService : INotificationService
|
||||
{
|
||||
private readonly object _lock = new();
|
||||
|
||||
public static NotifyIcon? SharedTrayIcon { get; set; }
|
||||
|
||||
public void ShowNotification(string title, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"[NotificationService] ShowNotification: {title} - {message}");
|
||||
System.Diagnostics.Debug.WriteLine($"[NotificationService] SharedTrayIcon is null: {SharedTrayIcon == null}");
|
||||
ShowBalloonTip(title, message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"[NotificationService] Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowBalloonTip(string title, string message)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (SharedTrayIcon != null)
|
||||
{
|
||||
SharedTrayIcon.BalloonTipTitle = title;
|
||||
SharedTrayIcon.BalloonTipText = message;
|
||||
SharedTrayIcon.BalloonTipIcon = ToolTipIcon.Info;
|
||||
SharedTrayIcon.ShowBalloonTip(5000);
|
||||
System.Diagnostics.Debug.WriteLine("[NotificationService] BalloonTip shown!");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("[NotificationService] SharedTrayIcon is null, cannot show balloon tip!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user