diff --git a/ElectronNET.API/Electron.cs b/ElectronNET.API/Electron.cs
index 23f9902..5c63616 100644
--- a/ElectronNET.API/Electron.cs
+++ b/ElectronNET.API/Electron.cs
@@ -88,5 +88,10 @@
/// Control your app in the macOS dock.
///
public static Dock Dock { get { return Dock.Instance; } }
+
+ ///
+ /// Electeon extensions to the Nodejs process object.
+ ///
+ public static Process Process { get { return Process.Instance; } }
}
}
\ No newline at end of file
diff --git a/ElectronNET.API/Process.cs b/ElectronNET.API/Process.cs
new file mode 100644
index 0000000..daa692b
--- /dev/null
+++ b/ElectronNET.API/Process.cs
@@ -0,0 +1,61 @@
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace ElectronNET.API
+{
+ ///
+ /// Electron's process object is extended from the Node.js process object. It adds the
+ /// events, properties, and methods.
+ ///
+ 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();
+
+ ///
+ /// TBD
+ ///
+ ///
+ public async Task GetExecPathAsync(CancellationToken cancellationToken = default)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var taskCompletionSource = new TaskCompletionSource();
+ 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);
+ }
+ }
+ }
+}
diff --git a/ElectronNET.API/ServiceCollectionExtensions.cs b/ElectronNET.API/ServiceCollectionExtensions.cs
index f933731..a63aacf 100644
--- a/ElectronNET.API/ServiceCollectionExtensions.cs
+++ b/ElectronNET.API/ServiceCollectionExtensions.cs
@@ -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);
}
}
diff --git a/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs b/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs
index fcefcd4..e9a890a 100644
--- a/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs
+++ b/ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs
@@ -33,6 +33,7 @@ namespace ElectronNET.CLI.Commands.Actions
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserView.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "powerMonitor.js", "api.");
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "nativeTheme.js", "api.");
+ EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "process.js", "api.");
string splashscreenFolder = Path.Combine(tempPath, "splashscreen");
if (Directory.Exists(splashscreenFolder) == false)
diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj
index a4bd011..792a135 100644
--- a/ElectronNET.CLI/ElectronNET.CLI.csproj
+++ b/ElectronNET.CLI/ElectronNET.CLI.csproj
@@ -74,6 +74,7 @@
+
diff --git a/ElectronNET.Host/api/process.js b/ElectronNET.Host/api/process.js
new file mode 100644
index 0000000..80bdaf7
--- /dev/null
+++ b/ElectronNET.Host/api/process.js
@@ -0,0 +1,10 @@
+"use strict";
+let electronSocket;
+module.exports = (socket) => {
+ electronSocket = socket;
+ socket.on('process-execPath', () => {
+ const value = process.execPath;
+ electronSocket.emit('process-execPathCompleted', value);
+ });
+};
+//# sourceMappingURL=process.js.map
\ No newline at end of file
diff --git a/ElectronNET.Host/api/process.js.map b/ElectronNET.Host/api/process.js.map
new file mode 100644
index 0000000..e2e659a
--- /dev/null
+++ b/ElectronNET.Host/api/process.js.map
@@ -0,0 +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"}
\ No newline at end of file
diff --git a/ElectronNET.Host/api/process.ts b/ElectronNET.Host/api/process.ts
new file mode 100644
index 0000000..a559869
--- /dev/null
+++ b/ElectronNET.Host/api/process.ts
@@ -0,0 +1,11 @@
+import { Socket } from 'net';
+let electronSocket;
+
+export = (socket: Socket) => {
+ electronSocket = socket;
+
+ socket.on('process-execPath', () => {
+ const value = process.execPath;
+ electronSocket.emit('process-execPathCompleted', value);
+ });
+};
diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js
index 459c47f..f984138 100644
--- a/ElectronNET.Host/main.js
+++ b/ElectronNET.Host/main.js
@@ -15,30 +15,11 @@ let mainWindowId, nativeTheme;
let dock;
let launchFile;
let launchUrl;
+let processApi;
let manifestJsonFileName = 'electron.manifest.json';
let watchable = false;
-// handle for opening the app with a file for win and linux
-if (process && process.argv.length > 1) {
-
- let firstAppArgument = process.argv[1];
-
- // With invoked via electronize, the first argument is the path to the main.js.
- // Per issue #337, the /args switch can also be present. If either are present,
- // we need to check the subsequent argument.
- if (firstAppArgument === '..\\..\\main.js' || firstAppArgument === '../../main.js' || firstAppArgument === '/args') {
- if (process.argv.length > 2) {
- firstAppArgument = process.argv[2];
- }
- }
-
- // only append the first app arg if it is not already a switch
- if (!firstAppArgument.startsWith("--")) {
- app.commandLine.appendSwitch("open-file", firstAppArgument);
- }
-}
-
if (app.commandLine.hasSwitch('manifest')) {
manifestJsonFileName = app.commandLine.getSwitchValue('manifest');
};
@@ -238,6 +219,7 @@ function startSocketApiBridge(port) {
if (powerMonitor === undefined) powerMonitor = require('./api/powerMonitor')(socket);
if (nativeTheme === undefined) nativeTheme = require('./api/nativeTheme')(socket);
if (dock === undefined) dock = require('./api/dock')(socket);
+ if (processApi === undefined) processApi = require('./api/process')(socket);
socket.on('register-app-open-file-event', (id) => {
global['electronsocket'] = socket;