using System.Threading; using System.Threading.Tasks; using ElectronNET.API.Interfaces; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace ElectronNET.API { /// /// Electron's process object is extended from the Node.js process object. It adds the /// events, properties, and methods. /// public sealed class Process : IProcess { 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(); /// /// The process.execPath property returns the absolute pathname of the executable that /// started the Node.js process. Symbolic links, if any, are resolved. /// public Task ExecPathAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-execPath", "process-execPath-Completed"); } } /// /// 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 /// public Task ArgvAsync { get { return BridgeConnector.GetArrayOverSocketAsync( "process-argv", "process-argv-Completed"); } } /// /// The process.execPath property returns the absolute pathname of the executable that /// started the Node.js process. Symbolic links, if any, are resolved. /// public Task TypeAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-type", "process-type-Completed"); } } /// /// The process.versions property returns an object listing the version strings of /// chrome and electron. /// public Task VersionsAsync { get { return BridgeConnector.GetObjectOverSocketAsync( "process-versions", "process-versions-Completed"); } } /// /// 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. /// public Task DefaultAppAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-defaultApp", "process-defaultApp-Completed"); } } /// /// 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 /// public Task IsMainFrameAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-isMainFrame", "process-isMainFrame-Completed"); } } /// /// A String representing the path to the resources directory. /// public Task ResourcesPathAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-resourcesPath", "process-resourcesPath-Completed"); } } /// /// 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. /// public Task UpTimeAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-uptime", "process-uptime-Completed"); } } /// /// The PID of the electron process /// public Task PidAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-pid", "process-pid-Completed"); } } /// /// The operating system CPU architecture for which the Node.js binary was compiled /// public Task ArchAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-arch", "process-arch-Completed"); } } /// /// A string identifying the operating system platform on which the Node.js process is running /// public Task PlatformAsync { get { return BridgeConnector.GetValueOverSocketAsync( "process-platform", "process-platform-Completed"); } } } }