mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-21 01:24:21 +00:00
Linux: Don't quote space-escaped paths in Process::openDocument() as it causes xdg-open to fail
This commit is contained in:
parent
5c03d13f0d
commit
6cd0ebd832
1 changed files with 11 additions and 15 deletions
|
|
@ -189,40 +189,36 @@ static bool isFileExecutable (const String& filename)
|
|||
|
||||
bool Process::openDocument (const String& fileName, const String& parameters)
|
||||
{
|
||||
String cmdString (fileName.replace (" ", "\\ ",false));
|
||||
auto cmdString = fileName.replace (" ", "\\ ", false);
|
||||
cmdString << " " << parameters;
|
||||
|
||||
if (/*URL::isProbablyAWebsiteURL (fileName)
|
||||
||*/ cmdString.startsWithIgnoreCase ("file:")
|
||||
/*|| URL::isProbablyAnEmailAddress (fileName)*/
|
||||
if (cmdString.startsWithIgnoreCase ("file:")
|
||||
|| File::createFileWithoutCheckingPath (fileName).isDirectory()
|
||||
|| ! isFileExecutable (fileName))
|
||||
{
|
||||
// create a command that tries to launch a bunch of likely browsers
|
||||
static const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
|
||||
"google-chrome", "chromium-browser", "opera", "konqueror" };
|
||||
StringArray cmdLines;
|
||||
|
||||
for (int i = 0; i < numElementsInArray (browserNames); ++i)
|
||||
cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
|
||||
for (auto browserName : { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla",
|
||||
"google-chrome", "chromium-browser", "opera", "konqueror" })
|
||||
{
|
||||
cmdLines.add (String (browserName) + " " + cmdString.trim());
|
||||
}
|
||||
|
||||
cmdString = cmdLines.joinIntoString (" || ");
|
||||
}
|
||||
|
||||
const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
|
||||
|
||||
const int cpid = fork();
|
||||
|
||||
if (cpid == 0)
|
||||
if (fork() == 0)
|
||||
{
|
||||
setsid();
|
||||
|
||||
// Child process
|
||||
execve (argv[0], (char**) argv, environ);
|
||||
exit (0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return cpid >= 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void File::revealToUser() const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue