diff --git a/MacPass/MPAutotypeDaemon.h b/MacPass/MPAutotypeDaemon.h index e3408f5d..9dd7633d 100644 --- a/MacPass/MPAutotypeDaemon.h +++ b/MacPass/MPAutotypeDaemon.h @@ -20,11 +20,5 @@ @property (weak) IBOutlet NSButton *performAutotypeButton; - (void)exectureAutotypeForEntry:(KPKEntry *)entry withWindowTitle:(NSString *)title; -/** - * Called by the selection window to start the autotype sequence - * - * @param sender sender of the action. - */ -- (IBAction)executeAutotypeWithSelectedMatch:(id)sender; @end diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 5f496d3e..769163c9 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -12,6 +12,7 @@ #import "MPDocument+Autotype.h" #import "MPAutotypeCommand.h" #import "MPAutotypeContext.h" +#import "MPAutotypePaste.h" #import "MPPasteBoardController.h" #import "MPSettingsHelper.h" @@ -28,6 +29,7 @@ NSString *const kMPApplciationNameKey = @"applicationName"; @interface MPAutotypeDaemon () @property (nonatomic, assign) BOOL enabled; +@property (copy) NSString *lastFrontMostApplication; @end @@ -53,18 +55,15 @@ NSString *const kMPApplciationNameKey = @"applicationName"; - (void)setEnabled:(BOOL)enabled { if(_enabled != enabled) { _enabled = enabled; - //self.enabled ? [self _registerHotKey] : [self _unregisterHotKey]; + self.enabled ? [self _registerHotKey] : [self _unregisterHotKey]; } } -- (void)exectureAutotypeForEntry:(KPKEntry *)entry withWindowTitle:(NSString *)title { - NSAssert(NO,@"Not Implemented"); -} - - (void)executeAutotypeWithSelectedMatch:(id)sender { NSMenuItem *item = [self.matchSelectionButton selectedItem]; MPAutotypeContext *context = [item representedObject]; [self.matchSelectionWindow orderOut:self]; + [self _performAutotypeForContext:context]; } - (void)_didPressHotKey { @@ -76,7 +75,7 @@ NSString *const kMPApplciationNameKey = @"applicationName"; break; } } - if(currentDocument.encrypted) { + if(!currentDocument) { return; // No need to search in closed documents } /* @@ -85,15 +84,15 @@ NSString *const kMPApplciationNameKey = @"applicationName"; */ NSDictionary *frontApplicationInfoDict = [self _frontMostApplicationInfoDict]; NSString *windowTitle = frontApplicationInfoDict[kMPWindowTitleKey]; - NSString *applicationName = frontApplicationInfoDict[kMPApplciationNameKey]; - NSLog(@"Looking for entries matching window title:%@ of applciation: %@", windowTitle, applicationName); + self.lastFrontMostApplication = frontApplicationInfoDict[kMPApplciationNameKey]; + //NSLog(@"Looking for entries matching window title:%@ of applciation: %@", windowTitle, applicationName); /* Query the document to generate a autotype command list for the window title We do not care where this came form, just get the autotype commands */ NSArray *autotypeCandidates = [currentDocument autotypContextsForWindowTitle:windowTitle]; - NSUInteger candiates = [autotypeCandidates count]; + NSInteger candiates = [autotypeCandidates count]; if(candiates == 0) { return; // No Entries found. } @@ -101,24 +100,23 @@ NSString *const kMPApplciationNameKey = @"applicationName"; [self _presentSelectionWindow:autotypeCandidates]; return; // Nothing to do, we get called back by the window } - /* Just in case it's not there anymore, order the app for the window we want to autotype back to the foreground! */ - [self _orderApplicationToFront:applicationName]; - /* - Implement! - */ - return; - - KPKEntry *selectedEntry = currentDocument.selectedEntry; - if(nil == currentDocument || nil == selectedEntry) { - return; // no open documents, no selected entry - } - - /* TODO: - Replace entry based palce holders - Replace global placeholders - Translate to paste/copy commands - Find correct key-codes for current keyboard layout to perform paste command - */ + [self _performAutotypeForContext:autotypeCandidates[0]]; +} + +- (void)_performAutotypeForContext:(MPAutotypeContext *)context { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSArray *commands = [MPAutotypeCommand commandsForContext:context]; + [MPAutotypeDaemon _orderApplicationToFront:self.lastFrontMostApplication]; + usleep(1000*1000); + BOOL lastCommandWasPaste = NO; + for(MPAutotypeCommand *command in commands) { + if(lastCommandWasPaste) { + usleep(500*1000); + } + [command execute]; + lastCommandWasPaste = [command isKindOfClass:[MPAutotypePaste class]]; + } + }); } - (void)_registerHotKey { @@ -161,8 +159,9 @@ NSString *const kMPApplciationNameKey = @"applicationName"; [associationMenu addItemWithTitle:NSLocalizedString(@"SELECT_AUTOTYPE_CANDIDATE", "") action:NULL keyEquivalent:@""]; [associationMenu addItem:[NSMenuItem separatorItem]]; [associationMenu setAutoenablesItems:NO]; + NSString *entryMask = NSLocalizedString(@"TITLE_%@_USERNAME_%@_PASSWORD_%@_AUTOTYPE_SEQUENCE_%@", "Mask to create autotype entries for selection by the user. %1 Title %2 Username %3 Password %4 Sequence"); for(MPAutotypeContext *context in candidates) { - NSString *title = [[NSString alloc] initWithFormat:@"%@: %@", context.entry.title, context.command]; + NSString *title = [[NSString alloc] initWithFormat:entryMask, context.entry.title, context.entry.username, context.entry.password, context.command]; NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:0 keyEquivalent:@""]; [item setRepresentedObject:context]; [associationMenu addItem:item]; @@ -172,11 +171,12 @@ NSString *const kMPApplciationNameKey = @"applicationName"; /* Setup Items in Popup */ } -- (void)_orderApplicationToFront:(NSString *)applicationName { - NSString *appleScript = [[NSString alloc] initWithFormat:@"activate application %@", applicationName]; ++ (void)_orderApplicationToFront:(NSString *)applicationName { + NSLog(@"Moving %@ to the front.", applicationName); + NSString *appleScript = [[NSString alloc] initWithFormat:@"activate application \"%@\"", applicationName]; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:appleScript]; NSDictionary *error; - [script executeAndReturnError:&error]; + NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&error]; } diff --git a/MacPass/MPAutotypePaste.m b/MacPass/MPAutotypePaste.m index 66d0b916..bb644ade 100644 --- a/MacPass/MPAutotypePaste.m +++ b/MacPass/MPAutotypePaste.m @@ -28,6 +28,7 @@ } - (void)execute { + [NSThread isMainThread] ? NSLog(@"MainThread") : NSLog(@"NonMainThread"); if([self.pasteData length] > 0) { MPPasteBoardController *controller = [MPPasteBoardController defaultController]; [controller copyObjects:@[self.pasteData]]; diff --git a/MacPass/MPIntegrationSettingsController.m b/MacPass/MPIntegrationSettingsController.m index b3b6da63..ee0f4510 100644 --- a/MacPass/MPIntegrationSettingsController.m +++ b/MacPass/MPIntegrationSettingsController.m @@ -41,7 +41,7 @@ [self.enableServerCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:serverKeyPath options:nil]; [self.enableServerCheckbutton setEnabled:NO]; [self.enableGlobalAutotypeCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeKeyPath options:nil]; - [self.enableGlobalAutotypeCheckbutton setEnabled:NO]; + //[self.enableGlobalAutotypeCheckbutton setEnabled:NO]; [self.enableQuicklookCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:quicklookKeyPath options:nil]; } diff --git a/MacPass/MPPasteBoardController.m b/MacPass/MPPasteBoardController.m index 3b7aada6..78bb34e5 100644 --- a/MacPass/MPPasteBoardController.m +++ b/MacPass/MPPasteBoardController.m @@ -73,6 +73,7 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas } - (void)copyObjects:(NSArray *)objects { + NSLog(@"ShoudlCopy %@", objects); /* Should we save the old content ?*/ [[NSPasteboard generalPasteboard] clearContents]; [[NSPasteboard generalPasteboard] writeObjects:objects]; diff --git a/MacPass/MPTemporaryFileStorage.m b/MacPass/MPTemporaryFileStorage.m index 53e4ba26..a62f708e 100644 --- a/MacPass/MPTemporaryFileStorage.m +++ b/MacPass/MPTemporaryFileStorage.m @@ -1,10 +1,10 @@ -;// - // MPTemporaryFileStorage.m - // MacPass - // - // Created by Michael Starke on 18/03/14. - // Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. - // +// +// MPTemporaryFileStorage.m +// MacPass +// +// Created by Michael Starke on 18/03/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// #import "MPTemporaryFileStorage.h" #import "MPTemporaryFileStorageCenter.h" diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index fc9513f2..1618758d 100644 Binary files a/MacPass/en.lproj/Localizable.strings and b/MacPass/en.lproj/Localizable.strings differ