mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 05:34:48 +00:00
#647 add initial Process class to ElectronNET.API
This commit is contained in:
@@ -88,5 +88,10 @@
|
||||
/// Control your app in the macOS dock.
|
||||
/// </summary>
|
||||
public static Dock Dock { get { return Dock.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Electeon extensions to the Nodejs process object.
|
||||
/// </summary>
|
||||
public static Process Process { get { return Process.Instance; } }
|
||||
}
|
||||
}
|
||||
61
ElectronNET.API/Process.cs
Normal file
61
ElectronNET.API/Process.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Electron's process object is extended from the Node.js process object. It adds the
|
||||
/// events, properties, and methods.
|
||||
/// </summary>
|
||||
public sealed class Process
|
||||
{
|
||||
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();
|
||||
|
||||
/// <summary>
|
||||
/// TBD
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public async Task<string> GetExecPathAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
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 await taskCompletionSource.Task
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ namespace ElectronNET.API
|
||||
.AddSingleton(provider => HostHook.Instance)
|
||||
.AddSingleton(provider => PowerMonitor.Instance)
|
||||
.AddSingleton(provider => NativeTheme.Instance)
|
||||
.AddSingleton(provider => Dock.Instance);
|
||||
.AddSingleton(provider => Dock.Instance)
|
||||
.AddSingleton(provider => Process.Instance);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user