Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ElectronNET.API/API/Electron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ public static class Electron
/// 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; } }
}
}
185 changes: 185 additions & 0 deletions src/ElectronNET.API/Process.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

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>
/// The process.execPath property returns the absolute pathname of the executable that
/// started the Node.js process. Symbolic links, if any, are resolved.
/// </summary>
public Task<string> ExecPathAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<string>(
"process-execPath", "process-execPath-Completed");
}
}

/// <summary>
/// The process.argv property returns an array containing the command-line arguments passed
/// when the Node.js process was launched. The first element will be process.execPath. See
/// process.argv0 if access to the original value of argv[0] is needed. The second element
/// will be the path to the JavaScript file being executed. The remaining elements will be
/// any additional command-line arguments
/// </summary>
public Task<string[]> ArgvAsync
{
get
{
return BridgeConnector.GetArrayOverSocketAsync<string[]>(
"process-argv", "process-argv-Completed");
}
}

/// <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>
public Task<string> TypeAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<string>(
"process-type", "process-type-Completed");
}
}


/// <summary>
/// The process.versions property returns an object listing the version strings of
/// chrome and electron.
/// </summary>
public Task<ProcessVersions> VersionsAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<ProcessVersions>(
"process-versions", "process-versions-Completed");
}
}


/// <summary>
/// A Boolean. When app is started by being passed as parameter to the default app, this
/// property is true in the main process, otherwise it is false.
/// </summary>
public Task<bool> DefaultAppAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<bool>(
"process-defaultApp", "process-defaultApp-Completed");
}
}

/// <summary>
/// A Boolean, true when the current renderer context is the "main" renderer frame. If you
/// want the ID of the current frame you should use webFrame.routingId
/// </summary>
public Task<bool> IsMainFrameAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<bool>(
"process-isMainFrame", "process-isMainFrame-Completed");
}
}

/// <summary>
/// A String representing the path to the resources directory.
/// </summary>
public Task<string> ResourcesPathAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<string>(
"process-resourcesPath", "process-resourcesPath-Completed");
}
}

/// <summary>
/// The number of seconds the current Node.js process has been running. The return value
/// includes fractions of a second. Use Math.floor() to get whole seconds.
/// </summary>
public Task<double> UpTimeAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<double>(
"process-uptime", "process-uptime-Completed");
}
}

/// <summary>
/// The PID of the electron process
/// </summary>
public Task<int> PidAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<int>(
"process-pid", "process-pid-Completed");
}
}


/// <summary>
/// The operating system CPU architecture for which the Node.js binary was compiled
/// </summary>
public Task<string> ArchAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<string>(
"process-arch", "process-arch-Completed");
}
}

/// <summary>
/// A string identifying the operating system platform on which the Node.js process is running
/// </summary>
public Task<string> PlatformAsync
{
get
{
return BridgeConnector.GetValueOverSocketAsync<string>(
"process-platform", "process-platform-Completed");
}
}

}
}
62 changes: 62 additions & 0 deletions src/ElectronNET.Host/api/process.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/ElectronNET.Host/api/process.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions src/ElectronNET.Host/api/process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Socket } from 'net';
let electronSocket;

export = (socket: Socket) => {
electronSocket = socket;

socket.on('process-execPath', () => {
const value = process.execPath;
electronSocket.emit('process-execPath-Completed', value);
});

socket.on('process-argv', () => {
const value = process.argv;
electronSocket.emit('process-argv-Completed', value);
});

socket.on('process-type', () => {
const value = process.type;
electronSocket.emit('process-type-Completed', value);
});

socket.on('process-versions', () => {
const value = process.versions;
electronSocket.emit('process-versions-Completed', value);
});

socket.on('process-defaultApp', () => {
if (process.defaultApp === undefined) {
electronSocket.emit('process-defaultApp-Completed', false);
return;
}
electronSocket.emit('process-defaultApp-Completed', process.defaultApp);
});

socket.on('process-isMainFrame', () => {
if (process.isMainFrame === undefined) {
electronSocket.emit('process-isMainFrame-Completed', false);
return;
}
electronSocket.emit('process-isMainFrame-Completed', process.isMainFrame);
});

socket.on('process-resourcesPath', () => {
const value = process.resourcesPath;
electronSocket.emit('process-resourcesPath-Completed', value);
});

socket.on('process-uptime', () => {
let value = process.uptime();
if (value === undefined) {
value = -1;
}
electronSocket.emit('process-uptime-Completed', value);
});

socket.on('process-pid', () => {
if (process.pid === undefined) {
electronSocket.emit('process-pid-Completed', -1);
return;
}
electronSocket.emit('process-pid-Completed', process.pid);
});

socket.on('process-arch', () => {
const value = process.arch;
electronSocket.emit('process-arch-Completed', value);
});

socket.on('process-platform', () => {
const value = process.platform;
electronSocket.emit('process-platform-Completed', value);
})
};
1 change: 1 addition & 0 deletions src/ElectronNET.Host/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let nativeTheme;
let dock;
let launchFile;
let launchUrl;
let processApi;

let manifestJsonFileName = 'package.json';
let unpackedelectron = false;
Expand Down
20 changes: 6 additions & 14 deletions src/ElectronNET.Host/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading