From c62e96f44acf1a8b3e24ea9708951338b94a5b01 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Fri, 15 Feb 2019 11:48:54 +0100 Subject: [PATCH] Added preferences to allow for universal clipboard support. Item menu actions now should work in more scenarios --- MacPass.xcodeproj/project.pbxproj | 4 +- MacPass/Base.lproj/GeneralSettings.xib | 50 ++++++++++++++++------ MacPass/Base.lproj/PasswordCreatorView.xib | 2 +- MacPass/MPActionHelper.h | 2 + MacPass/MPActionHelper.m | 2 + MacPass/MPDocument.m | 2 + MacPass/MPDocumentWindowController.h | 2 + MacPass/MPDocumentWindowController.m | 8 +++- MacPass/MPGeneralSettingsController.h | 1 + MacPass/MPGeneralSettingsController.m | 1 + MacPass/MPPasteBoardController.m | 3 +- MacPass/MPSettingsHelper.h | 1 + MacPass/MPSettingsHelper.m | 2 + MacPass/en.lproj/GeneralSettings.strings | 18 +++++--- 14 files changed, 72 insertions(+), 26 deletions(-) diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 38316f12..76bf831e 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -372,6 +372,7 @@ 4C10412A178CDD44001B5239 /* NSDate+Humanized.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+Humanized.h"; sourceTree = ""; }; 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Humanized.m"; sourceTree = ""; }; 4C15B74518BCA3B1003F8008 /* MPDocument+Search.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+Search.m"; sourceTree = ""; }; + 4C168CB02216CEC300BB1EB0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/GeneralSettings.strings; sourceTree = ""; }; 4C17D8E317A1C780006C8C1E /* MPDocumentWindowDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentWindowDelegate.h; sourceTree = ""; }; 4C17D8E417A1C780006C8C1E /* MPDocumentWindowDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentWindowDelegate.m; sourceTree = ""; }; 4C17F104184E630200E85625 /* 14_BatteryTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 14_BatteryTemplate.pdf; sourceTree = ""; }; @@ -779,7 +780,6 @@ 4CC6DB7817D23719002C6091 /* KPKNode+IconImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKNode+IconImage.h"; sourceTree = ""; }; 4CC6DB7917D23719002C6091 /* KPKNode+IconImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KPKNode+IconImage.m"; sourceTree = ""; }; 4CCA7EEC1797866F00B0B55E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/GeneralSettings.strings; sourceTree = ""; }; - 4CCA7EEE1797867200B0B55E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/GeneralSettings.strings; sourceTree = ""; }; 4CCA8E9A18D91ED9001A6754 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; }; 4CCCE7FF1D75CA48006AA951 /* MPArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPArrayController.h; sourceTree = ""; }; 4CCCE8001D75CA48006AA951 /* MPArrayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPArrayController.m; sourceTree = ""; }; @@ -2233,7 +2233,6 @@ children = ( 4C76155F1764C0590015A1A6 /* Base */, 4CCA7EEC1797866F00B0B55E /* de */, - 4CCA7EEE1797867200B0B55E /* en */, 4C5CD34517D158F5000B7F38 /* fr */, 601F811118E016340028F3DE /* zh-Hans */, BD6C365819484CF40089EB37 /* nl */, @@ -2242,6 +2241,7 @@ 4C840C471D773E5D0081F605 /* pl */, 4C4161041F50333B003BC0AF /* es */, 6A74B0652076F4B40049BC29 /* sv-SE */, + 4C168CB02216CEC300BB1EB0 /* en */, ); name = GeneralSettings.xib; sourceTree = ""; diff --git a/MacPass/Base.lproj/GeneralSettings.xib b/MacPass/Base.lproj/GeneralSettings.xib index dd07db63..fda1f476 100644 --- a/MacPass/Base.lproj/GeneralSettings.xib +++ b/MacPass/Base.lproj/GeneralSettings.xib @@ -1,8 +1,8 @@ - + - + @@ -14,6 +14,7 @@ + @@ -22,16 +23,16 @@ - + - + - + - + @@ -42,7 +43,7 @@ - + @@ -63,7 +64,7 @@ - + Enabling this compromises security. If enabled, your preferences will contain mappings from database to keyfile. Key locations for databases without a password will not be saved. @@ -137,17 +138,40 @@ + + + + + + Disabling this compromises security. If enabled, anything copied to the Clipboard in MacPass will be available on your connected iOS devices. You should clear the clipboard on those devices manually. + + + + + + + + + + + + - @@ -161,17 +185,15 @@ - - - + @@ -225,7 +247,7 @@ - + diff --git a/MacPass/Base.lproj/PasswordCreatorView.xib b/MacPass/Base.lproj/PasswordCreatorView.xib index e27b7c6f..25d837bf 100644 --- a/MacPass/Base.lproj/PasswordCreatorView.xib +++ b/MacPass/Base.lproj/PasswordCreatorView.xib @@ -293,7 +293,7 @@ - + diff --git a/MacPass/MPActionHelper.h b/MacPass/MPActionHelper.h index c1475247..7c2c984e 100644 --- a/MacPass/MPActionHelper.h +++ b/MacPass/MPActionHelper.h @@ -32,6 +32,8 @@ typedef NS_ENUM(NSUInteger, MPActionType) { MPActionDelete, // Delete entry or group MPActionCopyUsername, // copy username to pasteboard MPActionCopyPassword, // copy password to pasteboard + MPActionCopyCustomAttribute, // copy a custom attribute to the pasteboard + MPActionCopyAsReference, // copy a reference to the attribute {REF:…} to the pasteboard MPActionCopyURL, // copy url to pasteboard MPActionOpenURL, // open url in default browser MPActionToggleInspector, diff --git a/MacPass/MPActionHelper.m b/MacPass/MPActionHelper.m index e3ead086..f539b243 100644 --- a/MacPass/MPActionHelper.m +++ b/MacPass/MPActionHelper.m @@ -42,6 +42,8 @@ @(MPActionCopyPassword): NSStringFromSelector(@selector(copyPassword:)), @(MPActionCopyURL): NSStringFromSelector(@selector(copyURL:)), @(MPActionCopyUsername): NSStringFromSelector(@selector(copyUsername:)), + @(MPActionCopyCustomAttribute): NSStringFromSelector(@selector(copyCustomAttribute:)), + @(MPActionCopyAsReference): NSStringFromSelector(@selector(copyAsReference:)), @(MPActionDelete): NSStringFromSelector(@selector(delete:)), @(MPActionEditPassword): NSStringFromSelector(@selector(editPassword:)), @(MPActionOpenURL): NSStringFromSelector(@selector(openURL:)), diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 306993fd..df8c6a03 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -911,6 +911,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou valid &= (nil != targetEntry ) && (targetEntry.url.length > 0); break; case MPActionPerformAutotypeForSelectedEntry: + case MPActionCopyCustomAttribute: + case MPActionCopyAsReference: valid &= (nil != targetEntry); break; default: diff --git a/MacPass/MPDocumentWindowController.h b/MacPass/MPDocumentWindowController.h index 1cc2cccb..1750ad3f 100644 --- a/MacPass/MPDocumentWindowController.h +++ b/MacPass/MPDocumentWindowController.h @@ -72,9 +72,11 @@ - (IBAction)performAutotypeForEntry:(id)sender; +/* actions relayed to MPEntryViewController */ - (IBAction)copyUsername:(id)sender; - (IBAction)copyPassword:(id)sender; - (IBAction)copyCustomAttribute:(id)sender; +- (IBAction)copyAsReference:(id)sender; - (IBAction)copyURL:(id)sender; - (IBAction)openURL:(id)sender; diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index d24cf9f0..4e83993d 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -543,6 +543,8 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [contentView layoutSubtreeIfNeeded]; } +#pragma mark - +#pragma mark Actions forwarded to MPEntryViewController - (void)copyUsername:(id)sender { [self.entryViewController copyUsername:sender]; } @@ -555,6 +557,10 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [self.entryViewController copyCustomAttribute:sender]; } +- (void)copyAsReference:(id)sender { + [self.entryViewController copyAsReference:sender]; +} + - (void)copyURL:(id)sender { [self.entryViewController copyURL:sender]; } @@ -563,8 +569,6 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [self.entryViewController openURL:sender]; } - - #pragma mark Validation - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { return ([self.document validateMenuItem:menuItem]); diff --git a/MacPass/MPGeneralSettingsController.h b/MacPass/MPGeneralSettingsController.h index 894dd2b4..c7e5da84 100644 --- a/MacPass/MPGeneralSettingsController.h +++ b/MacPass/MPGeneralSettingsController.h @@ -28,6 +28,7 @@ @property (weak) IBOutlet NSButton *clearPasteboardOnQuitCheckButton; @property (weak) IBOutlet NSPopUpButton *clearPasteboardTimeoutPopup; +@property (strong) IBOutlet NSButton *preventUniversalClipboardSupportCheckButton; @property (weak) IBOutlet NSPopUpButton *idleTimeOutPopup; @property (weak) IBOutlet NSButton *lockOnSleepCheckButton; @property (weak) IBOutlet NSButton *lockOnLogoutCheckButton; diff --git a/MacPass/MPGeneralSettingsController.m b/MacPass/MPGeneralSettingsController.m index 4633f2d7..88137907 100644 --- a/MacPass/MPGeneralSettingsController.m +++ b/MacPass/MPGeneralSettingsController.m @@ -49,6 +49,7 @@ NSString *const MPGeneralSetingsIdentifier = @"GeneralSettingsTab"; [self.clearPasteboardOnQuitCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyClearPasteboardOnQuit] options:nil]; [self.clearPasteboardTimeoutPopup bind:NSSelectedTagBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPasteboardClearTimeout] options:nil]; + [self.preventUniversalClipboardSupportCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPreventUniversalClipboard] options:nil]; [self.lockOnSleepCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyLockOnSleep] options:nil]; [self.lockOnLogoutCheckButton bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingskeyLockOnLogout] options:nil]; [self.idleTimeOutPopup bind:NSSelectedTagBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyIdleLockTimeOut] options:nil]; diff --git a/MacPass/MPPasteBoardController.m b/MacPass/MPPasteBoardController.m index 06001fd5..3e3d0f13 100644 --- a/MacPass/MPPasteBoardController.m +++ b/MacPass/MPPasteBoardController.m @@ -106,7 +106,8 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas - (void)copyObjectsWithoutTimeout:(NSArray> *)objects { if(@available(macOS 10.12, *)) { - [NSPasteboard.generalPasteboard prepareForNewContentsWithOptions:NSPasteboardContentsCurrentHostOnly]; + NSPasteboardContentsOptions options = [NSUserDefaults.standardUserDefaults boolForKey:kMPSettingsKeyPreventUniversalClipboard] ? NSPasteboardContentsCurrentHostOnly : 0; + [NSPasteboard.generalPasteboard prepareForNewContentsWithOptions:options]; } else { [NSPasteboard.generalPasteboard clearContents]; diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index da25aa54..e3c830ae 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -25,6 +25,7 @@ /* Clipboard */ APPKIT_EXTERN NSString *const kMPSettingsKeyPasteboardClearTimeout; APPKIT_EXTERN NSString *const kMPSettingsKeyClearPasteboardOnQuit; +APPKIT_EXTERN NSString *const kMPSettingsKeyPreventUniversalClipboard; /* Behaviour */ APPKIT_EXTERN NSString *const kMPSettingsKeyPasswordEncoding; diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 9fb31a7b..100de325 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -28,6 +28,7 @@ NSString *const kMPSettingsKeyPasteboardClearTimeout = @"ClipboardClearTimeout"; NSString *const kMPSettingsKeyClearPasteboardOnQuit = @"ClearClipboardOnQuit"; +NSString *const kMPSettingsKeyPreventUniversalClipboard = @"PreventUniversalClipboard"; NSString *const kMPSettingsKeyBrowserBundleId = @"BrowserBundleId"; NSString *const kMPSettingsKeyOpenEmptyDatabaseOnLaunch = @"OpenEmptyDatabaseOnLaunch"; NSString *const kMPSettingsKeyReopenLastDatabaseOnLaunch = @"ReopenLastDatabaseOnLaunch"; @@ -122,6 +123,7 @@ NSString *const kMPDepricatedSettingsKeyLoadUnsecurePlugins = @"MP kMPSettingsKeyShowInspector: @YES, // Show the Inspector by default kMPSettingsKeyPasteboardClearTimeout: @30, // 30 seconds kMPSettingsKeyClearPasteboardOnQuit: @YES, + kMPSettingsKeyPreventUniversalClipboard: @YES, // Disable Universal Clipboard by default kMPSettingsKeyOpenEmptyDatabaseOnLaunch: @NO, kMPSettingsKeyReopenLastDatabaseOnLaunch: @YES, kMPSettingsKeyFileChangeStrategy: @(MPFileChangeStrategyAsk), // Ask what to do on a file change! diff --git a/MacPass/en.lproj/GeneralSettings.strings b/MacPass/en.lproj/GeneralSettings.strings index d4feb019..9e2b5acd 100644 --- a/MacPass/en.lproj/GeneralSettings.strings +++ b/MacPass/en.lproj/GeneralSettings.strings @@ -1,8 +1,3 @@ -/* Class = "NSMenuItem"; title = "after 5 Minutes"; ObjectID = "5gh-b6-cmG"; */ -"5gh-b6-cmG.title" = "after 5 Minutes"; - -/* Class = "NSButtonCell"; title = "Clear all stored locations"; ObjectID = "8Ri-2s-c39"; */ -"8Ri-2s-c39.title" = "Clear all stored locations"; /* Class = "NSMenu"; title = "ClipboardClearInterval"; ObjectID = "421"; */ "421.title" = "ClipboardClearInterval"; @@ -55,15 +50,26 @@ /* Class = "NSBox"; title = "File Handling"; ObjectID = "888"; */ "888.title" = "File Handling"; +/* Class = "NSMenuItem"; title = "after 5 Minutes"; ObjectID = "5gh-b6-cmG"; */ +"5gh-b6-cmG.title" = "after 5 Minutes"; + +/* Class = "NSButtonCell"; title = "Clear all stored locations"; ObjectID = "8Ri-2s-c39"; */ +"8Ri-2s-c39.title" = "Clear all stored locations"; + /* Class = "NSTextFieldCell"; title = "Enabling this compromises security. If enabled, your preferences will contain mappings from database to keyfile. Key locations for databases without a password will not be saved."; ObjectID = "ACh-7H-42N"; */ "ACh-7H-42N.title" = "Enabling this compromises security. If enabled, your preferences will contain mappings from database to keyfile. Key locations for databases without a password will not be saved."; /* Class = "NSButtonCell"; title = "Lock after log out"; ObjectID = "Dzn-9R-JjE"; */ "Dzn-9R-JjE.title" = "Lock after log out"; +/* Class = "NSTextFieldCell"; title = "Disabling this compromises security. If disabled, anything copied to the Clipboard in MacPass will be available on your connected iOS devices. You should clear the clipboard on those devices manually."; ObjectID = "JGX-Tp-KJk"; */ +"JGX-Tp-KJk.title" = "Disabling this compromises security. If disabled, anything copied to the Clipboard in MacPass will be available on your connected iOS devices. You should clear the clipboard on those devices manually."; + /* Class = "NSTextFieldCell"; title = "If file changes:"; ObjectID = "QrK-hM-Xt1"; */ "QrK-hM-Xt1.title" = "If file changes:"; +/* Class = "NSButtonCell"; title = "Prevent Universal Clipboard support"; ObjectID = "fNy-mS-phi"; */ +"fNy-mS-phi.title" = "Prevent Universal Clipboard support"; + /* Class = "NSButtonCell"; title = "Remember Keyfile for Databases"; ObjectID = "r6q-He-nYU"; */ "r6q-He-nYU.title" = "Remember Keyfile for Databases"; -