Veldrovive / MMM-Page-Selector

An easy way to set up and move between pages on a MagicMirror²
MIT License
35 stars 6 forks source link

Commands with functions #22

Closed djfattius closed 5 years ago

djfattius commented 5 years ago

Veldrovive-

Great job on Voice-Commands and Page-Selector. I don't know if this issue is with Voice-Commands for Page-Selector. So I will start here.

I cannot get voice commands with a function to work. I did some debug and I see that any commands that includes functions are not written out to the temp config.js created by Page Selector. I do not know if my syntax for creating the function is wrong and Page Selector doesn't recognize it, or if there is an issue with page selector.

Sample from original config.js:

commands: {
    "the eagle is on *page": "PAGE_SELECT",
    "Go to page *pagename": function(param){ 
        this.sendNotifications("PAGE_SELECT", param);
    }
}

Sample from temp config.js created by Page Selector:

"commands": {
    "the eagle is on *page": "PAGE_SELECT"
}

Full sample uploaded.

config.js.txt

I'm sure I'm crazy or using bad syntax. I simply can't get the config.js created by Page Selector to show any commands with functions.

Your input is greatly appreciated.

DJ Fattius

Veldrovive commented 5 years ago

Ah, this is a known problem with MMM-Page-Selector. I thought I had added it to the README but I guess not. In order to render modules that are not assigned a position, MMM-Page-Selector copies and edits the config.js to a new file, but unfortunately, this means that functions are deleted in the process. I may be able to fix this, but I have not as of yet. For now, the solution is to define positions for every module in its own config. This is more confusing syntax which is why I changed it in the first place, but it fixes this problem since making a temp config is unnecessary in that case.

djfattius commented 5 years ago

Veldrovive-

Thank you! I appreciate the confirmation. I will use the other syntax. Can't wait to get this rolling.

Thanks again-

DJ Fattius

Veldrovive commented 5 years ago

Hey, I updated the module so this wouldn't be an issue. If you get the latest commit, it should work even if you having functions in your config.js.

What happened under the hood is that I specified a new way to transform the json into a string that also serializes functions so that the temp config is an exact copy of the original config just with position props added.

djfattius commented 5 years ago

Hey Veldrovive-

It works great! Thanks for the quick turn-around!

DJ Fattius