MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    electronSwitches in config.js — am I reading the code wrong, or does it not actually work?

    Scheduled Pinned Locked Moved Solved Troubleshooting
    11 Posts 3 Posters 20 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rkorell Module Developer
      last edited by

      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 MB
      

      Some 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:

      1. 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?

      1. 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

      KristjanESPERANTOK S 2 Replies Last reply Reply Quote 1
      • KristjanESPERANTOK Offline
        KristjanESPERANTO Module Developer @rkorell
        last edited by

        @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!

        R 1 Reply Last reply Reply Quote 0
        • S Do not disturb
          sdetweil @rkorell
          last edited by

          @rkorell to switch to develop see
          https://forum.magicmirror.builders/topic/14327/testing-new-fixes-or-solving-current-problems-with-next-release-code

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          R 1 Reply Last reply Reply Quote 0
          • R Offline
            rkorell Module Developer @KristjanESPERANTO
            last edited by

            @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

            1 Reply Last reply Reply Quote 0
            • R rkorell has marked this topic as solved
            • R Offline
              rkorell Module Developer @sdetweil
              last edited by

              Dear Sam, @sdetweil,
              thanks to you as well!

              As mentioned above: A little bit shy …

              Warmest regards,
              Ralf

              S 1 Reply Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @rkorell
                last edited by

                @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 string

                commandLine.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

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                R 1 Reply Last reply Reply Quote 1
                • R Offline
                  rkorell Module Developer @sdetweil
                  last edited by rkorell

                  @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

                  S R 2 Replies Last reply Reply Quote 0
                  • S Do not disturb
                    sdetweil @rkorell
                    last edited by sdetweil

                    @rkorell

                    its already 2.36 now… we put out a sep release to fix a bunch of things.
                    2.37 is july 1

                    copy 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 2

                    I 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

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    R 1 Reply Last reply Reply Quote 0
                    • R Offline
                      rkorell Module Developer @sdetweil
                      last edited by

                      @sdetweil OK, thanks!
                      Still doesn’t sound THAT safe …

                      regards,
                      Ralf

                      S 1 Reply Last reply Reply Quote 0
                      • S Do not disturb
                        sdetweil @rkorell
                        last edited by

                        @rkorell don’t touch your old card. Backup, Make new,
                        Install MagicMirror, restore, test. Fallback to old card if you need to

                        As safe as it gets

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          rkorell Module Developer @rkorell
                          last edited by

                          @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

                          1 Reply Last reply Reply Quote 1

                          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
                          • 1 / 1
                          • First post
                            Last post
                          Enjoying MagicMirror? Please consider a donation!
                          MagicMirror created by Michael Teeuw.
                          Forum managed by Sam, technical setup by Karsten.
                          This forum is using NodeBB as its core | Contributors
                          Contact | Privacy Policy