mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-10 18:58:19 +00:00
Implement HostHook logic to CLI and API. Implement an example in the Web-App.
This commit is contained in:
@@ -60,7 +60,13 @@
|
||||
/// </summary>
|
||||
public static Clipboard Clipboard { get { return Clipboard.Instance; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to execute native JavaScript/TypeScript code from the host process.
|
||||
///
|
||||
/// It is only possible if the Electron.NET CLI has previously added an
|
||||
/// ElectronHostHook directory:
|
||||
/// <c>electronize add HostHook</c>
|
||||
/// </summary>
|
||||
public static HostHook HostHook { get { return HostHook.Instance; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows you to execute native JavaScript/TypeScript code from the host process.
|
||||
///
|
||||
/// It is only possible if the Electron.NET CLI has previously added an
|
||||
/// ElectronHostHook directory:
|
||||
/// <c>electronize add HostHook</c>
|
||||
/// </summary>
|
||||
public sealed class HostHook
|
||||
{
|
||||
private static HostHook _electronHostHook;
|
||||
@@ -33,6 +40,11 @@ namespace ElectronNET.API
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute native JavaScript/TypeScript code.
|
||||
/// </summary>
|
||||
/// <param name="socketEventName">Socket name registered on the host.</param>
|
||||
/// <param name="arguments">Optional parameters.</param>
|
||||
public void Call(string socketEventName, params dynamic[] arguments)
|
||||
{
|
||||
BridgeConnector.Socket.On(socketEventName + "Error" + oneCallguid, (result) =>
|
||||
@@ -44,6 +56,13 @@ namespace ElectronNET.API
|
||||
BridgeConnector.Socket.Emit(socketEventName, arguments, oneCallguid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute native JavaScript/TypeScript code.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Results from the executed host code.</typeparam>
|
||||
/// <param name="socketEventName">Socket name registered on the host.</param>
|
||||
/// <param name="arguments">Optional parameters.</param>
|
||||
/// <returns></returns>
|
||||
public Task<T> CallAsync<T>(string socketEventName, params dynamic[] arguments)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
|
||||
Reference in New Issue
Block a user