Electron.App.CommandLine.AppendSwitch does not seem to be working propertly #927

Open
opened 2026-01-29 16:52:07 +00:00 by claunia · 0 comments
Owner

Originally created by @Yuvix25 on GitHub (Feb 2, 2024).

  • Version: Electron.NET API 23.6.1, Electron.NET CLI 23.6.1.0
  • .NET Core Version 6.0
  • Node.js v18.12.1
  • Target: Windows

I'm building an app which is using a window with transparent background. While I did get it to work (thanks to #748 ), some users are seeing a black background instead of the transparent one. After doing some research, I stumbled upon this, so I tried adding the following flags:

Electron.App.CommandLine.AppendSwitch("disable-gpu-compositing");
Electron.App.CommandLine.AppendSwitch("disable-gpu");
Electron.App.CommandLine.AppendSwitch("disable-software-rasterizer");

However, when loading the chrome://gpu page to see that these arguments were applied, it appeared that wasn't the case:
image
I then tried manually adding the flags (electronize start /args --disable-gpu-compositing --disable-gpu --disable-software-rasterizer), which gave me this result:
image

So either I'm adding the Electron.App.CommandLine.AppendSwitchs wrong, or they do not work.
You can find the full source code of how I'm adding them here (note that you will only find the disable-gpu-compositing flag there, I added the rest locally without pushing yet)

If there is indeed a bug, is there any way I can get around this to force these arguments to always be passed?

Edit:

When manually adding the appendSwitchs to the main.js file in ElectronNET.Host, they do work. I also made sure that the append switch message sent from Electron.NET is received in Electron.js, so I guess the issue has something to do with the time of appending the switches. I also tried appending them right at the start of the Configure method - with no success.
This worked:

diff --git a/src/ElectronNET.Host/main.js b/src/ElectronNET.Host/main.js
index 0e4079c..179e0d9 100644
--- a/src/ElectronNET.Host/main.js
+++ b/src/ElectronNET.Host/main.js
@@ -26,6 +26,11 @@ if (app.commandLine.hasSwitch('watch')) {
   watchable = true;
 }

+app.commandLine.appendSwitch('enable-transparent-visuals');
+app.commandLine.appendSwitch('disable-gpu');
+app.commandLine.appendSwitch('disable-gpu-compositing');
+app.commandLine.appendSwitch('disable-software-rasterizer');
+
 let currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin');
 let manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName);

Originally created by @Yuvix25 on GitHub (Feb 2, 2024). * **Version**: Electron.NET API 23.6.1, Electron.NET CLI 23.6.1.0 * .NET Core Version 6.0 * Node.js v18.12.1 <!-- What target are you building for? --> * **Target**: Windows I'm building an app which is using a window with transparent background. While I did get it to work (thanks to #748 ), some users are seeing a black background instead of the transparent one. After doing some research, I stumbled upon [this](https://github.com/electron/electron/issues/40515), so I tried adding the following flags: ```c# Electron.App.CommandLine.AppendSwitch("disable-gpu-compositing"); Electron.App.CommandLine.AppendSwitch("disable-gpu"); Electron.App.CommandLine.AppendSwitch("disable-software-rasterizer"); ``` However, when loading the `chrome://gpu` page to see that these arguments were applied, it appeared that wasn't the case: ![image](https://github.com/ElectronNET/Electron.NET/assets/58216719/c8828758-1e34-4881-9912-602b4853bf31) I then tried manually adding the flags (`electronize start /args --disable-gpu-compositing --disable-gpu --disable-software-rasterizer`), which gave me this result: ![image](https://github.com/ElectronNET/Electron.NET/assets/58216719/5c3c95f6-6e80-4285-b956-c3cbd57e49b2) So either I'm adding the `Electron.App.CommandLine.AppendSwitch`s wrong, or they do not work. You can find the full source code of how I'm adding them [here](https://github.com/Yuvix25/ReHUD/blob/97ea359951529fc9177ac3648eeb9237caeb0867/Startup.cs#L95) (note that you will only find the `disable-gpu-compositing` flag there, I added the rest locally without pushing yet) If there is indeed a bug, is there any way I can get around this to force these arguments to always be passed? ### Edit: When manually adding the `appendSwitch`s to the `main.js` file in ElectronNET.Host, they do work. I also made sure that the append switch message sent from Electron.NET is received in Electron.js, so I guess the issue has something to do with the time of appending the switches. I also tried appending them right at the start of the `Configure` method - with no success. This worked: ```js diff --git a/src/ElectronNET.Host/main.js b/src/ElectronNET.Host/main.js index 0e4079c..179e0d9 100644 --- a/src/ElectronNET.Host/main.js +++ b/src/ElectronNET.Host/main.js @@ -26,6 +26,11 @@ if (app.commandLine.hasSwitch('watch')) { watchable = true; } +app.commandLine.appendSwitch('enable-transparent-visuals'); +app.commandLine.appendSwitch('disable-gpu'); +app.commandLine.appendSwitch('disable-gpu-compositing'); +app.commandLine.appendSwitch('disable-software-rasterizer'); + let currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin'); let manifestJsonFilePath = path.join(currentBinPath, manifestJsonFileName); ```
claunia added the bug label 2026-01-29 16:52:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#927