add socket events to emit console messages

This commit is contained in:
rafael-aero
2021-08-25 13:38:30 +02:00
parent 48d5497045
commit 5e82ae4246
2 changed files with 31 additions and 2 deletions

View File

@@ -207,6 +207,27 @@ namespace ElectronNET.API
}
}
/// <summary>
/// Log a message to the console output pipe. This is used when running with "detachedProcess" : true on the electron.manifest.json,
/// as in that case we can't open pipes to read the console output from the child process anymore
/// </summary>
/// <param name="text">Message to log</param>
public static void ConsoleLog(string text)
{
BridgeConnector.Emit("console-stdout", text);
}
/// <summary>
/// Log a message to the console error pipe. This is used when running with "detachedProcess" : true on the electron.manifest.json,
/// as in that case we can't open pipes to read the console output from the child process anymore
/// </summary>
/// <param name="text">Message to log</param>
public static void ConsoleError(string text)
{
BridgeConnector.Emit("console-stderr", text);
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),

View File

@@ -271,6 +271,14 @@ function startSocketApiBridge(port) {
}
});
socket.on('console-stdout', (data) => {
console.log(`stdout: ${data.toString()}`);
});
socket.on('console-stderr', (data) => {
console.log(`stderr: ${data.toString()}`);
});
try {
const hostHookScriptFilePath = path.join(__dirname, 'ElectronHostHook', 'index.js');
@@ -320,7 +328,7 @@ function startAspCoreBackend(electronPort) {
if (manifestJsonFile.hasOwnProperty('detachedProcess')) {
detachedProcess = manifestJsonFile.detachedProcess;
if (detachedProcess) {
stdioopt = ['ignore', 'pipe', 'pipe'];
stdioopt = 'ignore';
}
}
@@ -376,7 +384,7 @@ function startAspCoreBackendWithWatch(electronPort) {
if (manifestJsonFile.hasOwnProperty('detachedProcess')) {
detachedProcess = manifestJsonFile.detachedProcess;
if (detachedProcess) {
stdioopt = ['ignore', 'pipe', 'pipe'];
stdioopt = 'ignore';
}
}