merge from develop

This commit is contained in:
Gregor Biswanger
2017-10-15 22:09:25 +02:00
72 changed files with 4871 additions and 120 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
using Quobject.SocketIoClientDotNet.Client;
using System;
namespace ElectronNET.API
{
internal static class BridgeConnector
{
public static Socket Socket;
public static void StartConnection()
{
Socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
Socket.On(Socket.EVENT_CONNECT, () =>
{
Console.WriteLine("BridgeConnector connected!");
});
}
}
}

View File

@@ -0,0 +1,612 @@
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
{
public int Id { get; private set; }
internal BrowserWindow(int id) {
Id = id;
}
/// <summary>
/// Force closing the window, the unload and beforeunload event wont 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 doesnt 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 isnt 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 windows 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
/// doesnt care where the extra width and height are within the content viewonly 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 windows 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 windows 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 windows 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 windows 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 windows 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 windows client areas 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 windows 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 windows 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
};
}
}

89
ElectronNET.API/Dialog.cs Normal file
View File

@@ -0,0 +1,89 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Threading.Tasks;
namespace ElectronNET.API
{
public sealed class Dialog
{
private static Dialog _dialog;
internal Dialog() { }
internal static Dialog Instance
{
get
{
if (_dialog == null)
{
_dialog = new Dialog();
}
return _dialog;
}
}
/// <summary>
/// Shows a message box, it will block the process until the message box is closed.
/// It returns the index of the clicked button. The browserWindow argument allows
/// the dialog to attach itself to a parent window, making it modal. If a callback
/// is passed, the dialog will not block the process.The API call will be
/// asynchronous and the result will be passed via callback(response).
/// </summary>
/// <param name="messageBoxOptions"></param>
/// <returns>The API call will be asynchronous and the result will be passed via MessageBoxResult.</returns>
public async Task<MessageBoxResult> ShowMessageBoxAsync(MessageBoxOptions messageBoxOptions)
{
return await ShowMessageBoxAsync(null, messageBoxOptions);
}
/// <summary>
/// Shows a message box, it will block the process until the message box is closed.
/// It returns the index of the clicked button. If a callback
/// is passed, the dialog will not block the process.
/// </summary>
/// <param name="browserWindow">The browserWindow argument allows the dialog to attach itself to a parent window, making it modal.</param>
/// <param name="messageBoxOptions"></param>
/// <returns>The API call will be asynchronous and the result will be passed via MessageBoxResult.</returns>
public Task<MessageBoxResult> ShowMessageBoxAsync(BrowserWindow browserWindow, MessageBoxOptions messageBoxOptions)
{
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
BridgeConnector.Socket.On("showMessageBoxComplete", (args) =>
{
BridgeConnector.Socket.Off("showMessageBoxComplete");
var result = ((JArray)args);
taskCompletionSource.SetResult(new MessageBoxResult
{
Response = (int)result.First,
CheckboxChecked = (bool)result.Last
});
});
if (browserWindow == null)
{
BridgeConnector.Socket.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer));
} else
{
BridgeConnector.Socket.Emit("showMessageBox",
JObject.FromObject(browserWindow, _jsonSerializer),
JObject.FromObject(messageBoxOptions, _jsonSerializer));
}
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -0,0 +1,40 @@
namespace ElectronNET.API
{
public static class Electron
{
/// <summary>
/// Communicate asynchronously from the main process to renderer processes.
/// </summary>
public static IpcMain IpcMain { get { return IpcMain.Instance; } }
/// <summary>
/// Control your application's event lifecycle.
/// </summary>
public static App App { get { return App.Instance; } }
/// <summary>
/// Control your windows.
/// </summary>
public static WindowManager WindowManager { get { return WindowManager.Instance; } }
/// <summary>
/// Create native application menus and context menus.
/// </summary>
public static Menu Menu { get { return Menu.Instance; } }
/// <summary>
/// Display native system dialogs for opening and saving files, alerting, etc.
/// </summary>
public static Dialog Dialog { get { return Dialog.Instance; } }
/// <summary>
/// Create OS desktop notifications
/// </summary>
public static Notification Notification { get { return Notification.Instance; } }
/// <summary>
/// Add icons and context menus to the systems notification area.
/// </summary>
public static Tray Tray { get { return Tray.Instance; } }
}
}

View File

@@ -0,0 +1,30 @@
namespace ElectronNET.API.Entities
{
public class AboutPanelOptions
{
/// <summary>
/// The app's name.
/// </summary>
public string ApplicationName { get; set; }
/// <summary>
/// The app's version.
/// </summary>
public string ApplicationVersion { get; set; }
/// <summary>
/// Copyright information.
/// </summary>
public string Copyright { get; set; }
/// <summary>
/// Credit information.
/// </summary>
public string Credits { get; set; }
/// <summary>
/// The app's build version number.
/// </summary>
public string Version { get; set; }
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,16 @@
namespace ElectronNET.API.Entities
{
public class CPUUsage
{
/// <summary>
/// The number of average idle cpu wakeups per second since the last call to
/// getCPUUsage.First call returns 0.
/// </summary>
public int IdleWakeupsPerSecond { get; set; }
/// <summary>
/// Percentage of CPU used since the last call to getCPUUsage. First call returns 0.
/// </summary>
public int PercentCPUUsage { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace ElectronNET.API
{
public enum DockBounceType
{
critical,
informational
}
}

View File

@@ -0,0 +1,12 @@
namespace ElectronNET.API.Entities
{
public class FileIconOptions
{
public string Size { get; private set; }
public FileIconOptions(FileIconSize fileIconSize)
{
Size = fileIconSize.ToString();
}
}
}

View File

@@ -0,0 +1,9 @@
namespace ElectronNET.API.Entities
{
public enum FileIconSize
{
small,
normal,
large
}
}

View File

@@ -0,0 +1,82 @@
using Newtonsoft.Json;
namespace ElectronNET.API.Entities
{
public class GPUFeatureStatus
{
/// <summary>
/// Canvas
/// </summary>
[JsonProperty("2d_canvas")]
public string Canvas { get; set; }
/// <summary>
/// Flash
/// </summary>
[JsonProperty("flash_3d")]
public string Flash3D { get; set; }
/// <summary>
/// Flash Stage3D
/// </summary>
[JsonProperty("flash_stage3d")]
public string FlashStage3D { get; set; }
/// <summary>
/// Flash Stage3D Baseline profile
/// </summary>
[JsonProperty("flash_stage3d_baseline")]
public string FlashStage3dBaseline { get; set; }
/// <summary>
/// Compositing
/// </summary>
[JsonProperty("gpu_compositing")]
public string GpuCompositing { get; set; }
/// <summary>
/// Multiple Raster Threads
/// </summary>
[JsonProperty("multiple_raster_threads")]
public string MultipleRasterThreads { get; set; }
/// <summary>
/// Native GpuMemoryBuffers
/// </summary>
[JsonProperty("native_gpu_memory_buffers")]
public string NativeGpuMemoryBuffers { get; set; }
/// <summary>
/// Rasterization
/// </summary>
public string Rasterization { get; set; }
/// <summary>
/// Video Decode
/// </summary>
[JsonProperty("video_decode")]
public string VideoDecode { get; set; }
/// <summary>
/// Video Encode
/// </summary>
[JsonProperty("video_encode")]
public string VideoEncode { get; set; }
/// <summary>
/// VPx Video Decode
/// </summary>
[JsonProperty("vpx_decode")]
public string VpxDecode { get; set; }
/// <summary>
/// WebGL
/// </summary>
public string Webgl { get; set; }
/// <summary>
/// WebGL2
/// </summary>
public string Webgl2 { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace ElectronNET.API.Entities
{
public class ImportCertificateOptions
{
/// <summary>
/// Path for the pkcs12 file.
/// </summary>
public string Certificate { get; set; }
/// <summary>
/// Passphrase for the certificate.
/// </summary>
public string Password {get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using ElectronNET.API.Entities;
namespace ElectronNET.API
{
public class JumpListCategory
{
/// <summary>
/// Must be set if type is custom, otherwise it should be omitted.
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Array of objects if type is tasks or custom, otherwise it should be omitted.
/// </summary>
public JumpListItem[] Items { get; set; } = new JumpListItem[0];
/// <summary>
/// One of the following: "tasks" | "frequent" | "recent" | "custom"
/// </summary>
public string Type { get; set; } = "tasks";
}
}

View File

@@ -0,0 +1,51 @@
namespace ElectronNET.API.Entities
{
public class JumpListItem
{
/// <summary>
/// The command line arguments when program is executed. Should only be set if type is task.
/// </summary>
public string Args { get; set; } = string.Empty;
/// <summary>
/// Description of the task (displayed in a tooltip). Should only be set if type is task.
/// </summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// The index of the icon in the resource file. If a resource file contains multiple
/// icons this value can be used to specify the zero-based index of the icon that
/// should be displayed for this task.If a resource file contains only one icon,
/// this property should be set to zero.
/// </summary>
public int IconIndex { get; set; } = 0;
/// <summary>
/// The absolute path to an icon to be displayed in a Jump List, which can be an
/// arbitrary resource file that contains an icon(e.g. .ico, .exe, .dll). You can
/// usually specify process.execPath to show the program icon.
/// </summary>
public string IconPath { get; set; } = string.Empty;
/// <summary>
/// Path of the file to open, should only be set if type is file.
/// </summary>
public string Path { get; set; } = string.Empty;
/// <summary>
/// Path of the program to execute, usually you should specify process.execPath
/// which opens the current program.Should only be set if type is task.
/// </summary>
public string Program { get; set; } = string.Empty;
/// <summary>
/// The text to be displayed for the item in the Jump List. Should only be set if type is task.
/// </summary>
public string Title { get; set; } = string.Empty;
/// <summary>
/// One of the following: "task" | "separator" | "file"
/// </summary>
public string Type {get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,15 @@
namespace ElectronNET.API.Entities
{
public class JumpListSettings
{
/// <summary>
/// The minimum number of items that will be shown in the Jump List (for a more detailed description of this value see the MSDN docs).
/// </summary>
public int MinItems { get; set; } = 0;
/// <summary>
/// Array of JumpListItem objects that correspond to items that the user has explicitly removed from custom categories in the Jump List. These items must not be re-added to the Jump List in the next call to app.setJumpList(), Windows will not display any custom category that contains any of the removed items.
/// </summary>
public JumpListItem[] RemovedItems { get; set; } = new JumpListItem[0];
}
}

View File

@@ -0,0 +1,36 @@
namespace ElectronNET.API.Entities
{
public class LoginItemSettings
{
/// <summary>
/// true if the app is set to open at login.
/// </summary>
public bool OpenAtLogin { get; set; }
/// <summary>
/// true if the app is set to open as hidden at login. This setting is only
/// supported on macOS.
/// </summary>
public bool OpenAsHidden { get; set; }
/// <summary>
/// true if the app was opened at login automatically. This setting is only
/// supported on macOS.
/// </summary>
public bool WasOpenedAtLogin { get; set; }
/// <summary>
/// true if the app was opened as a hidden login item. This indicates that the app
/// should not open any windows at startup.This setting is only supported on macOS.
/// </summary>
public bool WasOpenedAsHidden { get; set; }
/// <summary>
/// true if the app was opened as a login item that should restore the state from
/// the previous session.This indicates that the app should restore the windows
/// that were open the last time the app was closed.This setting is only supported
/// on macOS.
/// </summary>
public bool RestoreState { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace ElectronNET.API.Entities
{
public class LoginItemSettingsOptions
{
/// <summary>
/// The executable path to compare against. Defaults to process.execPath.
/// </summary>
public string Path { get; set; }
/// <summary>
/// The command-line arguments to compare against. Defaults to an empty array.
/// </summary>
public string[] Args { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
namespace ElectronNET.API.Entities
{
public class LoginSettings
{
/// <summary>
/// true to open the app at login, false to remove the app as a login item. Defaults
/// to false.
/// </summary>
public bool OpenAtLogin { get; set; }
/// <summary>
/// true to open the app as hidden. Defaults to false. The user can edit this
/// setting from the System Preferences so
/// app.getLoginItemStatus().wasOpenedAsHidden should be checked when the app is
/// opened to know the current value.This setting is only supported on macOS.
/// </summary>
public bool OpenAsHidden { get; set; }
/// <summary>
/// The executable to launch at login. Defaults to process.execPath.
/// </summary>
public string Path { get; set; }
/// <summary>
/// The command-line arguments to pass to the executable. Defaults to an empty
/// array.Take care to wrap paths in quotes.
/// </summary>
public string[] Args { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
namespace ElectronNET.API.Entities
{
public class MemoryInfo
{
/// <summary>
/// The maximum amount of memory that has ever been pinned to actual physical RAM.
/// On macOS its value will always be 0.
/// </summary>
public int PeakWorkingSetSize { get; set; }
/// <summary>
/// Process id of the process.
/// </summary>
public int Pid { get; set; }
/// <summary>
/// The amount of memory not shared by other processes, such as JS heap or HTML
/// content.
/// </summary>
public int PrivateBytes { get; set; }
/// <summary>
/// The amount of memory shared between processes, typically memory consumed by the
/// Electron code itself
/// </summary>
public int SharedBytes { get; set; }
/// <summary>
/// The amount of memory currently pinned to actual physical RAM.
/// </summary>
public int WorkingSetSize {get; set; }
}
}

View File

@@ -0,0 +1,72 @@
using Newtonsoft.Json;
using System;
namespace ElectronNET.API.Entities
{
public class MenuItem
{
/// <summary>
/// Will be called with click(menuItem, browserWindow, event) when the menu item is
/// clicked.
/// </summary>
[JsonIgnore]
public Action Click { get; set; }
/// <summary>
/// Define the action of the menu item, when specified the click property will be
/// ignored.
/// </summary>
public string Role { get; set; }
/// <summary>
/// Can be normal, separator, submenu, checkbox or radio.
/// </summary>
public string Type { get; set; }
public string Label { get; set; }
public string Sublabel { get; set; }
public string Accelerator { get; set; }
public string Icon { get; set; }
/// <summary>
/// If false, the menu item will be greyed out and unclickable.
/// </summary>
public bool Enabled { get; set; }
/// <summary>
/// If false, the menu item will be entirely hidden.
/// </summary>
public bool Visible { get; set; }
/// <summary>
/// Should only be specified for checkbox or radio type menu items.
/// </summary>
public bool Checked { get; set; }
/// <summary>
/// Should be specified for submenu type menu items. If submenu is specified, the
/// type: 'submenu' can be omitted.If the value is not a Menu then it will be
/// automatically converted to one using Menu.buildFromTemplate.
/// </summary>
public MenuItem[] Submenu { get; set; }
/// <summary>
/// Unique within a single menu. If defined then it can be used as a reference to
/// this item by the position attribute.
/// </summary>
public string Id { get; internal set; }
/// <summary>
/// This field allows fine-grained definition of the specific location within a
/// given menu.
/// </summary>
public string Position { get; set; }
}
}

View File

@@ -0,0 +1,84 @@
namespace ElectronNET.API.Entities
{
public class MessageBoxOptions
{
/// <summary>
/// Can be "none", "info", "error", "question" or "warning". On Windows, "question"
/// displays the same icon as "info", unless you set an icon using the "icon"
/// option.On macOS, both "warning" and "error" display the same warning icon.
/// </summary>
public string Type { get; set; }
/// <summary>
/// Array of texts for buttons. On Windows, an empty array will result in one button
/// labeled "OK".
/// </summary>
public string[] Buttons { get; set; }
/// <summary>
/// Index of the button in the buttons array which will be selected by default when
/// the message box opens.
/// </summary>
public int DefaultId { get; set; }
/// <summary>
/// Title of the message box, some platforms will not show it.
/// </summary>
public string Title { get; set; }
/// <summary>
/// Content of the message box.
/// </summary>
public string Message { get; set; }
/// <summary>
/// Extra information of the message.
/// </summary>
public string Detail { get; set; }
/// <summary>
/// If provided, the message box will include a checkbox with the given label. The
/// checkbox state can be inspected only when using callback.
/// </summary>
public string CheckboxLabel { get; set; }
/// <summary>
/// Initial checked state of the checkbox. false by default.
/// </summary>
public bool CheckboxChecked { get; set; }
public string Icon { get; set; }
/// <summary>
/// The index of the button to be used to cancel the dialog, via the Esc key. By
/// default this is assigned to the first button with "cancel" or "no" as the label.
/// If no such labeled buttons exist and this option is not set, 0 will be used as
/// the return value or callback response. This option is ignored on Windows.
/// </summary>
public int CancelId { get; set; }
/// <summary>
/// On Windows Electron will try to figure out which one of the buttons are common
/// buttons(like "Cancel" or "Yes"), and show the others as command links in the
/// dialog.This can make the dialog appear in the style of modern Windows apps. If
/// you don't like this behavior, you can set noLink to true.
/// </summary>
public bool NoLink { get; set; }
/// <summary>
/// Normalize the keyboard access keys across platforms. Default is false. Enabling
/// this assumes & is used in the button labels for the placement of the keyboard
/// shortcut access key and labels will be converted so they work correctly on each
/// platform, & characters are removed on macOS, converted to _ on Linux, and left
/// untouched on Windows.For example, a button label of Vie&w will be converted to
/// Vie_w on Linux and View on macOS and can be selected via Alt-W on Windows and
/// Linux.
/// </summary>
public bool NormalizeAccessKeys { get; set; }
public MessageBoxOptions(string message)
{
Message = message;
}
}
}

View File

@@ -0,0 +1,9 @@
namespace ElectronNET.API.Entities
{
public class MessageBoxResult
{
public int Response { get; set; }
public bool CheckboxChecked { get; set; }
}
}

View File

@@ -0,0 +1,106 @@
namespace ElectronNET.API.Entities
{
// TODO: Fertig coden
public class NativeImage
{
// public static NativeImage CreateEmpty()
// {
// throw new NotImplementedException();
// }
// public static NativeImage CreateFromBuffer(byte[] buffer)
// {
// throw new NotImplementedException();
// }
// public static NativeImage CreateFromBuffer(byte[] buffer, CreateFromBufferOptions options)
// {
// throw new NotImplementedException();
// }
// public static NativeImage CreateFromDataURL(string dataURL)
// {
// throw new NotImplementedException();
// }
// public static NativeImage CreateFromPath(string path)
// {
// throw new NotImplementedException();
// }
// public void AddRepresentation(AddRepresentationOptions options)
// {
// throw new NotImplementedException();
// }
// public NativeImage Crop(Rectangle rect)
// {
// throw new NotImplementedException();
// }
// public int GetAspectRatio()
// {
// throw new NotImplementedException();
// }
// public byte[] GetBitmap()
// {
// throw new NotImplementedException();
// }
// public byte[] GetBitmap(BitmapOptions options)
// {
// throw new NotImplementedException();
// }
// public byte[] GetNativeHandle()
// {
// throw new NotImplementedException();
// }
// public Size GetSize()
// {
// throw new NotImplementedException();
// }
// public bool IsEmpty()
// {
// throw new NotImplementedException();
// }
// public bool IsTemplateImage()
// {
// throw new NotImplementedException();
// }
// public NativeImage Resize(ResizeOptions options)
// {
// throw new NotImplementedException();
// }
// public void SetTemplateImage(bool option)
// {
// throw new NotImplementedException();
// }
// public byte[] ToBitmap(ToBitmapOptions options)
// {
// throw new NotImplementedException();
// }
// public string ToDataURL(ToDataURLOptions options)
// {
// throw new NotImplementedException();
// }
// public byte[] ToJPEG(int quality)
// {
// throw new NotImplementedException();
// }
// public byte[] ToPNG(ToPNGOptions options)
// {
// throw new NotImplementedException();
// }
}
}

View File

@@ -2,7 +2,52 @@
{
public class NotificationOptions
{
/// <summary>
/// A title for the notification, which will be shown at the top of the notification
/// window when it is shown
/// </summary>
public string Title { get; set; }
/// <summary>
/// The body text of the notification, which will be displayed below the title or
/// subtitle
/// </summary>
public string Body { get; set; }
/// <summary>
/// A subtitle for the notification, which will be displayed below the title.
/// </summary>
public string Subtitle { get; set; }
/// <summary>
/// Whether or not to emit an OS notification noise when showing the notification
/// </summary>
public bool Silent { get; set; }
/// <summary>
/// An icon to use in the notification
/// </summary>
public string Icon { get; set; }
/// <summary>
/// Whether or not to add an inline reply option to the notification.
/// </summary>
public bool HasReply { get; set; }
/// <summary>
/// The placeholder to write in the inline reply input field.
/// </summary>
public string ReplyPlaceholder { get; set; }
/// <summary>
/// The name of the sound file to play when the notification is shown.
/// </summary>
public string Sound { get; set; }
public NotificationOptions(string title, string body)
{
Title = title;
Body = body;
}
}
}

View File

@@ -0,0 +1,76 @@
namespace ElectronNET.API.Entities
{
public enum PathName
{
/// <summary>
/// Users home directory.
/// </summary>
home,
/// <summary>
/// Per-user application data directory.
/// </summary>
appData,
/// <summary>
/// The directory for storing your apps configuration files,
/// which by default it is the appData directory appended with your apps name.
/// </summary>
userData,
/// <summary>
/// Temporary directory.
/// </summary>
temp,
/// <summary>
/// The current executable file.
/// </summary>
exe,
/// <summary>
/// The libchromiumcontent library.
/// </summary>
module,
/// <summary>
/// The current users Desktop directory.
/// </summary>
desktop,
/// <summary>
/// Directory for a users “My Documents”.
/// </summary>
documents,
/// <summary>
/// Directory for a users downloads.
/// </summary>
downloads,
/// <summary>
/// Directory for a users music.
/// </summary>
music,
/// <summary>
/// Directory for a users pictures.
/// </summary>
pictures,
/// <summary>
/// Directory for a users videos.
/// </summary>
videos,
/// <summary>
///
/// </summary>
logs,
/// <summary>
/// Full path to the system version of the Pepper Flash plugin.
/// </summary>
pepperFlashSystemPlugin
}
}

View File

@@ -0,0 +1,25 @@
namespace ElectronNET.API.Entities
{
public class ProcessMetric
{
/// <summary>
/// CPU usage of the process.
/// </summary>
public CPUUsage Cpu { get; set; }
/// <summary>
/// Memory information for the process.
/// </summary>
public MemoryInfo Memory {get; set;}
/// <summary>
/// Process id of the process.
/// </summary>
public int Pid { get; set; }
/// <summary>
/// Process type (Browser or Tab or GPU etc).
/// </summary>
public string Type { get; set; }
}
}

View 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; }
}
}

View File

@@ -0,0 +1,8 @@
namespace ElectronNET.API.Entities
{
public class RelaunchOptions
{
public string[] Args { get; set; }
public string ExecPath { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace ElectronNET.API.Entities
{
public class Size
{
public int Width { get; set; }
public int Height { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
namespace ElectronNET.API.Entities
{
public class UserTask
{
public string Arguments { get; set; }
public string Description { get; set; }
public int IconIndex { get; set; }
public string IconPath { get; set; }
public string Program { get; set; }
public string Title { get; set; }
}
}

View File

@@ -0,0 +1,186 @@
namespace ElectronNET.API.Entities
{
public class WebPreferences
{
/// <summary>
/// Whether to enable DevTools. If it is set to false, can not use
/// BrowserWindow.webContents.openDevTools() to open DevTools.Default is true.
/// </summary>
public bool DevTools { get; set; }
/// <summary>
/// Whether node integration is enabled. Default is true.
/// </summary>
public bool NodeIntegration { get; set; }
/// <summary>
/// Whether node integration is enabled in web workers. Default is false.
/// </summary>
public bool NodeIntegrationInWorker { get; set; }
/// <summary>
/// Specifies a script that will be loaded before other scripts run in the page.
/// This script will always have access to node APIs no matter whether node
/// integration is turned on or off.The value should be the absolute file path to
/// the script. When node integration is turned off, the preload script can
/// reintroduce Node global symbols back to the global scope.
/// </summary>
public string Preload { get; set; }
/// <summary>
/// If set, this will sandbox the renderer associated with the window, making it
/// compatible with the Chromium OS-level sandbox and disabling the Node.js engine.
/// This is not the same as the nodeIntegration option and the APIs available to the
/// preload script are more limited. Read more about the option.This option is
/// currently experimental and may change or be removed in future Electron releases.
/// </summary>
public bool Sandbox { get; set; }
/// <summary>
/// Sets the session used by the page according to the session's partition string.
/// If partition starts with persist:, the page will use a persistent session
/// available to all pages in the app with the same partition.If there is no
/// persist: prefix, the page will use an in-memory session. By assigning the same
/// partition, multiple pages can share the same session.Default is the default
/// session.
/// </summary>
public string Partition { get; set; }
/// <summary>
/// The default zoom factor of the page, 3.0 represents 300%. Default is 1.0.
/// </summary>
public int ZoomFactor { get; set; }
/// <summary>
/// Enables JavaScript support. Default is true.
/// </summary>
public bool Javascript { get; set; }
/// <summary>
/// When false, it will disable the same-origin policy (usually using testing
/// websites by people), and set allowRunningInsecureContent to true if this options
/// has not been set by user.Default is true.
/// </summary>
public bool WebSecurity { get; set; }
/// <summary>
/// Allow an https page to run JavaScript, CSS or plugins from http URLs. Default is
/// false.
/// </summary>
public bool AllowRunningInsecureContent { get; set; }
/// <summary>
/// Enables image support. Default is true.
/// </summary>
public bool Images { get; set; }
/// <summary>
/// Make TextArea elements resizable. Default is true.
/// </summary>
public bool TextAreasAreResizable { get; set; }
/// <summary>
/// Enables WebGL support. Default is true.
/// </summary>
public bool Webgl { get; set; }
/// <summary>
/// Enables WebAudio support. Default is true.
/// </summary>
public bool Webaudio { get; set; }
/// <summary>
/// Whether plugins should be enabled. Default is false.
/// </summary>
public bool Plugins { get; set; }
/// <summary>
/// Enables Chromium's experimental features. Default is false.
/// </summary>
public bool ExperimentalFeatures { get; set; }
/// <summary>
/// Enables Chromium's experimental canvas features. Default is false.
/// </summary>
public bool ExperimentalCanvasFeatures { get; set; }
/// <summary>
/// Enables scroll bounce (rubber banding) effect on macOS. Default is false.
/// </summary>
public bool ScrollBounce { get; set; }
/// <summary>
/// A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to
/// enable.The full list of supported feature strings can be found in the file.
/// </summary>
public string BlinkFeatures { get; set; }
/// <summary>
/// A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to
/// disable.The full list of supported feature strings can be found in the file.
/// </summary>
public string DisableBlinkFeatures { get; set; }
/// <summary>
/// Defaults to 16.
/// </summary>
public int DefaultFontSize { get; set; }
/// <summary>
/// Defaults to 13.
/// </summary>
public int DefaultMonospaceFontSize { get; set; }
/// <summary>
/// Defaults to 0.
/// </summary>
public int MinimumFontSize { get; set; }
/// <summary>
/// Defaults to ISO-8859-1.
/// </summary>
public string DefaultEncoding { get; set; }
/// <summary>
/// Whether to throttle animations and timers when the page becomes background. This
/// also affects the[Page Visibility API][#page-visibility]. Defaults to true.
/// </summary>
public bool BackgroundThrottling { get; set; }
/// <summary>
/// Whether to enable offscreen rendering for the browser window. Defaults to false.
/// </summary>
public bool Offscreen { get; set; }
/// <summary>
/// Whether to run Electron APIs and the specified preload script in a separate
/// JavaScript context.Defaults to false. The context that the preload script runs
/// in will still have full access to the document and window globals but it will
/// use its own set of JavaScript builtins (Array, Object, JSON, etc.) and will be
/// isolated from any changes made to the global environment by the loaded page.The
/// Electron API will only be available in the preload script and not the loaded
/// page. This option should be used when loading potentially untrusted remote
/// content to ensure the loaded content cannot tamper with the preload script and
/// any Electron APIs being used. This option uses the same technique used by . You
/// can access this context in the dev tools by selecting the 'Electron Isolated
/// Context' entry in the combo box at the top of the Console tab. This option is
/// currently experimental and may change or be removed in future Electron releases.
/// </summary>
public bool ContextIsolation { get; set; }
/// <summary>
/// Whether to use native window.open(). Defaults to false. This option is currently experimental.
/// </summary>
public bool NativeWindowOpen { get; set; }
/// <summary>
/// Whether to enable the . Defaults to the value of the nodeIntegration option. The
/// preload script configured for the<webview> will have node integration enabled
/// when it is executed so you should ensure remote/untrusted content is not able to
/// create a<webview> tag with a possibly malicious preload script.You can use the
/// will-attach-webview event on to strip away the preload script and to validate or
/// alter the<webview>'s initial settings.
/// </summary>
public bool WebviewTag { get; set; }
}
}

View 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;
}
}
}

View File

@@ -1,20 +1,32 @@
using System;
using Quobject.SocketIoClientDotNet.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
namespace ElectronNET.API
{
//
// Summary:
// Communicate asynchronously from the main process to renderer processes.
public class IpcMain
/// <summary>
/// Communicate asynchronously from the main process to renderer processes.
/// </summary>
public sealed class IpcMain
{
private Socket _socket;
private static IpcMain _ipcMain;
public IpcMain(Socket socket)
internal IpcMain() { }
internal static IpcMain Instance
{
_socket = socket;
get
{
if(_ipcMain == null)
{
_ipcMain = new IpcMain();
}
return _ipcMain;
}
}
/// <summary>
/// Listens to channel, when a new message arrives listener would be called with
/// listener(event, args...).
@@ -23,57 +35,50 @@ namespace ElectronNET.API
/// <param name="listener">Callback Method.</param>
public void On(string channel, Action<object> listener)
{
_socket.Emit("registerIpcMainChannel", channel);
_socket.On(channel, listener);
BridgeConnector.Socket.Emit("registerIpcMainChannel", channel);
BridgeConnector.Socket.On(channel, listener);
}
// Summary:
// Adds a one time listener method for the event. This listener is invoked only
// the next time a message is sent to channel, after which it is removed.
//
// Parameters:
// channel:
// Channelname.
//
// listener:
// Callback Method.
//
/// <summary>
/// Adds a one time listener method for the event. This listener is invoked only
/// the next time a message is sent to channel, after which it is removed.
/// </summary>
/// <param name="channel">Channelname.</param>
/// <param name="listener">Callback Method.</param>
public void Once(string channel, Action<object> listener)
{
_socket.Emit("registerOnceIpcMainChannel", channel);
_socket.On(channel, listener);
BridgeConnector.Socket.Emit("registerOnceIpcMainChannel", channel);
BridgeConnector.Socket.On(channel, listener);
}
//
// Summary:
// Removes listeners of the specified channel.
//
// Parameters:
// channel:
// Channelname.
//
/// <summary>
/// Removes listeners of the specified channel.
/// </summary>
/// <param name="channel">Channelname.</param>
public void RemoveAllListeners(string channel)
{
_socket.Emit("removeAllListenersIpcMainChannel", channel);
BridgeConnector.Socket.Emit("removeAllListenersIpcMainChannel", channel);
}
//
// Summary:
// Send a message to the renderer process asynchronously via channel, you can also send
// arbitrary arguments. Arguments will be serialized in JSON internally and hence
// no functions or prototype chain will be included. The renderer process handles it by
// listening for channel with ipcRenderer module.
//
// Parameters:
// channel:
// Channelname.
//
// data:
// Arguments data.
//
public void Send(string channel, params object[] data)
/// <summary>
/// Send a message to the renderer process asynchronously via channel, you can also send
/// arbitrary arguments. Arguments will be serialized in JSON internally and hence
/// 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(BrowserWindow browserWindow, string channel, params object[] data)
{
_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
};
}
}

53
ElectronNET.API/Menu.cs Normal file
View File

@@ -0,0 +1,53 @@
using ElectronNET.API.Entities;
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
{
public sealed class Menu
{
private static Menu _menu;
internal Menu() { }
internal static Menu Instance
{
get
{
if (_menu == null)
{
_menu = new Menu();
}
return _menu;
}
}
public IReadOnlyCollection<MenuItem> Items { get { return _items.AsReadOnly(); } }
private List<MenuItem> _items = new List<MenuItem>();
public void SetApplicationMenu(MenuItem[] menuItems)
{
menuItems.AddMenuItemsId();
BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer));
_items.AddRange(menuItems);
BridgeConnector.Socket.On("menuItemClicked", (id) => {
MenuItem menuItem = _items.GetMenuItem(id.ToString());
menuItem?.Click();
});
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -0,0 +1,39 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
namespace ElectronNET.API
{
public sealed class Notification
{
private static Notification _notification;
internal Notification() { }
internal static Notification Instance
{
get
{
if (_notification == null)
{
_notification = new Notification();
}
return _notification;
}
}
public void Show(NotificationOptions notificationOptions)
{
BridgeConnector.Socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

51
ElectronNET.API/Tray.cs Normal file
View File

@@ -0,0 +1,51 @@
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
{
public sealed class Tray
{
private static Tray _tray;
internal Tray() { }
internal static Tray Instance
{
get
{
if (_tray == null)
{
_tray = new Tray();
}
return _tray;
}
}
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()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -23,6 +23,8 @@ namespace ElectronNET.API
{
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
.UseUrls("http://0.0.0.0:" + BridgeSettings.WebPort);
BridgeConnector.StartConnection();
}
return builder;

View File

@@ -0,0 +1,69 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ElectronNET.API
{
public sealed class WindowManager
{
private static WindowManager _windowManager;
internal WindowManager() { }
internal static WindowManager Instance
{
get
{
if (_windowManager == null)
{
_windowManager = new WindowManager();
}
return _windowManager;
}
}
public IReadOnlyCollection<BrowserWindow> BrowserWindows { get { return _browserWindows.AsReadOnly(); } }
private List<BrowserWindow> _browserWindows = new List<BrowserWindow>();
public async Task<BrowserWindow> CreateWindowAsync(string loadUrl = "http://localhost")
{
return await CreateWindowAsync(new BrowserWindowOptions(), loadUrl);
}
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);
taskCompletionSource.SetResult(browserWindow);
});
if (loadUrl.ToUpper() == "HTTP://LOCALHOST")
{
loadUrl = $"{loadUrl}:{BridgeSettings.WebPort}";
}
BridgeConnector.Socket.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl);
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}