Skip to content

Conversation

@davidroth
Copy link
Contributor

I was debugging why my electron app does not respect the singleInstance property and found out that commit 688d6d8 regressed the single instance behaviour.

Problem: Commit 688d6d8 changed the check to == 'yes' but the configuration uses true.

@davidroth davidroth changed the base branch from main to develop December 18, 2025 13:35
@davidroth davidroth force-pushed the fix-single-instance branch 2 times, most recently from 89c5543 to 30393f1 Compare December 18, 2025 13:38
@davidroth
Copy link
Contributor Author

@FlorianRappl I tested it with my changes and it works now (both enabling + disabling). Not exactly sure why you changed it to "yes" in the original commit -maybe you can clarify? Thanks 😀

Tested by running the following command in the published output dir:

Manipulate "package.json" and configure "singleInstance" to either "true" or "false"

Run app twice via:

node node_modules/electron/cli.js main.js -unpackedelectron

Previously:

App always runs twice.

@github-actions
Copy link

github-actions bot commented Dec 18, 2025

pr-comment: Run #13

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1274 1130 0 0 0 144 0 3m 50s

🎉 All tests passed!

Github Test Reporter by CTRF 💚

🔄 This comment has been updated

@FlorianRappl
Copy link
Collaborator

FlorianRappl commented Dec 18, 2025

Yeah this I think is an artifact from the migration to pure .NET, i.e., no more serialization here. I think it might even make sense to remove the BuildInfo altogether. I don't see much value in this any more.

As far the issue - I think removal of the deserialization and comparing to True would be sufficient.

@softworkz
Copy link
Collaborator

The original mistake is in package.template.json:

"license": "$(License)",
 "executable": "$(TargetName)",
 "singleInstance": "$(ElectronSingleInstance)",
 "homepage": "$(ProjectUrl)",
 "splashscreen": {
   "imageFile": "$(ElectronSplashScreen)"
 },

The value should not be quoted.

And then in ElectronNET.LateImport.targets, this

<TemplateProperty Include="ElectronSingleInstance" Value="$(ElectronSingleInstance)" />

needs to be changed to this:

<TemplateProperty Include="ElectronSingleInstance" Value="$(ElectronSingleInstance.ToLower())" />

@softworkz
Copy link
Collaborator

Yeah this I think is an artifact from the migration to pure .NET, i.e., no more serialization here. I think it might even make sense to remove the BuildInfo altogether. I don't see much value in this any more.

BuildInfo is important. There are 3 internal usages:

image

For example, without it, the ElectronRuntime wouldn't know the name of the Electron executable to launch.

C# has no DEFINEs like C/C++, so it's not possible to get compile-time variables into the code, apart from the boolean-only definitions for conditional compilation.

Using assembly metadata attributes is an elegant replacement for this. The ElectronRuntime.BuildInfo unwraps those values, so that you don't need the ugly code everywhere for reading those attributes.

@softworkz
Copy link
Collaborator

@davidroth

Thanks a lot for the PR and bringing this to attention. This PR is close, but actually, that value should be a boolean in the first place, that's why #994 is a better way from my point of view.

@davidroth
Copy link
Contributor Author

Closed in favour of #996

@davidroth davidroth closed this Dec 18, 2025
@davidroth davidroth deleted the fix-single-instance branch December 18, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants