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.
This commit is contained in:
Robert McGovern 2021-06-01 00:09:33 +01:00
parent 3280ecffe2
commit 5f628ee106
1 changed files with 18 additions and 0 deletions

View File

@ -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;