Skip to content

Tray setContext #14188

Closed
Closed

Description

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

Expected Behavior
Once you set a tray context menu, you expect to a) detect the click, right-click and double-click events.

You also expect to be able to change the menu to original state (no menu).

Actual behavior

Once you set a context menu, you can't remove the context menu. You can change it to another menu though.

If you leave out the argument to setContextMenu or pass null, it will crash.
You also lose access to the events.

Activity

  1. codebytere commented on Aug 19, 2018

    @codebytere
    Member

    @pjebs can you potentially attach a minimal crash repro? i can take a look at it monday :)

  2. pjebs commented on Aug 19, 2018

    @pjebs
    Author

    No crashes. Just unexpected behaviour.

    Stated another way:

    Once you set a context menu, you can't remove it. You can change it to another menu (including an "empty" menu).

    Once you set a context menu, you also lose the ability to receive click... events. When you set it to an "empty" menu, those events are still not received, implying that the "empty" menu is not equivalent to the initial state ("no menu"), where you can receive the click... events.

  3. self-assigned this
    on Aug 27, 2018
  4. miniak commented on Aug 27, 2018

    @miniak
    Contributor

    @pjebs I have a fix in the attached PR. @codebytere I have a local repro.

  5. miniak commented on Aug 27, 2018

    @miniak
    Contributor

    Minimal repro using the console in default_app

    var {Menu, Tray, nativeImage} = require('electron').remote
    var tray = new Tray(nativeImage.createEmpty())
    tray.setContextMenu(null)
    
  6. pjebs commented on Aug 27, 2018

    @pjebs
    Author

    @miniak Thank you for the pull-request.
    What does your fix do? Accept null value and still receive events?

  7. codebytere commented on Aug 27, 2018

    @codebytere
    Member

    @pjebs that's what i meant originally:

    If you leave out the argument to setContextMenu or pass null, it will crash.

    but then,

    No crashes. Just unexpected behavior.

    It did crash, as you said yourself, but it was unclear what issue you were specifically seeking a fix for.

  8. pjebs commented on Aug 27, 2018

    @pjebs
    Author

    @codebytere With the fix, when you pass null (or just call setContext generally), will the click, right-click and double-click events be received? That's what I meant to ask. The bug I was highlighting was that the events cease to be received once you call setContext.

  9. pjebs commented on Aug 28, 2018

    @pjebs
    Author

    I'm using "electron": "^2.0.8". Is the fix applied for this version because the bug is still there.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions