This commit is contained in:
Florian Rappl
2026-09-04 14:05:36 +02:00
parent 042d8e6c70
commit 7cd552a78f
14 changed files with 159 additions and 17 deletions

View File

@@ -37,10 +37,18 @@
public ProcessRunner(string name)
{
this.Name = name;
this.ExitWaitTimeout = DefaultExitWaitTimeout;
}
public event EventHandler<EventArgs> ProcessExited;
/// <summary>Gets or sets the value <see cref="ExitWaitTimeout"/> is initialized with.</summary>
public static int DefaultExitWaitTimeout { get; set; } = 5000;
/// <summary>Gets or sets the time in milliseconds to wait for the process and its I/O to finish
/// after the exited event has been raised. Values of zero or less wait indefinitely.</summary>
public int ExitWaitTimeout { get; set; }
public bool IsDisposed { get; private set; }
private Process Process
@@ -498,8 +506,17 @@
{
try
{
var timeout = this.ExitWaitTimeout;
// This shouldn't throw here, but the mono process implementation doesn't always behave as it should.
this.process.WaitForExit();
if (timeout > 0)
{
this.process.WaitForExit(timeout);
}
else
{
this.process.WaitForExit();
}
}
catch (Exception ex)
{

View File

@@ -6,6 +6,8 @@
public string ElectronVersion { get; internal set; }
public string ElectronRootDir { get; internal set; }
public string RuntimeIdentifier { get; internal set; }
public bool ElectronSingleInstance { get; internal set; }

View File

@@ -0,0 +1,31 @@
namespace ElectronNET.Runtime.Helpers
{
using System;
using System.IO;
/// <summary>
/// Resolves the directory that contains the Electron binary of a packaged application.
/// </summary>
internal static class ElectronRootDirResolver
{
/// <summary>The location of the Electron binary relative to the .NET application directory in the
/// default (Electron-first) layout, where the .NET application is placed in 'resources/bin'.</summary>
internal const string DefaultElectronRootDir = "../..";
/// <summary>Resolves the Electron root directory relative to the given .NET application directory.</summary>
/// <param name="baseDirectory">The directory containing the .NET application.</param>
/// <returns>The directory containing the Electron binary.</returns>
public static DirectoryInfo Resolve(DirectoryInfo baseDirectory)
{
var rootDir = ElectronNetRuntime.BuildInfo?.ElectronRootDir;
if (string.IsNullOrWhiteSpace(rootDir))
{
rootDir = DefaultElectronRootDir;
}
// An absolute ElectronRootDir is used as-is by Path.Combine.
return new DirectoryInfo(Path.GetFullPath(Path.Combine(baseDirectory.FullName, rootDir)));
}
}
}

View File

@@ -69,6 +69,15 @@
return false;
}
// Packaged, if the Electron binary is found where ElectronRootDir points to.
var electronExecutable = ElectronNetRuntime.ElectronExecutable;
if (!string.IsNullOrEmpty(electronExecutable) &&
File.Exists(Path.Combine(ElectronRootDirResolver.Resolve(dir).FullName, electronExecutable)))
{
return false;
}
if (dir.GetDirectories().Any(e => e.Name == ".electron"))
{
return true;

View File

@@ -11,6 +11,7 @@
using System.Threading.Tasks;
using ElectronNET.Common;
using ElectronNET.Runtime.Data;
using ElectronNET.Runtime.Helpers;
/// <summary>
/// Launches and manages the Electron app process.
@@ -87,7 +88,7 @@
}
else
{
dir = dir.Parent!.Parent!;
dir = ElectronRootDirResolver.Resolve(dir);
startCmd = Path.Combine(dir.FullName, this.electronBinaryName);
args = $"-dotnetpacked -electronforcedport={this.socketPort:D} " + this.extraArguments;
workingDir = dir.FullName;

View File

@@ -178,6 +178,7 @@
{
buildInfo.ElectronExecutable = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronExecutable))?.Value;
buildInfo.ElectronVersion = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronVersion))?.Value;
buildInfo.ElectronRootDir = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronRootDir))?.Value;
buildInfo.RuntimeIdentifier = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.RuntimeIdentifier))?.Value;
buildInfo.Title = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.Title))?.Value;
buildInfo.Version = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.Version))?.Value;