From 688d6d83cc0d8f70ced6821a1bd0a5e12472e26f Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 2 Nov 2025 23:35:46 +0100 Subject: [PATCH] Fixed single instance behavior --- Changelog.md | 1 + src/ElectronNET.API/Runtime/StartupManager.cs | 12 ++++++++++-- src/ElectronNET.Host/main.js | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3d714eb..cd4caa0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ - Updated `PrintToPDFOptions` to also allow specifying the `PageSize` with an object (#769) - Updated splashscreen image to have 0 margin (#622) +- Fixed single instance behavior using the `ElectronSingleInstance` property (#901) - Added option to use `ElectronSplashScreen` with an HTML file (#799) - Added option to provide floating point value as aspect ratios with `SetAspectRatio` (#793) diff --git a/src/ElectronNET.API/Runtime/StartupManager.cs b/src/ElectronNET.API/Runtime/StartupManager.cs index 147c452..67c6f4c 100644 --- a/src/ElectronNET.API/Runtime/StartupManager.cs +++ b/src/ElectronNET.API/Runtime/StartupManager.cs @@ -136,18 +136,26 @@ buildInfo.ElectronExecutable = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronExecutable))?.Value; buildInfo.ElectronVersion = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronVersion))?.Value; buildInfo.RuntimeIdentifier = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.RuntimeIdentifier))?.Value; - buildInfo.ElectronSingleInstance = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronSingleInstance))?.Value; buildInfo.Title = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.Title))?.Value; buildInfo.Version = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.Version))?.Value; buildInfo.BuildConfiguration = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.BuildConfiguration))?.Value; var isAspNet = attributes.FirstOrDefault(e => e.Key == "IsAspNet")?.Value; + var isSingleInstance = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronSingleInstance))?.Value; + var httpPort = attributes.FirstOrDefault(e => e.Key == "AspNetHttpPort")?.Value; if (isAspNet?.Length > 0 && bool.TryParse(isAspNet, out var res) && res) { ElectronNetRuntime.DotnetAppType = DotnetAppType.AspNetCoreApp; } - var httpPort = attributes.FirstOrDefault(e => e.Key == "AspNetHttpPort")?.Value; + if (isSingleInstance?.Length > 0 && bool.TryParse(isSingleInstance, out var res) && res) + { + buildInfo.ElectronSingleInstance = "yes"; + } + else + { + buildInfo.ElectronSingleInstance = "no"; + } if (httpPort?.Length > 0 && int.TryParse(httpPort, out var port)) { diff --git a/src/ElectronNET.Host/main.js b/src/ElectronNET.Host/main.js index e0879c7..1c56801 100644 --- a/src/ElectronNET.Host/main.js +++ b/src/ElectronNET.Host/main.js @@ -92,7 +92,7 @@ app.on('will-finish-launching', () => { const manifestJsonFile = require(manifestJsonFilePath); -if (manifestJsonFile.singleInstance) { +if (manifestJsonFile.singleInstance === "yes") { const mainInstance = app.requestSingleInstanceLock(); app.on('second-instance', (events, args = []) => { args.forEach((parameter) => {