Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Commit

Permalink
Subscribe to launch notification synchronously
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kattrali committed Nov 13, 2015
1 parent 8fd26cd commit 601e2e9
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Alcatraz/Alcatraz.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 601e2e9

Please sign in to comment.