Display screenshot of target window in autotype confirmation/selection dialog.

This commit is contained in:
Michael Starke
2020-12-02 17:34:17 +01:00
parent 03c1d5ecee
commit b04c252a69
6 changed files with 55 additions and 17 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -18,16 +18,16 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="364"/>
<rect key="frame" x="0.0" y="0.0" width="480" height="402"/>
<subviews>
<scrollView wantsLayer="YES" verticalCompressionResistancePriority="250" autohidesScrollers="YES" horizontalLineScroll="38" horizontalPageScroll="10" verticalLineScroll="38" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7cB-re-3ys">
<rect key="frame" x="20" y="61" width="440" height="211"/>
<rect key="frame" x="20" y="61" width="440" height="249"/>
<clipView key="contentView" id="WSc-o2-GsZ">
<rect key="frame" x="1" y="1" width="438" height="209"/>
<rect key="frame" x="1" y="1" width="438" height="247"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="36" viewBased="YES" id="Ih2-lo-t2W">
<rect key="frame" x="0.0" y="0.0" width="438" height="209"/>
<rect key="frame" x="0.0" y="0.0" width="438" height="247"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -102,6 +102,9 @@
</tableView>
</subviews>
</clipView>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="50" id="0cD-ng-4sc"/>
</constraints>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="Xgd-fL-vdl">
<rect key="frame" x="1" y="235" width="92" height="16"/>
<autoresizingMask key="autoresizingMask"/>
@@ -137,19 +140,19 @@ DQ
<action selector="selectAutotypeContext:" target="-2" id="a2F-ID-uOd"/>
</connections>
</button>
<stackView distribution="fill" orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="82Y-g7-4wV">
<rect key="frame" x="20" y="280" width="440" height="64"/>
<stackView distribution="fill" orientation="vertical" alignment="centerX" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="82Y-g7-4wV">
<rect key="frame" x="20" y="318" width="440" height="72"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="bWJ-Ub-c10">
<rect key="frame" x="0.0" y="0.0" width="64" height="64"/>
<rect key="frame" x="204" y="40" width="32" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="64" id="Rzo-8n-W92"/>
<constraint firstAttribute="width" constant="64" id="uhc-Ce-lb8"/>
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="256" id="Rzo-8n-W92"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="256" id="uhc-Ce-lb8"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSApplicationIcon" id="d6x-JH-Lw2"/>
</imageView>
<textField verticalHuggingPriority="750" preferredMaxLayoutWidth="330" translatesAutoresizingMaskIntoConstraints="NO" id="kDw-2l-7gQ">
<rect key="frame" x="70" y="16" width="372" height="32"/>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kDw-2l-7gQ">
<rect key="frame" x="-2" y="0.0" width="444" height="32"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="There are multiple matches for the current window. Please select which match should be used." id="gcf-gb-ZsF">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -181,7 +184,7 @@ DQ
<constraint firstItem="zBX-HB-tR7" firstAttribute="top" secondItem="7cB-re-3ys" secondAttribute="bottom" constant="20" symbolic="YES" id="onA-YV-ezJ"/>
<constraint firstItem="82Y-g7-4wV" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="20" symbolic="YES" id="uoN-Et-pWh"/>
</constraints>
<point key="canvasLocation" x="-349" y="-1891"/>
<point key="canvasLocation" x="-353" y="-2145"/>
</customView>
</objects>
<resources>

View File

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

View File

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

View File

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

View File

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

View File

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