Repository navigation
fix: make tray not block main process - #18880
Conversation
3aea900 to
76f15c3
Compare
76f15c3 to
c019cd2
Compare
c019cd2 to
3acbd09
Compare
|
Release Notes Persisted
|
|
I was unable to backport this PR to "6-0-x" cleanly; |
|
I was unable to backport this PR to "4-2-x" cleanly; |
|
I was unable to backport this PR to "5-0-x" cleanly; |
* fix: make tray not block main process * make AtomMenuModel refcounted
|
A maintainer has manually backported this PR to "6-0-x", please check out #18969 |
deepak1556
left a comment
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@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.
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* fix: make tray not block main process * make AtomMenuModel refcounted
* 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
Description of Change
Fixes #13820.
When running this gist, previously
Awould print and thenBwould 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,
AandBare printed successively to console while the tray is open:cc @miniak @deepak1556 @MarshallOfSound @nornagon
Checklist
npm testpassesRelease Notes
Notes: Fixed an issue where the Tray icon context menu on macOS blocked the main process while open.