|
1 | 1 | using System.Threading;
|
2 | 2 | using System.Threading.Tasks;
|
| 3 | +using Newtonsoft.Json; |
| 4 | +using Newtonsoft.Json.Linq; |
3 | 5 |
|
4 | 6 | namespace ElectronNET.API
|
5 | 7 | {
|
@@ -34,27 +36,92 @@ internal static Process Instance
|
34 | 36 |
|
35 | 37 | private static readonly object _syncRoot = new();
|
36 | 38 |
|
| 39 | + /// <summary> |
| 40 | + /// The process.execPath property returns the absolute pathname of the executable that started the Node.js process. Symbolic links, if any, are resolved. |
| 41 | + /// </summary> |
| 42 | + /// <example> |
| 43 | + /// <code> |
| 44 | + /// var path = await Electron.Process.ExecPathAsync; |
| 45 | + /// </code> |
| 46 | + /// </example> |
| 47 | + public Task<string> ExecPathAsync |
| 48 | + { |
| 49 | + get |
| 50 | + { |
| 51 | + CancellationToken cancellationToken = new(); |
| 52 | + cancellationToken.ThrowIfCancellationRequested(); |
| 53 | + |
| 54 | + var taskCompletionSource = new TaskCompletionSource<string>(); |
| 55 | + using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) |
| 56 | + { |
| 57 | + BridgeConnector.Socket.On("process-execPathCompleted", (text) => |
| 58 | + { |
| 59 | + BridgeConnector.Socket.Off("process-execPathCompleted"); |
| 60 | + taskCompletionSource.SetResult((string) text); |
| 61 | + }); |
| 62 | + |
| 63 | + BridgeConnector.Socket.Emit("process-execPath"); |
| 64 | + |
| 65 | + return taskCompletionSource.Task; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
37 | 70 | /// <summary>
|
38 | 71 | /// TBD
|
39 | 72 | /// </summary>
|
40 | 73 | /// <value></value>
|
41 |
| - public async Task<string> GetExecPathAsync(CancellationToken cancellationToken = default) |
| 74 | + public Task<string[]> ArgvAsync |
42 | 75 | {
|
43 |
| - cancellationToken.ThrowIfCancellationRequested(); |
| 76 | + get |
| 77 | + { |
| 78 | + CancellationToken cancellationToken = new(); |
| 79 | + cancellationToken.ThrowIfCancellationRequested(); |
44 | 80 |
|
45 |
| - var taskCompletionSource = new TaskCompletionSource<string>(); |
46 |
| - using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) |
| 81 | + var taskCompletionSource = new TaskCompletionSource<string[]>(); |
| 82 | + using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) |
| 83 | + { |
| 84 | + BridgeConnector.Socket.On("process-argvCompleted", (value) => |
| 85 | + { |
| 86 | + BridgeConnector.Socket.Off("process-argvCompleted"); |
| 87 | + taskCompletionSource.SetResult( ((JArray)value).ToObject<string[]>() ); |
| 88 | + }); |
| 89 | + |
| 90 | + BridgeConnector.Socket.Emit("process-argv"); |
| 91 | + |
| 92 | + return taskCompletionSource.Task; |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// The process.execPath property returns the absolute pathname of the executable that started the Node.js process. Symbolic links, if any, are resolved. |
| 99 | + /// </summary> |
| 100 | + /// <example> |
| 101 | + /// <code> |
| 102 | + /// var path = await Electron.Process.ExecPathAsync; |
| 103 | + /// </code> |
| 104 | + /// </example> |
| 105 | + public Task<string> TypeAsync |
| 106 | + { |
| 107 | + get |
47 | 108 | {
|
48 |
| - BridgeConnector.Socket.On("process-execPathCompleted", (text) => |
| 109 | + CancellationToken cancellationToken = new(); |
| 110 | + cancellationToken.ThrowIfCancellationRequested(); |
| 111 | + |
| 112 | + var taskCompletionSource = new TaskCompletionSource<string>(); |
| 113 | + using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) |
49 | 114 | {
|
50 |
| - BridgeConnector.Socket.Off("process-execPathCompleted"); |
51 |
| - taskCompletionSource.SetResult((string) text); |
52 |
| - }); |
| 115 | + BridgeConnector.Socket.On("process-typeCompleted", (text) => |
| 116 | + { |
| 117 | + BridgeConnector.Socket.Off("process-typeCompleted"); |
| 118 | + taskCompletionSource.SetResult((string) text); |
| 119 | + }); |
53 | 120 |
|
54 |
| - BridgeConnector.Socket.Emit("process-execPath"); |
| 121 | + BridgeConnector.Socket.Emit("process-type"); |
55 | 122 |
|
56 |
| - return await taskCompletionSource.Task |
57 |
| - .ConfigureAwait(false); |
| 123 | + return taskCompletionSource.Task; |
| 124 | + } |
58 | 125 | }
|
59 | 126 | }
|
60 | 127 | }
|
|
0 commit comments