Skip to content

fix: make tray not block main process - #18880

Merged
codebytere merged 2 commits into
masterfrom
make-tray-not-block
Jun 25, 2019
Merged

codebytere merged 2 commits into
masterfrom
make-tray-not-block

Conversation

@codebytere

@codebytere codebytere commented Jun 19, 2019 •

Copy link
Copy Markdown
Member

Description of Change

Fixes #13820.

When running this gist, previously A would print and then B would only print to console after the tray had been closed. This PR fixes that issue by posting a task and allowing events to be pumped while the tray is open.

After this fix, A and B are printed successively to console while the tray is open:

Screen Shot 2019-06-19 at 9 10 08 AM

cc @miniak @deepak1556 @MarshallOfSound @nornagon

Checklist

Release Notes

Notes: Fixed an issue where the Tray icon context menu on macOS blocked the main process while open.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jun 19, 2019
@codebytere
codebytere force-pushed the make-tray-not-block branch 3 times, most recently from 3aea900 to 76f15c3 Compare June 20, 2019 14:57
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jun 20, 2019
Comment thread shell/browser/ui/tray_icon_cocoa.mm Resolved
@codebytere
codebytere force-pushed the make-tray-not-block branch from 76f15c3 to c019cd2 Compare June 24, 2019 18:09
@codebytere
codebytere force-pushed the make-tray-not-block branch from c019cd2 to 3acbd09 Compare June 24, 2019 20:20
@codebytere
codebytere merged commit dc2cd8e into master Jun 25, 2019
@release-clerk

release-clerk Bot commented Jun 25, 2019

Copy link
Copy Markdown

Release Notes Persisted

Fixed an issue where the Tray icon context menu on macOS blocked the main process while open.

@codebytere
codebytere deleted the make-tray-not-block branch June 25, 2019 02:30
@trop

trop Bot commented Jun 25, 2019

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "6-0-x" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Jun 25, 2019

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "4-2-x" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Jun 25, 2019

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "5-0-x" cleanly;
you will need to perform this backport manually.

codebytere added a commit that referenced this pull request Jun 25, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
@trop

trop Bot commented Jun 25, 2019

Copy link
Copy Markdown
Contributor

A maintainer has manually backported this PR to "6-0-x", please check out #18969

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. A few questions with the changes.


class AtomMenuModel : public ui::SimpleMenuModel {
class AtomMenuModel : public ui::SimpleMenuModel,
public base::RefCounted<AtomMenuModel> {

@deepak1556 deepak1556 Jun 25, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of reference counting, and in this specific case there doesn't seem to be a necessity. The task is not posted against a different sequence, rather just passes the object around in the same sequence and there is null check in popUpContextMenu which should be sufficient.

@codebytere codebytere Jun 25, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepak1556 the reason I chose to refcount it was that a valid (non-null) pointer can be posted to the same sequence and then synchronously destroyed from JavaScript:

  const tray = new Tray(/path/to/icon)

  const contextMenu = Menu.buildFromTemplate([
    { label: 'Item1', type: 'radio' },
    { label: 'Item2', type: 'radio' },
    { label: 'Item3', type: 'radio', checked: true },
    { label: 'Item4', type: 'radio' }
  ])

  tray.popUpContextMenu(contextMenu)
  tray.destroy()

which results in a use-after-free crash and which a null check would do nothing to prevent since it'd be a valid pointer and thus pass the check.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codebytere that shouldn't be a case to keep the class alive rather if the user destroyed it then we should respect it. We should use a base::WeakPtr rather than refcounting to have the right behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok! i can address that here: #18977

Comment thread shell/browser/ui/tray_icon_cocoa.mm Resolved
Comment thread shell/browser/ui/tray_icon_cocoa.mm Resolved
codebytere added a commit that referenced this pull request Jun 25, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
codebytere added a commit that referenced this pull request Jun 26, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
codebytere added a commit that referenced this pull request Jun 26, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jun 26, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jun 26, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
codebytere added a commit that referenced this pull request Jun 27, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
ckerr pushed a commit that referenced this pull request Jun 28, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
trop Bot pushed a commit that referenced this pull request Jun 28, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
trop Bot pushed a commit that referenced this pull request Jun 28, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
codebytere pushed a commit that referenced this pull request Jun 28, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jul 2, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jul 2, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jul 10, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jul 18, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
deermichel pushed a commit that referenced this pull request Jul 31, 2019
* fix: make tray not block main process

* make AtomMenuModel refcounted
MarshallOfSound pushed a commit that referenced this pull request Jul 31, 2019
* restore stash

revert

some things work others dont

tracking area for rescue

manual popup

restore drag n drop

cleanup

* fix: make tray not block main process (#18880)

* fix: make tray not block main process

* make AtomMenuModel refcounted

* add support for ansi codes in title

add remove TODOs

* chore: use ScopedPumpMessagesInPrivateModes in tray (#18977)

* chore: use ScopedPumpMessagesInPrivateModes in tray

* revert refcounting of AtomMenuModel

* Prefer WeakPtr for posting tasks to handle unexpected destruction

* cleanup .h

* cleanup .mm

* add imports

add missing include

* fix: crash when tray popup called twice (#18999)

* remove highlightMode and TODOs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tray.popUpContextMenu blocks javascript main thread on mac

3 participants