Skip to content

feat(electron): support object-based electronSwitches#4161

Open
KristjanESPERANTO wants to merge 2 commits into
MagicMirrorOrg:developfrom
KristjanESPERANTO:electron
Open

feat(electron): support object-based electronSwitches#4161
KristjanESPERANTO wants to merge 2 commits into
MagicMirrorOrg:developfrom
KristjanESPERANTO:electron

Conversation

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator

Previously, electronSwitches only accepted strings. This PR adds support for object entries, allowing switches with values:

electronSwitches: [
  "no-sandbox",
  { "js-flags": "--max-old-space-size=8192" }
]

I decided to put the logic into a helper file so it can be unit-tested independently, since electron.js itself requires a live Electron environment and cannot be tested in isolation.

Fixes #4159

Adds js/electron_helper.js with applyElectronSwitches(), which
handles both string and object entries in the electronSwitches
config array and logs each activated switch.

The hardcoded autoplay-policy default switch is moved into the
helper so all switch logic lives in one place.

Fixes MagicMirrorOrg#4159
Copy link
Copy Markdown
Collaborator

@sdetweil sdetweil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoplayPolicy is an object. And it looks like it’s moved to web preferences, altho there appears to be a cli parm with — prefix

Image

Electron's webPreferences.autoplayPolicy already defaults to
"no-user-gesture-required", making the commandLine switch redundant.
@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator Author

Good catch! I hadn't questioned it since it was already there before my changes. So you're right - since webPreferences.autoplayPolicy defaults to "no-user-gesture-required" anyway, the CLI switch is useless. I've removed it.

Copy link
Copy Markdown
Collaborator

@sdetweil sdetweil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the for loop name/value is there a way to catch value as string or number not object, so String(value) doesn’t fail

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator Author

Yes, we could add that check. I’m just not sure it’s a realistic case worth handling: valid values are normally strings or numbers, and passing an object/array would be a fairly unusual config mistake. It also wouldn’t crash - String(value) would produce "[object Object]" or similar, and Electron would just not apply the switch as intended. Happy to add it if you prefer, but I’d lean toward keeping this simple.

@sdetweil
Copy link
Copy Markdown
Collaborator

sdetweil commented May 19, 2026

Ok. I’m alright with no check if you think it is non fatal

this is a breaking change for my very old configs, I wonder who else it will impact..

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator Author

Since this never really worked correctly from what I can tell, I don’t see a big risk of breaking many existing setups. I might be wrong, of course, but my suggestion is to merge this and see if anyone reports a real-world config.

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.

2 participants