Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Autotype Workflow #928

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 21 additions & 12 deletions MacPass/MPAutotypeDaemon.m
Expand Up @@ -39,6 +39,7 @@

#import "KeePassKit/KeePassKit.h"
#import <Carbon/Carbon.h>
#import "MPDocumentController.h"

NSString *const kMPWindowTitleKey = @"kMPWindowTitleKey";
NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
Expand Down Expand Up @@ -241,6 +242,10 @@ - (void)_performAutotypeForEntry:(KPKEntry *)entryOrNil {
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
self.userActionRequested = NSDate.date.timeIntervalSinceReferenceDate;
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil];
if (!NSApp.isActive) {
amjunliang marked this conversation as resolved.
Show resolved Hide resolved
[((MPDocumentController*)NSDocumentController.sharedDocumentController) reopenLastDocument];
[NSApp activateIgnoringOtherApps:YES];
}
return; // Unlock should trigger autotype
}

Expand All @@ -267,18 +272,7 @@ - (void)_performAutotypeForEntry:(KPKEntry *)entryOrNil {
if(self.matchSelectionWindow) {
return; // we present the match selection window, just return
}
if(!entryOrNil) {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = NSApp.applicationName;
notification.userInfo = @{ MPUserNotificationTypeKey: MPUserNotificationTypeAutotypeFeedback };
if(context) {
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH_FOR_%@", "Notification: Autotype found a single match for %@ (string placeholder)."), self.targetWindowTitle];
}
else {
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH_FOR_%@", "Noticiation: Autotype failed to find a match for %@ (string placeholder)"), self.targetWindowTitle];
}
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
}

amjunliang marked this conversation as resolved.
Show resolved Hide resolved
[self _performAutotypeForContext:context];
}

Expand Down Expand Up @@ -315,6 +309,18 @@ - (void)_performAutotypeForContext:(MPAutotypeContext *)context {
/* TODO - we might be able to a notification to check if the app actally was activated instead of guessing a waiting time */
usleep(1 * NSEC_PER_MSEC);
}

NSUserNotification *notification = [[NSUserNotification alloc] init];
amjunliang marked this conversation as resolved.
Show resolved Hide resolved
notification.title = NSApp.applicationName;
notification.userInfo = @{ MPUserNotificationTypeKey: MPUserNotificationTypeAutotypeFeedback };
if(context) {
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH_FOR_%@", "Notification: Autotype found a single match for %@ (string placeholder)."), self.targetWindowTitle];
} else {
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH_FOR_%@", "Noticiation: Autotype failed to find a match for %@ (string placeholder)"), self.targetWindowTitle];
}
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];


for(MPAutotypeCommand *command in [MPAutotypeCommand commandsForContext:context]) {
/* dispatch commands to main thread since most of them translate key events which is disallowed on background thread */
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -385,6 +391,9 @@ - (void)_presentSelectionWindow:(NSArray *)candidates {
self.matchSelectionWindow.contentViewController = vc;

}
if(self.targetPID) {
amjunliang marked this conversation as resolved.
Show resolved Hide resolved
[self _orderApplicationToFront:self.targetPID];
}
[self.matchSelectionWindow center];
[self.matchSelectionWindow makeKeyAndOrderFront:self];
}
Expand Down