From d3caea91b073b1c38117135c7e720b2a7deef047 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 13 Nov 2015 13:05:16 +0800 Subject: [PATCH] Add paths from chrome_paths --- atom/app/atom_main_delegate.cc | 3 +++ atom/browser/api/atom_api_app.cc | 30 +++++++++++++----------------- docs/api/app.md | 8 ++++++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 3bc1ac497..802831310 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -16,6 +16,7 @@ #include "base/debug/stack_trace.h" #include "base/environment.h" #include "base/logging.h" +#include "chrome/common/chrome_paths.h" #include "content/public/common/content_switches.h" #include "ui/base/resource/resource_bundle.h" @@ -79,6 +80,8 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { if (enable_stack_dumping) base::debug::EnableInProcessStackDumping(); + chrome::RegisterPathProvider(); + return brightray::MainDelegate::BasicStartupComplete(exit_code); } diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index d6d961a08..e1fa03af5 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -22,9 +22,9 @@ #include "base/command_line.h" #include "base/environment.h" #include "base/files/file_path.h" -#include "base/nix/xdg_util.h" #include "base/path_service.h" #include "brightray/browser/brightray_paths.h" +#include "chrome/common/chrome_paths.h" #include "content/public/browser/client_certificate_delegate.h" #include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_switches.h" @@ -100,12 +100,22 @@ int GetPathConstant(const std::string& name) { return base::DIR_HOME; else if (name == "temp") return base::DIR_TEMP; - else if (name == "userDesktop") + else if (name == "userDesktop" || name == "desktop") return base::DIR_USER_DESKTOP; else if (name == "exe") return base::FILE_EXE; else if (name == "module") return base::FILE_MODULE; + else if (name == "documents") + return chrome::DIR_USER_DOCUMENTS; + else if (name == "downloads") + return chrome::DIR_DEFAULT_DOWNLOADS; + else if (name == "music") + return chrome::DIR_USER_MUSIC; + else if (name == "pictures") + return chrome::DIR_USER_PICTURES; + else if (name == "videos") + return chrome::DIR_USER_VIDEOS; else return -1; } @@ -156,17 +166,6 @@ void PassLoginInformation(scoped_refptr login_handler, login_handler->CancelAuth(); } -bool GetUserDownloadsDirectory(base::FilePath* path) { -#if defined(OS_LINUX) - *path = base::nix::GetXDGUserDirectory("DOWNLOAD", "Downloads"); - return true; -#elif defined(OS_MACOSX) - return false; -#elif defined(OS_WIN) - return false; -#endif -} - } // namespace App::App() { @@ -284,11 +283,8 @@ base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) { int key = GetPathConstant(name); if (key >= 0) succeed = PathService::Get(key, &path); - if (!succeed) { - if (name == "downloads" && GetUserDownloadsDirectory(&path)) - return path; + if (!succeed) args->ThrowError("Failed to get path"); - } return path; } diff --git a/docs/api/app.md b/docs/api/app.md index b145ce7f0..9d10bbb83 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -238,10 +238,14 @@ You can request the following paths by the name: * `userData` The directory for storing your app's configuration files, which by default it is the `appData` directory appended with your app's name. * `temp` Temporary directory. -* `userDesktop` The current user's Desktop directory. * `exe` The current executable file. * `module` The `libchromiumcontent` library. -* `downloads` User's download directory. +* `desktop` The current user's Desktop directory. +* `documents` Directory for a user's "My Documents". +* `downloads` Directory for a user's downloads. +* `music` Directory for a user's music. +* `pictures` Directory for a user's pictures. +* `videos` Directory for a user's videos. ### `app.setPath(name, path)`