mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-20 15:46:15 +00:00
implement BrowserWindow-API functions
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be manually maximized by user.
|
||||
///
|
||||
/// On Linux always returns true.
|
||||
/// </summary>
|
||||
/// <returns>On Linux always returns true.</returns>
|
||||
public Task<bool> IsMaximizableAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
|
||||
/// </summary>
|
||||
/// <param name="fullscreenable"></param>
|
||||
public void SetFullScreenable(bool fullscreenable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setFullScreenable", Id, fullscreenable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsFullScreenableAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window can be manually closed by user. On Linux does nothing.
|
||||
/// </summary>
|
||||
/// <param name="closable"></param>
|
||||
public void SetClosable(bool closable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setClosable", Id, closable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be manually closed by user.
|
||||
///
|
||||
/// On Linux always returns true.
|
||||
/// </summary>
|
||||
/// <returns>On Linux always returns true.</returns>
|
||||
public Task<bool> IsClosableAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void SetAlwaysOnTop(bool flag)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAlwaysOnTop", Id, flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
/// <param name="level">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</param>
|
||||
public void SetAlwaysOnTop(bool flag, string level)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAlwaysOnTop", Id, flag, level);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
/// <param name="level">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</param>
|
||||
/// <param name="relativeLevel">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.</param>
|
||||
public void SetAlwaysOnTop(bool flag, string level, int relativeLevel)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAlwaysOnTop", Id, flag, level, relativeLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is always on top of other windows.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsAlwaysOnTopAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves window to the center of the screen.
|
||||
/// </summary>
|
||||
public void Center()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-center", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves window to x and y.
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setPosition", Id, x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves window to x and y.
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="animate"></param>
|
||||
public void SetPosition(int x, int y, bool animate)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setPosition", Id, x, y, animate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the window’s current position.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<int[]> GetPositionAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<int[]>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getPosition-completed", (position) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getPosition-completed");
|
||||
|
||||
taskCompletionSource.SetResult(((JArray)position).ToObject<int[]>());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getPosition", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the title of native window to title.
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
public void SetTitle(string title)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setTitle", Id, title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The title of the native window.
|
||||
///
|
||||
/// Note: The title of web page can be different from the title of the native window.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<string> GetTitleAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="offsetY"></param>
|
||||
public void SetSheetOffset(float offsetY)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setSheetOffset", Id, offsetY);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="offsetY"></param>
|
||||
/// <param name="offsetX"></param>
|
||||
public void SetSheetOffset(float offsetY, float offsetX)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setSheetOffset", Id, offsetY, offsetX);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts or stops flashing the window to attract user’s attention.
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void FlashFrame(bool flag)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-flashFrame", Id, flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the window not show in the taskbar.
|
||||
/// </summary>
|
||||
/// <param name="skip"></param>
|
||||
public void SetSkipTaskbar(bool skip)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setSkipTaskbar", Id, skip);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enters or leaves the kiosk mode.
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void SetKiosk(bool flag)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setKiosk", Id, flag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is in kiosk mode.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsKioskAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the pathname of the file the window represents,
|
||||
/// and the icon of the file will show in window’s title bar.
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
public void SetRepresentedFilename(string filename)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setRepresentedFilename", Id, filename);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The pathname of the file the window represents.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<string> GetRepresentedFilenameAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether the window’s document has been edited,
|
||||
/// and the icon in title bar will become gray when set to true.
|
||||
/// </summary>
|
||||
/// <param name="edited"></param>
|
||||
public void SetDocumentEdited(bool edited)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setDocumentEdited", Id, edited);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window’s document has been edited.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsDocumentEditedAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The url can be a remote address (e.g. http://) or
|
||||
/// a path to a local HTML file using the file:// protocol.
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
public void LoadURL(string url)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-loadURL", Id, url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The url can be a remote address (e.g. http://) or
|
||||
/// a path to a local HTML file using the file:// protocol.
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="options"></param>
|
||||
public void LoadURL(string url, LoadURLOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-loadURL", Id, url, JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as webContents.reload.
|
||||
/// </summary>
|
||||
public void Reload()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-reload", Id);
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<MenuItem> Items { get { return _items.AsReadOnly(); } }
|
||||
private List<MenuItem> _items = new List<MenuItem>();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the menu as the window’s menu bar,
|
||||
/// setting it to null will remove the menu bar.
|
||||
/// </summary>
|
||||
/// <param name="menuItems"></param>
|
||||
public void SetMenu(MenuItem[] menuItems)
|
||||
{
|
||||
menuItems.AddMenuItemsId();
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("windowMenuItemClicked");
|
||||
BridgeConnector.Socket.On("windowMenuItemClicked", (id) => {
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
menuItem?.Click();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets progress value in progress bar. Valid range is [0, 1.0]. Remove progress
|
||||
/// bar when progress < 0; Change to indeterminate mode when progress > 1. On Linux
|
||||
/// platform, only supports Unity desktop environment, you need to specify the
|
||||
/// .desktop file name to desktopName field in package.json.By default, it will
|
||||
/// assume app.getName().desktop.On Windows, a mode can be passed.Accepted values
|
||||
/// are none, normal, indeterminate, error, and paused. If you call setProgressBar
|
||||
/// without a mode set (but with a value within the valid range), normal will be
|
||||
/// assumed.
|
||||
/// </summary>
|
||||
/// <param name="progress"></param>
|
||||
public void SetProgressBar(int progress)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setProgressBar", Id, progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets progress value in progress bar. Valid range is [0, 1.0]. Remove progress
|
||||
/// bar when progress < 0; Change to indeterminate mode when progress > 1. On Linux
|
||||
/// platform, only supports Unity desktop environment, you need to specify the
|
||||
/// .desktop file name to desktopName field in package.json.By default, it will
|
||||
/// assume app.getName().desktop.On Windows, a mode can be passed.Accepted values
|
||||
/// are none, normal, indeterminate, error, and paused. If you call setProgressBar
|
||||
/// without a mode set (but with a value within the valid range), normal will be
|
||||
/// assumed.
|
||||
/// </summary>
|
||||
/// <param name="progress"></param>
|
||||
/// <param name="progressBarOptions"></param>
|
||||
public void SetProgressBar(int progress, ProgressBarOptions progressBarOptions)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setProgressBar", Id, progress, JObject.FromObject(progressBarOptions, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window should have a shadow. On Windows and Linux does nothing.
|
||||
/// </summary>
|
||||
/// <param name="hasShadow"></param>
|
||||
public void SetHasShadow(bool hasShadow)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setHasShadow", Id, hasShadow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window has a shadow.
|
||||
///
|
||||
/// On Windows and Linux always returns true.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> HasShadowAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-hasShadow-completed", (hasShadow) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-hasShadow-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)hasShadow);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-hasShadow", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the properties for the window’s taskbar button.
|
||||
///
|
||||
/// Note: relaunchCommand and relaunchDisplayName must always be set together.
|
||||
/// If one of those properties is not set, then neither will be used.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public void SetAppDetails(AppDetailsOptions options)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAppDetails", Id, JObject.FromObject(options, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as webContents.showDefinitionForSelection().
|
||||
/// </summary>
|
||||
public void ShowDefinitionForSelection()
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-showDefinitionForSelection", Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window menu bar should hide itself automatically.
|
||||
/// Once set the menu bar will only show when users press the single Alt key.
|
||||
///
|
||||
/// If the menu bar is already visible, calling setAutoHideMenuBar(true) won’t hide it immediately.
|
||||
/// </summary>
|
||||
/// <param name="hide"></param>
|
||||
public void SetAutoHideMenuBar(bool hide)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAutoHideMenuBar", Id, hide);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether menu bar automatically hides itself.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsMenuBarAutoHideAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isMenuBarAutoHide-completed", (isMenuBarAutoHide) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isMenuBarAutoHide-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isMenuBarAutoHide);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isMenuBarAutoHide", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the menu bar should be visible. If the menu bar is auto-hide,
|
||||
/// users can still bring up the menu bar by pressing the single Alt key.
|
||||
/// </summary>
|
||||
/// <param name="visible"></param>
|
||||
public void SetMenuBarVisibility(bool visible)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setMenuBarVisibility", Id, visible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the menu bar is visible.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsMenuBarVisibleAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isMenuBarVisible-completed", (isMenuBarVisible) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isMenuBarVisible-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isMenuBarVisible);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isMenuBarVisible", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the window should be visible on all workspaces.
|
||||
///
|
||||
/// Note: This API does nothing on Windows.
|
||||
/// </summary>
|
||||
/// <param name="visible"></param>
|
||||
public void SetVisibleOnAllWorkspaces(bool visible)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setVisibleOnAllWorkspaces", Id, visible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window is visible on all workspaces.
|
||||
///
|
||||
/// Note: This API always returns false on Windows.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsVisibleOnAllWorkspacesAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-isVisibleOnAllWorkspaces-completed", (isVisibleOnAllWorkspaces) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-isVisibleOnAllWorkspaces-completed");
|
||||
|
||||
taskCompletionSource.SetResult((bool)isVisibleOnAllWorkspaces);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-isVisibleOnAllWorkspaces", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the window ignore all mouse events.
|
||||
///
|
||||
/// All mouse events happened in this window will be passed to the window
|
||||
/// below this window, but if this window has focus, it will still receive keyboard events.
|
||||
/// </summary>
|
||||
/// <param name="ignore"></param>
|
||||
public void SetIgnoreMouseEvents(bool ignore)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setIgnoreMouseEvents", Id, ignore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents the window contents from being captured by other apps.
|
||||
///
|
||||
/// On macOS it sets the NSWindow’s sharingType to NSWindowSharingNone.
|
||||
/// On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR.
|
||||
/// </summary>
|
||||
/// <param name="ignore"></param>
|
||||
public void SetContentProtection(bool enable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setContentProtection", Id, enable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes whether the window can be focused.
|
||||
/// </summary>
|
||||
/// <param name="focusable"></param>
|
||||
public void SetFocusable(bool focusable)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setFocusable", Id, focusable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets parent as current window’s parent window,
|
||||
/// passing null will turn current window into a top-level window.
|
||||
/// </summary>
|
||||
/// <param name="browserWindow"></param>
|
||||
public void SetParentWindow(BrowserWindow parent)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The parent window.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<BrowserWindow> GetParentWindowAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<BrowserWindow>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getParentWindow-completed", (id) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getParentWindow-completed");
|
||||
var browserWindowId = int.Parse(id.ToString());
|
||||
var browserWindow = Electron.WindowManager.BrowserWindows.ToList().Single(x => x.Id == browserWindowId);
|
||||
|
||||
taskCompletionSource.SetResult(browserWindow);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getParentWindow", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All child windows.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<List<BrowserWindow>> GetChildWindowsAsync()
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<List<BrowserWindow>>();
|
||||
|
||||
BridgeConnector.Socket.On("browserWindow-getChildWindows-completed", (ids) => {
|
||||
BridgeConnector.Socket.Off("browserWindow-getChildWindows-completed");
|
||||
var browserWindowIds = ((JArray)ids).ToObject<int[]>();
|
||||
var browserWindows = new List<BrowserWindow>();
|
||||
|
||||
browserWindowIds.ToList().ForEach(id =>
|
||||
{
|
||||
var browserWindow = Electron.WindowManager.BrowserWindows.ToList().Single(x => x.Id == id);
|
||||
browserWindows.Add(browserWindow);
|
||||
});
|
||||
|
||||
|
||||
taskCompletionSource.SetResult(browserWindows);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("browserWindow-getChildWindows", Id);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controls whether to hide cursor when typing.
|
||||
/// </summary>
|
||||
/// <param name="autoHide"></param>
|
||||
public void SetAutoHideCursor(bool autoHide)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setAutoHideCursor", Id, autoHide);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a vibrancy effect to the browser window.
|
||||
/// Passing null or an empty string will remove the vibrancy effect on the window.
|
||||
/// </summary>
|
||||
/// <param name="type">Can be appearance-based, light, dark, titlebar, selection,
|
||||
/// menu, popover, sidebar, medium-light or ultra-dark.
|
||||
/// See the macOS documentation for more details.</param>
|
||||
public void SetVibrancy(string type)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("browserWindow-setVibrancy", Id, type);
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
30
ElectronNET.API/Entities/AppDetailsOptions.cs
Normal file
30
ElectronNET.API/Entities/AppDetailsOptions.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class AppDetailsOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Window’s App User Model ID. It has to be set, otherwise the other options will have no effect.
|
||||
/// </summary>
|
||||
public string AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window’s Relaunch Icon.
|
||||
/// </summary>
|
||||
public string AppIconPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Index of the icon in appIconPath. Ignored when appIconPath is not set. Default is 0.
|
||||
/// </summary>
|
||||
public int AppIconIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window’s Relaunch Command.
|
||||
/// </summary>
|
||||
public string RelaunchCommand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Window’s Relaunch Display Name.
|
||||
/// </summary>
|
||||
public string RelaunchDisplayName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class BrowserWindowOptions
|
||||
{
|
||||
@@ -26,7 +28,7 @@
|
||||
|
||||
/// <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
|
||||
/// window's size will include window frame's size and be slightly larger. Default
|
||||
/// is false.
|
||||
/// </summary>
|
||||
public bool UseContentSize { get; set; }
|
||||
@@ -59,27 +61,32 @@
|
||||
/// <summary>
|
||||
/// Whether window is resizable. Default is true.
|
||||
/// </summary>
|
||||
public bool Resizable { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Resizable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is movable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Movable { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Movable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is minimizable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Minimizable { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Minimizable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is maximizable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Maximizable { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Maximizable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether window is closable. This is not implemented on Linux. Default is true.
|
||||
/// </summary>
|
||||
public bool Closable { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Closable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window can be focused. Default is true. On Windows setting
|
||||
@@ -87,7 +94,8 @@
|
||||
/// 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; }
|
||||
[DefaultValue(true)]
|
||||
public bool Focusable { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the window should always stay on top of other windows. Default is false.
|
||||
@@ -131,12 +139,14 @@
|
||||
/// <summary>
|
||||
/// Whether window should be shown when created. Default is true.
|
||||
/// </summary>
|
||||
public bool Show { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Show { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Specify false to create a . Default is true.
|
||||
/// </summary>
|
||||
public bool Frame { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool Frame { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this is a modal window. This only works when the window is a child
|
||||
@@ -208,9 +218,10 @@
|
||||
/// <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.
|
||||
/// animations. Default is true.
|
||||
/// </summary>
|
||||
public bool ThickFrame { get; set; }
|
||||
[DefaultValue(true)]
|
||||
public bool ThickFrame { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Add a type of vibrancy effect to the window, only on macOS. Can be
|
||||
|
||||
22
ElectronNET.API/Entities/LoadURLOptions.cs
Normal file
22
ElectronNET.API/Entities/LoadURLOptions.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class LoadURLOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// A HTTP Referrer url.
|
||||
/// </summary>
|
||||
public string HttpReferrer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A user agent originating the request.
|
||||
/// </summary>
|
||||
public string UserAgent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Base url (with trailing path separator) for files to be loaded by the data url.
|
||||
/// This is needed only if the specified url is a data url and needs to load other
|
||||
/// files.
|
||||
/// </summary>
|
||||
public string BaseURLForDataURL { get; set; }
|
||||
}
|
||||
}
|
||||
10
ElectronNET.API/Entities/ProgressBarOptions.cs
Normal file
10
ElectronNET.API/Entities/ProgressBarOptions.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class ProgressBarOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Mode for the progress bar. Can be 'none' | 'normal' | 'indeterminate' | 'error' | 'paused'.
|
||||
/// </summary>
|
||||
public string Mode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ElectronNET.API.Extensions;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -37,6 +35,7 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("menuItemClicked");
|
||||
BridgeConnector.Socket.On("menuItemClicked", (id) => {
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
menuItem?.Click();
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
_items.AddRange(menuItems);
|
||||
|
||||
BridgeConnector.Socket.Off("trayMenuItemClicked");
|
||||
BridgeConnector.Socket.On("trayMenuItemClicked", (id) => {
|
||||
MenuItem menuItem = _items.GetMenuItem(id.ToString());
|
||||
menuItem?.Click();
|
||||
|
||||
@@ -3,6 +3,7 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
@@ -49,6 +50,20 @@ namespace ElectronNET.API
|
||||
taskCompletionSource.SetResult(browserWindow);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Off("BrowserWindowClosed");
|
||||
BridgeConnector.Socket.On("BrowserWindowClosed", (ids) =>
|
||||
{
|
||||
var browserWindowIds = ((JArray)ids).ToObject<int[]>();
|
||||
|
||||
for (int index = 0; index < _browserWindows.Count; index++)
|
||||
{
|
||||
if (!browserWindowIds.Contains(_browserWindows[index].Id))
|
||||
{
|
||||
_browserWindows.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (loadUrl.ToUpper() == "HTTP://LOCALHOST")
|
||||
{
|
||||
loadUrl = $"{loadUrl}:{BridgeSettings.WebPort}";
|
||||
|
||||
@@ -3,19 +3,31 @@ exports.__esModule = true;
|
||||
var electron_1 = require("electron");
|
||||
var windows = [];
|
||||
module.exports = function (socket) {
|
||||
socket.on('register-browserWindow-ready-to-show', function (id) {
|
||||
getWindowById(id).on('ready-to-show', function () {
|
||||
socket.emit('browserWindow-ready-to-show');
|
||||
});
|
||||
});
|
||||
socket.on('createBrowserWindow', function (options, loadUrl) {
|
||||
var window = new electron_1.BrowserWindow(options);
|
||||
window.on('closed', function (sender) {
|
||||
for (var index = 0; index < windows.length; index++) {
|
||||
var windowItem = windows[index];
|
||||
var _loop_1 = function () {
|
||||
windowItem = windows[index];
|
||||
try {
|
||||
windowItem.id;
|
||||
}
|
||||
catch (error) {
|
||||
if (error.message === 'Object has been destroyed') {
|
||||
windows.splice(index, 1);
|
||||
var ids_1 = [];
|
||||
windows.forEach(function (x) { return ids_1.push(x.id); });
|
||||
socket.emit('BrowserWindowClosed', ids_1);
|
||||
}
|
||||
}
|
||||
};
|
||||
var windowItem;
|
||||
for (var index = 0; index < windows.length; index++) {
|
||||
_loop_1();
|
||||
}
|
||||
});
|
||||
if (loadUrl) {
|
||||
@@ -88,6 +100,261 @@ module.exports = function (socket) {
|
||||
var isFullScreen = getWindowById(id).isFullScreen();
|
||||
socket.emit('browserWindow-isFullScreen-completed', isFullScreen);
|
||||
});
|
||||
socket.on('browserWindow-setAspectRatio', function (id, aspectRatio, extraSize) {
|
||||
getWindowById(id).setAspectRatio(aspectRatio, extraSize);
|
||||
});
|
||||
socket.on('browserWindow-previewFile', function (id, path, displayname) {
|
||||
getWindowById(id).previewFile(path, displayname);
|
||||
});
|
||||
socket.on('browserWindow-closeFilePreview', function (id) {
|
||||
getWindowById(id).closeFilePreview();
|
||||
});
|
||||
socket.on('browserWindow-setBounds', function (id, bounds, animate) {
|
||||
getWindowById(id).setBounds(bounds, animate);
|
||||
});
|
||||
socket.on('browserWindow-getBounds', function (id) {
|
||||
var rectangle = getWindowById(id).getBounds();
|
||||
socket.emit('browserWindow-getBounds-completed', rectangle);
|
||||
});
|
||||
socket.on('browserWindow-setContentBounds', function (id, bounds, animate) {
|
||||
getWindowById(id).setContentBounds(bounds, animate);
|
||||
});
|
||||
socket.on('browserWindow-getContentBounds', function (id) {
|
||||
var rectangle = getWindowById(id).getContentBounds();
|
||||
socket.emit('browserWindow-getContentBounds-completed', rectangle);
|
||||
});
|
||||
socket.on('browserWindow-setSize', function (id, width, height, animate) {
|
||||
getWindowById(id).setSize(width, height, animate);
|
||||
});
|
||||
socket.on('browserWindow-getSize', function (id) {
|
||||
var size = getWindowById(id).getSize();
|
||||
socket.emit('browserWindow-getSize-completed', size);
|
||||
});
|
||||
socket.on('browserWindow-setContentSize', function (id, width, height, animate) {
|
||||
getWindowById(id).setContentSize(width, height, animate);
|
||||
});
|
||||
socket.on('browserWindow-getContentSize', function (id) {
|
||||
var size = getWindowById(id).getContentSize();
|
||||
socket.emit('browserWindow-getContentSize-completed', size);
|
||||
});
|
||||
socket.on('browserWindow-setMinimumSize', function (id, width, height) {
|
||||
getWindowById(id).setMinimumSize(width, height);
|
||||
});
|
||||
socket.on('browserWindow-getMinimumSize', function (id) {
|
||||
var size = getWindowById(id).getMinimumSize();
|
||||
socket.emit('browserWindow-getMinimumSize-completed', size);
|
||||
});
|
||||
socket.on('browserWindow-setMaximumSize', function (id, width, height) {
|
||||
getWindowById(id).setMaximumSize(width, height);
|
||||
});
|
||||
socket.on('browserWindow-getMaximumSize', function (id) {
|
||||
var size = getWindowById(id).getMaximumSize();
|
||||
socket.emit('browserWindow-getMaximumSize-completed', size);
|
||||
});
|
||||
socket.on('browserWindow-setResizable', function (id, resizable) {
|
||||
getWindowById(id).setResizable(resizable);
|
||||
});
|
||||
socket.on('browserWindow-isResizable', function (id) {
|
||||
var resizable = getWindowById(id).isResizable();
|
||||
socket.emit('browserWindow-isResizable-completed', resizable);
|
||||
});
|
||||
socket.on('browserWindow-setMovable', function (id, movable) {
|
||||
getWindowById(id).setMovable(movable);
|
||||
});
|
||||
socket.on('browserWindow-isMovable', function (id) {
|
||||
var movable = getWindowById(id).isMovable();
|
||||
socket.emit('browserWindow-isMovable-completed', movable);
|
||||
});
|
||||
socket.on('browserWindow-setMinimizable', function (id, minimizable) {
|
||||
getWindowById(id).setMinimizable(minimizable);
|
||||
});
|
||||
socket.on('browserWindow-isMinimizable', function (id) {
|
||||
var minimizable = getWindowById(id).isMinimizable();
|
||||
socket.emit('browserWindow-isMinimizable-completed', minimizable);
|
||||
});
|
||||
socket.on('browserWindow-setMaximizable', function (id, maximizable) {
|
||||
getWindowById(id).setMaximizable(maximizable);
|
||||
});
|
||||
socket.on('browserWindow-isMaximizable', function (id) {
|
||||
var maximizable = getWindowById(id).isMaximizable();
|
||||
socket.emit('browserWindow-isMaximizable-completed', maximizable);
|
||||
});
|
||||
socket.on('browserWindow-setFullScreenable', function (id, fullscreenable) {
|
||||
getWindowById(id).setFullScreenable(fullscreenable);
|
||||
});
|
||||
socket.on('browserWindow-isFullScreenable', function (id) {
|
||||
var fullscreenable = getWindowById(id).isFullScreenable();
|
||||
socket.emit('browserWindow-isFullScreenable-completed', fullscreenable);
|
||||
});
|
||||
socket.on('browserWindow-setClosable', function (id, closable) {
|
||||
getWindowById(id).setClosable(closable);
|
||||
});
|
||||
socket.on('browserWindow-isClosable', function (id) {
|
||||
var closable = getWindowById(id).isClosable();
|
||||
socket.emit('browserWindow-isClosable-completed', closable);
|
||||
});
|
||||
socket.on('browserWindow-setAlwaysOnTop', function (id, flag, level, relativeLevel) {
|
||||
getWindowById(id).setAlwaysOnTop(flag, level, relativeLevel);
|
||||
});
|
||||
socket.on('browserWindow-isAlwaysOnTop', function (id) {
|
||||
var isAlwaysOnTop = getWindowById(id).isAlwaysOnTop();
|
||||
socket.emit('browserWindow-isAlwaysOnTop-completed', isAlwaysOnTop);
|
||||
});
|
||||
socket.on('browserWindow-center', function (id) {
|
||||
getWindowById(id).center();
|
||||
});
|
||||
socket.on('browserWindow-setPosition', function (id, x, y, animate) {
|
||||
getWindowById(id).setPosition(x, y, animate);
|
||||
});
|
||||
socket.on('browserWindow-getPosition', function (id) {
|
||||
var position = getWindowById(id).getPosition();
|
||||
socket.emit('browserWindow-getPosition-completed', position);
|
||||
});
|
||||
socket.on('browserWindow-setTitle', function (id, title) {
|
||||
getWindowById(id).setTitle(title);
|
||||
});
|
||||
socket.on('browserWindow-getTitle', function (id) {
|
||||
var title = getWindowById(id).getTitle();
|
||||
socket.emit('browserWindow-getTitle-completed', title);
|
||||
});
|
||||
socket.on('browserWindow-setTitle', function (id, title) {
|
||||
getWindowById(id).setTitle(title);
|
||||
});
|
||||
socket.on('browserWindow-setSheetOffset', function (id, offsetY, offsetX) {
|
||||
if (offsetX) {
|
||||
getWindowById(id).setSheetOffset(offsetY, offsetX);
|
||||
}
|
||||
else {
|
||||
getWindowById(id).setSheetOffset(offsetY);
|
||||
}
|
||||
});
|
||||
socket.on('browserWindow-flashFrame', function (id, flag) {
|
||||
getWindowById(id).flashFrame(flag);
|
||||
});
|
||||
socket.on('browserWindow-setSkipTaskbar', function (id, skip) {
|
||||
getWindowById(id).setSkipTaskbar(skip);
|
||||
});
|
||||
socket.on('browserWindow-setKiosk', function (id, flag) {
|
||||
getWindowById(id).setKiosk(flag);
|
||||
});
|
||||
socket.on('browserWindow-isKiosk', function (id) {
|
||||
var isKiosk = getWindowById(id).isKiosk();
|
||||
socket.emit('browserWindow-isKiosk-completed', isKiosk);
|
||||
});
|
||||
socket.on('browserWindow-setRepresentedFilename', function (id, filename) {
|
||||
getWindowById(id).setRepresentedFilename(filename);
|
||||
});
|
||||
socket.on('browserWindow-getRepresentedFilename', function (id) {
|
||||
var pathname = getWindowById(id).getRepresentedFilename();
|
||||
socket.emit('browserWindow-getRepresentedFilename-completed', pathname);
|
||||
});
|
||||
socket.on('browserWindow-setDocumentEdited', function (id, edited) {
|
||||
getWindowById(id).setDocumentEdited(edited);
|
||||
});
|
||||
socket.on('browserWindow-isDocumentEdited', function (id) {
|
||||
var edited = getWindowById(id).isDocumentEdited();
|
||||
socket.emit('browserWindow-isDocumentEdited-completed', edited);
|
||||
});
|
||||
socket.on('browserWindow-focusOnWebView', function (id) {
|
||||
getWindowById(id).focusOnWebView();
|
||||
});
|
||||
socket.on('browserWindow-blurWebView', function (id) {
|
||||
getWindowById(id).blurWebView();
|
||||
});
|
||||
socket.on('browserWindow-loadURL', function (id, url, options) {
|
||||
getWindowById(id).loadURL(url, options);
|
||||
});
|
||||
socket.on('browserWindow-reload', function (id) {
|
||||
getWindowById(id).reload();
|
||||
});
|
||||
socket.on('browserWindow-setMenu', function (id, menuItems) {
|
||||
var menu = null;
|
||||
if (menuItems) {
|
||||
menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, function (id) {
|
||||
socket.emit("windowMenuItemClicked", id);
|
||||
});
|
||||
}
|
||||
getWindowById(id).setMenu(menu);
|
||||
});
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach(function (item) {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
if ("id" in item && item.id) {
|
||||
item.click = function () { callback(item.id); };
|
||||
}
|
||||
});
|
||||
}
|
||||
socket.on('browserWindow-setProgressBar', function (id, progress) {
|
||||
getWindowById(id).setProgressBar(progress);
|
||||
});
|
||||
socket.on('browserWindow-setHasShadow', function (id, hasShadow) {
|
||||
getWindowById(id).setHasShadow(hasShadow);
|
||||
});
|
||||
socket.on('browserWindow-hasShadow', function (id) {
|
||||
var hasShadow = getWindowById(id).hasShadow();
|
||||
socket.emit('browserWindow-hasShadow-completed', hasShadow);
|
||||
});
|
||||
socket.on('browserWindow-setAppDetails', function (id, options) {
|
||||
getWindowById(id).setAppDetails(options);
|
||||
});
|
||||
socket.on('browserWindow-showDefinitionForSelection', function (id) {
|
||||
getWindowById(id).showDefinitionForSelection();
|
||||
});
|
||||
socket.on('browserWindow-setAutoHideMenuBar', function (id, hide) {
|
||||
getWindowById(id).setAutoHideMenuBar(hide);
|
||||
});
|
||||
socket.on('browserWindow-isMenuBarAutoHide', function (id) {
|
||||
var isMenuBarAutoHide = getWindowById(id).isMenuBarAutoHide();
|
||||
socket.emit('browserWindow-isMenuBarAutoHide-completed', isMenuBarAutoHide);
|
||||
});
|
||||
socket.on('browserWindow-setMenuBarVisibility', function (id, visible) {
|
||||
getWindowById(id).setMenuBarVisibility(visible);
|
||||
});
|
||||
socket.on('browserWindow-isMenuBarVisible', function (id) {
|
||||
var isMenuBarVisible = getWindowById(id).isMenuBarVisible();
|
||||
socket.emit('browserWindow-isMenuBarVisible-completed', isMenuBarVisible);
|
||||
});
|
||||
socket.on('browserWindow-setVisibleOnAllWorkspaces', function (id, visible) {
|
||||
getWindowById(id).setVisibleOnAllWorkspaces(visible);
|
||||
});
|
||||
socket.on('browserWindow-isVisibleOnAllWorkspaces', function (id) {
|
||||
var isVisibleOnAllWorkspaces = getWindowById(id).isVisibleOnAllWorkspaces();
|
||||
socket.emit('browserWindow-isVisibleOnAllWorkspaces-completed', isVisibleOnAllWorkspaces);
|
||||
});
|
||||
socket.on('browserWindow-setIgnoreMouseEvents', function (id, ignore) {
|
||||
getWindowById(id).setIgnoreMouseEvents(ignore);
|
||||
});
|
||||
socket.on('browserWindow-setContentProtection', function (id, enable) {
|
||||
getWindowById(id).setContentProtection(enable);
|
||||
});
|
||||
socket.on('browserWindow-setFocusable', function (id, focusable) {
|
||||
getWindowById(id).setFocusable(focusable);
|
||||
});
|
||||
socket.on('browserWindow-setParentWindow', function (id, parent) {
|
||||
var browserWindow = electron_1.BrowserWindow.fromId(parent.id);
|
||||
getWindowById(id).setParentWindow(browserWindow);
|
||||
});
|
||||
socket.on('browserWindow-getParentWindow', function (id) {
|
||||
var browserWindow = getWindowById(id).getParentWindow();
|
||||
socket.emit('browserWindow-getParentWindow-completed', browserWindow.id);
|
||||
});
|
||||
socket.on('browserWindow-getChildWindows', function (id) {
|
||||
var browserWindows = getWindowById(id).getChildWindows();
|
||||
var ids = [];
|
||||
browserWindows.forEach(function (x) {
|
||||
ids.push(x.id);
|
||||
});
|
||||
socket.emit('browserWindow-getChildWindows-completed', ids);
|
||||
});
|
||||
socket.on('browserWindow-setAutoHideCursor', function (id, autoHide) {
|
||||
getWindowById(id).setAutoHideCursor(autoHide);
|
||||
});
|
||||
socket.on('browserWindow-setVibrancy', function (id, type) {
|
||||
getWindowById(id).setVibrancy(type);
|
||||
});
|
||||
function getWindowById(id) {
|
||||
for (var index = 0; index < windows.length; index++) {
|
||||
var element = windows[index];
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,13 @@
|
||||
import { BrowserWindow } from "electron";
|
||||
import { BrowserWindow, Menu } from "electron";
|
||||
const windows: Electron.BrowserWindow[] = []
|
||||
|
||||
module.exports = (socket: SocketIO.Server) => {
|
||||
socket.on('register-browserWindow-ready-to-show', (id) => {
|
||||
getWindowById(id).on('ready-to-show', () => {
|
||||
socket.emit('browserWindow-ready-to-show');
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('createBrowserWindow', (options, loadUrl) => {
|
||||
let window = new BrowserWindow(options);
|
||||
|
||||
@@ -13,6 +19,10 @@ module.exports = (socket: SocketIO.Server) => {
|
||||
} catch (error) {
|
||||
if (error.message === 'Object has been destroyed') {
|
||||
windows.splice(index, 1);
|
||||
|
||||
const ids = [];
|
||||
windows.forEach(x => ids.push(x.id));
|
||||
socket.emit('BrowserWindowClosed', ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,6 +232,254 @@ module.exports = (socket: SocketIO.Server) => {
|
||||
getWindowById(id).setMaximizable(maximizable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isMaximizable', (id) => {
|
||||
const maximizable = getWindowById(id).isMaximizable();
|
||||
|
||||
socket.emit('browserWindow-isMaximizable-completed', maximizable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setFullScreenable', (id, fullscreenable) => {
|
||||
getWindowById(id).setFullScreenable(fullscreenable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isFullScreenable', (id) => {
|
||||
const fullscreenable = getWindowById(id).isFullScreenable();
|
||||
|
||||
socket.emit('browserWindow-isFullScreenable-completed', fullscreenable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setClosable', (id, closable) => {
|
||||
getWindowById(id).setClosable(closable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isClosable', (id) => {
|
||||
const closable = getWindowById(id).isClosable();
|
||||
|
||||
socket.emit('browserWindow-isClosable-completed', closable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setAlwaysOnTop', (id, flag, level, relativeLevel) => {
|
||||
getWindowById(id).setAlwaysOnTop(flag, level, relativeLevel);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isAlwaysOnTop', (id) => {
|
||||
const isAlwaysOnTop = getWindowById(id).isAlwaysOnTop();
|
||||
|
||||
socket.emit('browserWindow-isAlwaysOnTop-completed', isAlwaysOnTop);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-center', (id) => {
|
||||
getWindowById(id).center();
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setPosition', (id, x, y, animate) => {
|
||||
getWindowById(id).setPosition(x, y, animate);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-getPosition', (id) => {
|
||||
const position = getWindowById(id).getPosition();
|
||||
|
||||
socket.emit('browserWindow-getPosition-completed', position);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setTitle', (id, title) => {
|
||||
getWindowById(id).setTitle(title);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-getTitle', (id) => {
|
||||
const title = getWindowById(id).getTitle();
|
||||
|
||||
socket.emit('browserWindow-getTitle-completed', title);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setTitle', (id, title) => {
|
||||
getWindowById(id).setTitle(title);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setSheetOffset', (id, offsetY, offsetX) => {
|
||||
if(offsetX) {
|
||||
getWindowById(id).setSheetOffset(offsetY, offsetX);
|
||||
} else {
|
||||
getWindowById(id).setSheetOffset(offsetY);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('browserWindow-flashFrame', (id, flag) => {
|
||||
getWindowById(id).flashFrame(flag);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setSkipTaskbar', (id, skip) => {
|
||||
getWindowById(id).setSkipTaskbar(skip);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setKiosk', (id, flag) => {
|
||||
getWindowById(id).setKiosk(flag);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isKiosk', (id) => {
|
||||
const isKiosk = getWindowById(id).isKiosk();
|
||||
|
||||
socket.emit('browserWindow-isKiosk-completed', isKiosk);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setRepresentedFilename', (id, filename) => {
|
||||
getWindowById(id).setRepresentedFilename(filename);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-getRepresentedFilename', (id) => {
|
||||
const pathname = getWindowById(id).getRepresentedFilename();
|
||||
|
||||
socket.emit('browserWindow-getRepresentedFilename-completed', pathname);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setDocumentEdited', (id, edited) => {
|
||||
getWindowById(id).setDocumentEdited(edited);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isDocumentEdited', (id) => {
|
||||
const edited = getWindowById(id).isDocumentEdited();
|
||||
|
||||
socket.emit('browserWindow-isDocumentEdited-completed', edited);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-focusOnWebView', (id) => {
|
||||
getWindowById(id).focusOnWebView();
|
||||
});
|
||||
|
||||
socket.on('browserWindow-blurWebView', (id) => {
|
||||
getWindowById(id).blurWebView();
|
||||
});
|
||||
|
||||
socket.on('browserWindow-loadURL', (id, url, options) => {
|
||||
getWindowById(id).loadURL(url, options);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-reload', (id) => {
|
||||
getWindowById(id).reload();
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setMenu', (id, menuItems) => {
|
||||
let menu = null;
|
||||
|
||||
if(menuItems) {
|
||||
menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
socket.emit("windowMenuItemClicked", id);
|
||||
});
|
||||
}
|
||||
|
||||
getWindowById(id).setMenu(menu);
|
||||
});
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if(item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
if("id" in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('browserWindow-setProgressBar', (id, progress) => {
|
||||
getWindowById(id).setProgressBar(progress);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setHasShadow', (id, hasShadow) => {
|
||||
getWindowById(id).setHasShadow(hasShadow);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-hasShadow', (id) => {
|
||||
const hasShadow = getWindowById(id).hasShadow();
|
||||
|
||||
socket.emit('browserWindow-hasShadow-completed', hasShadow);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setAppDetails', (id, options) => {
|
||||
getWindowById(id).setAppDetails(options);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-showDefinitionForSelection', (id) => {
|
||||
getWindowById(id).showDefinitionForSelection();
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setAutoHideMenuBar', (id, hide) => {
|
||||
getWindowById(id).setAutoHideMenuBar(hide);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isMenuBarAutoHide', (id) => {
|
||||
const isMenuBarAutoHide = getWindowById(id).isMenuBarAutoHide();
|
||||
|
||||
socket.emit('browserWindow-isMenuBarAutoHide-completed', isMenuBarAutoHide);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setMenuBarVisibility', (id, visible) => {
|
||||
getWindowById(id).setMenuBarVisibility(visible);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isMenuBarVisible', (id) => {
|
||||
const isMenuBarVisible = getWindowById(id).isMenuBarVisible();
|
||||
|
||||
socket.emit('browserWindow-isMenuBarVisible-completed', isMenuBarVisible);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setVisibleOnAllWorkspaces', (id, visible) => {
|
||||
getWindowById(id).setVisibleOnAllWorkspaces(visible);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-isVisibleOnAllWorkspaces', (id) => {
|
||||
const isVisibleOnAllWorkspaces = getWindowById(id).isVisibleOnAllWorkspaces();
|
||||
|
||||
socket.emit('browserWindow-isVisibleOnAllWorkspaces-completed', isVisibleOnAllWorkspaces);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setIgnoreMouseEvents', (id, ignore) => {
|
||||
getWindowById(id).setIgnoreMouseEvents(ignore);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setContentProtection', (id, enable) => {
|
||||
getWindowById(id).setContentProtection(enable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setFocusable', (id, focusable) => {
|
||||
getWindowById(id).setFocusable(focusable);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setParentWindow', (id, parent) => {
|
||||
const browserWindow = BrowserWindow.fromId(parent.id);
|
||||
|
||||
getWindowById(id).setParentWindow(browserWindow);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-getParentWindow', (id) => {
|
||||
const browserWindow = getWindowById(id).getParentWindow();
|
||||
|
||||
socket.emit('browserWindow-getParentWindow-completed', browserWindow.id);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-getChildWindows', (id) => {
|
||||
const browserWindows = getWindowById(id).getChildWindows();
|
||||
|
||||
const ids = [];
|
||||
|
||||
browserWindows.forEach(x => {
|
||||
ids.push(x.id);
|
||||
})
|
||||
|
||||
socket.emit('browserWindow-getChildWindows-completed', ids);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setAutoHideCursor', (id, autoHide) => {
|
||||
getWindowById(id).setAutoHideCursor(autoHide);
|
||||
});
|
||||
|
||||
socket.on('browserWindow-setVibrancy', (id, type) => {
|
||||
getWindowById(id).setVibrancy(type);
|
||||
});
|
||||
|
||||
function getWindowById(id: number): Electron.BrowserWindow {
|
||||
for (var index = 0; index < windows.length; index++) {
|
||||
var element = windows[index];
|
||||
|
||||
@@ -71,7 +71,13 @@ namespace ElectronNET.WebApp
|
||||
Electron.Menu.SetApplicationMenu(menuItems);
|
||||
Electron.Tray.Show("/Assets/electron_32x32.png", menuItems);
|
||||
|
||||
var browserWindow = await Electron.WindowManager.CreateWindowAsync();
|
||||
var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions {
|
||||
Show = false
|
||||
});
|
||||
|
||||
browserWindow.ReadyToShow += () => {
|
||||
browserWindow.Show();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user