|
| 1 | +using System.Threading; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Newtonsoft.Json; |
| 4 | +using Newtonsoft.Json.Linq; |
| 5 | + |
| 6 | +namespace ElectronNET.API |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Electron's process object is extended from the Node.js process object. It adds the |
| 10 | + /// events, properties, and methods. |
| 11 | + /// </summary> |
| 12 | + public sealed class Process |
| 13 | + { |
| 14 | + internal Process() { } |
| 15 | + |
| 16 | + internal static Process Instance |
| 17 | + { |
| 18 | + get |
| 19 | + { |
| 20 | + if (_process == null) |
| 21 | + { |
| 22 | + lock (_syncRoot) |
| 23 | + { |
| 24 | + if (_process == null) |
| 25 | + { |
| 26 | + _process = new Process(); |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + return _process; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + private static Process _process; |
| 36 | + |
| 37 | + private static readonly object _syncRoot = new(); |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// The process.execPath property returns the absolute pathname of the executable that |
| 41 | + /// started the Node.js process. Symbolic links, if any, are resolved. |
| 42 | + /// </summary> |
| 43 | + public Task<string> ExecPathAsync |
| 44 | + { |
| 45 | + get |
| 46 | + { |
| 47 | + return BridgeConnector.GetValueOverSocketAsync<string>( |
| 48 | + "process-execPath", "process-execPath-Completed"); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// The process.argv property returns an array containing the command-line arguments passed |
| 54 | + /// when the Node.js process was launched. The first element will be process.execPath. See |
| 55 | + /// process.argv0 if access to the original value of argv[0] is needed. The second element |
| 56 | + /// will be the path to the JavaScript file being executed. The remaining elements will be |
| 57 | + /// any additional command-line arguments |
| 58 | + /// </summary> |
| 59 | + public Task<string[]> ArgvAsync |
| 60 | + { |
| 61 | + get |
| 62 | + { |
| 63 | + return BridgeConnector.GetArrayOverSocketAsync<string[]>( |
| 64 | + "process-argv", "process-argv-Completed"); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// The process.execPath property returns the absolute pathname of the executable that |
| 70 | + /// started the Node.js process. Symbolic links, if any, are resolved. |
| 71 | + /// </summary> |
| 72 | + public Task<string> TypeAsync |
| 73 | + { |
| 74 | + get |
| 75 | + { |
| 76 | + return BridgeConnector.GetValueOverSocketAsync<string>( |
| 77 | + "process-type", "process-type-Completed"); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// The process.versions property returns an object listing the version strings of |
| 84 | + /// chrome and electron. |
| 85 | + /// </summary> |
| 86 | + public Task<ProcessVersions> VersionsAsync |
| 87 | + { |
| 88 | + get |
| 89 | + { |
| 90 | + return BridgeConnector.GetObjectOverSocketAsync<ProcessVersions>( |
| 91 | + "process-versions", "process-versions-Completed"); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// A Boolean. When app is started by being passed as parameter to the default app, this |
| 98 | + /// property is true in the main process, otherwise it is false. |
| 99 | + /// </summary> |
| 100 | + public Task<bool> DefaultAppAsync |
| 101 | + { |
| 102 | + get |
| 103 | + { |
| 104 | + return BridgeConnector.GetValueOverSocketAsync<bool>( |
| 105 | + "process-defaultApp", "process-defaultApp-Completed"); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// A Boolean, true when the current renderer context is the "main" renderer frame. If you |
| 111 | + /// want the ID of the current frame you should use webFrame.routingId |
| 112 | + /// </summary> |
| 113 | + public Task<bool> IsMainFrameAsync |
| 114 | + { |
| 115 | + get |
| 116 | + { |
| 117 | + return BridgeConnector.GetValueOverSocketAsync<bool>( |
| 118 | + "process-isMainFrame", "process-isMainFrame-Completed"); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + /// <summary> |
| 123 | + /// A String representing the path to the resources directory. |
| 124 | + /// </summary> |
| 125 | + public Task<string> ResourcesPathAsync |
| 126 | + { |
| 127 | + get |
| 128 | + { |
| 129 | + return BridgeConnector.GetValueOverSocketAsync<string>( |
| 130 | + "process-resourcesPath", "process-resourcesPath-Completed"); |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + /// <summary> |
| 135 | + /// The number of seconds the current Node.js process has been running. The return value |
| 136 | + /// includes fractions of a second. Use Math.floor() to get whole seconds. |
| 137 | + /// </summary> |
| 138 | + public Task<double> UpTimeAsync |
| 139 | + { |
| 140 | + get |
| 141 | + { |
| 142 | + return BridgeConnector.GetValueOverSocketAsync<double>( |
| 143 | + "process-uptime", "process-uptime-Completed"); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + /// <summary> |
| 148 | + /// The PID of the electron process |
| 149 | + /// </summary> |
| 150 | + public Task<int> PidAsync |
| 151 | + { |
| 152 | + get |
| 153 | + { |
| 154 | + return BridgeConnector.GetValueOverSocketAsync<int>( |
| 155 | + "process-pid", "process-pid-Completed"); |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// The operating system CPU architecture for which the Node.js binary was compiled |
| 162 | + /// </summary> |
| 163 | + public Task<string> ArchAsync |
| 164 | + { |
| 165 | + get |
| 166 | + { |
| 167 | + return BridgeConnector.GetValueOverSocketAsync<string>( |
| 168 | + "process-arch", "process-arch-Completed"); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + /// <summary> |
| 173 | + /// A string identifying the operating system platform on which the Node.js process is running |
| 174 | + /// </summary> |
| 175 | + public Task<string> PlatformAsync |
| 176 | + { |
| 177 | + get |
| 178 | + { |
| 179 | + return BridgeConnector.GetValueOverSocketAsync<string>( |
| 180 | + "process-platform", "process-platform-Completed"); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + } |
| 185 | +} |
0 commit comments