Merge pull request #11272 from syntropy-ai/1-7-x

Removed tracking area for tray to prevent mouse leave race condition crash
This commit is contained in:
Cheng Zhao 2018-01-10 13:13:10 +09:00 committed by GitHub
commit 143816bee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,6 +33,7 @@ const CGFloat kVerticalTitleMargin = 2;
base::scoped_nsobject<NSString> title_;
base::scoped_nsobject<NSMutableAttributedString> attributedTitle_;
base::scoped_nsobject<NSStatusItem> statusItem_;
base::scoped_nsobject<NSTrackingArea> trackingArea_;
}
@end // @interface StatusItemView
@ -61,12 +62,12 @@ const CGFloat kVerticalTitleMargin = 2;
[self updateDimensions];
// Add NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove events
auto trackingArea = [[[NSTrackingArea alloc]
trackingArea_.reset([[NSTrackingArea alloc]
initWithRect:[self bounds]
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways
owner:self
userInfo:nil] autorelease];
[self addTrackingArea:trackingArea];
userInfo:nil]);
[self addTrackingArea:trackingArea_];
}
return self;
}
@ -78,6 +79,11 @@ const CGFloat kVerticalTitleMargin = 2;
}
- (void)removeItem {
// Turn off tracking events to prevent crash
if (trackingArea_) {
[self removeTrackingArea:trackingArea_];
trackingArea_.reset();
}
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
statusItem_.reset();
}