mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-17 22:26:00 +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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\browserView.js" Link="ElectronHost\api\browserView.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\powerMonitor.js" Link="ElectronHost\api\powerMonitor.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\nativeTheme.js" Link="ElectronHost\api\nativeTheme.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\process.js" Link="ElectronHost\api\process.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
10
ElectronNET.Host/api/process.js
Normal file
10
ElectronNET.Host/api/process.js
Normal file
@@ -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
|
||||
1
ElectronNET.Host/api/process.js.map
Normal file
1
ElectronNET.Host/api/process.js.map
Normal file
@@ -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"}
|
||||
11
ElectronNET.Host/api/process.ts
Normal file
11
ElectronNET.Host/api/process.ts
Normal file
@@ -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);
|
||||
});
|
||||
};
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user