Change MenuItem label dynamically?


Is it possible to change a MenuItem label dynamically? If not, what is recommended if I have that need?


I’m personally a fan of ractive js for this purpose. You should be able to set your menu item label to a ractive variable and use ractive.set to change it dynamically. I do this in my app using the web contents executeJavaScript function. Just keep in mind that you can’t require ractive in your main process, only your renderer one. I’ve generally found it’s easier to get this to work if you include the ractive parts of your javascript in script tags in your html. I’m sure there’s a way around this if you really needed it.


That’s a pretty good idea.

I know a little bit about the whole reactive observable variables ideology, but I’ve not delved too deeply. So is it a case of setting a MenuItem based on an observed variable, and then building your MenuBar from an array of MenuItems as usual?

I’ve just finished writing my code for building and rebuilding my MenuBar, happens when users log in and out, because anything highly configurable is overkill. But this seems like a much better alternative, without the mass of pushes I’m doing to a big, ugly template object.