Files
Electron.NET/src/ElectronNET.API/Runtime/Helpers/LaunchOrderDetector.cs
Pierre Arnaud 03da5cd7cb Phase 4: Replace Console output with Debug.WriteLine in diagnostic code
- Replaced Console.WriteLine with System.Diagnostics.Debug.WriteLine in:
  * LaunchOrderDetector (probe scoring)
  * UnpackagedDetector (probe scoring)
  * ElectronProcessActive (StartInternal traces)
- Removed '[StartInternal]: after run:' trace
- Debug.WriteLine only outputs when debugger is attached

These were the noisiest debugging traces. Other Console.WriteLine usage
in StartupManager, ProcessRunner, etc. would require ILogger injection
which is a larger architectural change deferred for now.
2026-01-31 11:19:28 +01:00

73 lines
1.9 KiB
C#

namespace ElectronNET.Runtime.Helpers
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
internal class LaunchOrderDetector
{
public static bool CheckIsLaunchedByDotNet()
{
var tests = new List<Func<bool?>>();
tests.Add(CheckIsDotNetStartup1);
tests.Add(CheckIsDotNetStartup2);
tests.Add(CheckIsDotNetStartup3);
int scoreDotNet = 0, scoreElectron = 0;
foreach (var test in tests)
{
var res = test();
if (res == true)
{
scoreDotNet++;
}
if (res == false)
{
scoreElectron++;
}
}
// Debug trace - useful for diagnostics
System.Diagnostics.Debug.WriteLine($"Probe scored for launch origin: DotNet {scoreDotNet} vs. {scoreElectron} Electron");
return scoreDotNet > scoreElectron;
}
private static bool? CheckIsDotNetStartup1()
{
var hasPortArg = ElectronNetRuntime.ProcessArguments.Any(e => e.Contains(ElectronNetRuntime.ElectronPortArgumentName, StringComparison.OrdinalIgnoreCase));
if (hasPortArg)
{
return false;
}
return true;
}
private static bool? CheckIsDotNetStartup2()
{
var hasPidArg = ElectronNetRuntime.ProcessArguments.Any(e => e.Contains(ElectronNetRuntime.ElectronPidArgumentName, StringComparison.OrdinalIgnoreCase));
if (hasPidArg)
{
return false;
}
return true;
}
private static bool? CheckIsDotNetStartup3()
{
if (DebuggerHelper.IsAttached)
{
return true;
}
return null;
}
}
}