Add app.setDataPath API

This commit is contained in:
Cheng Zhao 2015-01-18 17:11:27 -08:00
parent c6fb645f6b
commit 45c26e0e5a
3 changed files with 10 additions and 16 deletions

View file

@ -16,6 +16,7 @@
#include "base/environment.h" #include "base/environment.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "brightray/browser/brightray_paths.h"
#include "native_mate/callback.h" #include "native_mate/callback.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h" #include "native_mate/object_template_builder.h"
@ -26,10 +27,6 @@
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#if defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#endif
using atom::Browser; using atom::Browser;
namespace mate { namespace mate {
@ -142,19 +139,14 @@ void App::OnFinishLaunching() {
Emit("ready"); Emit("ready");
} }
void App::SetDataPath(const base::FilePath& path) {
PathService::Override(brightray::DIR_USER_DATA, path);
}
base::FilePath App::GetDataPath() { base::FilePath App::GetDataPath() {
base::FilePath path; base::FilePath path;
#if defined(OS_LINUX) PathService::Get(brightray::DIR_USER_DATA, &path);
scoped_ptr<base::Environment> env(base::Environment::Create()); return path;
path = base::nix::GetXDGDirectory(env.get(),
base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir);
#else
PathService::Get(base::DIR_APP_DATA, &path);
#endif
return path.Append(base::FilePath::FromUTF8Unsafe(
Browser::Get()->GetName()));
} }
void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) { void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
@ -187,6 +179,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
.SetMethod("setUserTasks", .SetMethod("setUserTasks",
base::Bind(&Browser::SetUserTasks, browser)) base::Bind(&Browser::SetUserTasks, browser))
#endif #endif
.SetMethod("setDataPath", &App::SetDataPath)
.SetMethod("getDataPath", &App::GetDataPath) .SetMethod("getDataPath", &App::GetDataPath)
.SetMethod("resolveProxy", &App::ResolveProxy) .SetMethod("resolveProxy", &App::ResolveProxy)
.SetMethod("setDesktopName", &App::SetDesktopName); .SetMethod("setDesktopName", &App::SetDesktopName);

View file

@ -48,6 +48,7 @@ class App : public mate::EventEmitter,
v8::Isolate* isolate) override; v8::Isolate* isolate) override;
private: private:
void SetDataPath(const base::FilePath& path);
base::FilePath GetDataPath(); base::FilePath GetDataPath();
void ResolveProxy(const GURL& url, ResolveProxyCallback callback); void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
void SetDesktopName(const std::string& desktop_name); void SetDesktopName(const std::string& desktop_name);

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit 09dc5f11e9c83e6ff3c2b6b1b58ceb2b8eae35c4 Subproject commit 395b3359cb5e8209fa740b9c678fd60709789106