File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -173,8 +173,16 @@ - (void)popUpContextMenu:(electron::AtomMenuModel*)menu_model {
173173 useDefaultAccelerator: NO ]);
174174 // Hacky way to mimic design of ordinary tray menu.
175175 [statusItem_ setMenu: [menuController menu ]];
176+ // -performClick: is a blocking call, which will run the task loop inside
177+ // itself. This can potentially include running JS, which can result in
178+ // this object being released. We take a temporary reference here to make
179+ // sure we stay alive long enough to successfully return from this
180+ // function.
181+ // TODO(nornagon/codebytere): Avoid nesting task loops here.
182+ [self retain ];
176183 [[statusItem_ button ] performClick: self ];
177184 [statusItem_ setMenu: [menuController_ menu ]];
185+ [self release ];
178186 return ;
179187 }
180188
Original file line number Diff line number Diff line change @@ -51,6 +51,13 @@ describe('tray module', () => {
5151 } )
5252 tray . popUpContextMenu ( )
5353 } )
54+
55+ it ( 'can be called with a menu' , ( ) => {
56+ const menu = Menu . buildFromTemplate ( [ { label : 'Test' } ] )
57+ expect ( ( ) => {
58+ tray . popUpContextMenu ( menu )
59+ } ) . to . not . throw ( )
60+ } )
5461 } )
5562
5663 describe ( 'tray.getBounds()' , ( ) => {
You can’t perform that action at this time.
0 commit comments