From 3ef2c01859707efd96189eadd8387f3a9f0a2fb5 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Mon, 17 Jun 2019 11:23:39 +0200 Subject: [PATCH] Added delay settings key --- MacPass/MPAutotypeDaemon.m | 11 +++++++++++ MacPass/MPSettingsHelper.h | 1 + MacPass/MPSettingsHelper.m | 1 + 3 files changed, 13 insertions(+) diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index a23afb61..48191cdd 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -318,9 +318,20 @@ static MPAutotypeDaemon *_sharedInstance; /* TODO - we might be able to get a notification to check if the app actually was activated instead of guessing a waiting time */ usleep(1 * NSEC_PER_MSEC); } + + useconds_t delay = 0; + if(nil != [NSUserDefaults.standardUserDefaults objectForKey:kMPSettingsKeyGlobalAutotypeDelay]) { + /* limit the delay to 1000 ms */ + delay = (useconds_t)MIN([NSUserDefaults.standardUserDefaults integerForKey:kMPSettingsKeyGlobalAutotypeDelay], 1000); + } + + 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(), ^{ + if(delay > 0) { + usleep(delay * NSEC_PER_MSEC); + } [command execute]; }); } diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index 52d70470..a5bdf54e 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -69,6 +69,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyAutotypeMatchURL; // APPKIT_EXTERN NSString *const kMPSettingsKeyAutotypeMatchHost; // Autotype lookup includes host part of entry URL APPKIT_EXTERN NSString *const kMPSettingsKeyAutotypeMatchTags; // Autotype lookup includes tags for entries APPKIT_EXTERN NSString *const kMPSettingsKeyAutotypeHideAccessibiltyWarning; // Do not show an alert, when MacPass has no support for Autotype +APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeDelay; // A global delay in milliseconds for every autotype command to allow for workarounds for broken autotype on some applications (e.g. Steam) /* Search */ APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterContext; diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index eccbb4e2..9f31dcf4 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -60,6 +60,7 @@ NSString *const kMPSettingsKeyAutotypeMatchURL = @"Autoty NSString *const kMPSettingsKeyAutotypeMatchHost = @"AutotypeMatchHost"; NSString *const kMPSettingsKeyAutotypeMatchTags = @"AutotypeMatchTags"; NSString *const kMPSettingsKeyAutotypeHideAccessibiltyWarning = @"AutotypeHideAccessibiltyWarning"; +NSString *const kMPSettingsKeyGlobalAutotypeDelay = @"GlobalAutotypeDelay"; NSString *const kMPSettingsKeyEntrySearchFilterContext = @"EntrySearchFilterContext";