2025-10-13 13:26:26 +02:00
|
|
|
|
namespace ElectronNET.AspNet.Runtime
|
|
|
|
|
|
{
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2026-05-09 17:03:32 +02:00
|
|
|
|
using Microsoft.AspNetCore.Hosting.Server;
|
|
|
|
|
|
using ElectronNET.AspNet.Services;
|
2025-10-13 13:26:26 +02:00
|
|
|
|
using ElectronNET.Runtime.Data;
|
|
|
|
|
|
using ElectronNET.Runtime.Services.ElectronProcess;
|
|
|
|
|
|
|
|
|
|
|
|
internal class RuntimeControllerAspNetElectronFirst : RuntimeControllerAspNetBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private ElectronProcessBase electronProcess;
|
|
|
|
|
|
|
2026-06-20 01:26:00 +02:00
|
|
|
|
public RuntimeControllerAspNetElectronFirst(IServer server, AspNetLifetimeAdapter aspNetLifetimeAdapter, IAppReadyCallbackResolver callbackResolver, IElectronAuthenticationService authenticationService = null) : base(server, aspNetLifetimeAdapter, callbackResolver, authenticationService)
|
2025-10-13 13:26:26 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal override ElectronProcessBase ElectronProcess => this.electronProcess;
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task StartCore()
|
|
|
|
|
|
{
|
2026-05-09 17:03:32 +02:00
|
|
|
|
var port = ElectronNetRuntime.ElectronSocketPort.Value;
|
|
|
|
|
|
var token = ElectronNetRuntime.ElectronAuthToken;
|
2025-10-13 13:26:26 +02:00
|
|
|
|
|
|
|
|
|
|
if (!ElectronNetRuntime.ElectronProcessId.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("No electronPID has been specified by Electron!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-09 17:03:32 +02:00
|
|
|
|
this.CreateSocketBridge(port, token);
|
2025-10-13 13:26:26 +02:00
|
|
|
|
|
|
|
|
|
|
this.electronProcess = new ElectronProcessPassive(ElectronNetRuntime.ElectronProcessId.Value);
|
|
|
|
|
|
this.electronProcess.Stopped += this.ElectronProcess_Stopped;
|
|
|
|
|
|
|
|
|
|
|
|
this.electronProcess.Start();
|
|
|
|
|
|
|
|
|
|
|
|
Task.Run(() => this.TransitionState(LifetimeState.Started));
|
|
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task StopCore()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.electronProcess.Stop();
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ElectronProcess_Stopped(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.HandleStopped();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|