forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement the API Demo-App complete. Implement the Clipboard-, Screen…
…- and WebContents-API. Fix some bugs. Edit the Readme.
- Loading branch information
1 parent
248ddde
commit 778dde2
Showing
51 changed files
with
1,780 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 don’t 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 | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace ElectronNET.API.Entities | ||
{ | ||
public class Data | ||
{ | ||
public string Text { get; set; } | ||
public string Html { get; set; } | ||
public string Rtf { get; set; } | ||
|
||
/// <summary> | ||
/// The title of the url at text. | ||
/// </summary> | ||
public string Bookmark { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace ElectronNET.API.Entities | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class Display | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
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> | ||
/// | ||
/// </summary> | ||
public Size Size { get; set; } | ||
|
||
/// <summary> | ||
/// Can be available, unavailable, unknown. | ||
/// </summary> | ||
public string TouchSupport { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public Rectangle WorkArea { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public Size WorkAreaSize { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ElectronNET.API.Entities | ||
{ | ||
public class Point | ||
{ | ||
public int X { get; set; } | ||
public int Y { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace ElectronNET.API.Entities | ||
{ | ||
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ElectronNET.API.Entities | ||
{ | ||
public class ReadBookmark | ||
{ | ||
public string Title { get; set; } | ||
public string Url { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
namespace ElectronNET.API.Entities | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class Size | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public int Width { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public int Height { get; set; } | ||
} | ||
} |
Oops, something went wrong.