From f9dbdf45228ccda206b9e7280b481aa85a664f85 Mon Sep 17 00:00:00 2001 From: Anatzum Date: Sat, 28 Jan 2017 02:54:26 -0600 Subject: [PATCH 1/2] Updated MoveItemToTrash in platform_util_linux.cc If ELECTRON_TRASH is null, first check the DESKTOP_SESSION variable and set trash accordingly. Additional desktop environments can be added easily this way with the fallback of ELECTRON_DEFAULT_TRASH. --- atom/common/platform_util_linux.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/atom/common/platform_util_linux.cc b/atom/common/platform_util_linux.cc index 923adbd882be..66ef0cc477e2 100644 --- a/atom/common/platform_util_linux.cc +++ b/atom/common/platform_util_linux.cc @@ -98,11 +98,19 @@ void OpenExternal(const GURL& url, bool activate, bool MoveItemToTrash(const base::FilePath& full_path) { std::string trash; if (getenv(ELECTRON_TRASH) != NULL) { - trash = getenv(ELECTRON_TRASH); + trash = getenv(ELECTRON_TRASH); } else { - trash = ELECTRON_DEFAULT_TRASH; + // Determine desktop environment and set accordingly. + std::string desktopEnv = getenv(DESKTOP_SESSION); + if (desktopEnv.find("plasma") != std::string::npos) { + trash = "kioclient5"; + } else if (desktopEnv.find("kde") != std::string::npos) { + trash = "kioclient"; + } else { + trash = ELECTRON_DEFAULT_TRASH; + } } - + std::vector argv; if (trash.compare("kioclient5") == 0 || trash.compare("kioclient") == 0) { From 6db827cc9a6221cb20f7b9831187a4e3ffe0805a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 29 Mar 2017 16:21:38 +0900 Subject: [PATCH 2/2] Use GetDesktopEnvironment to determien desktop env Which can get a much more precise result for us. --- atom/common/platform_util_linux.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/atom/common/platform_util_linux.cc b/atom/common/platform_util_linux.cc index 66ef0cc477e2..5c0eaecdd1c2 100644 --- a/atom/common/platform_util_linux.cc +++ b/atom/common/platform_util_linux.cc @@ -7,7 +7,9 @@ #include #include "base/cancelable_callback.h" +#include "base/environment.h" #include "base/files/file_util.h" +#include "base/nix/xdg_util.h" #include "base/process/kill.h" #include "base/process/launch.h" #include "url/gurl.h" @@ -98,19 +100,22 @@ void OpenExternal(const GURL& url, bool activate, bool MoveItemToTrash(const base::FilePath& full_path) { std::string trash; if (getenv(ELECTRON_TRASH) != NULL) { - trash = getenv(ELECTRON_TRASH); + trash = getenv(ELECTRON_TRASH); } else { // Determine desktop environment and set accordingly. - std::string desktopEnv = getenv(DESKTOP_SESSION); - if (desktopEnv.find("plasma") != std::string::npos) { + std::unique_ptr env(base::Environment::Create()); + base::nix::DesktopEnvironment desktop_env( + base::nix::GetDesktopEnvironment(env.get())); + if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4 || + desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) { trash = "kioclient5"; - } else if (desktopEnv.find("kde") != std::string::npos) { + } else if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE3) { trash = "kioclient"; } else { - trash = ELECTRON_DEFAULT_TRASH; + trash = ELECTRON_DEFAULT_TRASH; } } - + std::vector argv; if (trash.compare("kioclient5") == 0 || trash.compare("kioclient") == 0) {