Replaces tracking removal with proper mem management

This commit is contained in:
Matt Way 2017-11-29 17:10:43 +10:00 committed by Cheng Zhao
parent 8df4402722
commit 5504294a6a

View file

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