mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
fix #647 add to ElectronNET.API Process member interfaces for various fields
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
namespace ElectronNET.API
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
internal static class BridgeConnector
|
||||
{
|
||||
@@ -28,6 +33,82 @@
|
||||
|
||||
return _socket;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> GetValueOverSocketAsync<T>(string eventString, string eventCompletedString)
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On(eventCompletedString, (value) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(eventCompletedString);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
Console.WriteLine($"ERROR: BridgeConnector (event: '{eventString}') returned null. Socket loop hang.");
|
||||
taskCompletionSource.SetCanceled();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
taskCompletionSource.SetResult( new JValue(value).ToObject<T>() );
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"ERROR: BridgeConnector (event: '{eventString}') exception: {e.Message}. Socket loop hung.");
|
||||
}
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit(eventString);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> GetObjectOverSocketAsync<T>(string eventString, string eventCompletedString)
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On(eventCompletedString, (value) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(eventCompletedString);
|
||||
taskCompletionSource.SetResult( ((JObject)value).ToObject<T>() );
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit(eventString);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> GetArrayOverSocketAsync<T>(string eventString, string eventCompletedString)
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On(eventCompletedString, (value) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(eventCompletedString);
|
||||
taskCompletionSource.SetResult( ((JArray)value).ToObject<T>() );
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit(eventString);
|
||||
|
||||
return await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
src/ElectronNET.API/Entities/Versions.cs
Normal file
18
src/ElectronNET.API/Entities/Versions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Versions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value representing Chrome's version string.
|
||||
/// </summary>
|
||||
public string Chrome { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value representing Electron's version string.
|
||||
/// </summary>
|
||||
public bool Electron { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -37,92 +37,145 @@ namespace ElectronNET.API
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
/// <summary>
|
||||
/// The process.execPath property returns the absolute pathname of the executable that started the Node.js process. Symbolic links, if any, are resolved.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// var path = await Electron.Process.ExecPathAsync;
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// The process.execPath property returns the absolute pathname of the executable that
|
||||
/// started the Node.js process. Symbolic links, if any, are resolved.
|
||||
/// </summary>
|
||||
public Task<string> ExecPathAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("process-execPathCompleted", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-execPathCompleted");
|
||||
taskCompletionSource.SetResult((string) text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-execPath");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
return BridgeConnector.GetValueOverSocketAsync<string>(
|
||||
"process-execPath", "process-execPath-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TBD
|
||||
/// The process.argv property returns an array containing the command-line arguments passed
|
||||
/// when the Node.js process was launched. The first element will be process.execPath. See
|
||||
/// process.argv0 if access to the original value of argv[0] is needed. The second element
|
||||
/// will be the path to the JavaScript file being executed. The remaining elements will be
|
||||
/// any additional command-line arguments
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Task<string[]> ArgvAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("process-argvCompleted", (value) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-argvCompleted");
|
||||
taskCompletionSource.SetResult( ((JArray)value).ToObject<string[]>() );
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-argv");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
return BridgeConnector.GetArrayOverSocketAsync<string[]>(
|
||||
"process-argv", "process-argv-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The process.execPath property returns the absolute pathname of the executable that started the Node.js process. Symbolic links, if any, are resolved.
|
||||
/// The process.execPath property returns the absolute pathname of the executable that
|
||||
/// started the Node.js process. Symbolic links, if any, are resolved.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// var path = await Electron.Process.ExecPathAsync;
|
||||
/// </code>
|
||||
/// </example>
|
||||
public Task<string> TypeAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("process-typeCompleted", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-typeCompleted");
|
||||
taskCompletionSource.SetResult((string) text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-type");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
return BridgeConnector.GetValueOverSocketAsync<string>(
|
||||
"process-type", "process-type-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<Versions> VersionsAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<Versions>(
|
||||
"process-versions", "process-versions-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<bool> DefaultAppAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<bool>(
|
||||
"process-defaultApp", "process-defaultApp-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<bool> IsMainFrameAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<bool>(
|
||||
"process-isMainFrame", "process-isMainFrame-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<string> ResourcesPathAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<string>(
|
||||
"process-resourcesPath", "process-resourcesPath-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<double> UpTimeAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<double>(
|
||||
"process-uptime", "process-uptime-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<int> PidAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<int>(
|
||||
"process-pid", "process-pid-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<string> ArchAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<string>(
|
||||
"process-arch", "process-arch-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Task<string> PlatformAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
return BridgeConnector.GetValueOverSocketAsync<string>(
|
||||
"process-platform", "process-platform-Completed");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user