diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 0b75c679..677c2486 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -51,6 +51,7 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey"; @property (assign) pid_t targetPID; // The pid of the process we want to sent commands to @property (copy) NSString *targetWindowTitle; // The title of the window that we are targeting @property (strong) NSRunningApplication *previousApplication; // The application that was active before we got invoked +@property (assign) NSTimeInterval userActionRequested; @end @@ -81,6 +82,7 @@ static MPAutotypeDaemon *_sharedInstance; if (self) { _enabled = NO; _targetPID = -1; + _userActionRequested = NSDate.distantPast.timeIntervalSinceReferenceDate; [self bind:NSStringFromSelector(@selector(enabled)) toObject:NSUserDefaultsController.sharedUserDefaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype] @@ -214,7 +216,7 @@ static MPAutotypeDaemon *_sharedInstance; #pragma mark Autotype Execution - (void)_performAutotypeForEntry:(KPKEntry *)entryOrNil { - if(!self.autotypeSupported) { + /*if(!self.autotypeSupported) { NSUserNotification *notification = [[NSUserNotification alloc] init]; notification.title = NSApp.applicationName; notification.informativeText = NSLocalizedString(@"AUTOTYPE_NOTIFICATION_MACPASS_HAS_NO_ACCESSIBILTY_PERMISSIONS", "Notification: Autotype failed, MacPass has no permission to send key strokes"); @@ -223,7 +225,7 @@ static MPAutotypeDaemon *_sharedInstance; notification.showsButtons = YES; [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; return; - } + }*/ NSInteger pid = NSProcessInfo.processInfo.processIdentifier; if(self.targetPID == pid) { return; // We do not perform Autotype on ourselves @@ -240,7 +242,9 @@ static MPAutotypeDaemon *_sharedInstance; notification.userInfo = @{ MPUserNotificationTypeKey: MPUserNotificationTypeAutotypeOpenDocumentRequest }; notification.showsButtons = YES; [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; - return; + self.userActionRequested = NSDate.date.timeIntervalSinceReferenceDate; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil]; + return; // Unlock should trigger autotype } NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary * _Nullable bindings) { @@ -256,6 +260,7 @@ static MPAutotypeDaemon *_sharedInstance; [document showWindows]; MPDocumentWindowController *wc = document.windowControllers.firstObject; [wc showPasswordInputWithMessage:NSLocalizedString(@"AUTOTYPE_MESSAGE_UNLOCK_DATABASE", @"Message displayed to the user to unlock the database to perform global autotype")]; + self.userActionRequested = NSDate.date.timeIntervalSinceReferenceDate; [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil]; return; // wait for the unlock to happen } @@ -392,7 +397,17 @@ static MPAutotypeDaemon *_sharedInstance; - (void)_didUnlockDatabase:(NSNotification *)notification { /* Remove ourselves and call again to search matches */ [NSNotificationCenter.defaultCenter removeObserver:self name:MPDocumentDidUnlockDatabaseNotification object:nil]; - [self _performAutotypeForEntry:nil]; + NSTimeInterval now = NSDate.date.timeIntervalSinceReferenceDate; + if(now - self.userActionRequested > 30) { + NSUserNotification *notification = [[NSUserNotification alloc] init]; + notification.title = NSApp.applicationName; + notification.informativeText = NSLocalizedString(@"AUTOTYPE_TIMED_OUT", "Notficication: Autotype timed out"); + notification.userInfo = @{ MPUserNotificationTypeKey: MPUserNotificationTypeAutotypeFeedback }; + [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; + } + else { + [self _performAutotypeForEntry:nil]; + } } #pragma mark - diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 2e38e53d..dc862291 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -430,7 +430,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou } #pragma mark Lock/Unlock/Decrypt - - (void)lockDatabase:(id)sender { /* [self saveDocument] is enqued so that dataOfType is called too late to actually save teh database. diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index 990a991c..cd6bb05a 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -211,7 +211,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [self showPasswordInput]; } -- (void)_didUnlockDatabase:(NSNotification *)notification { +- (void)_didUnlockDatabase:(NSNotification *)notification { [self showEntries]; /* Show password reminders */ [self _presentPasswordIntervalAlerts]; diff --git a/MacPass/de.lproj/Localizable.strings b/MacPass/de.lproj/Localizable.strings index 3fe49f07..f9464a61 100644 --- a/MacPass/de.lproj/Localizable.strings +++ b/MacPass/de.lproj/Localizable.strings @@ -107,6 +107,9 @@ /* Notification: Autotype found a single match for %@ (string placeholder). */ "AUTOTYPE_OVERLAY_SINGLE_MATCH_FOR_%@" = "Treffer für %@!"; +/* Notficication: Autotype timed out */ +"AUTOTYPE_TIMED_OUT" = "Autotype wegen zu langer Wartezeit abgebrochen"; + /* Enable autotype menu item */ "AUTOTYPE_YES" = "Autotype aktivieren"; diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index c6942577..5624dc74 100644 --- a/MacPass/en.lproj/Localizable.strings +++ b/MacPass/en.lproj/Localizable.strings @@ -107,6 +107,9 @@ /* Notification: Autotype found a single match for %@ (string placeholder). */ "AUTOTYPE_OVERLAY_SINGLE_MATCH_FOR_%@" = "Found Match for %@!"; +/* Notficication: Autotype timed out */ +"AUTOTYPE_TIMED_OUT" = "Autotype timed out."; + /* Enable autotype menu item */ "AUTOTYPE_YES" = "Enable Autotype";