MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.24.0 is available! For more information about this release, check out this topic.

    Send existing Notifications from a script

    Development
    3
    15
    617
    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.
    • thetobyde
      thetobyde last edited by

      Hey 🙂
      I want to re-write the “MMM-SmartTouch” Module to have an “App-Dock-Bar”. I was able to change the CSS file to have this look now:

      neu1.JPG

      I also was able to add the first 4 buttons with costom icons. I want to have these icons to change the pages with “MMM-pages”.
      The pages module listens on these Notifications: PAGE_CHANGED, pageNumber

      But I cant get it to work. This is my smartTouch.js and my nodeHelper:

      MMM-smartTouch.js :

      //Main Menu Bar
              var main_menu = document.createElement("div");
              main_menu.className = "main-menu"
              main_menu.id = "navbar"
              home_div.appendChild(main_menu)
              var main_menu_ul = document.createElement("ul");
              main_menu_ul.className = "navbar-nav"
              main_menu.appendChild(main_menu_ul)
      
      	//Page 1 (Home Screen)
              var main_menu_li_restart = document.createElement("span");
              main_menu_li_restart.innerHTML = "<span class='fas fa-home fa-3x'></span>" + "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
              main_menu_li_restart.className = "li-t"
              main_menu_ul.appendChild(main_menu_li_restart)
              main_menu_li_restart.addEventListener("click", () => this.sendSocketNotification("PAGEONE", {}));
      
      	//Page 2 (Wetter)
              var main_menu_li_restart = document.createElement("span");
              main_menu_li_restart.innerHTML = "<span class='fas fa-cloud-sun fa-3x'></span>" + "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
              main_menu_li_restart.className = "li-t"
              main_menu_ul.appendChild(main_menu_li_restart)
              main_menu_li_restart.addEventListener("click", () => this.sendSocketNotification("SHUTDOWN", {}));
      
      	//Page 3 (Drive Bilder)
              var main_menu_li_restart = document.createElement("span");
              main_menu_li_restart.innerHTML = "<span class='far fa-image fa-3x'></span>" + "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
              main_menu_li_restart.className = "li-t"
              main_menu_ul.appendChild(main_menu_li_restart)
              main_menu_li_restart.addEventListener("click", () => this.sendSocketNotification("SHUTDOWN", {}));
      
      	//Page 4 (Party Bilder)
              var main_menu_li_restart = document.createElement("span");
              main_menu_li_restart.innerHTML = "<span class='far fa-image fa-3x'></span>" + "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
              main_menu_li_restart.className = "li-t"
              main_menu_ul.appendChild(main_menu_li_restart)
              main_menu_li_restart.addEventListener("click", () => this.sendSocketNotification("SHUTDOWN", {}));
              
              //Power Off Button
              var main_menu_li_shutdown = document.createElement("span");
              main_menu_li_shutdown.innerHTML = "<span class='fa fa-power-off fa-3x'></span>" + "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
              main_menu_li_shutdown.className = "li-t"
              main_menu_ul.appendChild(main_menu_li_shutdown)
      
              //Onclick event to send shutdown notification
              main_menu_li_shutdown.addEventListener("click", () => this.sendSocketNotification("SHUTDOWN", {}));
      
              //Restart Button
              var main_menu_li_restart = document.createElement("span");
              main_menu_li_restart.innerHTML = "<span class='fa fa-repeat fa-3x'></span>" + "&nbsp" + "&nbsp" + "&nbsp" + "&nbsp";
              main_menu_li_restart.className = "li-t"
              main_menu_ul.appendChild(main_menu_li_restart)
              main_menu_li_restart.addEventListener("click", () => this.sendSocketNotification("RESTART", {}));
      
      

      and my nodeHelper.js:

      if (notification === "PAGEONE") {
                    console.log("Page1!")
                    require('child_process').this.sendSocketNotification("PAGE_CHANGED", 1);
                }
      
      	  if (notification === "SHUTDOWN") {
                    console.log("Shutting Down!")
                    require('child_process').exec('shutdown -h now', console.log)
                }
      
                if (notification === "RESTART") {
                    console.log("Restarting Magic Mirror!")
                    require('child_process').exec('sudo reboot', console.log)
                }
      

      nothing happens when i touch the first (Page1) icon…

      Thx for help! 🙂 Toby

      S 2 Replies Last reply Reply Quote 0
      • S
        sdetweil @thetobyde last edited by sdetweil

        @thetobyde in your click handlers, ‘this’ points to the button causing the click.

        this is why we do
        var self=this
        and use self. in handlers and callbacks
        instead of this.

        you should see the error reported in the developers window console

        Sam

        Create a working config
        How to add modules

        thetobyde 1 Reply Last reply Reply Quote 0
        • thetobyde
          thetobyde @sdetweil last edited by thetobyde

          @sdetweil thx for the fast answer. I change „this.send…“ to „self.send…“ but did not work sadly… i also changed the payload from 1 to 0, because the notifications from MMM-pages are zero-based. So page 1 is PAGE_CHANGED, 0…

          The var self = this is written by the Developer of MMM-SmartTouch

          S 1 Reply Last reply Reply Quote 0
          • S
            sdetweil @thetobyde last edited by

            @thetobyde did step thru the code w the developers window source tab?

            Sam

            Create a working config
            How to add modules

            1 Reply Last reply Reply Quote 0
            • S
              sdetweil last edited by sdetweil

              u changed the code here from this. to self.
              => this.sendSocketNotification("SHUTDOWN
              and all similar

              Sam

              Create a working config
              How to add modules

              thetobyde 2 Replies Last reply Reply Quote 0
              • thetobyde
                thetobyde @sdetweil last edited by

                @sdetweil i changed the code in the nodeHelper from this. to self.

                1 Reply Last reply Reply Quote 0
                • thetobyde
                  thetobyde @sdetweil last edited by

                  @sdetweil
                  meinCode

                  Like this 🙂

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    sdetweil @thetobyde last edited by

                    @thetobyde and the module code with the buttons?

                    Sam

                    Create a working config
                    How to add modules

                    thetobyde 1 Reply Last reply Reply Quote 0
                    • thetobyde
                      thetobyde @sdetweil last edited by

                      @sdetweil didt change that because it worked for the pre-existing Shutdown and Reboot button from the developer of MMM-smartTouch… isnt it right?

                      1 Reply Last reply Reply Quote 0
                      • S
                        sdetweil @thetobyde last edited by

                        @thetobyde said in Send existing Notifications from a script:

                        require('child_process').this.sendSocketNotification("PAGE_CHANGED", 1);
                        

                        well, you are not launching a program to chnage the page, and don’t need to send this down to the node_helper
                        as he has to send it back up to the module to send the notfication,

                        just do the sendNotification from the module (note its not sendsocketNotification(to my node helper) , just sendNotification(to other modules)

                        Sam

                        Create a working config
                        How to add modules

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy