From 79ba8feaf8485a0c7a94e717281d1e13deff9e6c Mon Sep 17 00:00:00 2001 From: Pete Burgers Date: Thu, 7 Apr 2016 17:04:15 +0100 Subject: [PATCH 1/3] 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 --- atom/common/platform_util_linux.cc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/atom/common/platform_util_linux.cc b/atom/common/platform_util_linux.cc index 1e437b866cc0..0419c1143bcb 100644 --- a/atom/common/platform_util_linux.cc +++ b/atom/common/platform_util_linux.cc @@ -13,7 +13,9 @@ 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 argv; argv.push_back(util); argv.push_back(arg); @@ -30,6 +32,9 @@ bool XDGUtil(const std::string& util, const std::string& arg) { if (!process.IsValid()) return false; + if (!wait_for_exit) + return true; + int exit_code = -1; if (!process.WaitForExit(&exit_code)) return false; @@ -37,12 +42,12 @@ bool XDGUtil(const std::string& util, const std::string& arg) { return (exit_code == 0); } -bool XDGOpen(const std::string& path) { - return XDGUtil("xdg-open", path); +bool XDGOpen(const std::string& path, bool wait_for_exit) { + return XDGUtil("xdg-open", path, wait_for_exit); } -bool XDGEmail(const std::string& email) { - return XDGUtil("xdg-email", email); +bool XDGEmail(const std::string& email, bool wait_for_exit) { + return XDGUtil("xdg-email", email, wait_for_exit); } } // namespace @@ -57,22 +62,24 @@ void ShowItemInFolder(const base::FilePath& full_path) { if (!base::DirectoryExists(dir)) return; - XDGOpen(dir.value()); + XDGOpen(dir.value(), true); } void OpenItem(const base::FilePath& full_path) { - XDGOpen(full_path.value()); + XDGOpen(full_path.value(), true); } 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")) - return XDGEmail(url.spec()); + return XDGEmail(url.spec(), false); else - return XDGOpen(url.spec()); + return XDGOpen(url.spec(), false); } bool MoveItemToTrash(const base::FilePath& full_path) { - return XDGUtil("gvfs-trash", full_path.value()); + return XDGUtil("gvfs-trash", full_path.value(), true); } void Beep() { From 46365f407627d24d22a7c7a4d7ccbe8e575d2550 Mon Sep 17 00:00:00 2001 From: Pete Burgers Date: Fri, 8 Apr 2016 08:32:45 +0100 Subject: [PATCH 2/3] wait_for_exit param should be const --- atom/common/platform_util_linux.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/common/platform_util_linux.cc b/atom/common/platform_util_linux.cc index 0419c1143bcb..e63dc83f6098 100644 --- a/atom/common/platform_util_linux.cc +++ b/atom/common/platform_util_linux.cc @@ -15,7 +15,7 @@ namespace { bool XDGUtil(const std::string& util, const std::string& arg, - bool wait_for_exit) { + const bool wait_for_exit) { std::vector argv; argv.push_back(util); argv.push_back(arg); @@ -42,11 +42,11 @@ bool XDGUtil(const std::string& util, return (exit_code == 0); } -bool XDGOpen(const std::string& path, bool wait_for_exit) { +bool XDGOpen(const std::string& path, const bool wait_for_exit) { return XDGUtil("xdg-open", path, wait_for_exit); } -bool XDGEmail(const std::string& email, bool wait_for_exit) { +bool XDGEmail(const std::string& email, const bool wait_for_exit) { return XDGUtil("xdg-email", email, wait_for_exit); } From 00ff209fe7f6c1fb25238c46c25b09eedc01446d Mon Sep 17 00:00:00 2001 From: Pete Burgers Date: Fri, 8 Apr 2016 08:35:35 +0100 Subject: [PATCH 3/3] Ensure process is cleaned up, to avoid leaks --- atom/common/platform_util_linux.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/atom/common/platform_util_linux.cc b/atom/common/platform_util_linux.cc index e63dc83f6098..9811c8760d06 100644 --- a/atom/common/platform_util_linux.cc +++ b/atom/common/platform_util_linux.cc @@ -32,8 +32,10 @@ bool XDGUtil(const std::string& util, if (!process.IsValid()) return false; - if (!wait_for_exit) + if (!wait_for_exit) { + base::EnsureProcessGetsReaped(process.Pid()); return true; + } int exit_code = -1; if (!process.WaitForExit(&exit_code))