Check-Menus.com

electron dynamic menu

by Prof. Brad Schumm Published 3 years ago Updated 2 years ago
image

Toggling an Electron menu item dynamically is quite simple, though not immediately clear from the official documentation. In an Electron app, the application menu consists of items such as File, Edit, View, and so on. Beside the standard menus found in most applications, you can also create your own menu entries with custom functionality.

Full Answer

How do you use the electron menu?

The desktop apps come with two types of menus – the application menu(on the top bar) and a context menu(right-click menu). We will learn how to create both of these in this chapter. We will be using two modules – the Menu and the MenuItem modules.

How do you hide an electron menu?

To remove menu bar from Electron app, we can set the autoHideMenuBar to true . to create a BrowserWindow instance by passing in an object with autoHideMenuBar set to true . As a result, the menu bar would be hidden in the app.

What is Electron kiosk mode?

Kiosk mode is a common way to lock down a Windows device when that device is used for a specific task or used in a public setting. So in electron kiosk mode, we'd have the ability to lock down our application to a point that users are restricted to the actions that we want them to perform.

How do I turn off DevTools in Electron app?

To open DevTools, use the shortcut "Ctrl+Shift+I" or the key. You can check out how to use devtools here.

Case study

I'm building SVGX, an Electron + Svelte app. I have a code area that I can edit. When the original code is modified, an 🟠 orange dot appears along with a revert icon. Clicking the icon reverts the code to the original state.

Main vs Renderer process

You can read more about the Main and Renderer processes in the official documentation, but here's how they fit into this scenario.

The solution

For simplicity, I will show only 3 of the modules involved in this process: index.js, menu.js, CodePane.svelte, and will strip out most of the code, except for the relevant bits.

Conclusion

I was stumped initially by how to enable and disable an Electron menu dynamically, but was certain there had to be a way.

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9