adding WebContents APIs for Zoom, Audio and DevTools

This commit is contained in:
agracio
2025-12-04 17:52:01 +00:00
parent c81ed54fff
commit dae521180f
6 changed files with 487 additions and 9 deletions

View File

@@ -123,7 +123,7 @@ public class WebContents : ApiBase
/// </summary>
public void OpenDevTools()
{
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id);
BridgeConnector.Socket.Emit("webContents-openDevTools", Id);
}
/// <summary>
@@ -132,7 +132,41 @@ public class WebContents : ApiBase
/// <param name="openDevToolsOptions"></param>
public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions)
{
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, openDevToolsOptions);
BridgeConnector.Socket.Emit("webContents-openDevTools", Id, openDevToolsOptions);
}
/// <summary>
/// Toggles the devtools.
/// </summary>
public void ToggleDevTools()
{
BridgeConnector.Socket.Emit("webContents-toggleDevTools", Id);
}
/// <summary>
/// Closes the devtools.
/// </summary>
public void CloseDevTools()
{
BridgeConnector.Socket.Emit("webContents-closeDevTools", Id);
}
/// <summary>
/// Returns boolean - Whether the devtools is opened.
/// </summary>
/// <returns></returns>
public bool IsDevToolsOpened()
{
return Task.Run(() => InvokeAsync<bool>()).Result;
}
/// <summary>
/// Returns boolean - Whether the devtools view is focused.
/// </summary>
/// <returns></returns>
public bool IsDevToolsFocused()
{
return Task.Run(() => InvokeAsync<bool>()).Result;
}
/// <summary>
@@ -280,4 +314,151 @@ public class WebContents : ApiBase
{
BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path);
}
/// <summary>
/// A number property that determines the zoom level for this web contents.
///The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively.
///The formula for this is scale := 1.2 ^ level.
/// </summary>
public int ZoomLevel
{
get
{
return Task.Run(() => this.InvokeAsync<int>()).Result;
}
set
{
BridgeConnector.Socket.Emit("webContents-zoomLevel-set", Id, value);
}
}
/// <summary>
/// A number property that determines the zoom factor for this web contents.
///The zoom factor is the zoom percent divided by 100, so 300% = 3.0.
/// </summary>
public double ZoomFactor
{
get
{
return Task.Run(() => this.InvokeAsync<double>()).Result;
}
set
{
BridgeConnector.Socket.Emit("webContents-zoomFactor-set", Id, value);
}
}
/// <summary>
/// Returns number - The current zoom factor.
/// </summary>
/// <returns></returns>
public Task<double> GetZoomFactorAsync() => InvokeAsync<double>();
/// <summary>
/// Changes the zoom factor to the specified factor.
/// Zoom factor is zoom percent divided by 100, so 300% = 3.0.
/// The factor must be greater than 0.0.
/// </summary>
/// <param name="factor"></param>
public void SetZoomFactor(double factor)
{
BridgeConnector.Socket.Emit("webContents-setZoomFactor", Id, factor);
}
/// <summary>
/// Returns number - The current zoom level.
/// </summary>
/// <returns></returns>
public Task<int> GetZoomLevelAsync() => InvokeAsync<int>();
/// <summary>
/// Changes the zoom level to the specified level.
/// The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively.
/// </summary>
/// <param name="level"></param>
public void SetZoomLevel(int level)
{
BridgeConnector.Socket.Emit("webContents-setZoomLevel", Id, level);
}
/// <summary>
/// Sets the maximum and minimum pinch-to-zoom level.
/// </summary>
/// <param name="minimumLevel"></param>
/// <param name="maximumLevel"></param>
public Task SetVisualZoomLevelLimitsAsync(int minimumLevel, int maximumLevel)
{
var tcs = new TaskCompletionSource();
BridgeConnector.Socket.Once("webContents-setVisualZoomLevelLimits-completed", tcs.SetResult);
BridgeConnector.Socket.Emit("webContents-setVisualZoomLevelLimits", Id, minimumLevel, maximumLevel);
return tcs.Task;
}
/// <summary>
/// A boolean property that determines whether this page is muted.
/// </summary>
public bool AudioMuted
{
get
{
return Task.Run(() => this.InvokeAsync<bool>()).Result;
}
set
{
BridgeConnector.Socket.Emit("webContents-audioMuted-set", Id, value);
}
}
/// <summary>
/// Returns boolean - Whether this page has been muted.
/// </summary>
/// <returns></returns>
public Task<bool> IsAudioMutedAsync() => InvokeAsync<bool>();
/// <summary>
/// Returns boolean - Whether audio is currently playing.
/// </summary>
/// <returns></returns>
public Task<bool> IsCurrentlyAudibleAsync() => InvokeAsync<bool>();
/// <summary>
/// Mute the audio on the current web page.
/// </summary>
/// <param name="muted"></param>
public void SetAudioMuted(bool muted)
{
BridgeConnector.Socket.Emit("webContents-setAudioMuted", Id, muted);
}
/// <summary>
/// A string property that determines the user agent for this web page.
/// </summary>
public string UserAgent
{
get
{
return Task.Run(() => this.InvokeAsync<string>()).Result;
}
set
{
BridgeConnector.Socket.Emit("webContents-userAgent-set", Id, value);
}
}
/// <summary>
/// Returns string - The user agent for this web page.
/// </summary>
/// <returns></returns>
public Task<string> GetUserAgentAsync() => InvokeAsync<string>();
/// <summary>
/// Overrides the user agent for this web page.
/// </summary>
/// <param name="userAgent"></param>
public void SetUserAgent(string userAgent)
{
BridgeConnector.Socket.Emit("webContents-setUserAgent", Id, userAgent);
}
}