mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-04-24 07:00:25 +00:00
#647 add to ElectronNET.API Process member interfaces for argv and type
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
@@ -34,27 +36,92 @@ namespace ElectronNET.API
|
||||
|
||||
private static readonly object _syncRoot = new();
|
||||
|
||||
/// <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>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// var path = await Electron.Process.ExecPathAsync;
|
||||
/// </code>
|
||||
/// </example>
|
||||
public Task<string> ExecPathAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("process-execPathCompleted", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-execPathCompleted");
|
||||
taskCompletionSource.SetResult((string) text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-execPath");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TBD
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public async Task<string> GetExecPathAsync(CancellationToken cancellationToken = default)
|
||||
public Task<string[]> ArgvAsync
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
get
|
||||
{
|
||||
BridgeConnector.Socket.On("process-execPathCompleted", (text) =>
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string[]>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-execPathCompleted");
|
||||
taskCompletionSource.SetResult((string) text);
|
||||
});
|
||||
BridgeConnector.Socket.On("process-argvCompleted", (value) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-argvCompleted");
|
||||
taskCompletionSource.SetResult( ((JArray)value).ToObject<string[]>() );
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-execPath");
|
||||
BridgeConnector.Socket.Emit("process-argv");
|
||||
|
||||
return await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// var path = await Electron.Process.ExecPathAsync;
|
||||
/// </code>
|
||||
/// </example>
|
||||
public Task<string> TypeAsync
|
||||
{
|
||||
get
|
||||
{
|
||||
CancellationToken cancellationToken = new();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>();
|
||||
using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled()))
|
||||
{
|
||||
BridgeConnector.Socket.On("process-typeCompleted", (text) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("process-typeCompleted");
|
||||
taskCompletionSource.SetResult((string) text);
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit("process-type");
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,13 @@ module.exports = (socket) => {
|
||||
const value = process.execPath;
|
||||
electronSocket.emit('process-execPathCompleted', value);
|
||||
});
|
||||
socket.on('process-argv', () => {
|
||||
const value = process.argv;
|
||||
electronSocket.emit('process-argvCompleted', value);
|
||||
});
|
||||
socket.on('process-type', () => {
|
||||
const value = process.type;
|
||||
electronSocket.emit('process-typeCompleted', value);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=process.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"process.js","sourceRoot":"","sources":["process.ts"],"names":[],"mappings":";AACA,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC/B,cAAc,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
{"version":3,"file":"process.js","sourceRoot":"","sources":["process.ts"],"names":[],"mappings":";AACA,IAAI,cAAc,CAAC;AAEnB,iBAAS,CAAC,MAAc,EAAE,EAAE;IACxB,cAAc,GAAG,MAAM,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC/B,cAAc,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,cAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,cAAc,CAAC,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
||||
@@ -8,4 +8,14 @@ export = (socket: Socket) => {
|
||||
const value = process.execPath;
|
||||
electronSocket.emit('process-execPathCompleted', value);
|
||||
});
|
||||
|
||||
socket.on('process-argv', () => {
|
||||
const value = process.argv;
|
||||
electronSocket.emit('process-argvCompleted', value);
|
||||
});
|
||||
|
||||
socket.on('process-type', () => {
|
||||
const value = process.type;
|
||||
electronSocket.emit('process-typeCompleted', value);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user