-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationManager.cs
More file actions
84 lines (76 loc) · 2.5 KB
/
NotificationManager.cs
File metadata and controls
84 lines (76 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Windows.Forms;
using System.Drawing;
namespace NodaStack
{
public static class NotificationManager
{
private static NotifyIcon? _notifyIcon;
static NotificationManager()
{
// Initialiser le NotifyIcon pour les notifications
_notifyIcon = new NotifyIcon
{
Visible = false,
Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location)
};
}
public static void ShowNotification(string title, string message, NotificationType type = NotificationType.Info)
{
try
{
if (_notifyIcon != null)
{
_notifyIcon.Visible = true;
_notifyIcon.ShowBalloonTip(5000, title, message, GetToolTipIcon(type));
}
}
catch (Exception ex)
{
// Fallback console
Console.WriteLine($"Notification: {title} - {message} ({type})");
Console.WriteLine($"Error showing notification: {ex.Message}");
}
}
public static void ShowNotification(string title, string message, NotificationType type, int durationMs, Action? onClick = null)
{
ShowNotification(title, message, type);
}
public static void ShowToastNotification(string title, string message, NotificationType type = NotificationType.Info)
{
ShowNotification(title, message, type);
}
public static void ClearAllNotifications()
{
try
{
if (_notifyIcon != null)
{
_notifyIcon.Visible = false;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error clearing notifications: {ex.Message}");
}
}
private static ToolTipIcon GetToolTipIcon(NotificationType type)
{
return type switch
{
NotificationType.Success => ToolTipIcon.Info,
NotificationType.Warning => ToolTipIcon.Warning,
NotificationType.Error => ToolTipIcon.Error,
NotificationType.Info => ToolTipIcon.Info,
_ => ToolTipIcon.Info
};
}
public enum NotificationType
{
Info,
Success,
Warning,
Error
}
}
}