using System; using System.Threading.Tasks; using ElectronNET.API.Entities; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; namespace ElectronNET.API { /// /// Query and modify a session's cookies. /// public class Cookies { /// /// Gets the identifier. /// /// /// The identifier. /// public int Id { get; private set; } internal Cookies(int id) { Id = id; } /// /// Emitted when a cookie is changed because it was added, edited, removed, or expired. /// public event Action OnChanged { add { if (_changed == null) { BridgeConnector.Socket.On("webContents-session-cookies-changed" + Id, (args) => { Cookie cookie = ((JArray)args)[0].ToObject(); CookieChangedCause cause = ((JArray)args)[1].ToObject(); bool removed = ((JArray)args)[2].ToObject(); _changed(cookie, cause, removed); }); BridgeConnector.Socket.Emit("register-webContents-session-cookies-changed", Id); } _changed += value; } remove { _changed -= value; if (_changed == null) BridgeConnector.Socket.Off("webContents-session-cookies-changed" + Id); } } private event Action _changed; private JsonSerializer _jsonSerializer = new JsonSerializer() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore }; } }