Skip to content

Commit 809b0a6

Browse files
committed
Added missing methods
1 parent ae3f755 commit 809b0a6

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## ElectronNET.Core
44

55
- Fixed handling of `Center` property for windows (#1001)
6+
- Added missing methods on `Cookies` (#1000)
67

78
# 0.4.0
89

src/ElectronNET.API/API/Cookies.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ElectronNET.API.Serialization;
33
using System;
44
using System.Text.Json;
5+
using System.Threading.Tasks;
56

67
namespace ElectronNET.API
78
{
@@ -54,10 +55,79 @@ public event Action<Cookie, CookieChangedCause, bool> OnChanged
5455
_changed -= value;
5556

5657
if (_changed == null)
58+
{
5759
BridgeConnector.Socket.Off("webContents-session-cookies-changed" + Id);
60+
}
5861
}
5962
}
6063

6164
private event Action<Cookie, CookieChangedCause, bool> _changed;
65+
66+
67+
68+
/// <summary>
69+
/// Sends a request to get all cookies matching filter, and resolves a callack with the response.
70+
/// </summary>
71+
/// <param name="filter">
72+
/// </param>
73+
/// <returns>A task which resolves an array of cookie objects.</returns>
74+
public Task<Cookie[]> GetAsync(CookieFilter filter)
75+
{
76+
var tcs = new TaskCompletionSource<Cookie[]>();
77+
var guid = Guid.NewGuid().ToString();
78+
79+
BridgeConnector.Socket.Once<Cookie[]>("webContents-session-cookies-get-completed" + guid, tcs.SetResult);
80+
BridgeConnector.Socket.Emit("webContents-session-cookies-get", Id, filter, guid);
81+
82+
return tcs.Task;
83+
}
84+
85+
/// <summary>
86+
///
87+
/// </summary>
88+
/// <param name="details"></param>
89+
/// <returns></returns>
90+
public Task SetAsync(CookieDetails details)
91+
{
92+
var tcs = new TaskCompletionSource<object>();
93+
var guid = Guid.NewGuid().ToString();
94+
95+
BridgeConnector.Socket.Once<object>("webContents-session-cookies-set-completed" + guid, tcs.SetResult);
96+
BridgeConnector.Socket.Emit("webContents-session-cookies-set", Id, details, guid);
97+
98+
return tcs.Task;
99+
}
100+
101+
/// <summary>
102+
/// Removes the cookies matching url and name
103+
/// </summary>
104+
/// <param name="url">The URL associated with the cookie.</param>
105+
/// <param name="name">The name of cookie to remove.</param>
106+
/// <returns>A task which resolves when the cookie has been removed</returns>
107+
public Task RemoveAsync(string url, string name)
108+
{
109+
var tcs = new TaskCompletionSource<object>();
110+
var guid = Guid.NewGuid().ToString();
111+
112+
BridgeConnector.Socket.Once<object>("webContents-session-cookies-remove-completed" + guid, tcs.SetResult);
113+
BridgeConnector.Socket.Emit("webContents-session-cookies-remove", Id, url, name, guid);
114+
115+
return tcs.Task;
116+
}
117+
118+
/// <summary>
119+
/// Writes any unwritten cookies data to disk.
120+
/// </summary>
121+
/// <returns>A task which resolves when the cookie store has been flushed</returns>
122+
public Task FlushStoreAsync()
123+
{
124+
var tcs = new TaskCompletionSource<object>();
125+
var guid = Guid.NewGuid().ToString();
126+
127+
BridgeConnector.Socket.Once<object>("webContents-session-cookies-flushStore-completed" + guid, tcs.SetResult);
128+
BridgeConnector.Socket.Emit("webContents-session-cookies-flushStore", Id, guid);
129+
130+
return tcs.Task;
131+
}
62132
}
63133
}

0 commit comments

Comments
 (0)