diff --git a/MacPass/Base.lproj/AutotypeCandidateSelectionView.xib b/MacPass/Base.lproj/AutotypeCandidateSelectionView.xib index d3344799..f623d7b9 100644 --- a/MacPass/Base.lproj/AutotypeCandidateSelectionView.xib +++ b/MacPass/Base.lproj/AutotypeCandidateSelectionView.xib @@ -1,8 +1,8 @@ - + - + @@ -18,16 +18,16 @@ - + - + - + - + @@ -102,6 +102,9 @@ + + + diff --git a/MacPass/MPAutotypeCandidateSelectionViewController.m b/MacPass/MPAutotypeCandidateSelectionViewController.m index 2c7b96a0..a680306c 100644 --- a/MacPass/MPAutotypeCandidateSelectionViewController.m +++ b/MacPass/MPAutotypeCandidateSelectionViewController.m @@ -49,7 +49,7 @@ NSRunningApplication *targetApplication = [NSRunningApplication runningApplicationWithProcessIdentifier:self.environment.pid]; if(nil != targetApplication) { - self.targetApplicationImageView.image = targetApplication.icon; + self.targetApplicationImageView.image = [self _composeInfoImage]; } NSString *template = @""; @@ -106,4 +106,28 @@ [MPAutotypeDaemon.defaultDaemon cancelAutotypeContextSelectionForEnvironment:self.environment]; } +- (NSImage *)_composeInfoImage { + static const uint32_t imageWidth = 512; + static const uint32_t iconSize = 128; + + NSRunningApplication *targetApplication = [NSRunningApplication runningApplicationWithProcessIdentifier:self.environment.pid]; + CGImageRef windowGrab = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, self.environment.windowId, kCGWindowImageDefault | kCGWindowImageBestResolution); + NSImage *windowImage = [[NSImage alloc] initWithCGImage:windowGrab size:NSZeroSize]; + CFRelease(windowGrab); + + CGFloat imageHeight = imageWidth * (windowImage.size.height / windowImage.size.width); + if(!targetApplication.icon) { + return windowImage; + } + + /* FIXME: respect tall windows correctly, we currently scale them up needlesly */ + + NSImage *composite = [[NSImage alloc] initWithSize:NSMakeSize(imageWidth, MAX(imageHeight, iconSize))]; + [composite lockFocus]; + [windowImage drawInRect:NSMakeRect(0, 0, imageWidth, imageHeight) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1]; + [targetApplication.icon drawInRect:NSMakeRect(0, 0, iconSize, iconSize) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1]; + [composite unlockFocus]; + return composite; +} + @end diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 367e3810..9ff98b8e 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -368,7 +368,7 @@ static MPAutotypeDaemon *_sharedInstance; - (void)_presentCandiadates:(NSArray *)candidates forEnvironment:(MPAutotypeEnvironment *)environment { if(!self.matchSelectionWindow) { self.matchSelectionWindow = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) - styleMask:NSWindowStyleMaskNonactivatingPanel|NSWindowStyleMaskTitled + styleMask:NSWindowStyleMaskResizable|NSWindowStyleMaskNonactivatingPanel|NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES]; self.matchSelectionWindow.level = kCGAssistiveTechHighWindowLevel; diff --git a/MacPass/MPAutotypeEnvironment.h b/MacPass/MPAutotypeEnvironment.h index c805327c..d2577ce1 100644 --- a/MacPass/MPAutotypeEnvironment.h +++ b/MacPass/MPAutotypeEnvironment.h @@ -21,7 +21,8 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readonly, weak, nullable) KPKEntry *preferredEntry; @property (readonly) pid_t pid; // the PID of the target application to which the key strokes should be sent -@property (readonly, copy) NSString *windowTitle; /// The window title of the target application. +@property (readonly) CGWindowID windowId; // the windowID of the target window of the target application +@property (readonly, copy) NSString *windowTitle; /// The title of the target window of the target application. @property (readonly) BOOL hidden; /// If set to YES, MacPass was hidden when autotype was initiated @property (readonly) BOOL isSelfTargeting; /// If MacPass should autotype to itself, YES, otherwise NO @property (readonly) NSString *overrideSequence; /// If set, this sequence is used for running the command regardless of the matched one diff --git a/MacPass/MPAutotypeEnvironment.m b/MacPass/MPAutotypeEnvironment.m index dd91af80..8d37f0b2 100644 --- a/MacPass/MPAutotypeEnvironment.m +++ b/MacPass/MPAutotypeEnvironment.m @@ -26,12 +26,14 @@ if(!targetApplication) { _pid = -1; _windowTitle = @""; + _windowId = -1; } else { NSDictionary *frontApplicationInfoDict = targetApplication.mp_infoDictionary; _pid = [frontApplicationInfoDict[MPProcessIdentifierKey] intValue]; _windowTitle = frontApplicationInfoDict[MPWindowTitleKey]; + _windowId = (CGWindowID)[frontApplicationInfoDict[MPWindowIDKey] integerValue]; /* if we have any resolvers, let them provide the window title */ NSArray *resolvers = [MPPluginHost.sharedHost windowTitleResolverForRunningApplication:targetApplication]; diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 192540e0..e5ac9b02 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -187,6 +187,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { [self _setupTOPTView]; [self _setupCustomFieldsButton]; [self _setupViewBindings]; + [self _updateFieldVisibilty]; } - (void)registerNotificationsForDocument:(MPDocument *)document { @@ -489,14 +490,17 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(username))] options:nullPlaceholderBindingOptionsDict]; + [self.URLTextField bind:NSValueBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(url))] options:nullPlaceholderBindingOptionsDict]; + [self.expiresCheckButton bind:NSTitleBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))] options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformerName }]; + [self.expiresCheckButton bind:NSValueBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))] @@ -573,6 +577,10 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { //[self.addCustomFieldButton setEnabled:NO forSegment:MPContextButtonSegmentContextButton]; } +- (void)_updateFieldVisibilty { + +} + - (void)_setupTOPTView { self.totpViewController = [[MPTOTPViewController alloc] init];