Skip to content

Commit dc019ad

Browse files
Todd Schaveyhillin
authored andcommitted
#647 add to ElectronNET.API Process member interfaces for argv and type
1 parent f7de17f commit dc019ad

File tree

4 files changed

+97
-12
lines changed

4 files changed

+97
-12
lines changed

src/ElectronNET.API/Process.cs

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Threading;
22
using System.Threading.Tasks;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
35

46
namespace ElectronNET.API
57
{
@@ -34,27 +36,92 @@ internal static Process Instance
3436

3537
private static readonly object _syncRoot = new();
3638

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+
3770
/// <summary>
3871
/// TBD
3972
/// </summary>
4073
/// <value></value>
41-
public async Task<string> GetExecPathAsync(CancellationToken cancellationToken = default)
74+
public Task<string[]> ArgvAsync
4275
{
43-
cancellationToken.ThrowIfCancellationRequested();
76+
get
77+
{
78+
CancellationToken cancellationToken = new();
79+
cancellationToken.ThrowIfCancellationRequested();
4480

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
47108
{
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()))
49114
{
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+
});
53120

54-
BridgeConnector.Socket.Emit("process-execPath");
121+
BridgeConnector.Socket.Emit("process-type");
55122

56-
return await taskCompletionSource.Task
57-
.ConfigureAwait(false);
123+
return taskCompletionSource.Task;
124+
}
58125
}
59126
}
60127
}

src/ElectronNET.Host/api/process.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/process.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/process.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@ export = (socket: Socket) => {
88
const value = process.execPath;
99
electronSocket.emit('process-execPathCompleted', value);
1010
});
11+
12+
socket.on('process-argv', () => {
13+
const value = process.argv;
14+
electronSocket.emit('process-argvCompleted', value);
15+
});
16+
17+
socket.on('process-type', () => {
18+
const value = process.type;
19+
electronSocket.emit('process-typeCompleted', value);
20+
});
1121
};

0 commit comments

Comments
 (0)