diff --git a/ElectronNET.API/Entities/DisplayBalloonOptions.cs b/ElectronNET.API/Entities/DisplayBalloonOptions.cs
new file mode 100644
index 0000000..da59480
--- /dev/null
+++ b/ElectronNET.API/Entities/DisplayBalloonOptions.cs
@@ -0,0 +1,9 @@
+namespace ElectronNET.API
+{
+ public class DisplayBalloonOptions
+ {
+ public string Icon { get; set; }
+ public string Title { get; set; }
+ public string Content { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/ElectronNET.API/Entities/HighlightMode.cs b/ElectronNET.API/Entities/HighlightMode.cs
new file mode 100644
index 0000000..19dc276
--- /dev/null
+++ b/ElectronNET.API/Entities/HighlightMode.cs
@@ -0,0 +1,20 @@
+namespace ElectronNET.API.Entities
+{
+ public enum HighlightMode
+ {
+ ///
+ /// Highlight the tray icon when it is clicked and also when its context menu is open. This is the default.
+ ///
+ selection,
+
+ ///
+ /// Always highlight the tray icon.
+ ///
+ always,
+
+ ///
+ /// Never highlight the tray icon.
+ ///
+ never
+ }
+}
\ No newline at end of file
diff --git a/ElectronNET.API/Entities/NotificationAction.cs b/ElectronNET.API/Entities/NotificationAction.cs
new file mode 100644
index 0000000..25bee11
--- /dev/null
+++ b/ElectronNET.API/Entities/NotificationAction.cs
@@ -0,0 +1,15 @@
+namespace ElectronNET.API.Entities
+{
+ public class NotificationAction
+ {
+ ///
+ /// The label for the given action.
+ ///
+ public string Text { get; set; }
+
+ ///
+ /// The type of action, can be button.
+ ///
+ public string Type { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/ElectronNET.API/Entities/NotificationOptions.cs b/ElectronNET.API/Entities/NotificationOptions.cs
index efa127f..f2fc91c 100644
--- a/ElectronNET.API/Entities/NotificationOptions.cs
+++ b/ElectronNET.API/Entities/NotificationOptions.cs
@@ -1,4 +1,7 @@
-namespace ElectronNET.API.Entities
+using Newtonsoft.Json;
+using System;
+
+namespace ElectronNET.API.Entities
{
public class NotificationOptions
{
@@ -44,6 +47,63 @@
///
public string Sound { get; set; }
+ ///
+ /// Actions to add to the notification. Please read the available actions and
+ /// limitations in the NotificationAction documentation
+ ///
+ public NotificationAction Actions { get; set; }
+
+ ///
+ /// Emitted when the notification is shown to the user,
+ /// note this could be fired multiple times as a notification
+ /// can be shown multiple times through the Show() method.
+ ///
+ [JsonIgnore]
+ public Action OnShow { get; set; }
+
+ [JsonProperty]
+ internal string ShowID { get; set; }
+
+ ///
+ /// Emitted when the notification is clicked by the user.
+ ///
+ [JsonIgnore]
+ public Action OnClick { get; set; }
+
+ [JsonProperty]
+ internal string ClickID { get; set; }
+
+ ///
+ /// Emitted when the notification is closed by manual intervention from the user.
+ ///
+ /// This event is not guarunteed to be emitted in all cases where the notification is closed.
+ ///
+ [JsonIgnore]
+ public Action OnClose { get; set; }
+
+ [JsonProperty]
+ internal string CloseID { get; set; }
+
+ ///
+ /// macOS only: Emitted when the user clicks the “Reply” button on a notification with hasReply: true.
+ ///
+ /// The string the user entered into the inline reply field
+ ///
+ [JsonIgnore]
+ public Action OnReply { get; set; }
+
+ [JsonProperty]
+ internal string ReplyID { get; set; }
+
+ ///
+ /// macOS only - The index of the action that was activated
+ ///
+ [JsonIgnore]
+ public Action OnAction { get; set; }
+
+ [JsonProperty]
+ internal string ActionID { get; set; }
+
public NotificationOptions(string title, string body)
{
Title = title;
diff --git a/ElectronNET.API/Entities/TrayClickEventArgs.cs b/ElectronNET.API/Entities/TrayClickEventArgs.cs
new file mode 100644
index 0000000..5e7b09b
--- /dev/null
+++ b/ElectronNET.API/Entities/TrayClickEventArgs.cs
@@ -0,0 +1,10 @@
+namespace ElectronNET.API
+{
+ public class TrayClickEventArgs
+ {
+ public bool AltKey { get; set; }
+ public bool ShiftKey { get; set; }
+ public bool CtrlKey { get; set; }
+ public bool MetaKey { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/ElectronNET.API/Notification.cs b/ElectronNET.API/Notification.cs
index ad396d0..b7fd081 100644
--- a/ElectronNET.API/Notification.cs
+++ b/ElectronNET.API/Notification.cs
@@ -2,6 +2,10 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
namespace ElectronNET.API
{
@@ -24,11 +28,105 @@ namespace ElectronNET.API
}
}
+ private static List _notificationOptions = new List();
+
+ ///
+ /// Create OS desktop notifications
+ ///
+ ///
public void Show(NotificationOptions notificationOptions)
{
+ GenerateIDsForDefinedActions(notificationOptions);
+
BridgeConnector.Socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
}
+ private static void GenerateIDsForDefinedActions(NotificationOptions notificationOptions)
+ {
+ bool isActionDefined = false;
+
+ if (notificationOptions.OnShow != null)
+ {
+ notificationOptions.ShowID = Guid.NewGuid().ToString();
+ isActionDefined = true;
+
+ BridgeConnector.Socket.Off("NotificationEventShow");
+ BridgeConnector.Socket.On("NotificationEventShow", (id) => {
+ _notificationOptions.Single(x => x.ShowID == id.ToString()).OnShow();
+ });
+ }
+
+ if (notificationOptions.OnClick != null)
+ {
+ notificationOptions.ClickID = Guid.NewGuid().ToString();
+ isActionDefined = true;
+
+ BridgeConnector.Socket.Off("NotificationEventClick");
+ BridgeConnector.Socket.On("NotificationEventClick", (id) => {
+ _notificationOptions.Single(x => x.ClickID == id.ToString()).OnClick();
+ });
+ }
+
+ if (notificationOptions.OnClose != null)
+ {
+ notificationOptions.CloseID = Guid.NewGuid().ToString();
+ isActionDefined = true;
+
+ BridgeConnector.Socket.Off("NotificationEventClose");
+ BridgeConnector.Socket.On("NotificationEventClose", (id) => {
+ _notificationOptions.Single(x => x.CloseID == id.ToString()).OnClose();
+ });
+ }
+
+ if (notificationOptions.OnReply != null)
+ {
+ notificationOptions.ReplyID = Guid.NewGuid().ToString();
+ isActionDefined = true;
+
+ BridgeConnector.Socket.Off("NotificationEventReply");
+ BridgeConnector.Socket.On("NotificationEventReply", (args) => {
+ var arguments = ((JArray)args).ToObject();
+ _notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnReply(arguments[1].ToString());
+ });
+ }
+
+ if (notificationOptions.OnAction != null)
+ {
+ notificationOptions.ActionID = Guid.NewGuid().ToString();
+ isActionDefined = true;
+
+ BridgeConnector.Socket.Off("NotificationEventAction");
+ BridgeConnector.Socket.On("NotificationEventAction", (args) => {
+ var arguments = ((JArray)args).ToObject();
+ _notificationOptions.Single(x => x.ReplyID == arguments[0].ToString()).OnAction(arguments[1].ToString());
+ });
+ }
+
+ if (isActionDefined)
+ {
+ _notificationOptions.Add(notificationOptions);
+ }
+ }
+
+ ///
+ /// Whether or not desktop notifications are supported on the current system.
+ ///
+ ///
+ public Task IsSupportedAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("notificationIsSupportedComplete", (isSupported) =>
+ {
+ BridgeConnector.Socket.Off("notificationIsSupportedComplete");
+ taskCompletionSource.SetResult((bool)isSupported);
+ });
+
+ BridgeConnector.Socket.Emit("notificationIsSupported");
+
+ return taskCompletionSource.Task;
+ }
+
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
diff --git a/ElectronNET.API/Tray.cs b/ElectronNET.API/Tray.cs
index bbb23dc..aa42268 100644
--- a/ElectronNET.API/Tray.cs
+++ b/ElectronNET.API/Tray.cs
@@ -3,12 +3,182 @@ using ElectronNET.API.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
+using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
namespace ElectronNET.API
{
public sealed class Tray
{
+ ///
+ /// Emitted when the tray icon is clicked.
+ ///
+ public event Action OnClick
+ {
+ add
+ {
+ if (_click == null)
+ {
+ BridgeConnector.Socket.On("tray-click-event", (result) =>
+ {
+ var args = ((JArray)result).ToObject