Don't wait for xdg-open to exit when OpenExternal is called (Linux)

Some browsers (eg. Firefox) may not return until the browser window is
closed. This causes the Electron application to lock up while the browser
window is open.

See https://github.com/atom/atom/issues/6320
This commit is contained in:
Pete Burgers 2016-04-07 17:04:15 +01:00
parent cf2a17cf88
commit 79ba8feaf8

View file

@ -13,7 +13,9 @@
namespace { namespace {
bool XDGUtil(const std::string& util, const std::string& arg) { bool XDGUtil(const std::string& util,
const std::string& arg,
bool wait_for_exit) {
std::vector<std::string> argv; std::vector<std::string> argv;
argv.push_back(util); argv.push_back(util);
argv.push_back(arg); argv.push_back(arg);
@ -30,6 +32,9 @@ bool XDGUtil(const std::string& util, const std::string& arg) {
if (!process.IsValid()) if (!process.IsValid())
return false; return false;
if (!wait_for_exit)
return true;
int exit_code = -1; int exit_code = -1;
if (!process.WaitForExit(&exit_code)) if (!process.WaitForExit(&exit_code))
return false; return false;
@ -37,12 +42,12 @@ bool XDGUtil(const std::string& util, const std::string& arg) {
return (exit_code == 0); return (exit_code == 0);
} }
bool XDGOpen(const std::string& path) { bool XDGOpen(const std::string& path, bool wait_for_exit) {
return XDGUtil("xdg-open", path); return XDGUtil("xdg-open", path, wait_for_exit);
} }
bool XDGEmail(const std::string& email) { bool XDGEmail(const std::string& email, bool wait_for_exit) {
return XDGUtil("xdg-email", email); return XDGUtil("xdg-email", email, wait_for_exit);
} }
} // namespace } // namespace
@ -57,22 +62,24 @@ void ShowItemInFolder(const base::FilePath& full_path) {
if (!base::DirectoryExists(dir)) if (!base::DirectoryExists(dir))
return; return;
XDGOpen(dir.value()); XDGOpen(dir.value(), true);
} }
void OpenItem(const base::FilePath& full_path) { void OpenItem(const base::FilePath& full_path) {
XDGOpen(full_path.value()); XDGOpen(full_path.value(), true);
} }
bool OpenExternal(const GURL& url, bool activate) { bool OpenExternal(const GURL& url, bool activate) {
// Don't wait for exit, since we don't want to wait for the browser/email
// client window to close before returning
if (url.SchemeIs("mailto")) if (url.SchemeIs("mailto"))
return XDGEmail(url.spec()); return XDGEmail(url.spec(), false);
else else
return XDGOpen(url.spec()); return XDGOpen(url.spec(), false);
} }
bool MoveItemToTrash(const base::FilePath& full_path) { bool MoveItemToTrash(const base::FilePath& full_path) {
return XDGUtil("gvfs-trash", full_path.value()); return XDGUtil("gvfs-trash", full_path.value(), true);
} }
void Beep() { void Beep() {