2025-11-04 17:22:15 +01:00
|
|
|
using ElectronNET.API.Entities;
|
2025-11-09 15:15:52 +01:00
|
|
|
using ElectronNET.API.Serialization;
|
2025-11-09 12:05:07 +01:00
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
namespace ElectronNET.API
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Electron's process object is extended from the Node.js process object. It adds the
|
|
|
|
|
/// events, properties, and methods.
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public sealed class Process: ApiBase
|
2025-11-04 17:22:15 +01:00
|
|
|
{
|
2025-11-12 10:43:32 +00:00
|
|
|
protected override SocketTaskEventNameTypes SocketTaskEventNameType => SocketTaskEventNameTypes.DashesLowerFirst;
|
|
|
|
|
protected override SocketTaskMessageNameTypes SocketTaskMessageNameType => SocketTaskMessageNameTypes.DashesLowerFirst;
|
2025-11-09 03:50:24 +01:00
|
|
|
internal Process()
|
|
|
|
|
{
|
|
|
|
|
}
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
internal static Process Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_process == null)
|
|
|
|
|
{
|
|
|
|
|
lock (_syncRoot)
|
|
|
|
|
{
|
|
|
|
|
if (_process == null)
|
|
|
|
|
{
|
|
|
|
|
_process = new Process();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _process;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Process _process;
|
|
|
|
|
|
|
|
|
|
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>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<string> ExecPathAsync => GetPropertyAsync<string>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<string[]> ArgvAsync => GetPropertyAsync<string[]>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <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>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<string> TypeAsync => GetPropertyAsync<string>();
|
2025-11-09 03:50:24 +01:00
|
|
|
|
2025-11-04 17:22:15 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// The process.versions property returns an object listing the version strings of
|
|
|
|
|
/// chrome and electron.
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<ProcessVersions> VersionsAsync => GetPropertyAsync<ProcessVersions>();
|
2025-11-09 03:50:24 +01:00
|
|
|
|
2025-11-04 17:22:15 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// A Boolean. When app is started by being passed as parameter to the default app, this
|
|
|
|
|
/// property is true in the main process, otherwise it is false.
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<bool> DefaultAppAsync => GetPropertyAsync<bool>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Boolean, true when the current renderer context is the "main" renderer frame. If you
|
|
|
|
|
/// want the ID of the current frame you should use webFrame.routingId
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<bool> IsMainFrameAsync => GetPropertyAsync<bool>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A String representing the path to the resources directory.
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<string> ResourcesPathAsync => GetPropertyAsync<string>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of seconds the current Node.js process has been running. The return value
|
|
|
|
|
/// includes fractions of a second. Use Math.floor() to get whole seconds.
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<double> UpTimeAsync => GetPropertyAsync<double>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The PID of the electron process
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<int> PidAsync => GetPropertyAsync<int>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The operating system CPU architecture for which the Node.js binary was compiled
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<string> ArchAsync => GetPropertyAsync<string>();
|
2025-11-04 17:22:15 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A string identifying the operating system platform on which the Node.js process is running
|
|
|
|
|
/// </summary>
|
2025-11-12 10:43:32 +00:00
|
|
|
public Task<string> PlatformAsync => GetPropertyAsync<string>();
|
2025-11-04 17:22:15 +01:00
|
|
|
}
|
2025-11-09 12:05:07 +01:00
|
|
|
}
|