mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
57 lines
1.2 KiB
Objective-C
57 lines
1.2 KiB
Objective-C
//
|
|
// MPAutotypePaste.m
|
|
// MacPass
|
|
//
|
|
// Created by Michael Starke on 24/11/13.
|
|
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
|
//
|
|
|
|
#import "MPAutotypePaste.h"
|
|
#import "MPPasteBoardController.h"
|
|
|
|
#import "KeePassKit/KeePassKit.h"
|
|
|
|
@interface MPAutotypePaste ()
|
|
|
|
@property (copy) NSString *pasteData;
|
|
|
|
@end
|
|
|
|
@implementation MPAutotypePaste
|
|
|
|
- (instancetype)initWithString:(NSString *)aString {
|
|
self = [super init];
|
|
if(self) {
|
|
self.pasteData = aString;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSString *)description {
|
|
return [[NSString alloc] initWithFormat:@"%@ paste:%@", [self class], self.pasteData];
|
|
}
|
|
|
|
- (void)appendString:(NSString *)aString {
|
|
self.pasteData = [self.pasteData stringByAppendingString:aString];
|
|
}
|
|
|
|
- (void)execute {
|
|
if([self.pasteData length] > 0) {
|
|
MPPasteBoardController *controller = [MPPasteBoardController defaultController];
|
|
[controller stashObjects];
|
|
[controller copyObjectsWithoutTimeout:@[self.pasteData]];
|
|
[self sendPasteKeyCode];
|
|
usleep(0.1 * NSEC_PER_MSEC); // on 10.10 we need to wait a bit before restoring the pasteboard contents
|
|
[controller restoreObjects];
|
|
}
|
|
}
|
|
|
|
- (BOOL)isValid {
|
|
/* Pasting should always be valid */
|
|
return YES;
|
|
}
|
|
|
|
|
|
|
|
@end
|