Merge branch 'master' into obj-desktop-per-target

This commit is contained in:
Robert Muehsig
2017-10-24 22:30:32 +02:00
committed by GitHub
207 changed files with 6732 additions and 225 deletions

View File

@@ -7,6 +7,9 @@ using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Control your application's event lifecycle.
/// </summary>
public sealed class App
{
/// <summary>
@@ -1334,7 +1337,7 @@ namespace ElectronNET.API
return await taskCompletionSource.Task;
}
// TODO: Menu lösung muss gemacht werden und imeplementiert
// TODO: Menu lösung für macOS muss gemacht werden und imeplementiert
/// <summary>
/// Sets the application's dock menu.
/// </summary>

View File

@@ -5,15 +5,27 @@ namespace ElectronNET.API
{
internal static class BridgeConnector
{
public static Socket Socket;
private static Socket _socket;
public static void StartConnection()
public static Socket Socket
{
Socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
Socket.On(Socket.EVENT_CONNECT, () =>
get
{
Console.WriteLine("BridgeConnector connected!");
});
if(_socket == null && HybridSupport.IsElectronActive)
{
_socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
_socket.On(Socket.EVENT_CONNECT, () =>
{
Console.WriteLine("BridgeConnector connected!");
});
}
else if(_socket == null && !HybridSupport.IsElectronActive)
{
_socket = IO.Socket(new Uri("http://localhost"), new IO.Options { AutoConnect = false });
}
return _socket;
}
}
}
}

View File

@@ -1,8 +1,24 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public static class BridgeSettings
{
public static string SocketPort { get; set; }
public static string WebPort { get; set; }
/// <summary>
/// Gets the socket port.
/// </summary>
/// <value>
/// The socket port.
/// </value>
public static string SocketPort { get; internal set; }
/// <summary>
/// Gets the web port.
/// </summary>
/// <value>
/// The web port.
/// </value>
public static string WebPort { get; internal set; }
}
}

View File

@@ -10,8 +10,17 @@ using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Create and control browser windows.
/// </summary>
public class BrowserWindow
{
/// <summary>
/// Gets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public int Id { get; private set; }
/// <summary>
@@ -156,7 +165,7 @@ namespace ElectronNET.API
{
if (_unresponsive == null)
{
BridgeConnector.Socket.On("browserWindow-unresponsive", () =>
BridgeConnector.Socket.On("browserWindow-unresponsive" + Id, () =>
{
_unresponsive();
});
@@ -182,7 +191,7 @@ namespace ElectronNET.API
{
if (_responsive == null)
{
BridgeConnector.Socket.On("browserWindow-responsive", () =>
BridgeConnector.Socket.On("browserWindow-responsive" + Id, () =>
{
_responsive();
});
@@ -807,6 +816,7 @@ namespace ElectronNET.API
internal BrowserWindow(int id) {
Id = id;
WebContents = new WebContents(id);
}
/// <summary>
@@ -1111,6 +1121,10 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("browserWindowSetBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
}
/// <summary>
/// Gets the bounds asynchronous.
/// </summary>
/// <returns></returns>
public Task<Rectangle> GetBoundsAsync()
{
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
@@ -1145,6 +1159,10 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("browserWindowSetContentBounds", Id, JObject.FromObject(bounds, _jsonSerializer), animate);
}
/// <summary>
/// Gets the content bounds asynchronous.
/// </summary>
/// <returns></returns>
public Task<Rectangle> GetContentBoundsAsync()
{
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
@@ -1165,7 +1183,6 @@ namespace ElectronNET.API
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="animate"></param>
public void SetSize(int width, int height)
{
BridgeConnector.Socket.Emit("browserWindowSetSize", Id, width, height);
@@ -1206,7 +1223,6 @@ namespace ElectronNET.API
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="animate"></param>
public void SetContentSize(int width, int height)
{
BridgeConnector.Socket.Emit("browserWindowSetContentSize", Id, width, height);
@@ -1741,11 +1757,17 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
/// <summary>
/// Focuses the on web view.
/// </summary>
public void FocusOnWebView()
{
BridgeConnector.Socket.Emit("browserWindowFocusOnWebView", Id);
}
/// <summary>
/// Blurs the web view.
/// </summary>
public void BlurWebView()
{
BridgeConnector.Socket.Emit("browserWindowBlurWebView", Id);
@@ -1780,7 +1802,13 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("browserWindowReload", Id);
}
public IReadOnlyCollection<MenuItem> Items { get { return _items.AsReadOnly(); } }
/// <summary>
/// Gets the menu items.
/// </summary>
/// <value>
/// The menu items.
/// </value>
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
private List<MenuItem> _items = new List<MenuItem>();
/// <summary>
@@ -1803,7 +1831,7 @@ namespace ElectronNET.API
/// <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
/// bar when progress smaler as 0; Change to indeterminate mode when progress bigger as 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
@@ -1819,7 +1847,7 @@ namespace ElectronNET.API
/// <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
/// bar when progress smaler as 0; Change to indeterminate mode when progress bigger as 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
@@ -1864,6 +1892,12 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
/// <summary>
/// Gets the thumbar buttons.
/// </summary>
/// <value>
/// The thumbar buttons.
/// </value>
public IReadOnlyCollection<ThumbarButton> ThumbarButtons { get { return _thumbarButtons.AsReadOnly(); } }
private List<ThumbarButton> _thumbarButtons = new List<ThumbarButton>();
@@ -2053,7 +2087,7 @@ namespace ElectronNET.API
/// On macOS it sets the NSWindows sharingType to NSWindowSharingNone.
/// On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR.
/// </summary>
/// <param name="ignore"></param>
/// <param name="enable"></param>
public void SetContentProtection(bool enable)
{
BridgeConnector.Socket.Emit("browserWindowSetContentProtection", Id, enable);
@@ -2072,7 +2106,7 @@ namespace ElectronNET.API
/// Sets parent as current windows parent window,
/// passing null will turn current window into a top-level window.
/// </summary>
/// <param name="browserWindow"></param>
/// <param name="parent"></param>
public void SetParentWindow(BrowserWindow parent)
{
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
@@ -2148,6 +2182,11 @@ namespace ElectronNET.API
BridgeConnector.Socket.Emit("browserWindowSetVibrancy", Id, type.GetDescription());
}
/// <summary>
/// Render and control web pages.
/// </summary>
public WebContents WebContents { get; internal set; }
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),

View File

@@ -0,0 +1,240 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Perform copy and paste operations on the system clipboard.
/// </summary>
public sealed class Clipboard
{
private static Clipboard _clipboard;
internal Clipboard() { }
internal static Clipboard Instance
{
get
{
if (_clipboard == null)
{
_clipboard = new Clipboard();
}
return _clipboard;
}
}
/// <summary>
/// Read the content in the clipboard as plain text.
/// </summary>
/// <param name="type"></param>
/// <returns>The content in the clipboard as plain text.</returns>
public Task<string> ReadTextAsync(string type = "")
{
var taskCompletionSource = new TaskCompletionSource<string>();
BridgeConnector.Socket.On("clipboard-readText-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readText-Completed");
taskCompletionSource.SetResult(text.ToString());
});
BridgeConnector.Socket.Emit("clipboard-readText", type);
return taskCompletionSource.Task;
}
/// <summary>
/// Writes the text into the clipboard as plain text.
/// </summary>
/// <param name="text"></param>
/// <param name="type"></param>
public void WriteText(string text, string type = "")
{
BridgeConnector.Socket.Emit("clipboard-writeText", text, type);
}
/// <summary>
/// The content in the clipboard as markup.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<string> ReadHTMLAsync(string type = "")
{
var taskCompletionSource = new TaskCompletionSource<string>();
BridgeConnector.Socket.On("clipboard-readHTML-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readHTML-Completed");
taskCompletionSource.SetResult(text.ToString());
});
BridgeConnector.Socket.Emit("clipboard-readHTML", type);
return taskCompletionSource.Task;
}
/// <summary>
/// Writes markup to the clipboard.
/// </summary>
/// <param name="markup"></param>
/// <param name="type"></param>
public void WriteHTML(string markup, string type = "")
{
BridgeConnector.Socket.Emit("clipboard-writeHTML", markup, type);
}
/// <summary>
/// The content in the clipboard as RTF.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<string> ReadRTFAsync(string type = "")
{
var taskCompletionSource = new TaskCompletionSource<string>();
BridgeConnector.Socket.On("clipboard-readRTF-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readRTF-Completed");
taskCompletionSource.SetResult(text.ToString());
});
BridgeConnector.Socket.Emit("clipboard-readRTF", type);
return taskCompletionSource.Task;
}
/// <summary>
/// Writes the text into the clipboard in RTF.
/// </summary>
/// <param name="text"></param>
/// <param name="type"></param>
public void WriteRTF(string text, string type = "")
{
BridgeConnector.Socket.Emit("clipboard-writeHTML", text, type);
}
/// <summary>
/// Returns an Object containing title and url keys representing
/// the bookmark in the clipboard. The title and url values will
/// be empty strings when the bookmark is unavailable.
/// </summary>
/// <returns></returns>
public Task<ReadBookmark> ReadBookmarkAsync()
{
var taskCompletionSource = new TaskCompletionSource<ReadBookmark>();
BridgeConnector.Socket.On("clipboard-readBookmark-Completed", (bookmark) =>
{
BridgeConnector.Socket.Off("clipboard-readBookmark-Completed");
taskCompletionSource.SetResult(((JObject)bookmark).ToObject<ReadBookmark>());
});
BridgeConnector.Socket.Emit("clipboard-readBookmark");
return taskCompletionSource.Task;
}
/// <summary>
/// Writes the title and url into the clipboard as a bookmark.
///
/// Note: Most apps on Windows dont support pasting bookmarks
/// into them so you can use clipboard.write to write both a
/// bookmark and fallback text to the clipboard.
/// </summary>
/// <param name="title"></param>
/// <param name="url"></param>
/// <param name="type"></param>
public void WriteBookmark(string title, string url, string type = "")
{
BridgeConnector.Socket.Emit("clipboard-writeBookmark", title, url, type);
}
/// <summary>
/// macOS: The text on the find pasteboard. This method uses synchronous IPC
/// when called from the renderer process. The cached value is reread from the
/// find pasteboard whenever the application is activated.
/// </summary>
/// <returns></returns>
public Task<string> ReadFindTextAsync()
{
var taskCompletionSource = new TaskCompletionSource<string>();
BridgeConnector.Socket.On("clipboard-readFindText-Completed", (text) =>
{
BridgeConnector.Socket.Off("clipboard-readFindText-Completed");
taskCompletionSource.SetResult(text.ToString());
});
BridgeConnector.Socket.Emit("clipboard-readFindText");
return taskCompletionSource.Task;
}
/// <summary>
/// macOS: Writes the text into the find pasteboard as plain text. This method uses
/// synchronous IPC when called from the renderer process.
/// </summary>
/// <param name="text"></param>
public void WriteFindText(string text)
{
BridgeConnector.Socket.Emit("clipboard-writeFindText", text);
}
/// <summary>
/// Clears the clipboard content.
/// </summary>
/// <param name="type"></param>
public void Clear(string type = "")
{
BridgeConnector.Socket.Emit("clipboard-clear", type);
}
/// <summary>
/// An array of supported formats for the clipboard type.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public Task<string[]> AvailableFormatsAsync(string type = "")
{
var taskCompletionSource = new TaskCompletionSource<string[]>();
BridgeConnector.Socket.On("clipboard-availableFormats-Completed", (formats) =>
{
BridgeConnector.Socket.Off("clipboard-availableFormats-Completed");
taskCompletionSource.SetResult(((JArray)formats).ToObject<string[]>());
});
BridgeConnector.Socket.Emit("clipboard-availableFormats", type);
return taskCompletionSource.Task;
}
/// <summary>
/// Writes data to the clipboard.
/// </summary>
/// <param name="data"></param>
/// <param name="type"></param>
public void Write(Data data, string type = "")
{
BridgeConnector.Socket.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type);
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -7,6 +7,9 @@ using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Display native system dialogs for opening and saving files, alerting, etc.
/// </summary>
public sealed class Dialog
{
private static Dialog _dialog;

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API
{
/// <summary>
/// The Electron.NET API
/// </summary>
public static class Electron
{
/// <summary>
@@ -36,5 +39,25 @@
/// Add icons and context menus to the systems notification area.
/// </summary>
public static Tray Tray { get { return Tray.Instance; } }
/// <summary>
/// Detect keyboard events when the application does not have keyboard focus.
/// </summary>
public static GlobalShortcut GlobalShortcut { get { return GlobalShortcut.Instance; } }
/// <summary>
/// Manage files and URLs using their default applications.
/// </summary>
public static Shell Shell { get { return Shell.Instance; } }
/// <summary>
/// Retrieve information about screen size, displays, cursor position, etc.
/// </summary>
public static Screen Screen { get { return Screen.Instance; } }
/// <summary>
/// Perform copy and paste operations on the system clipboard.
/// </summary>
public static Clipboard Clipboard { get { return Clipboard.Instance; } }
}
}

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class AboutPanelOptions
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class AppDetailsOptions
{
/// <summary>

View File

@@ -4,6 +4,9 @@ using System.ComponentModel;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class BrowserWindowOptions
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class CPUUsage
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Certificate
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class CertificatePrincipal
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class CertificateTrustDialogOptions
{
/// <summary>

View File

@@ -0,0 +1,38 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Data
{
/// <summary>
/// Gets or sets the text.
/// </summary>
/// <value>
/// The text.
/// </value>
public string Text { get; set; }
/// <summary>
/// Gets or sets the HTML.
/// </summary>
/// <value>
/// The HTML.
/// </value>
public string Html { get; set; }
/// <summary>
/// Gets or sets the RTF.
/// </summary>
/// <value>
/// The RTF.
/// </value>
public string Rtf { get; set; }
/// <summary>
/// The title of the url at text.
/// </summary>
public string Bookmark { get; set; }
}
}

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class DefaultFontFamily
{
/// <summary>

View File

@@ -0,0 +1,30 @@
namespace ElectronNET.API.Entities
{
/// <summary>
/// Opens the devtools with specified dock state, can be right, bottom, undocked,
/// detach.Defaults to last used dock state.In undocked mode it's possible to dock
/// back.In detach mode it's not.
/// </summary>
public enum DevToolsMode
{
/// <summary>
/// The right
/// </summary>
right,
/// <summary>
/// The bottom
/// </summary>
bottom,
/// <summary>
/// The undocked
/// </summary>
undocked,
/// <summary>
/// The detach
/// </summary>
detach
}
}

View File

@@ -0,0 +1,60 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Display
{
/// <summary>
/// Gets or sets the bounds.
/// </summary>
/// <value>
/// The bounds.
/// </value>
public Rectangle Bounds { get; set; }
/// <summary>
/// Unique identifier associated with the display.
/// </summary>
public string Id { get; set; }
/// <summary>
/// Can be 0, 90, 180, 270, represents screen rotation in clock-wise degrees.
/// </summary>
public int Rotation { get; set; }
/// <summary>
/// Output device's pixel scale factor.
/// </summary>
public int ScaleFactor { get; set; }
/// <summary>
/// Gets or sets the size.
/// </summary>
/// <value>
/// The size.
/// </value>
public Size Size { get; set; }
/// <summary>
/// Can be available, unavailable, unknown.
/// </summary>
public string TouchSupport { get; set; }
/// <summary>
/// Gets or sets the work area.
/// </summary>
/// <value>
/// The work area.
/// </value>
public Rectangle WorkArea { get; set; }
/// <summary>
/// Gets or sets the size of the work area.
/// </summary>
/// <value>
/// The size of the work area.
/// </value>
public Size WorkAreaSize { get; set; }
}
}

View File

@@ -1,9 +1,32 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public class DisplayBalloonOptions
{
/// <summary>
/// Gets or sets the icon.
/// </summary>
/// <value>
/// The icon.
/// </value>
public string Icon { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; }
/// <summary>
/// Gets or sets the content.
/// </summary>
/// <value>
/// The content.
/// </value>
public string Content { get; set; }
}
}

View File

@@ -1,8 +1,18 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public enum DockBounceType
{
/// <summary>
/// The critical
/// </summary>
critical,
/// <summary>
/// The informational
/// </summary>
informational
}
}

View File

@@ -0,0 +1,16 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Error
{
/// <summary>
/// Gets or sets the stack.
/// </summary>
/// <value>
/// The stack.
/// </value>
public string Stack { get; set; }
}
}

View File

@@ -1,8 +1,24 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class FileFilter
{
/// <summary>
/// Gets or sets the extensions.
/// </summary>
/// <value>
/// The extensions.
/// </value>
public string[] Extensions { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name { get; set; }
}
}

View File

@@ -1,9 +1,22 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class FileIconOptions
{
/// <summary>
/// Gets the size.
/// </summary>
/// <value>
/// The size.
/// </value>
public string Size { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="FileIconOptions"/> class.
/// </summary>
/// <param name="fileIconSize">Size of the file icon.</param>
public FileIconOptions(FileIconSize fileIconSize)
{
Size = fileIconSize.ToString();

View File

@@ -1,9 +1,23 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum FileIconSize
{
/// <summary>
/// The small
/// </summary>
small,
/// <summary>
/// The normal
/// </summary>
normal,
/// <summary>
/// The large
/// </summary>
large
}
}

View File

@@ -2,6 +2,9 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class GPUFeatureStatus
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum HighlightMode
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class ImportCertificateOptions
{
/// <summary>

View File

@@ -4,6 +4,9 @@ using Newtonsoft.Json.Converters;
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public class JumpListCategory
{
/// <summary>

View File

@@ -1,10 +1,28 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public enum JumpListCategoryType
{
/// <summary>
/// The tasks
/// </summary>
tasks,
/// <summary>
/// The frequent
/// </summary>
frequent,
/// <summary>
/// The recent
/// </summary>
recent,
/// <summary>
/// The custom
/// </summary>
custom
}
}

View File

@@ -3,6 +3,9 @@ using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class JumpListItem
{
/// <summary>

View File

@@ -1,9 +1,23 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum JumpListItemType
{
/// <summary>
/// The task
/// </summary>
task,
/// <summary>
/// The separator
/// </summary>
separator,
/// <summary>
/// The file
/// </summary>
file
}
}

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class JumpListSettings
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class LoadURLOptions
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class LoginItemSettings
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class LoginItemSettingsOptions
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class LoginSettings
{
/// <summary>

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class MemoryInfo
{
/// <summary>

View File

@@ -4,6 +4,9 @@ using System;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class MenuItem
{
/// <summary>
@@ -27,15 +30,39 @@ namespace ElectronNET.API.Entities
public MenuType Type { get; set; }
/// <summary>
/// Gets or sets the label.
/// </summary>
/// <value>
/// The label.
/// </value>
public string Label { get; set; }
/// <summary>
/// Gets or sets the sublabel.
/// </summary>
/// <value>
/// The sublabel.
/// </value>
public string Sublabel { get; set; }
/// <summary>
/// Gets or sets the accelerator.
/// </summary>
/// <value>
/// The accelerator.
/// </value>
public string Accelerator { get; set; }
/// <summary>
/// Gets or sets the icon.
/// </summary>
/// <value>
/// The icon.
/// </value>
public string Icon { get; set; }
/// <summary>

View File

@@ -1,14 +1,48 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum MenuRole
{
/// <summary>
/// The undo
/// </summary>
undo,
/// <summary>
/// The redo
/// </summary>
redo,
/// <summary>
/// The cut
/// </summary>
cut,
/// <summary>
/// The copy
/// </summary>
copy,
/// <summary>
/// The paste
/// </summary>
paste,
/// <summary>
/// The pasteandmatchstyle
/// </summary>
pasteandmatchstyle,
/// <summary>
/// The selectall
/// </summary>
selectall,
/// <summary>
/// The delete
/// </summary>
delete,
/// <summary>

View File

@@ -1,11 +1,33 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum MenuType
{
/// <summary>
/// The normal
/// </summary>
normal,
/// <summary>
/// The separator
/// </summary>
separator,
/// <summary>
/// The submenu
/// </summary>
submenu,
/// <summary>
/// The checkbox
/// </summary>
checkbox,
/// <summary>
/// The radio
/// </summary>
radio
}
}

View File

@@ -3,6 +3,9 @@ using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class MessageBoxOptions
{
/// <summary>
@@ -51,6 +54,12 @@ namespace ElectronNET.API.Entities
/// </summary>
public bool CheckboxChecked { get; set; }
/// <summary>
/// Gets or sets the icon.
/// </summary>
/// <value>
/// The icon.
/// </value>
public string Icon { get; set; }
/// <summary>
@@ -80,6 +89,10 @@ namespace ElectronNET.API.Entities
/// </summary>
public bool NormalizeAccessKeys { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="MessageBoxOptions"/> class.
/// </summary>
/// <param name="message">The message.</param>
public MessageBoxOptions(string message)
{
Message = message;

View File

@@ -1,9 +1,24 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class MessageBoxResult
{
/// <summary>
/// Gets or sets the response.
/// </summary>
/// <value>
/// The response.
/// </value>
public int Response { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [checkbox checked].
/// </summary>
/// <value>
/// <c>true</c> if [checkbox checked]; otherwise, <c>false</c>.
/// </value>
public bool CheckboxChecked { get; set; }
}
}

View File

@@ -1,11 +1,33 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum MessageBoxType
{
/// <summary>
/// The none
/// </summary>
none,
/// <summary>
/// The information
/// </summary>
info,
/// <summary>
/// The error
/// </summary>
error,
/// <summary>
/// The question
/// </summary>
question,
/// <summary>
/// The warning
/// </summary>
warning
}
}

View File

@@ -1,6 +1,9 @@
namespace ElectronNET.API.Entities
{
// TODO: Fertig coden
// TODO: Need some of real code :)
/// <summary>
///
/// </summary>
public class NativeImage
{
// public static NativeImage CreateEmpty()

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class NotificationAction
{
/// <summary>

View File

@@ -3,6 +3,9 @@ using System;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class NotificationOptions
{
/// <summary>
@@ -61,6 +64,12 @@ namespace ElectronNET.API.Entities
[JsonIgnore]
public Action OnShow { get; set; }
/// <summary>
/// Gets or sets the show identifier.
/// </summary>
/// <value>
/// The show identifier.
/// </value>
[JsonProperty]
internal string ShowID { get; set; }
@@ -70,6 +79,12 @@ namespace ElectronNET.API.Entities
[JsonIgnore]
public Action OnClick { get; set; }
/// <summary>
/// Gets or sets the click identifier.
/// </summary>
/// <value>
/// The click identifier.
/// </value>
[JsonProperty]
internal string ClickID { get; set; }
@@ -81,6 +96,12 @@ namespace ElectronNET.API.Entities
[JsonIgnore]
public Action OnClose { get; set; }
/// <summary>
/// Gets or sets the close identifier.
/// </summary>
/// <value>
/// The close identifier.
/// </value>
[JsonProperty]
internal string CloseID { get; set; }
@@ -92,6 +113,12 @@ namespace ElectronNET.API.Entities
[JsonIgnore]
public Action<string> OnReply { get; set; }
/// <summary>
/// Gets or sets the reply identifier.
/// </summary>
/// <value>
/// The reply identifier.
/// </value>
[JsonProperty]
internal string ReplyID { get; set; }
@@ -101,9 +128,20 @@ namespace ElectronNET.API.Entities
[JsonIgnore]
public Action<string> OnAction { get; set; }
/// <summary>
/// Gets or sets the action identifier.
/// </summary>
/// <value>
/// The action identifier.
/// </value>
[JsonProperty]
internal string ActionID { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="NotificationOptions"/> class.
/// </summary>
/// <param name="title">The title.</param>
/// <param name="body">The body.</param>
public NotificationOptions(string title, string body)
{
Title = title;

View File

@@ -2,19 +2,53 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum OnTopLevel
{
/// <summary>
/// The normal
/// </summary>
normal,
/// <summary>
/// The floating
/// </summary>
floating,
/// <summary>
/// The torn off menu
/// </summary>
[Description("torn-off-menu")]
tornOffMenu,
/// <summary>
/// The modal panel
/// </summary>
[Description("modal-panel")]
modalPanel,
/// <summary>
/// The main menu
/// </summary>
[Description("main-menu")]
mainMenu,
/// <summary>
/// The status
/// </summary>
status,
/// <summary>
/// The pop up menu
/// </summary>
[Description("pop-up-menu")]
popUpMenu,
/// <summary>
/// The screen saver
/// </summary>
[Description("screen-saver")]
screenSaver
}

View File

@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class OpenDevToolsOptions
{
/// <summary>
/// Opens the devtools with specified dock state, can be right, bottom, undocked,
/// detach.Defaults to last used dock state.In undocked mode it's possible to dock
/// back.In detach mode it's not.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public DevToolsMode Mode { get; set; }
}
}

View File

@@ -3,9 +3,25 @@ using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class OpenDialogOptions
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; }
/// <summary>
/// Gets or sets the default path.
/// </summary>
/// <value>
/// The default path.
/// </value>
public string DefaultPath { get; set; }
/// <summary>

View File

@@ -1,14 +1,48 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum OpenDialogProperty
{
/// <summary>
/// The open file
/// </summary>
openFile,
/// <summary>
/// The open directory
/// </summary>
openDirectory,
/// <summary>
/// The multi selections
/// </summary>
multiSelections,
/// <summary>
/// The show hidden files
/// </summary>
showHiddenFiles,
/// <summary>
/// The create directory
/// </summary>
createDirectory,
/// <summary>
/// The prompt to create
/// </summary>
promptToCreate,
/// <summary>
/// The no resolve aliases
/// </summary>
noResolveAliases,
/// <summary>
/// The treat package as directory
/// </summary>
treatPackageAsDirectory
}
}

View File

@@ -0,0 +1,16 @@
using System.ComponentModel;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class OpenExternalOptions
{
/// <summary>
/// true to bring the opened application to the foreground. The default is true.
/// </summary>
[DefaultValue(true)]
public bool Activate { get; set; } = true;
}
}

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum PathName
{
/// <summary>
@@ -64,7 +67,7 @@
videos,
/// <summary>
///
/// The logs
/// </summary>
logs,

View File

@@ -0,0 +1,24 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Point
{
/// <summary>
/// Gets or sets the x.
/// </summary>
/// <value>
/// The x.
/// </value>
public int X { get; set; }
/// <summary>
/// Gets or sets the y.
/// </summary>
/// <value>
/// The y.
/// </value>
public int Y { get; set; }
}
}

View File

@@ -0,0 +1,35 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class PrintToPDFOptions
{
/// <summary>
/// Specifies the type of margins to use. Uses 0 for default margin, 1 for no
/// margin, and 2 for minimum margin.
/// </summary>
public int MarginsType { get; set; }
/// <summary>
/// Specify page size of the generated PDF. Can be A3, A4, A5, Legal, Letter,
/// Tabloid or an Object containing height and width in microns.
/// </summary>
public string PageSize { get; set; }
/// <summary>
/// Whether to print CSS backgrounds.
/// </summary>
public bool PrintBackground { get; set; }
/// <summary>
/// Whether to print selection only.
/// </summary>
public bool PrintSelectionOnly { get; set; }
/// <summary>
/// true for landscape, false for portrait.
/// </summary>
public bool Landscape { get; set; }
}
}

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class ProcessMetric
{
/// <summary>

View File

@@ -1,11 +1,33 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum ProgressBarMode
{
/// <summary>
/// The none
/// </summary>
none,
/// <summary>
/// The normal
/// </summary>
normal,
/// <summary>
/// The indeterminate
/// </summary>
indeterminate,
/// <summary>
/// The error
/// </summary>
error,
/// <summary>
/// The paused
/// </summary>
paused
}
}

View File

@@ -3,6 +3,9 @@ using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class ProgressBarOptions
{
/// <summary>

View File

@@ -0,0 +1,24 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class ReadBookmark
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; }
/// <summary>
/// Gets or sets the URL.
/// </summary>
/// <value>
/// The URL.
/// </value>
public string Url { get; set; }
}
}

View File

@@ -1,10 +1,40 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Rectangle
{
/// <summary>
/// Gets or sets the x.
/// </summary>
/// <value>
/// The x.
/// </value>
public int X { get; set; }
/// <summary>
/// Gets or sets the y.
/// </summary>
/// <value>
/// The y.
/// </value>
public int Y { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public int Width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>
/// The height.
/// </value>
public int Height { get; set; }
}
}

View File

@@ -1,8 +1,24 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class RelaunchOptions
{
/// <summary>
/// Gets or sets the arguments.
/// </summary>
/// <value>
/// The arguments.
/// </value>
public string[] Args { get; set; }
/// <summary>
/// Gets or sets the execute path.
/// </summary>
/// <value>
/// The execute path.
/// </value>
public string ExecPath { get; set; }
}
}

View File

@@ -2,8 +2,17 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public class SaveDialogOptions
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; }
/// <summary>

View File

@@ -0,0 +1,44 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public class ShortcutDetails
{
/// <summary>
/// The Application User Model ID. Default is empty.
/// </summary>
public string AppUserModelId { get; set; }
/// <summary>
/// The arguments to be applied to target when launching from this shortcut. Default is empty.
/// </summary>
public string Args { get; set; }
/// <summary>
/// The working directory. Default is empty.
/// </summary>
public string Cwd { get; set; }
/// <summary>
/// The description of the shortcut. Default is empty.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The path to the icon, can be a DLL or EXE. icon and iconIndex have to be set
/// together.Default is empty, which uses the target's icon.
/// </summary>
public string Icon { get; set; }
/// <summary>
/// The resource ID of icon when icon is a DLL or EXE. Default is 0.
/// </summary>
public int IconIndex { get; set; }
/// <summary>
/// The target to launch from this shortcut.
/// </summary>
public string Target { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public enum ShortcutLinkOperation
{
/// <summary>
/// Creates a new shortcut, overwriting if necessary.
/// </summary>
create,
/// <summary>
/// Updates specified properties only on an existing shortcut.
/// </summary>
update,
/// <summary>
/// Overwrites an existing shortcut, fails if the shortcut doesnt exist.
/// </summary>
replace
}
}

View File

@@ -1,9 +1,24 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class Size
{
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public int Width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>
/// The height.
/// </value>
public int Height { get; set; }
}
}

View File

@@ -4,10 +4,25 @@ using System;
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class ThumbarButton
{
/// <summary>
/// Gets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public string Id { get; internal set; }
/// <summary>
/// Gets or sets the click.
/// </summary>
/// <value>
/// The click.
/// </value>
[JsonIgnore]
public Action Click { get; set; }
@@ -34,6 +49,10 @@ namespace ElectronNET.API.Entities
/// </summary>
public string Tooltip { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ThumbarButton"/> class.
/// </summary>
/// <param name="icon">The icon.</param>
public ThumbarButton(string icon)
{
Icon = icon;

View File

@@ -1,5 +1,8 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum ThumbarButtonFlag
{
/// <summary>

View File

@@ -2,12 +2,30 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum TitleBarStyle
{
/// <summary>
/// The default style
/// </summary>
[JsonProperty("default")]
defaultStyle,
/// <summary>
/// The hidden
/// </summary>
hidden,
/// <summary>
/// The hidden inset
/// </summary>
hiddenInset,
/// <summary>
/// The custom buttons on hover
/// </summary>
customButtonsOnHover
}
}

View File

@@ -1,10 +1,43 @@
namespace ElectronNET.API
/// <summary>
///
/// </summary>
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public class TrayClickEventArgs
{
/// <summary>
/// Gets or sets a value indicating whether [alt key].
/// </summary>
/// <value>
/// <c>true</c> if [alt key]; otherwise, <c>false</c>.
/// </value>
public bool AltKey { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [shift key].
/// </summary>
/// <value>
/// <c>true</c> if [shift key]; otherwise, <c>false</c>.
/// </value>
public bool ShiftKey { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [control key].
/// </summary>
/// <value>
/// <c>true</c> if [control key]; otherwise, <c>false</c>.
/// </value>
public bool CtrlKey { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [meta key].
/// </summary>
/// <value>
/// <c>true</c> if [meta key]; otherwise, <c>false</c>.
/// </value>
public bool MetaKey { get; set; }
}
}

View File

@@ -1,12 +1,56 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class UserTask
{
/// <summary>
/// Gets or sets the arguments.
/// </summary>
/// <value>
/// The arguments.
/// </value>
public string Arguments { get; set; }
/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// The description.
/// </value>
public string Description { get; set; }
/// <summary>
/// Gets or sets the index of the icon.
/// </summary>
/// <value>
/// The index of the icon.
/// </value>
public int IconIndex { get; set; }
/// <summary>
/// Gets or sets the icon path.
/// </summary>
/// <value>
/// The icon path.
/// </value>
public string IconPath { get; set; }
/// <summary>
/// Gets or sets the program.
/// </summary>
/// <value>
/// The program.
/// </value>
public string Program { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; }
}
}

View File

@@ -2,19 +2,61 @@
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public enum Vibrancy
{
/// <summary>
/// The appearance based
/// </summary>
[JsonProperty("appearance-based")]
appearanceBased,
/// <summary>
/// The light
/// </summary>
light,
/// <summary>
/// The dark
/// </summary>
dark,
/// <summary>
/// The titlebar
/// </summary>
titlebar,
/// <summary>
/// The selection
/// </summary>
selection,
/// <summary>
/// The menu
/// </summary>
menu,
/// <summary>
/// The popover
/// </summary>
popover,
/// <summary>
/// The sidebar
/// </summary>
sidebar,
/// <summary>
/// The medium light
/// </summary>
[JsonProperty("medium-light")]
mediumLight,
/// <summary>
/// The ultra dark
/// </summary>
[JsonProperty("ultra-dark")]
ultraDark
}

View File

@@ -1,8 +1,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ElectronNET.API.Entities
namespace ElectronNET.API.Entities
{
/// <summary>
///
/// </summary>
public class WebPreferences
{
/// <summary>
@@ -182,13 +182,16 @@ namespace ElectronNET.API.Entities
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
/// Whether to enable the Webview. 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
/// 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.
/// alter the Webview's initial settings.
/// </summary>
/// <value>
/// <c>true</c> if [webview tag]; otherwise, <c>false</c>.
/// </value>
public bool WebviewTag { get; set; }
}
}

View File

@@ -17,7 +17,7 @@ namespace ElectronNET.API.Extensions
AddMenuItemsId(menuItem.Submenu);
}
if (string.IsNullOrEmpty(menuItem.Id))
if (string.IsNullOrEmpty(menuItem.Id) && menuItem.Click != null)
{
menuItem.Id = Guid.NewGuid().ToString();
}

View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Detect keyboard events when the application does not have keyboard focus.
/// </summary>
public sealed class GlobalShortcut
{
private static GlobalShortcut _globalShortcut;
internal GlobalShortcut() { }
internal static GlobalShortcut Instance
{
get
{
if (_globalShortcut == null)
{
_globalShortcut = new GlobalShortcut();
}
return _globalShortcut;
}
}
private Dictionary<string, Action> _shortcuts = new Dictionary<string, Action>();
/// <summary>
/// Registers a global shortcut of accelerator.
/// The callback is called when the registered shortcut is pressed by the user.
///
/// When the accelerator is already taken by other applications, this call will
/// silently fail.This behavior is intended by operating systems, since they dont
/// want applications to fight for global shortcuts.
/// </summary>
public void Register(string accelerator, Action function)
{
if (!_shortcuts.ContainsKey(accelerator))
{
_shortcuts.Add(accelerator, function);
BridgeConnector.Socket.Off("globalShortcut-pressed");
BridgeConnector.Socket.On("globalShortcut-pressed", (shortcut) =>
{
if (_shortcuts.ContainsKey(shortcut.ToString()))
{
_shortcuts[shortcut.ToString()]();
}
});
BridgeConnector.Socket.Emit("globalShortcut-register", accelerator);
}
}
/// <summary>
/// When the accelerator is already taken by other applications,
/// this call will still return false. This behavior is intended by operating systems,
/// since they dont want applications to fight for global shortcuts.
/// </summary>
/// <returns>Whether this application has registered accelerator.</returns>
public Task<bool> IsRegisteredAsync(string accelerator)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("globalShortcut-isRegisteredCompleted", (isRegistered) =>
{
BridgeConnector.Socket.Off("globalShortcut-isRegisteredCompleted");
taskCompletionSource.SetResult((bool)isRegistered);
});
BridgeConnector.Socket.Emit("globalShortcut-isRegistered", accelerator);
return taskCompletionSource.Task;
}
/// <summary>
/// Unregisters the global shortcut of accelerator.
/// </summary>
public void Unregister(string accelerator)
{
_shortcuts.Remove(accelerator);
BridgeConnector.Socket.Emit("globalShortcut-unregister", accelerator);
}
/// <summary>
/// Unregisters all of the global shortcuts.
/// </summary>
public void UnregisterAll()
{
_shortcuts.Clear();
BridgeConnector.Socket.Emit("globalShortcut-unregisterAll");
}
}
}

View File

@@ -0,0 +1,22 @@
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public static class HybridSupport
{
/// <summary>
/// Gets a value indicating whether this instance is electron active.
/// </summary>
/// <value>
/// <c>true</c> if this instance is electron active; otherwise, <c>false</c>.
/// </value>
public static bool IsElectronActive
{
get
{
return !string.IsNullOrEmpty(BridgeSettings.SocketPort);
}
}
}
}

View File

@@ -2,6 +2,9 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ElectronNET.API
{
@@ -36,7 +39,64 @@ namespace ElectronNET.API
public void On(string channel, Action<object> listener)
{
BridgeConnector.Socket.Emit("registerIpcMainChannel", channel);
BridgeConnector.Socket.On(channel, listener);
BridgeConnector.Socket.On(channel, (args) =>
{
List<object> objectArray = FormatArguments(args);
if(objectArray.Count == 1)
{
listener(objectArray.First());
}
else
{
listener(objectArray);
}
});
}
private List<object> FormatArguments(object args)
{
List<object> objectArray = ((JArray)args).ToObject<object[]>().ToList();
for (int index = 0; index < objectArray.Count; index++)
{
var item = objectArray[index];
if (item == null)
{
objectArray.Remove(item);
}
}
return objectArray;
}
/// <summary>
/// Send a message to the renderer process synchronously via channel,
/// you can also send arbitrary arguments.
///
/// Note: Sending a synchronous message will block the whole renderer process,
/// unless you know what you are doing you should never use it.
/// </summary>
/// <param name="channel"></param>
/// <param name="listener"></param>
public void OnSync(string channel, Func<object, object> listener)
{
BridgeConnector.Socket.Emit("registerSyncIpcMainChannel", channel);
BridgeConnector.Socket.On(channel, (args) => {
List<object> objectArray = FormatArguments(args);
object parameter;
if (objectArray.Count == 1)
{
parameter = objectArray.First();
}
else
{
parameter = objectArray;
}
var result = listener(parameter);
BridgeConnector.Socket.Emit(channel + "Sync", result);
});
}
/// <summary>
@@ -48,7 +108,19 @@ namespace ElectronNET.API
public void Once(string channel, Action<object> listener)
{
BridgeConnector.Socket.Emit("registerOnceIpcMainChannel", channel);
BridgeConnector.Socket.On(channel, listener);
BridgeConnector.Socket.On(channel, (args) =>
{
List<object> objectArray = FormatArguments(args);
if (objectArray.Count == 1)
{
listener(objectArray.First());
}
else
{
listener(objectArray);
}
});
}
/// <summary>
@@ -71,7 +143,32 @@ namespace ElectronNET.API
/// <param name="data">Arguments data.</param>
public void Send(BrowserWindow browserWindow, string channel, params object[] data)
{
BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, data);
List<JObject> jobjects = new List<JObject>();
List<JArray> jarrays = new List<JArray>();
List<Object> objects = new List<Object>();
foreach (var parameterObject in data)
{
if(parameterObject.GetType().IsArray || parameterObject.GetType().IsGenericType && parameterObject is IEnumerable)
{
jarrays.Add(JArray.FromObject(parameterObject, _jsonSerializer));
} else if(parameterObject.GetType().IsClass && !parameterObject.GetType().IsPrimitive && !(parameterObject is string))
{
jobjects.Add(JObject.FromObject(parameterObject, _jsonSerializer));
} else if(parameterObject.GetType().IsPrimitive || (parameterObject is string))
{
objects.Add(parameterObject);
}
}
if(jobjects.Count > 0 || jarrays.Count > 0)
{
BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, jarrays.ToArray(), jobjects.ToArray(), objects.ToArray());
}
else
{
BridgeConnector.Socket.Emit("sendToIpcRenderer", JObject.FromObject(browserWindow, _jsonSerializer), channel, data);
}
}
private JsonSerializer _jsonSerializer = new JsonSerializer()

View File

@@ -4,9 +4,15 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using ElectronNET.API.Extensions;
using System.Linq;
using System.Collections.ObjectModel;
using System;
namespace ElectronNET.API
{
/// <summary>
/// Create native application menus and context menus.
/// </summary>
public sealed class Menu
{
private static Menu _menu;
@@ -26,22 +32,80 @@ namespace ElectronNET.API
}
}
public IReadOnlyCollection<MenuItem> Items { get { return _items.AsReadOnly(); } }
private List<MenuItem> _items = new List<MenuItem>();
/// <summary>
/// Gets the menu items.
/// </summary>
/// <value>
/// The menu items.
/// </value>
public IReadOnlyCollection<MenuItem> MenuItems { get { return _menuItems.AsReadOnly(); } }
private List<MenuItem> _menuItems = new List<MenuItem>();
/// <summary>
/// Sets the application menu.
/// </summary>
/// <param name="menuItems">The menu items.</param>
public void SetApplicationMenu(MenuItem[] menuItems)
{
_menuItems.Clear();
menuItems.AddMenuItemsId();
BridgeConnector.Socket.Emit("menu-setApplicationMenu", JArray.FromObject(menuItems, _jsonSerializer));
_items.AddRange(menuItems);
_menuItems.AddRange(menuItems);
BridgeConnector.Socket.Off("menuItemClicked");
BridgeConnector.Socket.On("menuItemClicked", (id) => {
MenuItem menuItem = _items.GetMenuItem(id.ToString());
menuItem?.Click();
MenuItem menuItem = _menuItems.GetMenuItem(id.ToString());
menuItem.Click?.Invoke();
});
}
/// <summary>
/// Gets the context menu items.
/// </summary>
/// <value>
/// The context menu items.
/// </value>
public IReadOnlyDictionary<int, ReadOnlyCollection<MenuItem>> ContextMenuItems { get; internal set; }
private Dictionary<int, List<MenuItem>> _contextMenuItems = new Dictionary<int, List<MenuItem>>();
/// <summary>
/// Sets the context menu.
/// </summary>
/// <param name="browserWindow">The browser window.</param>
/// <param name="menuItems">The menu items.</param>
public void SetContextMenu(BrowserWindow browserWindow, MenuItem[] menuItems)
{
if (!_contextMenuItems.ContainsKey(browserWindow.Id))
{
menuItems.AddMenuItemsId();
BridgeConnector.Socket.Emit("menu-setContextMenu", browserWindow.Id, JArray.FromObject(menuItems, _jsonSerializer));
_contextMenuItems.Add(browserWindow.Id, menuItems.ToList());
var x = _contextMenuItems.ToDictionary(kv => kv.Key, kv => kv.Value.AsReadOnly());
ContextMenuItems = new ReadOnlyDictionary<int, ReadOnlyCollection<MenuItem>>(x);
BridgeConnector.Socket.Off("contextMenuItemClicked");
BridgeConnector.Socket.On("contextMenuItemClicked", (results) =>
{
var id = ((JArray)results).First.ToString();
var browserWindowId = (int)((JArray)results).Last;
MenuItem menuItem = _contextMenuItems[browserWindowId].GetMenuItem(id);
menuItem.Click?.Invoke();
});
}
}
/// <summary>
/// Contexts the menu popup.
/// </summary>
/// <param name="browserWindow">The browser window.</param>
public void ContextMenuPopup(BrowserWindow browserWindow)
{
BridgeConnector.Socket.Emit("menu-contextMenuPopup", browserWindow.Id);
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),

View File

@@ -9,6 +9,9 @@ using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Create OS desktop notifications
/// </summary>
public sealed class Notification
{
private static Notification _notification;

243
ElectronNET.API/Screen.cs Normal file
View File

@@ -0,0 +1,243 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Retrieve information about screen size, displays, cursor position, etc.
/// </summary>
public sealed class Screen
{
/// <summary>
/// Emitted when an new Display has been added.
/// </summary>
public event Action<Display> OnDisplayAdded
{
add
{
if (_onDisplayAdded == null)
{
BridgeConnector.Socket.On("screen-display-added-event" + GetHashCode(), (display) =>
{
_onDisplayAdded(((JObject)display).ToObject<Display>());
});
BridgeConnector.Socket.Emit("register-screen-display-added", GetHashCode());
}
_onDisplayAdded += value;
}
remove
{
_onDisplayAdded -= value;
}
}
private event Action<Display> _onDisplayAdded;
/// <summary>
/// Emitted when oldDisplay has been removed.
/// </summary>
public event Action<Display> OnDisplayRemoved
{
add
{
if (_onDisplayRemoved == null)
{
BridgeConnector.Socket.On("screen-display-removed-event" + GetHashCode(), (display) =>
{
_onDisplayRemoved(((JObject)display).ToObject<Display>());
});
BridgeConnector.Socket.Emit("register-screen-display-removed", GetHashCode());
}
_onDisplayRemoved += value;
}
remove
{
_onDisplayRemoved -= value;
}
}
private event Action<Display> _onDisplayRemoved;
/// <summary>
/// Emitted when one or more metrics change in a display.
/// The changedMetrics is an array of strings that describe the changes.
/// Possible changes are bounds, workArea, scaleFactor and rotation.
/// </summary>
public event Action<Display, string[]> OnDisplayMetricsChanged
{
add
{
if (_onDisplayMetricsChanged == null)
{
BridgeConnector.Socket.On("screen-display-metrics-changed-event" + GetHashCode(), (args) =>
{
var display = ((JArray)args).First.ToObject<Display>();
var metrics = ((JArray)args).Last.ToObject<string[]>();
_onDisplayMetricsChanged(display, metrics);
});
BridgeConnector.Socket.Emit("register-screen-display-metrics-changed", GetHashCode());
}
_onDisplayMetricsChanged += value;
}
remove
{
_onDisplayMetricsChanged -= value;
}
}
private event Action<Display, string[]> _onDisplayMetricsChanged;
private static Screen _screen;
internal Screen() { }
internal static Screen Instance
{
get
{
if (_screen == null)
{
_screen = new Screen();
}
return _screen;
}
}
/// <summary>
/// The current absolute position of the mouse pointer.
/// </summary>
/// <returns></returns>
public Task<Point> GetCursorScreenPointAsync()
{
var taskCompletionSource = new TaskCompletionSource<Point>();
BridgeConnector.Socket.On("screen-getCursorScreenPointCompleted", (point) =>
{
BridgeConnector.Socket.Off("screen-getCursorScreenPointCompleted");
taskCompletionSource.SetResult(((JObject)point).ToObject<Point>());
});
BridgeConnector.Socket.Emit("screen-getCursorScreenPoint");
return taskCompletionSource.Task;
}
/// <summary>
/// macOS: The height of the menu bar in pixels.
/// </summary>
/// <returns>The height of the menu bar in pixels.</returns>
public Task<int> GetMenuBarHeightAsync()
{
var taskCompletionSource = new TaskCompletionSource<int>();
BridgeConnector.Socket.On("screen-getMenuBarHeightCompleted", (height) =>
{
BridgeConnector.Socket.Off("screen-getMenuBarHeightCompleted");
taskCompletionSource.SetResult(int.Parse(height.ToString()));
});
BridgeConnector.Socket.Emit("screen-getMenuBarHeight");
return taskCompletionSource.Task;
}
/// <summary>
/// The primary display.
/// </summary>
/// <returns></returns>
public Task<Display> GetPrimaryDisplayAsync()
{
var taskCompletionSource = new TaskCompletionSource<Display>();
BridgeConnector.Socket.On("screen-getPrimaryDisplayCompleted", (display) =>
{
BridgeConnector.Socket.Off("screen-getPrimaryDisplayCompleted");
taskCompletionSource.SetResult(((JObject)display).ToObject<Display>());
});
BridgeConnector.Socket.Emit("screen-getPrimaryDisplay");
return taskCompletionSource.Task;
}
/// <summary>
/// An array of displays that are currently available.
/// </summary>
/// <returns>An array of displays that are currently available.</returns>
public Task<Display[]> GetAllDisplaysAsync()
{
var taskCompletionSource = new TaskCompletionSource<Display[]>();
BridgeConnector.Socket.On("screen-getAllDisplaysCompleted", (displays) =>
{
BridgeConnector.Socket.Off("screen-getAllDisplaysCompleted");
taskCompletionSource.SetResult(((JArray)displays).ToObject<Display[]>());
});
BridgeConnector.Socket.Emit("screen-getAllDisplays");
return taskCompletionSource.Task;
}
/// <summary>
/// The display nearest the specified point.
/// </summary>
/// <returns>The display nearest the specified point.</returns>
public Task<Display> GetDisplayNearestPointAsync(Point point)
{
var taskCompletionSource = new TaskCompletionSource<Display>();
BridgeConnector.Socket.On("screen-getDisplayNearestPointCompleted", (display) =>
{
BridgeConnector.Socket.Off("screen-getDisplayNearestPointCompleted");
taskCompletionSource.SetResult(((JObject)display).ToObject<Display>());
});
BridgeConnector.Socket.Emit("screen-getDisplayNearestPoint", JObject.FromObject(point, _jsonSerializer));
return taskCompletionSource.Task;
}
/// <summary>
/// The display that most closely intersects the provided bounds.
/// </summary>
/// <param name="rectangle"></param>
/// <returns>The display that most closely intersects the provided bounds.</returns>
public Task<Display> GetDisplayMatchingAsync(Rectangle rectangle)
{
var taskCompletionSource = new TaskCompletionSource<Display>();
BridgeConnector.Socket.On("screen-getDisplayMatching", (display) =>
{
BridgeConnector.Socket.Off("screen-getDisplayMatching");
taskCompletionSource.SetResult(((JObject)display).ToObject<Display>());
});
BridgeConnector.Socket.Emit("screen-getDisplayMatching", JObject.FromObject(rectangle, _jsonSerializer));
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

244
ElectronNET.API/Shell.cs Normal file
View File

@@ -0,0 +1,244 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Manage files and URLs using their default applications.
/// </summary>
public sealed class Shell
{
private static Shell _shell;
internal Shell() { }
internal static Shell Instance
{
get
{
if (_shell == null)
{
_shell = new Shell();
}
return _shell;
}
}
/// <summary>
/// Show the given file in a file manager. If possible, select the file.
/// </summary>
/// <param name="fullPath"></param>
/// <returns>Whether the item was successfully shown.</returns>
public Task<bool> ShowItemInFolderAsync(string fullPath)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-showItemInFolderCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-showItemInFolderCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-showItemInFolder", fullPath);
return taskCompletionSource.Task;
}
/// <summary>
/// Open the given file in the desktops default manner.
/// </summary>
/// <param name="fullPath"></param>
/// <returns>Whether the item was successfully opened.</returns>
public Task<bool> OpenItemAsync(string fullPath)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-openItemCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-openItemCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-openItem", fullPath);
return taskCompletionSource.Task;
}
/// <summary>
/// Open the given external protocol URL in the desktops default manner.
/// (For example, mailto: URLs in the users default mail agent).
/// </summary>
/// <param name="url"></param>
/// <returns>Whether an application was available to open the URL.
/// If callback is specified, always returns true.</returns>
public Task<bool> OpenExternalAsync(string url)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-openExternalCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-openExternalCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-openExternal", url);
return taskCompletionSource.Task;
}
/// <summary>
/// Open the given external protocol URL in the desktops default manner.
/// (For example, mailto: URLs in the users default mail agent).
/// </summary>
/// <param name="url"></param>
/// <param name="options">macOS only</param>
/// <returns>Whether an application was available to open the URL.
/// If callback is specified, always returns true.</returns>
public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-openExternalCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-openExternalCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer));
return taskCompletionSource.Task;
}
/// <summary>
/// Open the given external protocol URL in the desktops default manner.
/// (For example, mailto: URLs in the users default mail agent).
/// </summary>
/// <param name="url"></param>
/// <param name="options">macOS only</param>
/// <param name="action">macOS only</param>
/// <returns>Whether an application was available to open the URL.
/// If callback is specified, always returns true.</returns>
public Task<bool> OpenExternalAsync(string url, OpenExternalOptions options, Action<Error> action)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-openExternalCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-openExternalCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Off("shell-openExternalCallback");
BridgeConnector.Socket.On("shell-openExternalCallback", (args) => {
var urlKey = ((JArray)args).First.ToString();
var error = ((JArray)args).Last.ToObject<Error>();
if(_openExternalCallbacks.ContainsKey(urlKey))
{
_openExternalCallbacks[urlKey](error);
}
});
_openExternalCallbacks.Add(url, action);
BridgeConnector.Socket.Emit("shell-openExternal", url, JObject.FromObject(options, _jsonSerializer), true);
return taskCompletionSource.Task;
}
private Dictionary<string, Action<Error>> _openExternalCallbacks = new Dictionary<string, Action<Error>>();
/// <summary>
/// Move the given file to trash and returns a boolean status for the operation.
/// </summary>
/// <param name="fullPath"></param>
/// <returns> Whether the item was successfully moved to the trash.</returns>
public Task<bool> MoveItemToTrashAsync(string fullPath)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-moveItemToTrashCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-moveItemToTrashCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-moveItemToTrash", fullPath);
return taskCompletionSource.Task;
}
/// <summary>
/// Play the beep sound.
/// </summary>
public void Beep()
{
BridgeConnector.Socket.Emit("shell-beep");
}
/// <summary>
/// Creates or updates a shortcut link at shortcutPath.
/// </summary>
/// <param name="shortcutPath"></param>
/// <param name="operation"></param>
/// <param name="options"></param>
/// <returns>Whether the shortcut was created successfully.</returns>
public Task<bool> WriteShortcutLinkAsync(string shortcutPath, ShortcutLinkOperation operation, ShortcutDetails options)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("shell-writeShortcutLinkCompleted", (success) =>
{
BridgeConnector.Socket.Off("shell-writeShortcutLinkCompleted");
taskCompletionSource.SetResult((bool)success);
});
BridgeConnector.Socket.Emit("shell-writeShortcutLink", shortcutPath, operation.ToString(), JObject.FromObject(options, _jsonSerializer));
return taskCompletionSource.Task;
}
/// <summary>
/// Resolves the shortcut link at shortcutPath.
///
/// An exception will be thrown when any error happens.
/// </summary>
/// <param name="shortcutPath"></param>
/// <returns></returns>
public Task<ShortcutDetails> ReadShortcutLinkAsync(string shortcutPath)
{
var taskCompletionSource = new TaskCompletionSource<ShortcutDetails>();
BridgeConnector.Socket.On("shell-readShortcutLinkCompleted", (shortcutDetails) =>
{
BridgeConnector.Socket.Off("shell-readShortcutLinkCompleted");
taskCompletionSource.SetResult((ShortcutDetails)shortcutDetails);
});
BridgeConnector.Socket.Emit("shell-readShortcutLink", shortcutPath);
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -9,6 +9,9 @@ using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Add icons and context menus to the system's notification area.
/// </summary>
public sealed class Tray
{
/// <summary>
@@ -196,9 +199,30 @@ namespace ElectronNET.API
}
}
public IReadOnlyCollection<MenuItem> Items { get { return _items.AsReadOnly(); } }
/// <summary>
/// Gets the menu items.
/// </summary>
/// <value>
/// The menu items.
/// </value>
public IReadOnlyCollection<MenuItem> MenuItems { get { return _items.AsReadOnly(); } }
private List<MenuItem> _items = new List<MenuItem>();
/// <summary>
/// Shows the Traybar.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="menuItem">The menu item.</param>
public void Show(string image, MenuItem menuItem)
{
Show(image, new MenuItem[] { menuItem });
}
/// <summary>
/// Shows the Traybar.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="menuItems">The menu items.</param>
public void Show(string image, MenuItem[] menuItems)
{
menuItems.AddMenuItemsId();
@@ -206,7 +230,8 @@ namespace ElectronNET.API
_items.AddRange(menuItems);
BridgeConnector.Socket.Off("trayMenuItemClicked");
BridgeConnector.Socket.On("trayMenuItemClicked", (id) => {
BridgeConnector.Socket.On("trayMenuItemClicked", (id) =>
{
MenuItem menuItem = _items.GetMenuItem(id.ToString());
menuItem?.Click();
});
@@ -218,6 +243,7 @@ namespace ElectronNET.API
public void Destroy()
{
BridgeConnector.Socket.Emit("tray-destroy");
_items.Clear();
}
/// <summary>

View File

@@ -0,0 +1,131 @@
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
/// Render and control web pages.
/// </summary>
public class WebContents
{
public int Id { get; private set; }
/// <summary>
/// Emitted when the renderer process crashes or is killed.
/// </summary>
public event Action<bool> OnCrashed
{
add
{
if (_crashed == null)
{
BridgeConnector.Socket.On("webContents-crashed" + Id, (killed) =>
{
_crashed((bool)killed);
});
BridgeConnector.Socket.Emit("register-webContents-crashed", Id);
}
_crashed += value;
}
remove
{
_crashed -= value;
}
}
private event Action<bool> _crashed;
/// <summary>
/// Emitted when the navigation is done, i.e. the spinner of the tab has
/// stopped spinning, and the onload event was dispatched.
/// </summary>
public event Action OnDidFinishLoad
{
add
{
if (_didFinishLoad == null)
{
BridgeConnector.Socket.On("webContents-didFinishLoad" + Id, () =>
{
_didFinishLoad();
});
BridgeConnector.Socket.Emit("register-webContents-didFinishLoad", Id);
}
_didFinishLoad += value;
}
remove
{
_didFinishLoad -= value;
}
}
private event Action _didFinishLoad;
internal WebContents(int id)
{
Id = id;
}
/// <summary>
/// Opens the devtools.
/// </summary>
public void OpenDevTools()
{
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id);
}
/// <summary>
/// Opens the devtools.
/// </summary>
/// <param name="openDevToolsOptions"></param>
public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions)
{
BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, JObject.FromObject(openDevToolsOptions, _jsonSerializer));
}
/// <summary>
/// Prints window's web page as PDF with Chromium's preview printing custom
/// settings.The landscape will be ignored if @page CSS at-rule is used in the web page.
/// By default, an empty options will be regarded as: Use page-break-before: always;
/// CSS style to force to print to a new page.
/// </summary>
/// <param name="path"></param>
/// <param name="options"></param>
/// <returns>success</returns>
public Task<bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) =>
{
BridgeConnector.Socket.Off("webContents-printToPDF-completed");
taskCompletionSource.SetResult((bool)success);
});
if(options == null)
{
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path);
}
else
{
BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path);
}
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
};
}
}

View File

@@ -3,8 +3,17 @@ using System;
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public static class WebHostBuilderExtensions
{
/// <summary>
/// Use a Electron support for this .NET Core Project.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="args">The arguments.</param>
/// <returns></returns>
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args)
{
foreach (string argument in args)
@@ -19,20 +28,13 @@ namespace ElectronNET.API
}
}
if(IsElectronActive())
if(HybridSupport.IsElectronActive)
{
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
.UseUrls("http://0.0.0.0:" + BridgeSettings.WebPort);
BridgeConnector.StartConnection();
}
return builder;
}
private static bool IsElectronActive()
{
return !string.IsNullOrEmpty(BridgeSettings.SocketPort);
}
}
}

View File

@@ -8,6 +8,9 @@ using System.Threading.Tasks;
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public sealed class WindowManager
{
private static WindowManager _windowManager;
@@ -27,14 +30,31 @@ namespace ElectronNET.API
}
}
/// <summary>
/// Gets the browser windows.
/// </summary>
/// <value>
/// The browser windows.
/// </value>
public IReadOnlyCollection<BrowserWindow> BrowserWindows { get { return _browserWindows.AsReadOnly(); } }
private List<BrowserWindow> _browserWindows = new List<BrowserWindow>();
/// <summary>
/// Creates the window asynchronous.
/// </summary>
/// <param name="loadUrl">The load URL.</param>
/// <returns></returns>
public async Task<BrowserWindow> CreateWindowAsync(string loadUrl = "http://localhost")
{
return await CreateWindowAsync(new BrowserWindowOptions(), loadUrl);
}
/// <summary>
/// Creates the window asynchronous.
/// </summary>
/// <param name="options">The options.</param>
/// <param name="loadUrl">The load URL.</param>
/// <returns></returns>
public Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options, string loadUrl = "http://localhost")
{
var taskCompletionSource = new TaskCompletionSource<BrowserWindow>();

View File

@@ -108,6 +108,11 @@ namespace ElectronNET.CLI.Commands
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
Console.WriteLine("Start npm install...");
ProcessHelper.CmdExecute("npm install", tempPath);

View File

@@ -65,6 +65,11 @@ namespace ElectronNET.CLI.Commands
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
Console.WriteLine("Start npm install...");
ProcessHelper.CmdExecute("npm install", tempPath);

View File

@@ -49,10 +49,6 @@ This package contains the dotnet tooling to electronize your application.</Descr
<EmbeddedResource Include="..\ElectronNET.Host\main.js" Link="ElectronHost\main.js" />
</ItemGroup>
<ItemGroup>
<Folder Include="ElectronHost\api\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\ipc.js" Link="ElectronHost\api\ipc.js" />
</ItemGroup>
@@ -68,6 +64,17 @@ This package contains the dotnet tooling to electronize your application.</Descr
<EmbeddedResource Include="..\ElectronNET.Host\api\notification.js" Link="ElectronHost\api\notification.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\tray.js" Link="ElectronHost\api\tray.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\globalShortcut.js" Link="ElectronHost\api\globalShortcut.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\screen.js" Link="ElectronHost\api\screen.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\shell.js" Link="ElectronHost\api\shell.js" />
<EmbeddedResource Include="..\ElectronNET.Host\api\webContents.js" Link="ElectronHost\api\webContents.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\ElectronNET.Host\api\clipboard.js" Link="ElectronHost\api\clipboard.js" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' == 'Windows_NT'">
<Exec Command="$(ProjectDir)devCleanup.cmd" IgnoreExitCode="true" />
</Target>

View File

@@ -31,12 +31,12 @@ module.exports = function (socket) {
});
socket.on('register-browserWindow-unresponsive', function (id) {
getWindowById(id).on('unresponsive', function () {
socket.emit('browserWindow-unresponsive');
socket.emit('browserWindow-unresponsive' + id);
});
});
socket.on('register-browserWindow-responsive', function (id) {
getWindowById(id).on('responsive', function () {
socket.emit('browserWindow-responsive');
socket.emit('browserWindow-responsive' + id);
});
});
socket.on('register-browserWindow-blur', function (id) {

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,7 @@ const path = require('path');
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');
@@ -35,13 +36,13 @@ module.exports = (socket: SocketIO.Server) => {
socket.on('register-browserWindow-unresponsive', (id) => {
getWindowById(id).on('unresponsive', () => {
socket.emit('browserWindow-unresponsive');
socket.emit('browserWindow-unresponsive' + id);
});
});
socket.on('register-browserWindow-responsive', (id) => {
getWindowById(id).on('responsive', () => {
socket.emit('browserWindow-responsive');
socket.emit('browserWindow-responsive' + id);
});
});

View File

@@ -0,0 +1,51 @@
"use strict";
exports.__esModule = true;
var electron_1 = require("electron");
module.exports = function (socket) {
socket.on('clipboard-readText', function (type) {
var text = electron_1.clipboard.readText(type);
socket.emit('clipboard-readText-Completed', text);
});
socket.on('clipboard-writeText', function (text, type) {
electron_1.clipboard.writeText(text, type);
});
socket.on('clipboard-readHTML', function (type) {
var content = electron_1.clipboard.readHTML(type);
socket.emit('clipboard-readHTML-Completed', content);
});
socket.on('clipboard-writeHTML', function (markup, type) {
electron_1.clipboard.writeHTML(markup, type);
});
socket.on('clipboard-readRTF', function (type) {
var content = electron_1.clipboard.readRTF(type);
socket.emit('clipboard-readRTF-Completed', content);
});
socket.on('clipboard-writeRTF', function (text, type) {
electron_1.clipboard.writeHTML(text, type);
});
socket.on('clipboard-readBookmark', function () {
var bookmark = electron_1.clipboard.readBookmark();
socket.emit('clipboard-readBookmark-Completed', bookmark);
});
socket.on('clipboard-writeBookmark', function (title, url, type) {
electron_1.clipboard.writeBookmark(title, url, type);
});
socket.on('clipboard-readFindText', function () {
var content = electron_1.clipboard.readFindText();
socket.emit('clipboard-readFindText-Completed', content);
});
socket.on('clipboard-writeFindText', function (text) {
electron_1.clipboard.writeFindText(text);
});
socket.on('clipboard-clear', function (type) {
electron_1.clipboard.clear(type);
});
socket.on('clipboard-availableFormats', function (type) {
var formats = electron_1.clipboard.availableFormats(type);
socket.emit('clipboard-availableFormats-Completed', formats);
});
socket.on('clipboard-write', function (data, type) {
electron_1.clipboard.write(data, type);
});
};
//#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

View File

@@ -0,0 +1,62 @@
import { clipboard } from "electron";
module.exports = (socket: SocketIO.Server) => {
socket.on('clipboard-readText', (type) => {
const text = clipboard.readText(type);
socket.emit('clipboard-readText-Completed', text);
});
socket.on('clipboard-writeText', (text, type) => {
clipboard.writeText(text, type);
});
socket.on('clipboard-readHTML', (type) => {
const content = clipboard.readHTML(type);
socket.emit('clipboard-readHTML-Completed', content);
});
socket.on('clipboard-writeHTML', (markup, type) => {
clipboard.writeHTML(markup, type);
});
socket.on('clipboard-readRTF', (type) => {
const content = clipboard.readRTF(type);
socket.emit('clipboard-readRTF-Completed', content);
});
socket.on('clipboard-writeRTF', (text, type) => {
clipboard.writeHTML(text, type);
});
socket.on('clipboard-readBookmark', () => {
const bookmark = clipboard.readBookmark();
socket.emit('clipboard-readBookmark-Completed', bookmark);
});
socket.on('clipboard-writeBookmark', (title, url, type) => {
clipboard.writeBookmark(title, url, type);
});
socket.on('clipboard-readFindText', () => {
const content = clipboard.readFindText();
socket.emit('clipboard-readFindText-Completed', content);
});
socket.on('clipboard-writeFindText', (text) => {
clipboard.writeFindText(text);
});
socket.on('clipboard-clear', (type) => {
clipboard.clear(type);
});
socket.on('clipboard-availableFormats', (type) => {
const formats = clipboard.availableFormats(type);
socket.emit('clipboard-availableFormats-Completed', formats);
});
socket.on('clipboard-write', (data, type) => {
clipboard.write(data, type);
});
}

View File

@@ -0,0 +1,24 @@
"use strict";
exports.__esModule = true;
var electron_1 = require("electron");
module.exports = function (socket) {
socket.on('globalShortcut-register', function (accelerator) {
electron_1.globalShortcut.register(accelerator, function () {
socket.emit('globalShortcut-pressed', accelerator);
});
});
socket.on('globalShortcut-isRegistered', function (accelerator) {
var isRegistered = electron_1.globalShortcut.isRegistered(accelerator);
socket.emit('globalShortcut-isRegisteredCompleted', isRegistered);
});
socket.on('globalShortcut-unregister', function (accelerator) {
electron_1.globalShortcut.unregister(accelerator);
});
socket.on('globalShortcut-unregisterAll', function () {
try {
electron_1.globalShortcut.unregisterAll();
}
catch (error) { }
});
};
//# sourceMappingURL=globalShortcut.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"globalShortcut.js","sourceRoot":"","sources":["globalShortcut.ts"],"names":[],"mappings":";;AAAA,qCAA0C;AAE1C,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,UAAC,WAAW;QAC7C,yBAAc,CAAC,QAAQ,CAAC,WAAW,EAAE;YACjC,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,WAAW,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,6BAA6B,EAAE,UAAC,WAAW;QACjD,IAAM,YAAY,GAAG,yBAAc,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAE9D,MAAM,CAAC,IAAI,CAAC,sCAAsC,EAAE,YAAY,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,2BAA2B,EAAE,UAAC,WAAW;QAC/C,yBAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,8BAA8B,EAAE;QACtC,IAAI,CAAC;YACD,yBAAc,CAAC,aAAa,EAAE,CAAC;QACnC,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"}

View File

@@ -0,0 +1,25 @@
import { globalShortcut } from "electron";
module.exports = (socket: SocketIO.Server) => {
socket.on('globalShortcut-register', (accelerator) => {
globalShortcut.register(accelerator, () => {
socket.emit('globalShortcut-pressed', accelerator);
});
});
socket.on('globalShortcut-isRegistered', (accelerator) => {
const isRegistered = globalShortcut.isRegistered(accelerator);
socket.emit('globalShortcut-isRegisteredCompleted', isRegistered);
});
socket.on('globalShortcut-unregister', (accelerator) => {
globalShortcut.unregister(accelerator);
});
socket.on('globalShortcut-unregisterAll', () => {
try {
globalShortcut.unregisterAll();
} catch (error) { }
});
}

View File

@@ -7,6 +7,16 @@ module.exports = function (socket) {
socket.emit(channel, [event.preventDefault(), args]);
});
});
socket.on('registerSyncIpcMainChannel', function (channel) {
electron_1.ipcMain.on(channel, function (event, args) {
var x = socket;
x.removeAllListeners(channel + 'Sync');
socket.on(channel + 'Sync', function (result) {
event.returnValue = result;
});
socket.emit(channel, [event.preventDefault(), args]);
});
});
socket.on('registerOnceIpcMainChannel', function (channel) {
electron_1.ipcMain.once(channel, function (event, args) {
socket.emit(channel, [event.preventDefault(), args]);
@@ -22,8 +32,9 @@ module.exports = function (socket) {
}
var window = electron_1.BrowserWindow.fromId(browserWindow.id);
if (window) {
window.webContents.send(channel, data);
(_a = window.webContents).send.apply(_a, [channel].concat(data));
}
var _a;
});
};
//# sourceMappingURL=ipc.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["ipc.ts"],"names":[],"mappings":";;AAAA,qCAAkD;AAElD,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,wBAAwB,EAAE,UAAC,OAAO;QACxC,kBAAO,CAAC,EAAE,CAAC,OAAO,EAAE,UAAC,KAAK,EAAE,IAAI;YAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,UAAC,OAAO;QAC5C,kBAAO,CAAC,IAAI,CAAC,OAAO,EAAE,UAAC,KAAK,EAAE,IAAI;YAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC,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,MAAM;gBAC/B,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC;YAC/B,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,4BAA4B,EAAE,UAAC,OAAO;QAC5C,kBAAO,CAAC,IAAI,CAAC,OAAO,EAAE,UAAC,KAAK,EAAE,IAAI;YAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,kCAAkC,EAAE,UAAC,OAAO;QAClD,kBAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,mBAAmB,EAAE,UAAC,aAAa,EAAE,OAAO;QAAE,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,6BAAO;;QAC3D,IAAM,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAEtD,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACT,CAAA,KAAA,MAAM,CAAC,WAAW,CAAA,CAAC,IAAI,YAAC,OAAO,SAAK,IAAI,GAAE;QAC9C,CAAC;;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"}

View File

@@ -7,6 +7,18 @@ module.exports = (socket: SocketIO.Server) => {
});
});
socket.on('registerSyncIpcMainChannel', (channel) => {
ipcMain.on(channel, (event, args) => {
let x = <any>socket;
x.removeAllListeners(channel + 'Sync');
socket.on(channel + 'Sync', (result) => {
event.returnValue = result;
});
socket.emit(channel, [event.preventDefault(), args]);
});
});
socket.on('registerOnceIpcMainChannel', (channel) => {
ipcMain.once(channel, (event, args) => {
socket.emit(channel, [event.preventDefault(), args]);
@@ -21,7 +33,7 @@ module.exports = (socket: SocketIO.Server) => {
const window = BrowserWindow.fromId(browserWindow.id);
if (window) {
window.webContents.send(channel, data);
window.webContents.send(channel, ...data);
}
});
}

View File

@@ -1,7 +1,36 @@
"use strict";
exports.__esModule = true;
var electron_1 = require("electron");
var contextMenuItems = [];
module.exports = function (socket) {
socket.on('menu-setContextMenu', function (browserWindowId, menuItems) {
var menu = electron_1.Menu.buildFromTemplate(menuItems);
addContextMenuItemClickConnector(menu.items, browserWindowId, function (id, browserWindowId) {
socket.emit("contextMenuItemClicked", [id, browserWindowId]);
});
contextMenuItems.push({
menu: menu,
browserWindowId: browserWindowId
});
});
function addContextMenuItemClickConnector(menuItems, browserWindowId, callback) {
menuItems.forEach(function (item) {
if (item.submenu && item.submenu.items.length > 0) {
addContextMenuItemClickConnector(item.submenu.items, browserWindowId, callback);
}
if ("id" in item && item.id) {
item.click = function () { callback(item.id, browserWindowId); };
}
});
}
socket.on('menu-contextMenuPopup', function (browserWindowId) {
contextMenuItems.forEach(function (x) {
if (x.browserWindowId === browserWindowId) {
var browserWindow = electron_1.BrowserWindow.fromId(browserWindowId);
x.menu.popup(browserWindow);
}
});
});
socket.on('menu-setApplicationMenu', function (menuItems) {
var menu = electron_1.Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, function (id) {

View File

@@ -1 +1 @@
{"version":3,"file":"menu.js","sourceRoot":"","sources":["menu.ts"],"names":[],"mappings":";;AAAA,qCAAgC;AAEhC,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,UAAC,SAAS;QAC3C,IAAM,IAAI,GAAG,eAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAE/C,yBAAyB,CAAC,IAAI,CAAC,KAAK,EAAE,UA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