From 29756c00b36d3a1686ad7d8a1d3fe03eafefd5cb Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 23 Nov 2022 16:30:00 +0100 Subject: [PATCH] added double-click copy action to TOTP column we no longer copy empty stuff to the pasteboard on double-click --- MacPass/MPEntryViewController.h | 1 + MacPass/MPEntryViewController.m | 21 ++++++++++++++++----- MacPass/MPPasteBoardController.h | 1 + MacPass/MPPasteBoardController.m | 5 +++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/MacPass/MPEntryViewController.h b/MacPass/MPEntryViewController.h index 1af412b9..64757cfe 100644 --- a/MacPass/MPEntryViewController.h +++ b/MacPass/MPEntryViewController.h @@ -48,6 +48,7 @@ typedef NS_ENUM(NSUInteger, MPDisplayMode) { - (IBAction)copyPassword:(id)sender; - (IBAction)copyCustomAttribute:(id)sender; - (IBAction)copyURL:(id)sender; +- (IBAction)copyTOTP:(id)sender; - (IBAction)openURL:(id)sender; - (IBAction)copyAsReference:(id)sender; diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index b3afe786..68d864ae 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -739,7 +739,6 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell"; } __weak MPEntryViewController *welf = self; self.totpUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) { - NSLog(@"Update TOTP Column Content"); NSIndexSet *columnIndex = [NSIndexSet indexSetWithIndex:[welf.entryTable columnWithIdentifier:MPEntryTableTOTPColumnIdentifier]]; NSIndexSet *rowIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,welf.entryTable.numberOfRows)]; [welf.entryTable reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndex]; @@ -751,7 +750,7 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell"; NSArray *nodes = self.currentTargetNodes; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; NSString *value = [selectedEntry.password kpk_finalValueForEntry:selectedEntry]; - if(value) { + if(value.length > 0) { [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoPassword name:nil atView:self.view]; } } @@ -760,11 +759,20 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell"; NSArray *nodes = self.currentTargetNodes; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; NSString *value = [selectedEntry.username kpk_finalValueForEntry:selectedEntry]; - if(value) { + if(value.length > 0) { [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoUsername name:nil atView:self.view]; } } +- (void)copyTOTP:(id)sender { + NSArray *nodes = self.currentTargetNodes; + KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; + NSString *value = selectedEntry.timeOTP; + if(value.length > 0) { + [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoTOTP name:nil atView:self.view]; + } +} + - (void)copyCustomAttribute:(id)sender { NSArray *nodes = self.currentTargetNodes; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; @@ -773,7 +781,7 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell"; NSAssert((index >= 0) && (index < selectedEntry.customAttributes.count), @"Index for custom field needs to be valid"); KPKAttribute *attribute = selectedEntry.customAttributes[index]; NSString *value = attribute.evaluatedValue; - if(value) { + if(value.length > 0) { [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoCustom name:attribute.key atView:self.view]; } } @@ -783,7 +791,7 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell"; NSArray *nodes = self.currentTargetNodes; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; NSString *value = [selectedEntry.url kpk_finalValueForEntry:selectedEntry]; - if(value) { + if(value.length > 0) { [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoURL name:nil atView:self.view]; } } @@ -852,6 +860,9 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell"; else if([identifier isEqualToString:MPEntryTableUserNameColumnIdentifier]) { [self copyUsername:nil]; } + else if([identifier isEqualToString:MPEntryTableTOTPColumnIdentifier]) { + [self copyTOTP:nil]; + } else if([identifier isEqualToString:MPEntryTableURLColumnIdentifier]) { [self _executeURLColumnDoubleClick]; } diff --git a/MacPass/MPPasteBoardController.h b/MacPass/MPPasteBoardController.h index 57aad9dd..98ca94fa 100644 --- a/MacPass/MPPasteBoardController.h +++ b/MacPass/MPPasteBoardController.h @@ -28,6 +28,7 @@ typedef NS_ENUM(NSUInteger, MPPasteboardOverlayInfoType) { MPPasteboardOverlayInfoPassword, MPPasteboardOverlayInfoUsername, MPPasteboardOverlayInfoURL, + MPPasteboardOverlayInfoTOTP, MPPasteboardOverlayInfoCustom, // overlay info that a custom field was copied MPPasteboardOverlayInfoReference // overlay info that a reference that was copied }; diff --git a/MacPass/MPPasteBoardController.m b/MacPass/MPPasteBoardController.m index aae3e18c..b770fa86 100644 --- a/MacPass/MPPasteBoardController.m +++ b/MacPass/MPPasteBoardController.m @@ -154,6 +154,11 @@ NSString *const MPPasteBoardTypeSource = @"org.nspasteboard.source"; infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard"); break; + case MPPasteboardOverlayInfoTOTP: + infoImage = [MPIconHelper icon:MPIconPassword]; + infoText = NSLocalizedString(@"COPIED_TOTP", "TOTP was copied to the pasteboard"); + break; + case MPPasteboardOverlayInfoCustom: infoImage = [MPIconHelper icon:MPIconPassword]; infoText = [NSString stringWithFormat:NSLocalizedString(@"COPIED_FIELD_%@", "Field name that was copied to the pasteboard"), name];