mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 05:34:51 +00:00
Add dom-ready event for WebContents
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user