Read the statement by Michael Teeuw here.
electronSwitches in config.js — am I reading the code wrong, or does it not actually work?
-
Dear all,
I have been chasing a runaway Electron disk cache on my Mirror (Pi 5, MM 2.34.0) and added what I thought was the obvious fix to my config.js:
electronSwitches: ["disk-cache-size", "104857600"], // 100 MBSome months later the cache had grown to 2 GB (260,000+ files in ~/.config/Electron/Cache/Cache_Data/).
My limit appeared to be ignored entirely.When I looked at js/electron.js line 47 I think I see why, but I want to sanity-check this with the community — maybe I am simply misreading the code.
The line is:
app.commandLine.appendSwitch(...new Set(electronSwitchesDefaults, config.electronSwitches));As far as I understand it, two things are happening here:
- new Set(a, b) silently drops the second argument.
The Set constructor signature is new Set([iterable]) — it accepts exactly one iterable. Any further arguments are ignored. So I believe this is equivalent to:
new Set(electronSwitchesDefaults)and config.electronSwitches never makes it in.
Is that right?
Or am I missing some clever JavaScript I have not seen before?- appendSwitch only takes one switch per call.
The Electron docs state the signature is appendSwitch(switch, value?). Spreading a flat array of multiple switches into a single call should — if I understand correctly — only honour the first switch/value pair and silently discard the rest.
The defaults array ([“autoplay-policy”, “no-user-gesture-required”]) happens to be exactly one switch with one value, so that one works. But anything a user adds via config.electronSwitches would never take effect, even if point 1 were fixed.
If both readings are correct, the natural fix would be a loop, something like:
const switches = [["autoplay-policy", "no-user-gesture-required"], ...(config.electronSwitches || [])]; switches.forEach(([s, v]) => app.commandLine.appendSwitch(s, v));or, if electronSwitches is documented as a flat array, the user-facing schema would need to be specified more clearly first.
My questions to the forum:
- Is my reading of new Set(a, b) correct here?
- Has anyone successfully used electronSwitches to actually change Electron behaviour, and if so, with what syntax?
- Is this maybe legacy code that the community has worked around in other ways I am not aware of?
Thanks,
Ralf -
@rkorell That should already be fixed in the develop branch by https://github.com/MagicMirrorOrg/MagicMirror/pull/4161 and will be in the next release. It would be great if you could switch to the develop branch and test it before the release :) Good analysis, by the way!
-
-
@KristjanESPERANTO
Thanks!
To be honest, I’m hesitating with upgrades …
And pulling develop branches ist defnitely not my favourite way of using my mirror.I even refused to install the last reelase- caused by the major changes in config.js location …
I will think about, but …
mmmmhhmmmm…Thanks anyway for your feedback - highly appreciated!
Warmest regards,
Ralf -
R rkorell has marked this topic as solved
-
Dear Sam, @sdetweil,
thanks to you as well!As mentioned above: A little bit shy …
Warmest regards,
Ralf -
@rkorell so much fun!!! you can code it to maybe fix your problem.
net, the new electronSwitches is still an array , but now contains an object for the key:value pair, or just a string for those switches that are just single value
[ "string" { "id":"value"]., ... ]and the
appendSwitch can be either single stringcommandLine.appendSwitch(sw);or two part,
commandLine.appendSwitch(name, String(value));code here in a sep function
https://github.com/MagicMirrorOrg/MagicMirror/blob/develop/js/electron_helper.js -
@sdetweil , yes.
I’ve really thought about this.How do you see the update?
I’m currently on 2.34.
Switch to 2.35 is SUBSTANCIAL !- changes of standard-module location, changes of location for custom.css, electron new …
Will this break my system?
Or am I fine with just using your great update-script?
Thanks for any advice (I KNOW that you cannot provide any guarantee. I’m just interested in gut-feeling…)(and: if it brake: is there a way back??? )
Warmest regards,
Ralf -
its already 2.36 now… we put out a sep release to fix a bunch of things.
2.37 is july 1copy the MM folder to save so you don’t lose anything
use my upgrade script
my backup/restore will move things too
no functional 3rd party module content changed,
modules didn’t move location
just location of default modules (you shouldn’t care)
and USER files, config.js, custom.css now in ONE folder instead of 2I have to fix my MMM-Config for the electronSwitches structure change(before july 1), already fixed for css move and default modules move.
must you may ALSO need new OS to support new nodejs and electron…
my backup/restore will help put the old config on new system after new MM install
backup existing, store on github., versioned too, not only copy on sd card.
make new sd card
boot
install MM, make sure it runs
restore (from github) (it reinstalls modules, this is NOT a binary backup, just text very small)
restart MM -
@sdetweil OK, thanks!
Still doesn’t sound THAT safe …regards,
Ralf -
@rkorell don’t touch your old card. Backup, Make new,
Install MagicMirror, restore, test. Fallback to old card if you need toAs safe as it gets
-
@sdetweil , @kristjanesperanto ,
I’ve decided to resolve it by myself - with Sam’s hint/advice/helper-file.
It seems to work - will double check my cache size in a few days.Thanks again for your great support.
Migration is a bigger task and wihout any need currently too much - even cache-growth wouldn’t change this.- never touch a running system :-)
Warm regards,
Ralf
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login