Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 183 additions & 2 deletions src/ElectronNET.API/API/WebContents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal WebContents(int id)
/// </summary>
public void OpenDevTools()
{
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id);
BridgeConnector.Socket.Emit("webContents-openDevTools", Id);
}

/// <summary>
Expand All @@ -132,7 +132,41 @@ public void OpenDevTools()
/// <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;
}
Comment on lines +158 to 170
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties should be async. It could deadlock like this.


/// <summary>
Expand Down Expand Up @@ -280,4 +314,151 @@ public void InsertCSS(bool isBrowserWindow, string path)
{
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);
}
}
Comment on lines +323 to +349
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> async!


/// <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);
}
}
Comment on lines +402 to +412
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> async


/// <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);
}
}
Comment on lines +438 to +448
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> async


/// <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);
}
}
89 changes: 88 additions & 1 deletion src/ElectronNET.Host/api/webContents.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading