Electron App Shows Electron On Mac Menu Bar Rating: 5,6/10 6824 reviews
  • Electron Tutorial

Timing’s smart timeline shows you exactly what you did at any given time, including which app, document or website you were using. And it even makes suggestions for blocks of time that belong together — just click the '+' button to assign a whole block at once! This lets you assign many hours of tracked time in just a few seconds. May 04, 2017  Many developers are now using Electron to build desktop utilities and even menubar widgets (those little pop-up menus that live in the top-right corner of the Mac menu bar. Note that the application menu is hidden by default for a minimal UI. You can press the alt keyboard key to access it. How it works. Simple drawing software for mac free. A template app with the appropriate plumbing is included in the./app folder. When nativefier is run, this template is parameterized, and packaged using Electron Packager. Building a Node application for all three platforms is pretty easy and I have done that a million times. Building my Electron app for Windows and Linux using the electron-builder is no rocket science either. In theory they should also run on MacOS. However I have never actually built an Electron app for MacOS.

  • Electron Useful Resources
  • Selected Reading

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. Note that the Menu and the MenuItem modules are only available in the main process. For using these modules in the renderer process, you need the remote module. We will come across this when we create a context menu.

Jan 22, 2018  Without a taskbar, it can be difficult for ex-Windows users to discern which programs are open on a Mac and how to switch between them. Thankfully, Apple provides a. Mac Jun 27, 2019  When you’re working on your Mac, the simplest shortcuts can help you do things faster and easier. Whether it’s gestures or keyboard shortcuts, there are plenty of ways to navigate your Mac and your apps. So, for more to add to your list of shortcuts, here’s how to quickly switch between windows and apps on Mac.

Now, let us create a new main.js file for the main process −

We are building a menu from a template here. This means that we provide the menu as a JSON to the function and it will take care of the rest. Now we have to set this menu as the Application menu.

Now create an empty HTML file called index.html and run this application using −

On the normal position of application menus, you will see a menu based on the above template.

We created this menu from the main process. Let us now create a context menu for our app. We will do this in our HTML file −

We imported the Menu and MenuItem modules using the remote module; then, we created a menu and appended our menuitems to it one by one. Further, we prevented the default action of right-click in chromium and replaced it with our menu.

The creation of menus in Electron is a very simple task. Now you can attach your event handlers to these items and handle the events according to your needs.

This tutorial shows you how to add an Electron menu to your app. It will also make standard keyboard shortcuts, like copy and paste, work on MacOS.

We’ve actually got our work pretty much done for us thanks to the Electron documentation giving us a good template to use. We just need to implement and do some changes to it (If you want to that is). As always this tutorial uses Electron tutorial app as a canvas so you can download and/or look at the code on github.

1.Adding the menu

Open up a new file and paste this menu definition to it (this is the code from the documentation, with minor adjustments):

Save this in a new folder called menu, and why not name the file mainmenu.js

If you take a look at the two last lines in mainmenu.js you see two calls, one to buildFromTemplate(), which basically takes the array defined above, and creates a menu from it. Then we pass the menu to setApplicationMenu()

2. Showing the menu in the app

Now open up main.js and add require(‘./menu/mainmenu’) after creating the window. In the Electron tutorial app it is added to line 45, right before closing the createWindow function. We add it there because the call to setApplicationMenu needs to been done after the ready event is fired. Which it has in createWindow.

If you start the app now, you can see that you have a different menu already.

3. Menu items

Let us look at what the mainmenu.js contains. It’s an array that defines MenuItems.

Label

Labels are what the menu item will say when it is displayed. It is required to set when you are defining a menu item that does not use Role(which we will look at soon). You can use this when localizing your menu items.

Submenu

A submenu is what you think it is. It is an array containing menuitems for a submenu.

Role

Electron provides us with roles that are predefined for Platform specific menu items such as undo, redo and those standard functions. The existing roles are:

  • undo
  • redo
  • cut
  • copy
  • paste
  • pasteandmatchstyle
  • selectall
  • delete
  • minimize - Minimize current window
  • close - Close current window
  • quit - Quit the application
  • togglefullscreen - Toggle full screen mode on the current window
  • resetzoom - Reset the focused page’s zoom level to the original size
  • zoomin - Zoom in the focused page by 10%
  • zoomout - Zoom out the focused page by 10%
Electron app shows electron on mac menu bar dock

On macOS role can also have following additional values:

  • about - Map to the orderFrontStandardAboutPanel action
  • hide - Map to the hide action
  • hideothers - Map to the hideOtherApplications action
  • unhide - Map to the unhideAllApplications action
  • startspeaking - Map to the startSpeaking action
  • stopspeaking - Map to the stopSpeaking action
  • front - Map to the arrangeInFront action
  • zoom - Map to the performZoom action
  • window - The submenu is a “Window” menu
  • help - The submenu is a “Help” menu
  • services - The submenu is a “Services” menu

When specifying role on macOS, label and accelerator are the only options that will affect the MenuItem. All other options will be ignored.

Accelerator

If you scroll down a bit in mainmenu.js to line 43 you can see something called accelerator. With the accelerator you can add keyboard shortcuts to your menu item. Built in accelerators are:

  • Command (or Cmd for short)
  • Control (or Ctrl for short)
  • CommandOrControl (or CmdOrCtrl for short)
  • Alt
  • Option
  • AltGr
  • Shift
  • Super

One interesting accelerator to look at is the CommandOrControl. It uses the command button on macs, but on windows it maps to control instead since Windows doesn’t use the command button.

click

When a menuItem is clicked you can define what code will be executed by defining a click event.

Type

Electron App Shows Electron On Mac Menu Bar Dock

Shows

Electron App Shows Electron On Mac Menu Bar Settings

You can se a type to a menuitem, a type can for example be a separator. If you look at line 56 in mainmenu.js you can see it being used. But there are more types defined:

  • type String - Can be normal, separator, submenu, checkbox or radio.

Read more

Electron App Shows Electron On Mac Menu Bar Download

To learn more about this topic you can read about Menu and MenuItem in the official docs. You can also take a look at the implemented menu on the Electron tutorial app repository on github

Next step in this tutorial series walks you through how to translate the menu and the rest of your electron app

Electron On Mac

I hope you find this post valuable. If you click the ad below I get paid by someone else and can continue to publish posts for free. I would appreciate it very much.