Skip to content

tray.popUpContextMenu blocks javascript main thread on mac #13820

Closed

Description

@pjebs
  • Electron Version: latest
  • Operating System (Platform and Version): mac
  • Last known working Electron version: n/a

Expected Behavior
When the tray icon menu is popped up manually (but on a tray click event callback), I expect the menu to open up but not necessarily block the main process.

Actual behavior
It blocks the main process until the menu is closed. This is creating issues with other timers etc that I have running on the main process.

Activity

  1. pjebs commented on Jul 26, 2018

    @pjebs
    Author

    An async version would be great

  2. pjebs commented on Jul 26, 2018

    @pjebs
    Author

    I think it's related to #1854 but my issue has nothing to do with render process.

  3. pjebs commented on Jul 26, 2018

    @pjebs
    Author

    @kevinsawicki would this be hard to implement for tray?: #8702

  4. pjebs commented on Jul 27, 2018

    @pjebs
    Author

    @sofianguy For #1854, @zcbenz labelled it a "bug" and removed "enhancement". This issue should also be labelled a "bug".

  5. self-assigned this
    on Aug 1, 2018
  6. zhenchaoli commented on Aug 8, 2018

    @zhenchaoli

    Hmm, I tried to reproduce the issue with both 2.0.6 and 3.0.0-beta2 but could not. Here's what I did:

    tray.js

    const {app, Menu, Tray, BrowserWindow } = require('electron')
    
    let tray = null
    app.on('ready', () => {
        tray = new Tray('/Users/zhenchao/Desktop/icon.png')
        const contextMenu = Menu.buildFromTemplate([
            {label: 'Item1', type: 'radio'},
            {label: 'Item2', type: 'radio'},
            {label: 'Item3', type: 'radio', checked: true},
            {label: 'Item4', type: 'radio'}
        ])
        tray.setToolTip('This is my application.')
        tray.setContextMenu(contextMenu)
    
        let win = new BrowserWindow();
        win.loadURL('https://www.youtube.com');
    
        setInterval(() => { console.log('test'); }, 1000);
    })
    
    

    I uploaded a screen recording of what I did here: https://youtu.be/_tzUf631dQE

    As you can see, timers in main process, console as well as video playbacks are not blocked.

    @pjebs can you provide some more details about how this can be reproduced?

  7. pjebs commented on Aug 9, 2018

    @pjebs
    Author

    Try popUpContextMenu on a tray click event callback

  8. ckerr commented on Aug 9, 2018

    @ckerr
    Member

    if one of y'all could make a fork of https://github.com/electron/electron-quick-start that repros this, that would be great. I like @fantasticsid's approach of using a simple timer to display whether or not something's blocked!

  9. added
    status/reviewed
    on Aug 9, 2018
  10. pjebs commented on Aug 10, 2018

    @pjebs
    Author
    const {
        app,
        Menu,
        Tray,
        BrowserWindow
    } = require('electron')
    
    let tray = null
    app.on('ready', () => {
        tray = new Tray("/Users/X/Developer/Y/desktop-app/app/assets/img/tray/trayTemplate.png")
        const contextMenu = Menu.buildFromTemplate([{
                label: 'Item1',
                type: 'radio'
            },
            {
                label: 'Item4',
                type: 'radio'
            }
        ])
    
        tray.on('click', () => {
            console.log("A")
            tray.popUpContextMenu(contextMenu)
    
            console.log("B") // Doesn't reach here until popup menu is closed
        })
    
        let win = new BrowserWindow();
        win.loadURL('https://www.youtube.com');
    
        setInterval(() => {
            console.log('test');
        }, 1000);
    })
    

    console.log('b') is not printed out until after menu is closed.

  11. 1 remaining item

  12. zhenchaoli commented on Aug 10, 2018

    @zhenchaoli

    @pjebs I'm seeing the same behavior :) my knowledge about runloop is lacking but I'll take a further look

  13. pjebs commented on Aug 16, 2018

    @pjebs
    Author

    @ckerr @codebytere If I need to find a freelancer to fix this bug, what skills should they have? Should I require them to be skilled in Objective-C++ or Objective-C? I don't have a Windows PC. Does this bug exist in Windows? If so, what skills should they have for windows? Is it C#?

  14. removed their assignment
    on Sep 30, 2018
  15. added
    status/confirmed
    and removed
    status/reviewed
    on Nov 14, 2018
  16. self-assigned this
    on Nov 14, 2018
  17. pjebs commented on May 24, 2019

    @pjebs
    Author

    Has this been fixed for Electron 5?

  18. codebytere commented on Jun 19, 2019

    @codebytere
    Member

    @pjebs no, but i've just jumped up a PR for it so i'll plan to backport it to all supported release lines :)

  19. pjebs commented on Jun 20, 2019

    @pjebs
    Author

    @codebytere Can you take a look at #14036 this again.
    I don't believe it's been fixed. In fact, you can use the official electron sampler to see the application crash: https://github.com/electron/electron-api-demos/blob/2a8c1f46b582b2762c2cf0afc7559082726255b5/main-process/native-ui/tray/tray.js#L23

  20. pjebs commented on Jun 25, 2019

    @pjebs
    Author

    @miniak The vaguely related issue of #14036 is not fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

2-0-xbug 🪲platform/macOSstatus/confirmed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions