added double-click copy action to TOTP column

we no longer copy empty stuff to the pasteboard on double-click
This commit is contained in:
Michael Starke
2022-11-23 16:30:00 +01:00
parent 05ba068632
commit 29756c00b3
4 changed files with 23 additions and 5 deletions

View File

@@ -48,6 +48,7 @@ typedef NS_ENUM(NSUInteger, MPDisplayMode) {
- (IBAction)copyPassword:(id)sender; - (IBAction)copyPassword:(id)sender;
- (IBAction)copyCustomAttribute:(id)sender; - (IBAction)copyCustomAttribute:(id)sender;
- (IBAction)copyURL:(id)sender; - (IBAction)copyURL:(id)sender;
- (IBAction)copyTOTP:(id)sender;
- (IBAction)openURL:(id)sender; - (IBAction)openURL:(id)sender;
- (IBAction)copyAsReference:(id)sender; - (IBAction)copyAsReference:(id)sender;

View File

@@ -739,7 +739,6 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell";
} }
__weak MPEntryViewController *welf = self; __weak MPEntryViewController *welf = self;
self.totpUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) { 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 *columnIndex = [NSIndexSet indexSetWithIndex:[welf.entryTable columnWithIdentifier:MPEntryTableTOTPColumnIdentifier]];
NSIndexSet *rowIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,welf.entryTable.numberOfRows)]; NSIndexSet *rowIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,welf.entryTable.numberOfRows)];
[welf.entryTable reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndex]; [welf.entryTable reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndex];
@@ -751,7 +750,7 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell";
NSArray *nodes = self.currentTargetNodes; NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = [selectedEntry.password kpk_finalValueForEntry:selectedEntry]; NSString *value = [selectedEntry.password kpk_finalValueForEntry:selectedEntry];
if(value) { if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoPassword name:nil atView:self.view]; [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoPassword name:nil atView:self.view];
} }
} }
@@ -760,11 +759,20 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell";
NSArray *nodes = self.currentTargetNodes; NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = [selectedEntry.username kpk_finalValueForEntry:selectedEntry]; NSString *value = [selectedEntry.username kpk_finalValueForEntry:selectedEntry];
if(value) { if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoUsername name:nil atView:self.view]; [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 { - (void)copyCustomAttribute:(id)sender {
NSArray *nodes = self.currentTargetNodes; NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; 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"); NSAssert((index >= 0) && (index < selectedEntry.customAttributes.count), @"Index for custom field needs to be valid");
KPKAttribute *attribute = selectedEntry.customAttributes[index]; KPKAttribute *attribute = selectedEntry.customAttributes[index];
NSString *value = attribute.evaluatedValue; NSString *value = attribute.evaluatedValue;
if(value) { if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoCustom name:attribute.key atView:self.view]; [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoCustom name:attribute.key atView:self.view];
} }
} }
@@ -783,7 +791,7 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell";
NSArray *nodes = self.currentTargetNodes; NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil; KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = [selectedEntry.url kpk_finalValueForEntry:selectedEntry]; NSString *value = [selectedEntry.url kpk_finalValueForEntry:selectedEntry];
if(value) { if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoURL name:nil atView:self.view]; [MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoURL name:nil atView:self.view];
} }
} }
@@ -852,6 +860,9 @@ NSString *const _MPTableMonoSpacedStringCellView = @"MonospacedStringCell";
else if([identifier isEqualToString:MPEntryTableUserNameColumnIdentifier]) { else if([identifier isEqualToString:MPEntryTableUserNameColumnIdentifier]) {
[self copyUsername:nil]; [self copyUsername:nil];
} }
else if([identifier isEqualToString:MPEntryTableTOTPColumnIdentifier]) {
[self copyTOTP:nil];
}
else if([identifier isEqualToString:MPEntryTableURLColumnIdentifier]) { else if([identifier isEqualToString:MPEntryTableURLColumnIdentifier]) {
[self _executeURLColumnDoubleClick]; [self _executeURLColumnDoubleClick];
} }

View File

@@ -28,6 +28,7 @@ typedef NS_ENUM(NSUInteger, MPPasteboardOverlayInfoType) {
MPPasteboardOverlayInfoPassword, MPPasteboardOverlayInfoPassword,
MPPasteboardOverlayInfoUsername, MPPasteboardOverlayInfoUsername,
MPPasteboardOverlayInfoURL, MPPasteboardOverlayInfoURL,
MPPasteboardOverlayInfoTOTP,
MPPasteboardOverlayInfoCustom, // overlay info that a custom field was copied MPPasteboardOverlayInfoCustom, // overlay info that a custom field was copied
MPPasteboardOverlayInfoReference // overlay info that a reference that was copied MPPasteboardOverlayInfoReference // overlay info that a reference that was copied
}; };

View File

@@ -154,6 +154,11 @@ NSString *const MPPasteBoardTypeSource = @"org.nspasteboard.source";
infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard"); infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard");
break; break;
case MPPasteboardOverlayInfoTOTP:
infoImage = [MPIconHelper icon:MPIconPassword];
infoText = NSLocalizedString(@"COPIED_TOTP", "TOTP was copied to the pasteboard");
break;
case MPPasteboardOverlayInfoCustom: case MPPasteboardOverlayInfoCustom:
infoImage = [MPIconHelper icon:MPIconPassword]; infoImage = [MPIconHelper icon:MPIconPassword];
infoText = [NSString stringWithFormat:NSLocalizedString(@"COPIED_FIELD_%@", "Field name that was copied to the pasteboard"), name]; infoText = [NSString stringWithFormat:NSLocalizedString(@"COPIED_FIELD_%@", "Field name that was copied to the pasteboard"), name];