From 65d4ec7ea48f339bc3fb9db7adf9cd134200c2b6 Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Thu, 2 Jan 2025 02:12:44 +0000 Subject: [PATCH] macos: Open files from finder fixing #12603 #12465 #12439 Needs to be tested on MacOS below 15 (Sonoma) --- app/gui/gui-unique.c | 49 ++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/app/gui/gui-unique.c b/app/gui/gui-unique.c index 56e3d96e150..355b658888d 100644 --- a/app/gui/gui-unique.c +++ b/app/gui/gui-unique.c @@ -265,27 +265,50 @@ gui_unique_quartz_idle_open (GFile *file) - (void) handleEvent: (NSAppleEventDescriptor *) inEvent andReplyWith: (NSAppleEventDescriptor *) replyEvent { - NSAutoreleasePool *urlpool; - NSInteger count; - NSInteger i; + NSAutoreleasePool *urlpool; + NSInteger count; + NSInteger i; + NSAppleEventDescriptor *filesList; urlpool = [[NSAutoreleasePool alloc] init]; - count = [inEvent numberOfItems]; + filesList = [inEvent paramDescriptorForKeyword:keyDirectObject]; + g_return_if_fail (filesList); + + count = [filesList numberOfItems]; for (i = 1; i <= count; i++) { - NSURL *url; - const gchar *path; - GSource *source; - GClosure *closure; - - url = [NSURL URLWithString: [[inEvent descriptorAtIndex: i] stringValue]]; - path = [[url path] UTF8String]; + const gchar *path; + GSource *source; + GClosure *closure; + NSAppleEventDescriptor *fileDescriptor; + NSString *filePath; + NSURL *fileURL; + + fileDescriptor = [filesList descriptorAtIndex:i]; + filePath = [[fileDescriptor stringValue] stringByResolvingSymlinksInPath]; + if (filePath) + { + fileURL = [NSURL URLWithString:filePath]; + if ([fileURL isFileURL]) + { + path = [[fileURL path] UTF8String]; + } + else + { + g_printerr ("Descriptor is not a valid file URL: %s\n", [filePath UTF8String]); + continue; + } + } + else + { + g_printerr ("Could not resolve file path for descriptor\n"); + continue; + } closure = g_cclosure_new (G_CALLBACK (gui_unique_quartz_idle_open), - g_file_new_for_path (path), - (GClosureNotify) g_object_unref); + g_file_new_for_path (path), (GClosureNotify) g_object_unref); g_object_watch_closure (G_OBJECT (unique_gimp), closure); -- GitLab