Add dom-ready event for WebContents

This commit is contained in:
softworkz
2023-09-24 16:36:41 +02:00
parent 23f4d39a30
commit a15db713ad
3 changed files with 48 additions and 0 deletions

View File

@@ -114,6 +114,35 @@ public class WebContents
private event Action<InputEvent> _inputEvent;
/// <summary>
/// Emitted when the document in the top-level frame is loaded.
/// </summary>
public event Action OnDomReady
{
add
{
if (_domReady == null)
{
BridgeConnector.Socket.On("webContents-domReady" + Id, () =>
{
_domReady();
});
BridgeConnector.Socket.Emit("register-webContents-domReady", Id);
}
_domReady += value;
}
remove
{
_domReady -= value;
if (_domReady == null)
BridgeConnector.Socket.Off("webContents-domReady" + Id);
}
}
private event Action _domReady;
internal WebContents(int id)
{
Id = id;

View File

@@ -28,6 +28,16 @@ module.exports = (socket) => {
}
});
});
socket.on('register-webContents-domReady', (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners('dom-ready');
browserWindow.webContents.on('dom-ready', () => {
electronSocket.emit('webContents-domReady' + id);
});
});
socket.on('webContentsOpenDevTools', (id, options) => {
if (options) {
getWindowById(id).webContents.openDevTools(options);

View File

@@ -35,6 +35,15 @@ export = (socket: Socket) => {
});
});
socket.on('register-webContents-domReady', (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners('dom-ready');
browserWindow.webContents.on('dom-ready', () => {
electronSocket.emit('webContents-domReady' + id);
});
});
socket.on('webContentsOpenDevTools', (id, options) => {
if (options) {
getWindowById(id).webContents.openDevTools(options);