using ElectronNET.API.Entities;
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;
using ElectronNET.Common;
// ReSharper disable InconsistentNaming
namespace ElectronNET.API
{
///
/// Add icons and context menus to the system's notification area.
///
public sealed class Tray
{
///
/// Emitted when the tray icon is clicked.
///
public event Action OnClick
{
add => ApiEventManager.AddTrayEvent("tray-click", GetHashCode(), _click, value);
remove => ApiEventManager.RemoveTrayEvent("tray-click", GetHashCode(), _click, value);
}
private event Action _click;
///
/// macOS, Windows: Emitted when the tray icon is right clicked.
///
public event Action OnRightClick
{
add => ApiEventManager.AddTrayEvent("tray-right-click", GetHashCode(), _rightClick, value);
remove => ApiEventManager.RemoveTrayEvent("tray-right-click", GetHashCode(), _rightClick, value);
}
private event Action _rightClick;
///
/// macOS, Windows: Emitted when the tray icon is double clicked.
///
public event Action OnDoubleClick
{
add => ApiEventManager.AddTrayEvent("tray-double-click", GetHashCode(), _doubleClick, value);
remove => ApiEventManager.RemoveTrayEvent("tray-double-click", GetHashCode(), _doubleClick, value);
}
private event Action _doubleClick;
///
/// Windows: Emitted when the tray balloon shows.
///
public event Action OnBalloonShow
{
add => ApiEventManager.AddEvent("tray-balloon-show", GetHashCode(), _balloonShow, value);
remove => ApiEventManager.RemoveEvent("tray-balloon-show", GetHashCode(), _balloonShow, value);
}
private event Action _balloonShow;
///
/// Windows: Emitted when the tray balloon is clicked.
///
public event Action OnBalloonClick
{
add => ApiEventManager.AddEvent("tray-balloon-click", GetHashCode(), _balloonClick, value);
remove => ApiEventManager.RemoveEvent("tray-balloon-click", GetHashCode(), _balloonClick, value);
}
private event Action _balloonClick;
///
/// Windows: Emitted when the tray balloon is closed
/// because of timeout or user manually closes it.
///
public event Action OnBalloonClosed
{
add => ApiEventManager.AddEvent("tray-balloon-closed", GetHashCode(), _balloonClosed, value);
remove => ApiEventManager.RemoveEvent("tray-balloon-closed", GetHashCode(), _balloonClosed, value);
}
private event Action _balloonClosed;
// TODO: Implement macOS Events
private static Tray _tray;
private static readonly object _syncRoot = new();
internal Tray() { }
internal static Tray Instance
{
get
{
if (_tray == null)
{
lock (_syncRoot)
{
if (_tray == null)
{
_tray = new Tray();
}
}
}
return _tray;
}
}
///
/// Gets the menu items.
///
///
/// The menu items.
///
public IReadOnlyCollection