From 601e2e95386c24befd12c77733e7cecab4ec39c1 Mon Sep 17 00:00:00 2001 From: Delisa Mason Date: Fri, 13 Nov 2015 08:44:10 -0800 Subject: [PATCH] Subscribe to launch notification synchronously There seems to be a (common) edge case where the subscription to the notification would be deferred until after the notification is fired. This change fixes it by subscribing immediately upon initialization and then deferring the menu item creation block instead as may be needed. --- Alcatraz/Alcatraz.m | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Alcatraz/Alcatraz.m b/Alcatraz/Alcatraz.m index 5755a63..e3ca011 100644 --- a/Alcatraz/Alcatraz.m +++ b/Alcatraz/Alcatraz.m @@ -52,24 +52,22 @@ + (NSString *)localizedStringForKey:(NSString *)key { - (id)initWithBundle:(NSBundle *)plugin { if (self = [super init]) { self.bundle = plugin; - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(xcodeDidFinishLaunching:) - name:NSApplicationDidFinishLaunchingNotification - object:nil]; - }]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(xcodeDidFinishLaunching:) + name:NSApplicationDidFinishLaunchingNotification + object:nil]; [self updateAlcatraz]; } return self; } -- (void) xcodeDidFinishLaunching: (NSNotification *) notification { - [self createMenuItem]; - +- (void)xcodeDidFinishLaunching: (NSNotification *) notification { [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidFinishLaunchingNotification object:nil]; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [self createMenuItem]; + }]; } #pragma mark - Private