Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Menus, Application M | Electron.js Desktop App Development l | BraveProgrammer
  1. Courses
  2. /
  3. Electron.js Desktop App Development

Lesson 27 of 28

·javascript

Menus, Application Menu & Tray Icons

10 mins

Course progress96%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `Menu` and `MenuItem` let you build native menus that work on macOS, Windows and Linux.
  • Use the `role` property for common actions (`quit`, `undo`, `copy`, …).
  • `Tray` creates a persistent icon in the system tray / menu bar.

Menus, Application Menu & Tray Icons

Create a native menu:

const { Menu } = require('electron');
const template = [
  {
    label: 'File',
    submenu: [
      { role: 'quit' }
    ]
  },
  {
    label: 'Edit',
    submenu: [
      { role: 'undo' },
      { role: 'redo' },
      { type: 'separator' },
      { role: 'copy' },
      { role: 'paste' }
    ]
  }
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);

Tray (system‑level icon):

const { Tray, nativeImage } = require('electron');
let tray = null;
app.whenReady().then(() => {
  const icon = nativeImage.createFromPath('assets/tray.png');
  tray = new Tray(icon);
  tray.setToolTip('My Electron App');
  tray.setContextMenu(Menu.buildFromTemplate([
    { label: 'Show', click: () => win.show() },
    { label: 'Quit', click: () => app.quit() }
  ]));
});
Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Electron.js Desktop App DevelopmentBrowse activities
Previous lessonLoading Local HTML, Remote URLs & Custom ProtocolsContinue to lesson 28Inter‑process Communication (IPC)Back to Electron.js Desktop App Development curriculum