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:
parent
cf2a17cf88
commit
79ba8feaf8
1 changed files with 17 additions and 10 deletions
|
@ -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<std::string> 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() {
|
||||
|
|
Loading…
Reference in a new issue