Skip to content

Commit 959def9

Browse files
committed
+ WebContent.GetUrl()
+ LoadURLOptions.ExtraHeaders
1 parent c4c0bba commit 959def9

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

ElectronNET.API/Entities/LoadURLOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace ElectronNET.API.Entities
1+
using System.Collections.Generic;
2+
3+
namespace ElectronNET.API.Entities
24
{
35
/// <summary>
46
///
@@ -21,5 +23,10 @@ public class LoadURLOptions
2123
/// files.
2224
/// </summary>
2325
public string BaseURLForDataURL { get; set; }
26+
27+
/// <summary>
28+
/// Extra headers for the request.
29+
/// </summary>
30+
public string ExtraHeaders { get; set; }
2431
}
2532
}

ElectronNET.API/WebContents.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
132132
return taskCompletionSource.Task;
133133
}
134134

135+
public Task<string> GetUrl()
136+
{
137+
var taskCompletionSource = new TaskCompletionSource<string>();
138+
139+
var eventString = "webContents-getUrl" + Id;
140+
BridgeConnector.Socket.On(eventString, (url) =>
141+
{
142+
BridgeConnector.Socket.Off(eventString);
143+
taskCompletionSource.SetResult((string)url);
144+
});
145+
146+
BridgeConnector.Socket.Emit("webContents-getUrl", Id);
147+
148+
return taskCompletionSource.Task;
149+
}
150+
135151
private JsonSerializer _jsonSerializer = new JsonSerializer()
136152
{
137153
ContractResolver = new CamelCasePropertyNamesContractResolver(),

ElectronNET.Host/api/webContents.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElectronNET.Host/api/webContents.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElectronNET.Host/api/webContents.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ module.exports = (socket: SocketIO.Server) => {
4444
});
4545
});
4646

47+
socket.on('webContents-getUrl', function (id) {
48+
var browserWindow = getWindowById(id);
49+
socket.emit('webContents-getUrl' + id, browserWindow.webContents.getURL());
50+
});
51+
4752
function getWindowById(id: number): Electron.BrowserWindow {
4853
return BrowserWindow.fromId(id);
4954
}

0 commit comments

Comments
 (0)