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.

    MMM-ProfileSwitcher, A Profile/User/Layout Switching Module

    Scheduled Pinned Locked Moved Utilities
    userswitchprofilelayoutmodule
    91 Posts 21 Posters 146.5k Views 23 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.
    • tosti007T Offline
      tosti007 Module Developer @tosti007
      last edited by

      @tosti007 said in MMM-ProfileSwitcher, A Profile/User/Layout Switching Module:

      I will update the line numbers aswell, thank you! I will let you know when I changed it.

      @Snille Updated :) You have to remove only a few lines more and then it should work like before! Also added your translations :) thank you once more

      If there is anything don't hesitate to contact me!
      ProfileSwitcher, TouchNotifications

      1 Reply Last reply Reply Quote 0
      • tosti007T Offline
        tosti007 Module Developer
        last edited by tosti007

        @All Hello everybody! Version 2 is out now :D You can set a timer to switch from one profile to another after a certain amount of time! For an explanation on how to configure them check the README. After a feature request of @shashank.

        If there is anything don't hesitate to contact me!
        ProfileSwitcher, TouchNotifications

        S 1 Reply Last reply Reply Quote 1
        • M Offline
          Mar
          last edited by Mar

          So i’ve added the MMM-ProfileSwitcher to the config file along with “classes: ‘default xyz’” etc to each module under the config file. With one module having only a class of “PAGE2”.

          Using MMM-Buttons i have it successfully pushing a notification saying PAGE2 but nothing is happening on my MM, also all the modules are showing up? When the notification is pushed in the pm2 logs i see all the modules receiving the notification but i dont ever see profileswitcher in that list.

          I honestly dont know what im doing wrong, the profileswitcher is loading according to the pm2 logs (with an error) but for instance one of my modules I have a unique class set so it should only be visible for that profile but it still shows up when the mirror loads on the default page.

          edit:
          Noticed this error on pm2 logs x

          0|mm       | ** Message: console message: http://localhost:8080/modules/MMM-ProfileSwitcher//MMM-ProfileSwitcher.js @87: SyntaxError: Unexpected token '>'
          

          Line reads:

          self.config.ignoreModules.some((m) => classes.includes(m)) || // Should this module be ignored?
          

          Also same at line 204/108 wondering if it should be an =, >=, or perhaps a < =? It also doesnt seem to like line 205 return statement (but im not sure what this one means).

          tosti007T 1 Reply Last reply Reply Quote 0
          • S Offline
            shashank @tosti007
            last edited by

            @tosti007 Hi, Thanks a Lot, Profile switch timer is working fine, tested the same.

            1 Reply Last reply Reply Quote 0
            • tosti007T Offline
              tosti007 Module Developer @Mar
              last edited by tosti007

              @Mar After a helpfull pull request by @Jopyth this line got removed. Try pulling the new changes and let me know if still gives problems! Thank you for letting me know that bug.

              @All The module uses lockstrings now! This due to some problems in combination with other modules. Give the README configurables a look if you want to disable this.

              Edit: Ugh I just noticed I made a terrible mistake in that line. the => should have been >==. Thanks again!
              Edit 2: Double ugh, read it again and it was right.

              If there is anything don't hesitate to contact me!
              ProfileSwitcher, TouchNotifications

              M 1 Reply Last reply Reply Quote 0
              • M Offline
                Mar @tosti007
                last edited by Mar

                @tosti007 Thanks for the updates, still looks like lines 214 & 218 contain the “=>” were these supposed to be switched to >== also?

                So just getting those error so far, but still no luck on the switcher. Im really not sure what I’m doing wrong. I’ve simplified my config file to the following to try make it load the default profile and just switch to ‘PAGE2’. But when the MM loads I get both the clock and weather still on the screen.

                modules: [
                                {
                                        module: 'alert',
                                },
                                {
                                        module: "updatenotification",
                                        position: "top_bar"
                                },
                                {
                                        module: 'MMM-ProfileSwitcher',
                                        config: {
                                                // See 'Configuration options' for more information.
                                        }
                                },
                                {
                                        module: 'MMM-Buttons',
                                        config: {
                                        buttons: [
                                                {
                                                        pin: 5,
                                                        name: "power",
                                                        shortPress: {
                                                                notification: "PROFILE_SWITCH",
                                                                payload: {action: "PAGE2"}
                                                        }
                                                }
                                        ]
                                        }
                                },
                                {
                                        module: 'clock',
                                        classes: 'default',
                                        position: 'top_left',
                                },
                                {
                                        module: 'currentweather',
                                        classes: 'PAGE2',
                                        position: 'top_right',
                                        config: {
                                                location: '...',
                                                locationID: '...',
                                                appid: '...'
                                        }
                                },
                        ]
                
                

                and when i press the button pm2 logs only shows this but nothing happens on the screen.

                0|mm       | ** Message: console message: [native code] @0: clock received a module notification: PROFILE_SWITCH from sender: MMM-Buttons
                

                edit: On the main HDMI cable monitor the mirror is showing both modules, but if i go via chrome on my laptop it only shows the clock (but still doesnt switch when pressing the button). The inspector in Chrome shows that its hiding non-default modules…seems like Midori doesnt get to this (but I have no way to check)

                strawberry 3.141S 1 Reply Last reply Reply Quote 0
                • strawberry 3.141S Offline
                  strawberry 3.141 Project Sponsor Module Developer @Mar
                  last edited by

                  @Mar => are big arrow functions from ecmascript6, which is the newest standard of javascript

                  Please create a github issue if you need help, so I can keep track

                  M 1 Reply Last reply Reply Quote 1
                  • M Offline
                    Mar @strawberry 3.141
                    last edited by

                    @strawberry-3.141 Thanks, I never seem to have had any issues with these before but only on my pi zero. Loading up the latest profile switcher (using my simple 2 module) i get this error relating to that line

                    0|mm       | ** Message: console message: http://localhost:8080/modules/MMM-ProfileSwitcher//MMM-ProfileSwitcher.js @214: SyntaxError: Unexpected token '>'
                    

                    But it seems to work via a remote browser (i.e chrome but switching doesnt work) and not the pi’s midori which still shows both modules.

                    strawberry 3.141S 1 Reply Last reply Reply Quote 0
                    • strawberry 3.141S Offline
                      strawberry 3.141 Project Sponsor Module Developer @Mar
                      last edited by

                      @Mar for me electron is supporting all those es6 features, just heard of that some users had problems with some of my modules with the midori browser

                      Please create a github issue if you need help, so I can keep track

                      M 2 Replies Last reply Reply Quote 0
                      • M Offline
                        Mar @strawberry 3.141
                        last edited by Mar

                        @strawberry-3.141 Yeah seems to be a midori thing, unfortunately I’m using a pi zero so need to use midori as it runs pretty amazing with the pi. Electron really slows it down.

                        Wondering if there is a way around this at all? Maybe breaking out the arrow functions to normal one might work?

                        1 Reply Last reply Reply Quote 0
                        • M Offline
                          Mar @strawberry 3.141
                          last edited by

                          @strawberry-3.141

                          So ive broken out those functions to the following and now get no errors:

                          
                          *OLD*
                                          value = value.map((x) => {
                                              return x === true ? translated : x;
                                          });
                          
                          
                          *NEW*
                                          value = value.map(
                                                  function(x){
                                                          return x === true ? translated :x;
                                                  }
                                          );				
                          
                          
                          
                          
                          
                          *OLD*
                                          classes.split(" ").forEach((key) => {
                                              if (result[key] === undefined) {
                                                  result[key] = [];
                                              }
                          
                                              result[key] = result[key].concat(value);
                                          });
                          
                          *NEW*
                          				classes.split(" ").forEach(
                          					function(key) {
                          	                    if (result[key] === undefined) {
                          	                        result[key] = [];
                          	                    }
                          
                          	                    result[key] = result[key].concat(value);
                          	                }
                          	            );
                          

                          Now the only error i am getting is on line 89

                          TypeError: undefined is not a function (evaluating 'classes.includes(self.current_profile)')
                          

                          But im not sure how to fix this one. And this is the function that decides what to show which could be where Midori cannot parse it properly.

                          strawberry 3.141S 1 Reply Last reply Reply Quote 0
                          • strawberry 3.141S Offline
                            strawberry 3.141 Project Sponsor Module Developer @Mar
                            last edited by

                            @Mar that is also an es6 feature try classes.indexOf(self.current_profile) !== -1

                            Please create a github issue if you need help, so I can keep track

                            M 1 Reply Last reply Reply Quote 1
                            • M Offline
                              Mar @strawberry 3.141
                              last edited by Mar

                              @strawberry-3.141 Thanks, I couldnt figure that one out.

                              return classes.indexOf(self.current_profile) !== -1;
                              

                              Along with the changes in the previous post I’ve have fully loaded ProfileSwitcher Midori without any errors. It also is showing the correct modules on load (classes = default).

                              Thanks for the help through this @strawberry-3-141

                              Managed to figure this all out so thanks to everyone!

                              1 Reply Last reply Reply Quote 0
                              • tosti007T Offline
                                tosti007 Module Developer
                                last edited by

                                @strawberry-3-141 thank you for helping @Mar

                                @All @Mar I didn’t know that that browser doesn’t support those features. I will rewite those parts so then it should work out of the box.

                                If there is anything don't hesitate to contact me!
                                ProfileSwitcher, TouchNotifications

                                1 Reply Last reply Reply Quote 1
                                • tosti007T Offline
                                  tosti007 Module Developer
                                  last edited by

                                  @all I pushed a small update so that older browers should also be able to use this module.
                                  @Mar They are the same changes that you made.

                                  If there is anything don't hesitate to contact me!
                                  ProfileSwitcher, TouchNotifications

                                  M 1 Reply Last reply Reply Quote 1
                                  • M Offline
                                    Mar @tosti007
                                    last edited by

                                    @tosti007 Thanks for updating your module so quickly! and obviously thanks for taking the time to respond and maintain.

                                    1 Reply Last reply Reply Quote 1
                                    • tosti007T Offline
                                      tosti007 Module Developer
                                      last edited by

                                      @all Thanks to @roramirez we now have Spanish translations! :D

                                      If there is anything don't hesitate to contact me!
                                      ProfileSwitcher, TouchNotifications

                                      1 Reply Last reply Reply Quote 1
                                      • M Offline
                                        mortenbirkelund
                                        last edited by

                                        @tosti007 When switching between profiles, there is a short timespan where both the modules of the old profile and of the new profile, is present at the screen at the same time. Is there a way to ensure that the old modules fadeout first, and once they are gone, the new modules will fade in?

                                        tosti007T 1 Reply Last reply Reply Quote 0
                                        • tosti007T Offline
                                          tosti007 Module Developer @mortenbirkelund
                                          last edited by tosti007

                                          @mortenbirkelund Yes there is, however that would mean that the code has to loop over the modules twice, which isn’t a great thing to do performance wise. I will write a bit of code that does it for you and post it here soon.

                                          Edit: here is the code, all you need to do it replace the whole set_profile function inside the MMM-ProfileSwitcher.js file.

                                          The code:

                                          // Change the current layout into the new layout given the current profile
                                          set_profile: function (useEveryone) {
                                              var self = this;
                                          
                                              var options = {};
                                              if (self.config.useLockStrings) {
                                                  options.lockString = self.identifier;
                                              }
                                          
                                              MM.getModules().exceptWithClass(self.config.ignoreModules).enumerate(function (module) {
                                                  if (!self.isVisible(self, useEveryone, module.data.classes)) {
                                                      module.hide(self.config.animationDuration, function () {
                                                          Log.log(module.name + " is hidden.");
                                                      }, options);
                                                  }
                                              });
                                          
                                              MM.getModules().exceptWithClass(self.config.ignoreModules).enumerate(function (module) {
                                                  if (self.isVisible(self, useEveryone, module.data.classes)) {
                                                      module.show(self.config.animationDuration, function () {
                                                          Log.log(module.name + " is shown.");
                                                      }, options);
                                                  }
                                              });
                                          },
                                          

                                          Note: Once again this is not so great performance wise, but I dont think you will notice much of it

                                          If there is anything don't hesitate to contact me!
                                          ProfileSwitcher, TouchNotifications

                                          M 2 Replies Last reply Reply Quote 1
                                          • M Offline
                                            mortenbirkelund @tosti007
                                            last edited by

                                            @tosti007 Thank you very much. Very kind of you to create the code for me.

                                            I am new to using Git. How do i alter your my copy of your module, without risking that it will be overwritten on an update? Or is that not something that i should be concerned about?

                                            tosti007T 1 Reply Last reply Reply Quote 0

                                            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
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 2 / 5
                                            • 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