Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove images paste logic #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions Messenger/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -410,49 +410,7 @@ - (IBAction)findPeopleAndGroups:(id)sender {
}

- (IBAction)paste:(id)sender {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];

// If we've got an image, let's paste it!
// Ain't nobody got time for dirty hax with React.
if ([pasteboard canReadObjectForClasses:@[[NSImage class]] options:nil]) {
NSImage *pastedImage = [[pasteboard readObjectsForClasses:@[[NSImage class]] options:nil] firstObject];

// Try to grab the URL to the image being pasted (if it's available) to just repurpose the already useable pasteboard.
NSURL *pastedFileURL = [[pasteboard readObjectsForClasses:@[[NSURL class]] options:nil] firstObject];

// If we haven't got a file URL (screenshot), we need to write it out first.
if (pastedFileURL == nil) {
// Convert the pasteboard image to a PNG.
NSRect proposedRect = NSMakeRect(0, 0, pastedImage.size.width, pastedImage.size.height);
CGImageRef pastedImageRef = [pastedImage CGImageForProposedRect:&proposedRect
context:NULL
hints:nil];
NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc] initWithCGImage:pastedImageRef];
NSData *PNGImageData = [bitmapImageRep representationUsingType:NSPNGFileType properties:@{}];

// Save it (temporarily with a new name).
NSString *uniqueFilename = [[NSUUID UUID].UUIDString stringByAppendingString:@".png"];
NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:uniqueFilename];
[PNGImageData writeToFile:tmpPath atomically:YES];

pastedFileURL = [NSURL fileURLWithPath:tmpPath];

// Write our newly saved file to the pasteboard.
[pasteboard clearContents];
[pasteboard declareTypes:@[NSFilenamesPboardType] owner:self];
[pasteboard writeObjects:@[pastedFileURL]];
}

if (pastedFileURL != nil) {
// Fire off a completely falsified (and bs) drag+drop event. >:D
MMFakeDragInfo *info = [[MMFakeDragInfo alloc] initWithImage:pastedImage pasteboard:pasteboard];
[_webView draggingEntered:info];
[_webView draggingUpdated:info];
[_webView performDragOperation:info];
}
} else {
[[NSApplication sharedApplication] sendAction:@selector(paste:) to:nil from:self];
}
}

- (void)showActiveFriends {
Expand Down