Skip to content

Commit

Permalink
platform_util shouldn't know about mate::Arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Aug 10, 2019
1 parent f7c1a41 commit 6917260
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
9 changes: 8 additions & 1 deletion shell/common/api/atom_api_shell.cc
Expand Up @@ -71,6 +71,13 @@ v8::Local<v8::Promise> OpenExternal(const GURL& url, mate::Arguments* args) {
return handle;
}

bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) {
bool delete_on_fail = false;
args->GetNext(&delete_on_fail);

return platform_util::MoveItemToTrash(full_path, delete_on_fail);
}

#if defined(OS_WIN)
bool WriteShortcutLink(const base::FilePath& shortcut_path,
mate::Arguments* args) {
Expand Down Expand Up @@ -134,7 +141,7 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
dict.SetMethod("openItem", &platform_util::OpenItem);
dict.SetMethod("openExternal", &OpenExternal);
dict.SetMethod("moveItemToTrash", &platform_util::MoveItemToTrash);
dict.SetMethod("moveItemToTrash", &MoveItemToTrash);
dict.SetMethod("beep", &platform_util::Beep);
#if defined(OS_WIN)
dict.SetMethod("writeShortcutLink", &WriteShortcutLink);
Expand Down
2 changes: 1 addition & 1 deletion shell/common/platform_util.h
Expand Up @@ -42,7 +42,7 @@ void OpenExternal(const GURL& url,
OpenExternalCallback callback);

// Move a file to trash.
bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args);
bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail);

void Beep();

Expand Down
2 changes: 1 addition & 1 deletion shell/common/platform_util_linux.cc
Expand Up @@ -82,7 +82,7 @@ void OpenExternal(const GURL& url,
std::move(callback).Run(XDGOpen(url.spec(), false) ? "" : "Failed to open");
}

bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) {
bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) {
std::unique_ptr<base::Environment> env(base::Environment::Create());

// find the trash method
Expand Down
7 changes: 3 additions & 4 deletions shell/common/platform_util_mac.mm
Expand Up @@ -115,10 +115,10 @@ void OpenExternal(const GURL& url,
});
}

bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) {
bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail) {
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
if (!path_string) {
args->ThrowError("moveItemToTrash(): Invalid path.");
LOG(WARNING) << "Invalid file path " << full_path.value();
return false;
}

Expand All @@ -128,8 +128,7 @@ bool MoveItemToTrash(const base::FilePath& full_path, mate::Arguments* args) {
resultingItemURL:nil
error:&err];

bool delete_on_fail = false;
if (args->GetNext(&delete_on_fail) && delete_on_fail) {
if (delete_on_fail) {
// Some volumes may not support a Trash folder or it may be disabled
// so these methods will report failure by returning NO or nil and
// an NSError with NSFeatureUnsupportedError.
Expand Down
2 changes: 1 addition & 1 deletion shell/common/platform_util_win.cc
Expand Up @@ -335,7 +335,7 @@ void OpenExternal(const GURL& url,
std::move(callback));
}

bool MoveItemToTrash(const base::FilePath& path, mate::Arguments* args) {
bool MoveItemToTrash(const base::FilePath& path, bool delete_on_fail) {
base::win::ScopedCOMInitializer com_initializer;
if (!com_initializer.Succeeded())
return false;
Expand Down

0 comments on commit 6917260

Please sign in to comment.