Permalink
Browse files

Fix window activation issues

  • Loading branch information...
1 parent f549264 commit 62ec6dd08ce2f5c7a2569ecc08c93acc15346052 @viveksjain committed Oct 11, 2012
Showing with 19 additions and 5 deletions.
  1. +19 −5 Heracles/HeraclesAppDelegate.m
@@ -43,13 +43,22 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
selector:@selector(authenticateInBackgroundWithNotification:)
name:kReachabilityChangedNotification
object:nil];
+
/*
- * Since LSUIElement is set to true, it seems that the Heracles will not be
- * the topmost app when launched, so activate it manually (but only if
+ * Since `LSUIElement` is set to true, it seems that the Heracles will not
+ * be the topmost app when launched, so activate it manually (but only if
* the window is visible, i.e. it is not being run as a hidden login
* item).
*/
- if ([window isVisible]) [NSApp activateIgnoringOtherApps:YES];
+ if ([window isVisible]) {
+ /*
+ * When run in XCode, for some reason the window doesn't become
+ * topmost if `[NSApp activateIgnoringOtherApps:YES]` is called
+ * immediately, so call it with a timer to allow the application to
+ * initialize before becoming frontmost.
+ */
+ [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(activate) userInfo:nil repeats:NO];
+ }
username = [[NSUserDefaults standardUserDefaults] stringForKey:@"username"];
if (username == nil) {
@@ -80,12 +89,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
}
+- (void)activate {
+ [NSApp activateIgnoringOtherApps:YES];
+}
+
/*
* Activates the main window when the application is reopened.
*/
- (BOOL)applicationShouldHandleReopen:(NSApplication *)app hasVisibleWindows:(BOOL)flag {
- if (!flag) [window makeKeyAndOrderFront:nil];
- return YES;
+ [NSApp activateIgnoringOtherApps:YES];
+ [window makeKeyAndOrderFront:self];
+ return NO;
}
- (IBAction)rightButtonClicked:(id)sender {

0 comments on commit 62ec6dd

Please sign in to comment.