Skip to content

Commit 688d6d8

Browse files
committed
Fixed single instance behavior
1 parent 7bcc5c9 commit 688d6d8

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Updated `PrintToPDFOptions` to also allow specifying the `PageSize` with an object (#769)
66
- Updated splashscreen image to have 0 margin (#622)
7+
- Fixed single instance behavior using the `ElectronSingleInstance` property (#901)
78
- Added option to use `ElectronSplashScreen` with an HTML file (#799)
89
- Added option to provide floating point value as aspect ratios with `SetAspectRatio` (#793)
910

src/ElectronNET.API/Runtime/StartupManager.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,26 @@ private BuildInfo GatherBuildInfo()
136136
buildInfo.ElectronExecutable = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronExecutable))?.Value;
137137
buildInfo.ElectronVersion = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronVersion))?.Value;
138138
buildInfo.RuntimeIdentifier = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.RuntimeIdentifier))?.Value;
139-
buildInfo.ElectronSingleInstance = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronSingleInstance))?.Value;
140139
buildInfo.Title = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.Title))?.Value;
141140
buildInfo.Version = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.Version))?.Value;
142141
buildInfo.BuildConfiguration = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.BuildConfiguration))?.Value;
143142
var isAspNet = attributes.FirstOrDefault(e => e.Key == "IsAspNet")?.Value;
143+
var isSingleInstance = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronSingleInstance))?.Value;
144+
var httpPort = attributes.FirstOrDefault(e => e.Key == "AspNetHttpPort")?.Value;
144145

145146
if (isAspNet?.Length > 0 && bool.TryParse(isAspNet, out var res) && res)
146147
{
147148
ElectronNetRuntime.DotnetAppType = DotnetAppType.AspNetCoreApp;
148149
}
149150

150-
var httpPort = attributes.FirstOrDefault(e => e.Key == "AspNetHttpPort")?.Value;
151+
if (isSingleInstance?.Length > 0 && bool.TryParse(isSingleInstance, out var res) && res)
152+
{
153+
buildInfo.ElectronSingleInstance = "yes";
154+
}
155+
else
156+
{
157+
buildInfo.ElectronSingleInstance = "no";
158+
}
151159

152160
if (httpPort?.Length > 0 && int.TryParse(httpPort, out var port))
153161
{

src/ElectronNET.Host/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ app.on('will-finish-launching', () => {
9292

9393
const manifestJsonFile = require(manifestJsonFilePath);
9494

95-
if (manifestJsonFile.singleInstance) {
95+
if (manifestJsonFile.singleInstance === "yes") {
9696
const mainInstance = app.requestSingleInstanceLock();
9797
app.on('second-instance', (events, args = []) => {
9898
args.forEach((parameter) => {

0 commit comments

Comments
 (0)