fixing file params in wxCocoaLaunch

unfortunately the API does not work as advertised, so use a newer one if possible, fallback to individually sending an open
This commit is contained in:
Stefan Csomor
2019-11-05 09:39:33 +01:00
parent 6421ddb9b2
commit 442149e723

View File

@@ -22,6 +22,7 @@
#include "wx/apptrait.h"
#include "wx/osx/private.h"
#include "wx/osx/private/available.h"
#if (defined(__WXOSX_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10) \
|| (defined(__WXOSX_IPHONE__) && defined(__IPHONE_8_0))
@@ -234,10 +235,13 @@ bool wxCocoaLaunch(const char* const* argv, pid_t &pid)
return false;
}
NSMutableArray *params = [[NSMutableArray alloc] init];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
if ( WX_IS_MACOS_AVAILABLE(10, 10) )
{
// Loop through command line arguments to the bundle,
// turn them into CFURLs and then put them in cfaFiles
// For use to launch services call
NSMutableArray *params = [[NSMutableArray alloc] init];
for( ; *argv != NULL; ++argv )
{
NSURL *cfurlCurrentFile;
@@ -275,10 +279,42 @@ bool wxCocoaLaunch(const char* const* argv, pid_t &pid)
// release it as the CFArray adds a ref count to it
[params addObject:cfurlCurrentFile];
}
}
#endif
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSRunningApplication *app = [ws launchApplicationAtURL:url options:NSWorkspaceLaunchAsync
configuration:[NSDictionary dictionaryWithObject:params forKey:NSWorkspaceLaunchConfigurationArguments]
NSRunningApplication *app = nil;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
if ( WX_IS_MACOS_AVAILABLE(10, 10) && [params count] > 0 )
{
app = [ws openURLs:params withApplicationAtURL:url
options:NSWorkspaceLaunchAsync
configuration:[NSDictionary dictionary]
error:&error];
}
else
#endif
{
app = [ws launchApplicationAtURL:url
options:NSWorkspaceLaunchAsync
configuration:[NSDictionary dictionary]
error:&error];
// this was already processed argv is NULL and nothing bad will happen
for( ; *argv != NULL; ++argv )
{
wxString currfile(*argv);
if( [ws openFile:wxCFStringRef(currfile).AsNSString()
withApplication:wxCFStringRef(path).AsNSString()] == NO )
{
wxLogDebug(wxT("wxCocoaLaunch Could not open argument:%s"), *argv);
return false;
}
}
}
[params release];
if( app != nil )