When calling wxLaunchDefaultBrowser() with a local file URL on macOS, it fails with a -50 error.
wxLaunchDefaultBrowser() calls wxDoLaunchDefaultBrowser() on macOS which doesn't work with file system urls. Also, wxDoLaunchDefaultBrowser() is leaking
Expected to work, observed fails with -50 error which is a parameter error.
This line Creates a standard URL with a file:/// uri. It will return NULL which then causes LSOpenCFURLRef to fail.
If you're creating a local file URL you need to use CFURLCreateWithFileSystemPath() with the file system path.
Here's an example:
CFStringRef cfPath = CFStringCreateWithCString(NULL, file.GetFullPath().utf8_str(), kCFStringEncodingUTF8);
if ( cfPath )
{
CFURLRef curl = CFURLCreateWithFileSystemPath(NULL, cfPath, kCFURLPOSIXPathStyle, false);
if ( curl )
{
LSOpenCFURLRef(curl, NULL);
CFRelease(curl);
}
CFRelease(cfPath);
}
Call wxLaunchDefaultBrowser() with a local file path URL.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
It looks like we could just do this:
diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp index 26b5c36696..5830546ca6 100644 --- a/src/osx/utils_osx.cpp +++ b/src/osx/utils_osx.cpp @@ -84,6 +84,13 @@ bool wxLaunchDefaultApplication(const wxString& document, int flags) bool wxDoLaunchDefaultBrowser(const wxLaunchBrowserParams& params) { + if ( !params.path.empty() ) + { + // We need to use a separate URL-creation function for local paths, but + // luckily we already have it. + return wxLaunchDefaultApplication(params.path); + } + wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault, wxCFStringRef( params.url ), nullptr ) ); OSStatus err = LSOpenCFURLRef( curl , nullptr );
Does it work for you?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
This works, however, it points out that wxLaunchDefaultBrowser() doesn't actually launch the default browser, it is simply opening the default application for the file type.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Here's something I quickly cooked up to always open the file with the default browser. This would be much easier if you bridge into cocoa instead of using Core Foundation. Also note the lack of error checking or memory management.
CFStringRef cfPath = CFStringCreateWithCString(NULL, file.GetFullPath().utf8_str(), kCFStringEncodingUTF8);
if ( cfPath )
{
CFURLRef curls[1];
curls[0] = CFURLCreateWithFileSystemPath(NULL, cfPath, kCFURLPOSIXPathStyle, false);
if ( curls[0] )
{
CFURLRef scheme = CFURLCreateWithString(NULL, CFSTR("http://"), NULL);
CFURLRef appURL = LSCopyDefaultApplicationURLForURL(scheme, kLSRolesAll, NULL);
CFArrayRef urls = CFArrayCreate(NULL, (const void **)curls, 1, NULL);
LSLaunchURLSpec spec = {};
spec.appURL = appURL;
spec.itemURLs = urls;
LSOpenFromURLSpec(&spec, NULL);
}
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
We could define a function using Cocoa directly in src/osx/cocoa/utils.mm and call it from wxDoLaunchDefaultBrowser(). I'd still reuse wxOSXCreateURLFromFileSystemPath() because there doesn't seem to be any reason not to (and it calls CFStringNormalize(), which is not done by the code above).
As usual, if you could please make a PR implementing this, it would be gratefully accepted!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()