diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs
index 790f0f0..d08319d 100644
--- a/ElectronNET.API/BrowserWindow.cs
+++ b/ElectronNET.API/BrowserWindow.cs
@@ -1,7 +1,11 @@
using ElectronNET.API.Entities;
+using ElectronNET.API.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
+using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
namespace ElectronNET.API
@@ -10,6 +14,29 @@ namespace ElectronNET.API
{
public int Id { get; private set; }
+ public event Action ReadyToShow
+ {
+ add
+ {
+ if (_readyToShow == null)
+ {
+ BridgeConnector.Socket.On("browserWindow-ready-to-show", () =>
+ {
+ _readyToShow();
+ });
+
+ BridgeConnector.Socket.Emit("register-browserWindow-ready-to-show", Id);
+ }
+ _readyToShow += value;
+ }
+ remove
+ {
+ _readyToShow -= value;
+ }
+ }
+
+ private event Action _readyToShow;
+
internal BrowserWindow(int id) {
Id = id;
}
@@ -602,11 +629,702 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("browserWindow-setMaximizable", Id, maximizable);
}
+ ///
+ /// Whether the window can be manually maximized by user.
+ ///
+ /// On Linux always returns true.
+ ///
+ /// On Linux always returns true.
+ public Task IsMaximizableAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-isMaximizable-completed", (maximizable) => {
+ BridgeConnector.Socket.Off("browserWindow-isMaximizable-completed");
+
+ taskCompletionSource.SetResult((bool)maximizable);
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-isMaximizable", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
+ ///
+ ///
+ public void SetFullScreenable(bool fullscreenable)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setFullScreenable", Id, fullscreenable);
+ }
+
+ ///
+ /// Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
+ ///
+ ///
+ public Task IsFullScreenableAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-isFullScreenable-completed", (fullscreenable) => {
+ BridgeConnector.Socket.Off("browserWindow-isFullScreenable-completed");
+
+ taskCompletionSource.SetResult((bool)fullscreenable);
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-isFullScreenable", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Sets whether the window can be manually closed by user. On Linux does nothing.
+ ///
+ ///
+ public void SetClosable(bool closable)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setClosable", Id, closable);
+ }
+
+ ///
+ /// Whether the window can be manually closed by user.
+ ///
+ /// On Linux always returns true.
+ ///
+ /// On Linux always returns true.
+ public Task IsClosableAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-isClosable-completed", (closable) => {
+ BridgeConnector.Socket.Off("browserWindow-isClosable-completed");
+
+ taskCompletionSource.SetResult((bool)closable);
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-isClosable", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Sets whether the window should show always on top of other windows.
+ /// After setting this, the window is still a normal window, not a toolbox
+ /// window which can not be focused on.
+ ///
+ ///
+ public void SetAlwaysOnTop(bool flag)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setAlwaysOnTop", Id, flag);
+ }
+
+ ///
+ /// Sets whether the window should show always on top of other windows.
+ /// After setting this, the window is still a normal window, not a toolbox
+ /// window which can not be focused on.
+ ///
+ ///
+ /// Values include normal, floating, torn-off-menu, modal-panel, main-menu,
+ /// status, pop-up-menu and screen-saver. The default is floating.
+ /// See the macOS docs
+ public void SetAlwaysOnTop(bool flag, string level)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setAlwaysOnTop", Id, flag, level);
+ }
+
+ ///
+ /// Sets whether the window should show always on top of other windows.
+ /// After setting this, the window is still a normal window, not a toolbox
+ /// window which can not be focused on.
+ ///
+ ///
+ /// Values include normal, floating, torn-off-menu, modal-panel, main-menu,
+ /// status, pop-up-menu and screen-saver. The default is floating.
+ /// See the macOS docs
+ /// The number of layers higher to set this window relative to the given level.
+ /// The default is 0. Note that Apple discourages setting levels higher than 1 above screen-saver.
+ public void SetAlwaysOnTop(bool flag, string level, int relativeLevel)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setAlwaysOnTop", Id, flag, level, relativeLevel);
+ }
+
+ ///
+ /// Whether the window is always on top of other windows.
+ ///
+ ///
+ public Task IsAlwaysOnTopAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-isAlwaysOnTop-completed", (isAlwaysOnTop) => {
+ BridgeConnector.Socket.Off("browserWindow-isAlwaysOnTop-completed");
+
+ taskCompletionSource.SetResult((bool)isAlwaysOnTop);
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-isAlwaysOnTop", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Moves window to the center of the screen.
+ ///
+ public void Center()
+ {
+ BridgeConnector.Socket.Emit("browserWindow-center", Id);
+ }
+
+ ///
+ /// Moves window to x and y.
+ ///
+ ///
+ ///
+ public void SetPosition(int x, int y)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setPosition", Id, x, y);
+ }
+
+ ///
+ /// Moves window to x and y.
+ ///
+ ///
+ ///
+ ///
+ public void SetPosition(int x, int y, bool animate)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setPosition", Id, x, y, animate);
+ }
+
+ ///
+ /// Contains the window’s current position.
+ ///
+ ///
+ public Task GetPositionAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-getPosition-completed", (position) => {
+ BridgeConnector.Socket.Off("browserWindow-getPosition-completed");
+
+ taskCompletionSource.SetResult(((JArray)position).ToObject());
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-getPosition", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Changes the title of native window to title.
+ ///
+ ///
+ public void SetTitle(string title)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setTitle", Id, title);
+ }
+
+ ///
+ /// The title of the native window.
+ ///
+ /// Note: The title of web page can be different from the title of the native window.
+ ///
+ ///
+ public Task GetTitleAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-getTitle-completed", (title) => {
+ BridgeConnector.Socket.Off("browserWindow-getTitle-completed");
+
+ taskCompletionSource.SetResult(title.ToString());
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-getTitle", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Changes the attachment point for sheets on macOS.
+ /// By default, sheets are attached just below the window frame,
+ /// but you may want to display them beneath a HTML-rendered toolbar.
+ ///
+ ///
+ public void SetSheetOffset(float offsetY)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setSheetOffset", Id, offsetY);
+ }
+
+ ///
+ /// Changes the attachment point for sheets on macOS.
+ /// By default, sheets are attached just below the window frame,
+ /// but you may want to display them beneath a HTML-rendered toolbar.
+ ///
+ ///
+ ///
+ public void SetSheetOffset(float offsetY, float offsetX)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setSheetOffset", Id, offsetY, offsetX);
+ }
+
+ ///
+ /// Starts or stops flashing the window to attract user’s attention.
+ ///
+ ///
+ public void FlashFrame(bool flag)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-flashFrame", Id, flag);
+ }
+
+ ///
+ /// Makes the window not show in the taskbar.
+ ///
+ ///
+ public void SetSkipTaskbar(bool skip)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setSkipTaskbar", Id, skip);
+ }
+
+ ///
+ /// Enters or leaves the kiosk mode.
+ ///
+ ///
+ public void SetKiosk(bool flag)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setKiosk", Id, flag);
+ }
+
+ ///
+ /// Whether the window is in kiosk mode.
+ ///
+ ///
+ public Task IsKioskAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-isKiosk-completed", (isKiosk) => {
+ BridgeConnector.Socket.Off("browserWindow-isKiosk-completed");
+
+ taskCompletionSource.SetResult((bool)isKiosk);
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-isKiosk", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Sets the pathname of the file the window represents,
+ /// and the icon of the file will show in window’s title bar.
+ ///
+ ///
+ public void SetRepresentedFilename(string filename)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setRepresentedFilename", Id, filename);
+ }
+
+ ///
+ /// The pathname of the file the window represents.
+ ///
+ ///
+ public Task GetRepresentedFilenameAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-getRepresentedFilename-completed", (pathname) => {
+ BridgeConnector.Socket.Off("browserWindow-getRepresentedFilename-completed");
+
+ taskCompletionSource.SetResult(pathname.ToString());
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-getRepresentedFilename", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ ///
+ /// Specifies whether the window’s document has been edited,
+ /// and the icon in title bar will become gray when set to true.
+ ///
+ ///
+ public void SetDocumentEdited(bool edited)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-setDocumentEdited", Id, edited);
+ }
+
+ ///
+ /// Whether the window’s document has been edited.
+ ///
+ ///
+ public Task IsDocumentEditedAsync()
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+
+ BridgeConnector.Socket.On("browserWindow-isDocumentEdited-completed", (edited) => {
+ BridgeConnector.Socket.Off("browserWindow-isDocumentEdited-completed");
+
+ taskCompletionSource.SetResult((bool)edited);
+ });
+
+ BridgeConnector.Socket.Emit("browserWindow-isDocumentEdited", Id);
+
+ return taskCompletionSource.Task;
+ }
+
+ public void FocusOnWebView()
+ {
+ BridgeConnector.Socket.Emit("browserWindow-focusOnWebView", Id);
+ }
+
+ public void BlurWebView()
+ {
+ BridgeConnector.Socket.Emit("browserWindow-blurWebView", Id);
+ }
+
+ ///
+ /// The url can be a remote address (e.g. http://) or
+ /// a path to a local HTML file using the file:// protocol.
+ ///
+ ///
+ public void LoadURL(string url)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-loadURL", Id, url);
+ }
+
+ ///
+ /// The url can be a remote address (e.g. http://) or
+ /// a path to a local HTML file using the file:// protocol.
+ ///
+ ///
+ ///
+ public void LoadURL(string url, LoadURLOptions options)
+ {
+ BridgeConnector.Socket.Emit("browserWindow-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer));
+ }
+
+ ///
+ /// Same as webContents.reload.
+ ///
+ public void Reload()
+ {
+ BridgeConnector.Socket.Emit("browserWindow-reload", Id);
+ }
+
+ public IReadOnlyCollection