2025-11-09 12:05:07 +01:00
|
|
|
using ElectronNET.API.Entities;
|
|
|
|
|
using ElectronNET.API.Serialization;
|
|
|
|
|
using System.Text.Json;
|
2020-04-23 03:29:52 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ElectronNET.API
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2025-11-09 12:05:07 +01:00
|
|
|
/// A BrowserView can be used to embed additional web content into a BrowserWindow.
|
|
|
|
|
/// It is like a child window, except that it is positioned relative to its owning window.
|
2020-04-23 03:29:52 +02:00
|
|
|
/// It is meant to be an alternative to the webview tag.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BrowserView
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the identifier.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Id { get; internal set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Render and control web pages.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public WebContents WebContents { get; internal set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resizes and moves the view to the supplied bounds relative to the window.
|
|
|
|
|
/// (experimental)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Rectangle Bounds
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2025-11-10 10:40:51 +01:00
|
|
|
var tcs = new TaskCompletionSource<Rectangle>();
|
2020-04-23 03:29:52 +02:00
|
|
|
|
2025-11-09 02:39:42 +01:00
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2025-11-10 10:40:51 +01:00
|
|
|
BridgeConnector.Socket.Once<Rectangle>("browserView-getBounds-reply", tcs.SetResult);
|
2020-04-23 03:29:52 +02:00
|
|
|
BridgeConnector.Socket.Emit("browserView-getBounds", Id);
|
2025-11-09 02:39:42 +01:00
|
|
|
});
|
2020-04-23 03:29:52 +02:00
|
|
|
|
2025-11-10 10:40:51 +01:00
|
|
|
return tcs.Task.GetAwaiter().GetResult();
|
2020-04-23 03:29:52 +02:00
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2025-11-09 12:05:07 +01:00
|
|
|
BridgeConnector.Socket.Emit("browserView-setBounds", Id, value);
|
2020-04-23 03:29:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// BrowserView
|
|
|
|
|
/// </summary>
|
2025-11-09 03:50:24 +01:00
|
|
|
internal BrowserView(int id)
|
2020-04-23 03:29:52 +02:00
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
|
|
|
|
|
// Workaround: increase the Id so as not to conflict with BrowserWindow id
|
|
|
|
|
// the backend detect about the value an BrowserView
|
|
|
|
|
WebContents = new WebContents(id + 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// (experimental)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="options"></param>
|
|
|
|
|
public void SetAutoResize(AutoResizeOptions options)
|
|
|
|
|
{
|
2025-11-09 12:05:07 +01:00
|
|
|
BridgeConnector.Socket.Emit("browserView-setAutoResize", Id, options);
|
2020-04-23 03:29:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Color in #aarrggbb or #argb form. The alpha channel is optional.
|
|
|
|
|
/// (experimental)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="color">Color in #aarrggbb or #argb form. The alpha channel is optional.</param>
|
|
|
|
|
public void SetBackgroundColor(string color)
|
|
|
|
|
{
|
|
|
|
|
BridgeConnector.Socket.Emit("browserView-setBackgroundColor", Id, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-09 12:05:07 +01:00
|
|
|
}
|
|
|
|
|
|