2022-01-02 16:46:14 -05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-01-25 10:45:49 -06:00
|
|
|
|
using ElectronNET.API.Interfaces;
|
2022-01-02 18:28:39 -05:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2022-01-02 16:46:14 -05: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>
|
2022-01-25 10:45:49 -06:00
|
|
|
|
public sealed class Process : IProcess
|
2022-01-02 16:46:14 -05:00
|
|
|
|
{
|
|
|
|
|
|
internal Process() { }
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
2022-01-02 18:28:39 -05:00
|
|
|
|
/// <summary>
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// The process.execPath property returns the absolute pathname of the executable that
|
|
|
|
|
|
/// started the Node.js process. Symbolic links, if any, are resolved.
|
|
|
|
|
|
/// </summary>
|
2022-01-02 18:28:39 -05:00
|
|
|
|
public Task<string> ExecPathAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2022-01-02 22:46:53 -05:00
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<string>(
|
|
|
|
|
|
"process-execPath", "process-execPath-Completed");
|
2022-01-02 18:28:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-02 16:46:14 -05:00
|
|
|
|
/// <summary>
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// 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
|
2022-01-02 16:46:14 -05:00
|
|
|
|
/// </summary>
|
2022-01-02 18:28:39 -05:00
|
|
|
|
public Task<string[]> ArgvAsync
|
2022-01-02 16:46:14 -05:00
|
|
|
|
{
|
2022-01-02 18:28:39 -05:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2022-01-02 22:46:53 -05:00
|
|
|
|
return BridgeConnector.GetArrayOverSocketAsync<string[]>(
|
|
|
|
|
|
"process-argv", "process-argv-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-02 16:46:14 -05:00
|
|
|
|
|
2022-01-02 22:46:53 -05: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>
|
|
|
|
|
|
public Task<string> TypeAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<string>(
|
|
|
|
|
|
"process-type", "process-type-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// The process.versions property returns an object listing the version strings of
|
|
|
|
|
|
/// chrome and electron.
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
2022-01-02 23:11:01 -05:00
|
|
|
|
public Task<ProcessVersions> VersionsAsync
|
2022-01-02 22:46:53 -05:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2022-01-02 23:11:01 -05:00
|
|
|
|
return BridgeConnector.GetObjectOverSocketAsync<ProcessVersions>(
|
2022-01-02 22:46:53 -05:00
|
|
|
|
"process-versions", "process-versions-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// 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.
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<bool> DefaultAppAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<bool>(
|
|
|
|
|
|
"process-defaultApp", "process-defaultApp-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-02 18:28:39 -05:00
|
|
|
|
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// 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
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<bool> IsMainFrameAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<bool>(
|
|
|
|
|
|
"process-isMainFrame", "process-isMainFrame-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-02 18:28:39 -05:00
|
|
|
|
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// A String representing the path to the resources directory.
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<string> ResourcesPathAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<string>(
|
|
|
|
|
|
"process-resourcesPath", "process-resourcesPath-Completed");
|
2022-01-02 18:28:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// 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.
|
2022-01-02 18:28:39 -05:00
|
|
|
|
/// </summary>
|
2022-01-02 22:46:53 -05:00
|
|
|
|
public Task<double> UpTimeAsync
|
2022-01-02 18:28:39 -05:00
|
|
|
|
{
|
|
|
|
|
|
get
|
2022-01-02 16:46:14 -05:00
|
|
|
|
{
|
2022-01-02 22:46:53 -05:00
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<double>(
|
|
|
|
|
|
"process-uptime", "process-uptime-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-02 18:28:39 -05:00
|
|
|
|
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// The PID of the electron process
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<int> PidAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<int>(
|
|
|
|
|
|
"process-pid", "process-pid-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-02 16:46:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// The operating system CPU architecture for which the Node.js binary was compiled
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<string> ArchAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<string>(
|
|
|
|
|
|
"process-arch", "process-arch-Completed");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-01-03 00:21:48 -05:00
|
|
|
|
/// A string identifying the operating system platform on which the Node.js process is running
|
2022-01-02 22:46:53 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Task<string> PlatformAsync
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return BridgeConnector.GetValueOverSocketAsync<string>(
|
|
|
|
|
|
"process-platform", "process-platform-Completed");
|
2022-01-02 16:46:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-02 22:46:53 -05:00
|
|
|
|
|
2022-01-02 16:46:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|