Merge pull request #7178 from aichingm/master
🐧 Add support for different trash implementations
This commit is contained in:
commit
20d5a50ac9
1 changed files with 36 additions and 7 deletions
|
@ -11,15 +11,13 @@
|
||||||
#include "base/process/launch.h"
|
#include "base/process/launch.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
|
#define ELECTRON_TRASH "ELECTRON_TRASH"
|
||||||
|
#define ELECTRON_DEFAULT_TRASH "gvfs-trash"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool XDGUtil(const std::string& util,
|
bool XDGUtilV(const std::vector<std::string>& argv,
|
||||||
const std::string& arg,
|
|
||||||
const bool wait_for_exit) {
|
const bool wait_for_exit) {
|
||||||
std::vector<std::string> argv;
|
|
||||||
argv.push_back(util);
|
|
||||||
argv.push_back(arg);
|
|
||||||
|
|
||||||
base::LaunchOptions options;
|
base::LaunchOptions options;
|
||||||
options.allow_new_privs = true;
|
options.allow_new_privs = true;
|
||||||
// xdg-open can fall back on mailcap which eventually might plumb through
|
// xdg-open can fall back on mailcap which eventually might plumb through
|
||||||
|
@ -44,6 +42,16 @@ bool XDGUtil(const std::string& util,
|
||||||
return (exit_code == 0);
|
return (exit_code == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool XDGUtil(const std::string& util,
|
||||||
|
const std::string& arg,
|
||||||
|
const bool wait_for_exit) {
|
||||||
|
std::vector<std::string> argv;
|
||||||
|
argv.push_back(util);
|
||||||
|
argv.push_back(arg);
|
||||||
|
|
||||||
|
return XDGUtilV(argv, wait_for_exit);
|
||||||
|
}
|
||||||
|
|
||||||
bool XDGOpen(const std::string& path, const bool wait_for_exit) {
|
bool XDGOpen(const std::string& path, const bool wait_for_exit) {
|
||||||
return XDGUtil("xdg-open", path, wait_for_exit);
|
return XDGUtil("xdg-open", path, wait_for_exit);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +89,28 @@ bool OpenExternal(const GURL& url, bool activate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoveItemToTrash(const base::FilePath& full_path) {
|
bool MoveItemToTrash(const base::FilePath& full_path) {
|
||||||
return XDGUtil("gvfs-trash", full_path.value(), true);
|
std::string trash;
|
||||||
|
if (getenv(ELECTRON_TRASH) != NULL) {
|
||||||
|
trash = getenv(ELECTRON_TRASH);
|
||||||
|
} else {
|
||||||
|
trash = ELECTRON_DEFAULT_TRASH;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> argv;
|
||||||
|
|
||||||
|
if (trash.compare("kioclient5") == 0 || trash.compare("kioclient") == 0) {
|
||||||
|
argv.push_back(trash);
|
||||||
|
argv.push_back("move");
|
||||||
|
argv.push_back(full_path.value());
|
||||||
|
argv.push_back("trash:/");
|
||||||
|
} else if (trash.compare("trash-cli") == 0) {
|
||||||
|
argv.push_back("trash-put");
|
||||||
|
argv.push_back(full_path.value());
|
||||||
|
} else {
|
||||||
|
argv.push_back(ELECTRON_DEFAULT_TRASH);
|
||||||
|
argv.push_back(full_path.value());
|
||||||
|
}
|
||||||
|
return XDGUtilV(argv, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Beep() {
|
void Beep() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue