Completed APIs from #956

This commit is contained in:
Florian Rappl
2026-09-04 16:57:44 +02:00
parent fffd7dfb79
commit a04ca0b9bc
6 changed files with 150 additions and 1 deletions

View File

@@ -131,6 +131,34 @@ public class WebContents : ApiBase
remove => RemoveEvent(value, Id);
}
/// <summary>
/// Emitted when media becomes audible or inaudible. The parameter is true if one or more
/// frames or child web contents are emitting audio.
/// </summary>
public event Action<bool> OnAudioStateChanged
{
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
/// <summary>
/// Emitted when media starts playing.
/// </summary>
public event Action OnMediaStartedPlaying
{
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
/// <summary>
/// Emitted when media is paused or done playing.
/// </summary>
public event Action OnMediaPaused
{
add => AddEvent(value, Id);
remove => RemoveEvent(value, Id);
}
internal WebContents(int id)
{
Id = id;
@@ -611,6 +639,22 @@ public class WebContents : ApiBase
BridgeConnector.Socket.Emit("webContents-centerSelection", Id);
}
/// <summary>
/// Scrolls to the top of the current web page.
/// </summary>
public void ScrollToTop()
{
BridgeConnector.Socket.Emit("webContents-scrollToTop", Id);
}
/// <summary>
/// Scrolls to the bottom of the current web page.
/// </summary>
public void ScrollToBottom()
{
BridgeConnector.Socket.Emit("webContents-scrollToBottom", Id);
}
/// <summary>
/// Inserts text to the focused element.
/// </summary>

View File

@@ -125,6 +125,27 @@ module.exports = (socket) => {
electronSocket.emit("webContents-foundInPage" + id, result);
});
});
socket.on("register-webContents-audioStateChanged", (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners("audio-state-changed");
browserWindow.webContents.on("audio-state-changed", (event) => {
electronSocket.emit("webContents-audioStateChanged" + id, event.audible);
});
});
socket.on("register-webContents-mediaStartedPlaying", (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners("media-started-playing");
browserWindow.webContents.on("media-started-playing", () => {
electronSocket.emit("webContents-mediaStartedPlaying" + id);
});
});
socket.on("register-webContents-mediaPaused", (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners("media-paused");
browserWindow.webContents.on("media-paused", () => {
electronSocket.emit("webContents-mediaPaused" + id);
});
});
socket.on("webContents-openDevTools", (id, options) => {
if (options) {
getWindowById(id).webContents.openDevTools(options);
@@ -491,6 +512,12 @@ module.exports = (socket) => {
socket.on("webContents-centerSelection", (id) => {
getWindowById(id).webContents.centerSelection();
});
socket.on("webContents-scrollToTop", (id) => {
getWindowById(id).webContents.scrollToTop();
});
socket.on("webContents-scrollToBottom", (id) => {
getWindowById(id).webContents.scrollToBottom();
});
socket.on("webContents-insertText", async (id, text) => {
await getWindowById(id).webContents.insertText(text);
electronSocket.emit("webContents-insertText-completed" + id);

File diff suppressed because one or more lines are too long

View File

@@ -121,6 +121,33 @@ export = (socket: Socket) => {
});
});
socket.on("register-webContents-audioStateChanged", (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners("audio-state-changed");
browserWindow.webContents.on("audio-state-changed", (event) => {
electronSocket.emit("webContents-audioStateChanged" + id, event.audible);
});
});
socket.on("register-webContents-mediaStartedPlaying", (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners("media-started-playing");
browserWindow.webContents.on("media-started-playing", () => {
electronSocket.emit("webContents-mediaStartedPlaying" + id);
});
});
socket.on("register-webContents-mediaPaused", (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners("media-paused");
browserWindow.webContents.on("media-paused", () => {
electronSocket.emit("webContents-mediaPaused" + id);
});
});
socket.on("webContents-openDevTools", (id, options) => {
if (options) {
getWindowById(id).webContents.openDevTools(options);
@@ -682,6 +709,14 @@ export = (socket: Socket) => {
getWindowById(id).webContents.centerSelection();
});
socket.on("webContents-scrollToTop", (id) => {
getWindowById(id).webContents.scrollToTop();
});
socket.on("webContents-scrollToBottom", (id) => {
getWindowById(id).webContents.scrollToBottom();
});
socket.on("webContents-insertText", async (id, text) => {
await getWindowById(id).webContents.insertText(text);
electronSocket.emit("webContents-insertText-completed" + id);