From 5f628ee106050a9c28c87b51d8a8f23fef1d06c3 Mon Sep 17 00:00:00 2001 From: Robert McGovern Date: Tue, 1 Jun 2021 00:09:33 +0100 Subject: [PATCH] Returns focus to finder after unarchiving a file Returns focus to finder after unarchiving a file IF app already open. Not ideal solution as noted in the comment, causes preferences window to disappear. --- QuietUnrarAppDelegate.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/QuietUnrarAppDelegate.m b/QuietUnrarAppDelegate.m index 5df504b..866a7e7 100644 --- a/QuietUnrarAppDelegate.m +++ b/QuietUnrarAppDelegate.m @@ -107,6 +107,7 @@ BOOL appRunning = NO; unarchiver = [[TDNUnarchiver alloc] init]; unarchiver.quietUnrar = self; } + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ for (NSString * filename in self->arrayOfFilesToProcess) { BOOL extracted = [self->unarchiver extractArchiveWithFilename:filename]; @@ -118,10 +119,27 @@ BOOL appRunning = NO; } } } + + // If we're in the foreground, hide and return focus to whereever + // has side effect of making the preferences window disappear after a short time + // which is not what I want. + // + // I'd like to use the frontmostApplication trick to store old app, and restore + // focus to it, but if app already running it appears to be my app, even though + // I did the open from Finder. Hmm + // NSRunningApplication * oldApp = [[NSWorkspace sharedWorkspace] frontmostApplication]; + // do activity + // [_oldApp activateWithOptions:NSApplicationActivateIgnoringOtherApps]; + [NSApp hide:self]; }); } } +- (void)applicationWillBecomeActive:(NSNotification *)notification { + //no use, if app is already running when I try and openfile it is my apps bundle id + NSLog(@"%@", [[NSWorkspace sharedWorkspace] frontmostApplication].bundleIdentifier); +} + - (BOOL)application:(id)sender openFileWithoutUI:(NSString *)filename { NSLog(@"called openFileWithoutUI %@", filename); return YES;