diff --git a/MacPass/MPAutotypeCandidateSelectionViewController.h b/MacPass/MPAutotypeCandidateSelectionViewController.h index 0247b4e0..e74fc5d8 100644 --- a/MacPass/MPAutotypeCandidateSelectionViewController.h +++ b/MacPass/MPAutotypeCandidateSelectionViewController.h @@ -22,13 +22,17 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface MPAutotypeCandidateSelectionViewController : NSViewController @property (copy) NSArray *candidates; @property (copy) NSString *windowTitle; - +@property (nonatomic, copy, nullable) void (^completionHandler)(void); + - (IBAction)selectAutotypeContext:(id)sender; - (IBAction)cancelSelection:(id)sender; - @end + +NS_ASSUME_NONNULL_END diff --git a/MacPass/MPAutotypeCandidateSelectionViewController.m b/MacPass/MPAutotypeCandidateSelectionViewController.m index 5eb20ab8..e5123bdd 100644 --- a/MacPass/MPAutotypeCandidateSelectionViewController.m +++ b/MacPass/MPAutotypeCandidateSelectionViewController.m @@ -80,6 +80,9 @@ - (void)selectAutotypeContext:(id)sender { NSInteger selectedRow = self.contextTableView.selectedRow; if(selectedRow >= 0 && selectedRow < self.candidates.count) { + if(self.completionHandler) { + self.completionHandler(); + } [MPAutotypeDaemon.defaultDaemon selectAutotypeCandiate:self.candidates[selectedRow]]; } else { @@ -88,7 +91,10 @@ } - (void)cancelSelection:(id)sender { - [[MPAutotypeDaemon defaultDaemon] cancelAutotypeCandidateSelection]; + if(self.completionHandler) { + self.completionHandler(); + } + [MPAutotypeDaemon.defaultDaemon cancelAutotypeCandidateSelection]; } diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 3f73ca1a..252cc5df 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -258,13 +258,11 @@ static MPAutotypeDaemon *_sharedInstance; [autotypeCandidates addObjectsFromArray:contexts]; } } - NSUInteger candidates = autotypeCandidates.count; - if(candidates == 0) { - return nil; - } - if(candidates == 1 ) { + + if(autotypeCandidates.count <= 1) { return autotypeCandidates.lastObject; } + [self _presentCandiadates:autotypeCandidates forWindowTitle:windowTitle]; return nil; // Nothing to do, we get called back by the window } @@ -340,9 +338,9 @@ static MPAutotypeDaemon *_sharedInstance; if(zIndex < minZIndex) { minZIndex = zIndex; infoDict = @{ - kMPWindowTitleKey: windowTitle, - kMPProcessIdentifierKey : processId - }; + kMPWindowTitleKey: windowTitle, + kMPProcessIdentifierKey : processId + }; } } } @@ -363,6 +361,11 @@ static MPAutotypeDaemon *_sharedInstance; MPAutotypeCandidateSelectionViewController *vc = [[MPAutotypeCandidateSelectionViewController alloc] init]; vc.candidates = candidates; vc.windowTitle = windowTitle; + if(NSRunningApplication.currentApplication.isHidden) { + vc.completionHandler = ^{ + [NSRunningApplication.currentApplication hide]; + }; + } self.matchSelectionWindow.collectionBehavior |= (NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorMoveToActiveSpace | NSWindowCollectionBehaviorTransient );