mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-04-25 15:40:39 +00:00
implement BrowserWindow-API functions
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
namespace ElectronNET.API
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public class BrowserWindow
|
||||
{
|
||||
@@ -8,9 +14,599 @@
|
||||
Id = id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force closing the window, the unload and beforeunload event won’t be
|
||||
/// emitted for the web page, and close event will also not be emitted
|
||||
/// for this window, but it guarantees the closed event will be emitted.
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-destroy", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to close the window. This has the same effect as a user manually
|
||||
/// clicking the close button of the window. The web page may cancel the close though.
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-close", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Focuses on the window.
|
||||
/// </summary>
|
||||
public void Focus()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-focus", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes focus from the window.
|
||||
/// </summary>
|
||||
public void Blur()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-blur", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is focused.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsFocusedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isFocused-completed", (isFocused) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isFocused-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isFocused);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isFocused", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is destroyed.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsDestroyedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isDestroyed-completed", (isDestroyed) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isDestroyed-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isDestroyed);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isDestroyed", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows and gives focus to the window.
|
||||
/// </summary>
|
||||
public void Show()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-show", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the window but doesn’t focus on it.
|
||||
/// </summary>
|
||||
public void ShowInactive()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-showInactive", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the window.
|
||||
/// </summary>
|
||||
public void Hide()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-hide", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is visible to the user.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsVisibleAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isVisible-completed", (isVisible) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isVisible-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isVisible);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isVisible", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether current window is a modal window.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsModalAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isModal-completed", (isModal) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isModal-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isModal);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isModal", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maximizes the window. This will also show (but not focus) the window if it isn’t being displayed already.
|
||||
/// </summary>
|
||||
public void Maximize()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-maximize", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unmaximizes the window.
|
||||
/// </summary>
|
||||
public void Unmaximize()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-unmaximize", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is maximized.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsMaximizedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isMaximized-completed", (isMaximized) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isMaximized-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isMaximized);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isMaximized", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Minimizes the window. On some platforms the minimized window will be shown in the Dock.
|
||||
/// </summary>
|
||||
public void Minimize()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-minimize", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the window from minimized state to its previous state.
|
||||
/// </summary>
|
||||
public void Restore()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-restore", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is minimized.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsMinimizedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isMinimized-completed", (isMinimized) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isMinimized-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isMinimized);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isMinimized", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window should be in fullscreen mode.
|
||||
/// </summary>
|
||||
public void SetFullScreen(bool flag)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setFullScreen", Id, flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is in fullscreen mode.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsFullScreenAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isFullScreen-completed", (isFullScreen) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isFullScreen-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isFullScreen);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isFullScreen", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will make a window maintain an aspect ratio. The extra size allows a developer to have space,
|
||||
/// specified in pixels, not included within the aspect ratio calculations. This API already takes into
|
||||
/// account the difference between a window’s size and its content size.
|
||||
///
|
||||
/// Consider a normal window with an HD video player and associated controls.Perhaps there are 15 pixels
|
||||
/// of controls on the left edge, 25 pixels of controls on the right edge and 50 pixels of controls below
|
||||
/// the player. In order to maintain a 16:9 aspect ratio (standard aspect ratio for HD @1920x1080) within
|
||||
/// the player itself we would call this function with arguments of 16/9 and[40, 50]. The second argument
|
||||
/// doesn’t care where the extra width and height are within the content view–only that they exist. Just
|
||||
/// sum any extra width and height areas you have within the overall content view.
|
||||
/// </summary>
|
||||
/// <param name="aspectRatio">The aspect ratio to maintain for some portion of the content view.</param>
|
||||
/// <param name="extraSize">The extra size not to be included while maintaining the aspect ratio.</param>
|
||||
public void SetAspectRatio(int aspectRatio, Size extraSize)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAspectRatio", Id, aspectRatio, JObject.FromObject(extraSize, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses Quick Look to preview a file at a given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The absolute path to the file to preview with QuickLook. This is important as
|
||||
/// Quick Look uses the file name and file extension on the path to determine the content type of the
|
||||
/// file to open.</param>
|
||||
public void PreviewFile(string path)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-previewFile", Id, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses Quick Look to preview a file at a given path.
|
||||
/// </summary>
|
||||
/// <param name="path">The absolute path to the file to preview with QuickLook. This is important as
|
||||
/// Quick Look uses the file name and file extension on the path to determine the content type of the
|
||||
/// file to open.</param>
|
||||
/// <param name="displayname">The name of the file to display on the Quick Look modal view. This is
|
||||
/// purely visual and does not affect the content type of the file. Defaults to path.</param>
|
||||
public void PreviewFile(string path, string displayname)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-previewFile", Id, path, displayname);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the currently open Quick Look panel.
|
||||
/// </summary>
|
||||
public void CloseFilePreview()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-closeFilePreview", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the window to the supplied bounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
public void SetBounds(Rectangle bounds)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setBounds", Id, JObject.FromObject(bounds, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the window to the supplied bounds
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetBounds(Rectangle bounds, bool animate)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
|
||||
}
|
||||
|
||||
public Task<Rectangle> GetBoundsAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getBounds-completed", (getBounds) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getBounds-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)getBounds).ToObject<Rectangle>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getBounds", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds.
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
public void SetContentBounds(Rectangle bounds)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes and moves the window’s client area (e.g. the web page) to the supplied bounds.
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetContentBounds(Rectangle bounds, bool animate)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
|
||||
}
|
||||
|
||||
public Task<Rectangle> GetContentBoundsAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getContentBounds-completed", (getContentBounds) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getContentBounds-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JObject)getContentBounds).ToObject<Rectangle>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getContentBounds", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the window to width and height.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetSize(int width, int height)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setSize", Id, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the window to width and height.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetSize(int width, int height, bool animate)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setSize", Id, width, height, animate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the window’s width and height.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<int[]> GetSizeAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int[]>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getSize-completed", (size) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getSize-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)size).ToObject<int[]>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getSize", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the window’s client area (e.g. the web page) to width and height.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetContentSize(int width, int height)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setContentSize", Id, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the window’s client area (e.g. the web page) to width and height.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetContentSize(int width, int height, bool animate)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setContentSize", Id, width, height, animate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the window’s client area’s width and height.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<int[]> GetContentSizeAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int[]>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getContentSize-completed", (size) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getContentSize-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)size).ToObject<int[]>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getContentSize", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the minimum size of window to width and height.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetMinimumSize(int width, int height)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMinimumSize", Id, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the window’s minimum width and height.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<int[]> GetMinimumSizeAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int[]>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getMinimumSize-completed", (size) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getMinimumSize-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)size).ToObject<int[]>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getMinimumSize", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the maximum size of window to width and height.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void SetMaximumSize(int width, int height)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMaximumSize", Id, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the window’s maximum width and height.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<int[]> GetMaximumSizeAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int[]>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getMaximumSize-completed", (size) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getMaximumSize-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)size).ToObject<int[]>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getMaximumSize", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window can be manually resized by user.
|
||||
/// </summary>
|
||||
/// <param name="resizable"></param>
|
||||
public void SetResizable(bool resizable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setResizable", Id, resizable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be manually resized by user.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsResizableAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isResizable-completed", (resizable) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isResizable-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)resizable);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isResizable", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window can be moved by user. On Linux does nothing.
|
||||
/// </summary>
|
||||
/// <param name="movable"></param>
|
||||
public void SetMovable(bool movable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMovable", Id, movable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be moved by user.
|
||||
///
|
||||
/// On Linux always returns true.
|
||||
/// </summary>
|
||||
/// <returns>On Linux always returns true.</returns>
|
||||
public Task<bool> IsMovableAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isMovable-completed", (movable) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isMovable-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)movable);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isMovable", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window can be manually minimized by user. On Linux does nothing.
|
||||
/// </summary>
|
||||
/// <param name="minimizable"></param>
|
||||
public void SetMinimizable(bool minimizable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMinimizable", Id, minimizable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be manually minimized by user.
|
||||
///
|
||||
/// On Linux always returns true.
|
||||
/// </summary>
|
||||
/// <returns>On Linux always returns true.</returns>
|
||||
public Task<bool> IsMinimizableAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isMinimizable-completed", (minimizable) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isMinimizable-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)minimizable);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isMinimizable", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window can be manually maximized by user. On Linux does nothing.
|
||||
/// </summary>
|
||||
/// <param name="maximizable"></param>
|
||||
public void SetMaximizable(bool maximizable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMaximizable", Id, maximizable);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class BrowserWindowConstructorOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Window's width in pixels. Default is 800.
|
||||
/// </summary>
|
||||
public int Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's height in pixels. Default is 600.
|
||||
/// </summary>
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ( if y is used) Window's left offset from screen. Default is to center the
|
||||
/// window.
|
||||
/// </summary>
|
||||
public int X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ( if x is used) Window's top offset from screen. Default is to center the
|
||||
/// window.
|
||||
/// </summary>
|
||||
public int Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The width and height would be used as web page's size, which means the actual
|
||||
/// window's size will include window frame's size and be slightly larger.Default
|
||||
/// is false.
|
||||
/// </summary>
|
||||
public bool UseContentSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Show window in the center of the screen.
|
||||
/// </summary>
|
||||
public bool Center { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's minimum width. Default is 0.
|
||||
/// </summary>
|
||||
public int MinWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's minimum height. Default is 0.
|
||||
/// </summary>
|
||||
public int MinHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's maximum width. Default is no limit.
|
||||
/// </summary>
|
||||
public int MaxWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's maximum height. Default is no limit.
|
||||
/// </summary>
|
||||
public int MaxHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is resizable. Default is true.
|
||||
/// </summary>
|
||||
public bool Resizable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is movable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Movable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is minimizable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Minimizable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is maximizable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Maximizable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is closable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Closable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be focused. Default is true. On Windows setting
|
||||
/// focusable: false also implies setting skipTaskbar: true. On Linux setting
|
||||
/// focusable: false makes the window stop interacting with wm, so the window will
|
||||
/// always stay on top in all workspaces.
|
||||
/// </summary>
|
||||
public bool Focusable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window should always stay on top of other windows. Default is false.
|
||||
/// </summary>
|
||||
public bool AlwaysOnTop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window should show in fullscreen. When explicitly set to false the
|
||||
/// fullscreen button will be hidden or disabled on macOS.Default is false.
|
||||
/// </summary>
|
||||
public bool Fullscreen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be put into fullscreen mode. On macOS, also whether the
|
||||
/// maximize/zoom button should toggle full screen mode or maximize window.Default
|
||||
/// is true.
|
||||
/// </summary>
|
||||
public bool Fullscreenable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the window in taskbar. Default is false.
|
||||
/// </summary>
|
||||
public bool SkipTaskbar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The kiosk mode. Default is false.
|
||||
/// </summary>
|
||||
public bool Kiosk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default window title. Default is "Electron.NET".
|
||||
/// </summary>
|
||||
public string Title { get; set; } = "Electron.NET";
|
||||
|
||||
/// <summary>
|
||||
/// The window icon. On Windows it is recommended to use ICO icons to get best
|
||||
/// visual effects, you can also leave it undefined so the executable's icon will be used.
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window should be shown when created. Default is true.
|
||||
/// </summary>
|
||||
public bool Show { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specify false to create a . Default is true.
|
||||
/// </summary>
|
||||
public bool Frame { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this is a modal window. This only works when the window is a child
|
||||
/// window.Default is false.
|
||||
/// </summary>
|
||||
public bool Modal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the web view accepts a single mouse-down event that simultaneously
|
||||
/// activates the window.Default is false.
|
||||
/// </summary>
|
||||
public bool AcceptFirstMouse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to hide cursor when typing. Default is false.
|
||||
/// </summary>
|
||||
public bool DisableAutoHideCursor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Auto hide the menu bar unless the Alt key is pressed. Default is false.
|
||||
/// </summary>
|
||||
public bool AutoHideMenuBar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enable the window to be resized larger than screen. Default is false.
|
||||
/// </summary>
|
||||
public bool EnableLargerThanScreen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's background color as Hexadecimal value, like #66CD00 or #FFF or
|
||||
/// #80FFFFFF (alpha is supported). Default is #FFF (white).
|
||||
/// </summary>
|
||||
public string BackgroundColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window should have a shadow. This is only implemented on macOS. Default
|
||||
/// is true.
|
||||
/// </summary>
|
||||
public bool HasShadow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Forces using dark theme for the window, only works on some GTK+3 desktop
|
||||
/// environments.Default is false.
|
||||
/// </summary>
|
||||
public bool DarkTheme { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Makes the window . Default is false.
|
||||
/// </summary>
|
||||
public bool Transparent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of window, default is normal window. See more about this below.
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The style of window title bar. Default is default. Possible values are:
|
||||
/// 'default' | 'hidden' | 'hidden-inset' | 'hiddenInset' | 'customButtonsOnHover'
|
||||
/// </summary>
|
||||
public string TitleBarStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shows the title in the tile bar in full screen mode on macOS for all
|
||||
/// titleBarStyle options.Default is false.
|
||||
/// </summary>
|
||||
public bool FullscreenWindowTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use WS_THICKFRAME style for frameless windows on Windows, which adds standard
|
||||
/// window frame.Setting it to false will remove window shadow and window
|
||||
/// animations.Default is true.
|
||||
/// </summary>
|
||||
public bool ThickFrame { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Add a type of vibrancy effect to the window, only on macOS. Can be
|
||||
/// appearance-based, light, dark, titlebar, selection, menu, popover, sidebar,
|
||||
/// medium-light or ultra-dark.
|
||||
/// </summary>
|
||||
public string Vibrancy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls the behavior on macOS when option-clicking the green stoplight button
|
||||
/// on the toolbar or by clicking the Window > Zoom menu item.If true, the window
|
||||
/// will grow to the preferred width of the web page when zoomed, false will cause
|
||||
/// it to zoom to the width of the screen.This will also affect the behavior when
|
||||
/// calling maximize() directly.Default is false.
|
||||
/// </summary>
|
||||
public bool ZoomToPageWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tab group name, allows opening the window as a native tab on macOS 10.12+.
|
||||
/// Windows with the same tabbing identifier will be grouped together.This also
|
||||
/// adds a native new tab button to your window's tab bar and allows your app and
|
||||
/// window to receive the new-window-for-tab event.
|
||||
/// </summary>
|
||||
public string TabbingIdentifier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Settings of web page's features.
|
||||
/// </summary>
|
||||
public WebPreferences WebPreferences { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,243 @@
|
||||
{
|
||||
public class BrowserWindowOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Window's width in pixels. Default is 800.
|
||||
/// </summary>
|
||||
public int Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's height in pixels. Default is 600.
|
||||
/// </summary>
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ( if y is used) Window's left offset from screen. Default is to center the
|
||||
/// window.
|
||||
/// </summary>
|
||||
public int X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ( if x is used) Window's top offset from screen. Default is to center the
|
||||
/// window.
|
||||
/// </summary>
|
||||
public int Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The width and height would be used as web page's size, which means the actual
|
||||
/// window's size will include window frame's size and be slightly larger.Default
|
||||
/// is false.
|
||||
/// </summary>
|
||||
public bool UseContentSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Show window in the center of the screen.
|
||||
/// </summary>
|
||||
public bool Center { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's minimum width. Default is 0.
|
||||
/// </summary>
|
||||
public int MinWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's minimum height. Default is 0.
|
||||
/// </summary>
|
||||
public int MinHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's maximum width. Default is no limit.
|
||||
/// </summary>
|
||||
public int MaxWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's maximum height. Default is no limit.
|
||||
/// </summary>
|
||||
public int MaxHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is resizable. Default is true.
|
||||
/// </summary>
|
||||
public bool Resizable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is movable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Movable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is minimizable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Minimizable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is maximizable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Maximizable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is closable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Closable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be focused. Default is true. On Windows setting
|
||||
/// focusable: false also implies setting skipTaskbar: true. On Linux setting
|
||||
/// focusable: false makes the window stop interacting with wm, so the window will
|
||||
/// always stay on top in all workspaces.
|
||||
/// </summary>
|
||||
public bool Focusable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window should always stay on top of other windows. Default is false.
|
||||
/// </summary>
|
||||
public bool AlwaysOnTop { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window should show in fullscreen. When explicitly set to false the
|
||||
/// fullscreen button will be hidden or disabled on macOS.Default is false.
|
||||
/// </summary>
|
||||
public bool Fullscreen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be put into fullscreen mode. On macOS, also whether the
|
||||
/// maximize/zoom button should toggle full screen mode or maximize window.Default
|
||||
/// is true.
|
||||
/// </summary>
|
||||
public bool Fullscreenable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the window in taskbar. Default is false.
|
||||
/// </summary>
|
||||
public bool SkipTaskbar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The kiosk mode. Default is false.
|
||||
/// </summary>
|
||||
public bool Kiosk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default window title. Default is "Electron.NET".
|
||||
/// </summary>
|
||||
public string Title { get; set; } = "Electron.NET";
|
||||
|
||||
/// <summary>
|
||||
/// The window icon. On Windows it is recommended to use ICO icons to get best
|
||||
/// visual effects, you can also leave it undefined so the executable's icon will be used.
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window should be shown when created. Default is true.
|
||||
/// </summary>
|
||||
public bool Show { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specify false to create a . Default is true.
|
||||
/// </summary>
|
||||
public bool Frame { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this is a modal window. This only works when the window is a child
|
||||
/// window.Default is false.
|
||||
/// </summary>
|
||||
public bool Modal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the web view accepts a single mouse-down event that simultaneously
|
||||
/// activates the window.Default is false.
|
||||
/// </summary>
|
||||
public bool AcceptFirstMouse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to hide cursor when typing. Default is false.
|
||||
/// </summary>
|
||||
public bool DisableAutoHideCursor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Auto hide the menu bar unless the Alt key is pressed. Default is false.
|
||||
/// </summary>
|
||||
public bool AutoHideMenuBar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enable the window to be resized larger than screen. Default is false.
|
||||
/// </summary>
|
||||
public bool EnableLargerThanScreen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window's background color as Hexadecimal value, like #66CD00 or #FFF or
|
||||
/// #80FFFFFF (alpha is supported). Default is #FFF (white).
|
||||
/// </summary>
|
||||
public string BackgroundColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether window should have a shadow. This is only implemented on macOS. Default
|
||||
/// is true.
|
||||
/// </summary>
|
||||
public bool HasShadow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Forces using dark theme for the window, only works on some GTK+3 desktop
|
||||
/// environments.Default is false.
|
||||
/// </summary>
|
||||
public bool DarkTheme { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Makes the window . Default is false.
|
||||
/// </summary>
|
||||
public bool Transparent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of window, default is normal window.
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The style of window title bar. Default is default. Possible values are:
|
||||
/// 'default' | 'hidden' | 'hidden-inset' | 'hiddenInset' | 'customButtonsOnHover'
|
||||
/// </summary>
|
||||
public string TitleBarStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shows the title in the tile bar in full screen mode on macOS for all
|
||||
/// titleBarStyle options.Default is false.
|
||||
/// </summary>
|
||||
public bool FullscreenWindowTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use WS_THICKFRAME style for frameless windows on Windows, which adds standard
|
||||
/// window frame.Setting it to false will remove window shadow and window
|
||||
/// animations.Default is true.
|
||||
/// </summary>
|
||||
public bool ThickFrame { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Add a type of vibrancy effect to the window, only on macOS. Can be
|
||||
/// appearance-based, light, dark, titlebar, selection, menu, popover, sidebar,
|
||||
/// medium-light or ultra-dark.
|
||||
/// </summary>
|
||||
public string Vibrancy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls the behavior on macOS when option-clicking the green stoplight button
|
||||
/// on the toolbar or by clicking the Window > Zoom menu item.If true, the window
|
||||
/// will grow to the preferred width of the web page when zoomed, false will cause
|
||||
/// it to zoom to the width of the screen.This will also affect the behavior when
|
||||
/// calling maximize() directly.Default is false.
|
||||
/// </summary>
|
||||
public bool ZoomToPageWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tab group name, allows opening the window as a native tab on macOS 10.12+.
|
||||
/// Windows with the same tabbing identifier will be grouped together.This also
|
||||
/// adds a native new tab button to your window's tab bar and allows your app and
|
||||
/// window to receive the new-window-for-tab event.
|
||||
/// </summary>
|
||||
public string TabbingIdentifier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Settings of web page's features.
|
||||
/// </summary>
|
||||
public WebPreferences WebPreferences { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
10
ElectronNET.API/Entities/Rectangle.cs
Normal file
10
ElectronNET.API/Entities/Rectangle.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class Rectangle
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
}
|
||||
}
|
||||
9
ElectronNET.API/Entities/Size.cs
Normal file
9
ElectronNET.API/Entities/Size.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class Size
|
||||
{
|
||||
public int Width { get; set; }
|
||||
|
||||
public int Height { get; set; }
|
||||
}
|
||||
}
|
||||
53
ElectronNET.API/Extensions/MenuItemExtensions.cs
Normal file
53
ElectronNET.API/Extensions/MenuItemExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ElectronNET.API.Extensions
|
||||
{
|
||||
internal static class MenuItemExtensions
|
||||
{
|
||||
public static MenuItem[] AddMenuItemsId(this MenuItem[] menuItems)
|
||||
{
|
||||
for (int index = 0; index < menuItems.Length; index++)
|
||||
{
|
||||
var menuItem = menuItems[index];
|
||||
if (menuItem?.Submenu?.Length > 0)
|
||||
{
|
||||
AddMenuItemsId(menuItem.Submenu);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(menuItem.Role) &&
|
||||
string.IsNullOrEmpty(menuItem.Id))
|
||||
{
|
||||
menuItem.Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
public static MenuItem GetMenuItem(this List<MenuItem> menuItems, string id)
|
||||
{
|
||||
MenuItem result = new MenuItem();
|
||||
|
||||
foreach (var item in menuItems)
|
||||
{
|
||||
if (item.Id == id)
|
||||
{
|
||||
result = item;
|
||||
}
|
||||
else if (item?.Submenu?.Length > 0)
|
||||
{
|
||||
var menuItem = GetMenuItem(item.Submenu.ToList(), id);
|
||||
if (menuItem.Id == id)
|
||||
{
|
||||
result = menuItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -63,11 +66,19 @@ namespace ElectronNET.API
|
||||
/// no functions or prototype chain will be included. The renderer process handles it by
|
||||
/// listening for channel with ipcRenderer module.
|
||||
/// </summary>
|
||||
/// <param name="browserWindow">BrowserWindow with channel.</param>
|
||||
/// <param name="channel">Channelname.</param>
|
||||
/// <param name="data">Arguments data.</param>
|
||||
public void Send(string channel, params object[] data)
|
||||
public void Send(BrowserWindow browserWindow, string channel, params object[] data)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("sendToIpcRenderer", channel, data);
|
||||
BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, data);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ElectronNET.API.Extensions;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -32,56 +33,16 @@ namespace ElectronNET.API
|
||||
|
||||
public void SetApplicationMenu(MenuItem[] menuItems)
|
||||
{
|
||||
AddMenuItemsId(menuItems);
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.On("menuItemClicked", (id) => {
|
||||
MenuItem menuItem = GetMenuItem(_items, id.ToString());
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
menuItem?.Click();
|
||||
});
|
||||
}
|
||||
|
||||
private void AddMenuItemsId(MenuItem[] menuItems)
|
||||
{
|
||||
for (int index = 0; index < menuItems.Length; index++)
|
||||
{
|
||||
var menuItem = menuItems[index];
|
||||
if(menuItem?.Submenu?.Length > 0)
|
||||
{
|
||||
AddMenuItemsId(menuItem.Submenu);
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(menuItem.Role))
|
||||
{
|
||||
menuItem.Id = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MenuItem GetMenuItem(List<MenuItem> menuItems, string id)
|
||||
{
|
||||
MenuItem result = new MenuItem();
|
||||
|
||||
foreach (var item in menuItems)
|
||||
{
|
||||
if(item.Id == id)
|
||||
{
|
||||
result = item;
|
||||
}
|
||||
else if(item?.Submenu?.Length > 0)
|
||||
{
|
||||
var menuItem = GetMenuItem(item.Submenu.ToList(), id);
|
||||
if(menuItem.Id == id)
|
||||
{
|
||||
result = menuItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using ElectronNET.API.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -24,9 +26,19 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<MenuItem> Items { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
|
||||
public void Show(string image, MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.On("trayMenuItemClicked", (id) => {
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
menuItem?.Click();
|
||||
});
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
|
||||
@@ -31,15 +31,17 @@ namespace ElectronNET.API
|
||||
|
||||
public async Task<BrowserWindow> CreateWindowAsync(string loadUrl = "http://localhost")
|
||||
{
|
||||
return await CreateWindowAsync(new BrowserWindowConstructorOptions(), loadUrl);
|
||||
return await CreateWindowAsync(new BrowserWindowOptions(), loadUrl);
|
||||
}
|
||||
|
||||
public Task<BrowserWindow> CreateWindowAsync(BrowserWindowConstructorOptions options, string loadUrl = "http://localhost")
|
||||
public Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options, string loadUrl = "http://localhost")
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserWindow>();
|
||||
|
||||
BridgeConnector.Socket.On("BrowserWindowCreated", (id) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("BrowserWindowCreated");
|
||||
|
||||
string windowId = id.ToString();
|
||||
BrowserWindow browserWindow = new BrowserWindow(int.Parse(windowId));
|
||||
_browserWindows.Add(browserWindow);
|
||||
|
||||
Reference in New Issue
Block a user