Skip to content

Tray icon not shown (macos) #27128

@jerrygreen

Description

@jerrygreen

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version: v11.1.0
  • Operating System: macOS Big Sur 11.0.1
  • Last Known Working Electron version: not sure

Expected Behavior

Tray icon to appear when I'm opening my electron app.

Actual Behavior

Tray icon isn't showing

To Reproduce

Use this function:

import { Tray, Menu, app, BrowserWindow } from 'electron'
import path from 'path'

export default (win: BrowserWindow) => {
  let appIcon = new Tray(path.join(__dirname, 'images/logo.png'))
  const contextMenu = Menu.buildFromTemplate([
    {
      label: 'Show',
      click: () => {
        win.show()
      },
    },
    {
      label: 'Exit',
      click: () => {
        ;(win as any).isQuiting = true
        app.quit()
      },
    },
  ])

  appIcon.on('click', (event) => {
    if (win.isVisible() && !win.isMinimized()) {
      win.hide()
    } else {
      win.show()
    }
  })
  appIcon.setToolTip('Test')
  appIcon.setContextMenu(contextMenu)
  appIcon.setIgnoreDoubleClickEvents(true)
  return appIcon
}

Inside the place where you create a BrowserWindow, like this:

  win = new BrowserWindow(browserOptions)

  win.on('close', (event) => {
    if (!isProd || win.isQuiting) {
      saveState()
    } else {
      event.preventDefault()
      win.hide()
    }
  })

  win.tray = createTray(win)

Since it's placed into win object, it is not garbage collected.

Additional Information

It works perfectly on windows: tray icon is shown, everything works as intended. But on macos tray icon isn't shown by some reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions