Disabled direct fail of autotype on missing access. Added time out for user interaction to prevent unexpected behaviour

This commit is contained in:
Michael Starke
2018-11-16 11:23:08 +01:00
parent 4b56167b56
commit 409632714c
5 changed files with 26 additions and 6 deletions

View File

@@ -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<NSString *,id> * _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 -

View File

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

View File

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

View File

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

View File

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