From be6599807d83e8fd59fd4584ce96a33a9a8c86ee Mon Sep 17 00:00:00 2001 From: Corne Dorrestijn Date: Tue, 12 Aug 2014 17:01:56 +0200 Subject: [PATCH] Added getAppData function to the app api --- atom/browser/api/atom_api_app.cc | 26 +++++++++++++++++++++++++- atom/browser/api/atom_api_app.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 6ea5464d6f32..19e6e677b4b8 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -8,12 +8,19 @@ #include "base/values.h" #include "base/command_line.h" +#include "base/environment.h" +#include "base/files/file_path.h" +#include "base/path_service.h" #include "atom/browser/browser.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "atom/common/node_includes.h" +#if defined(OS_LINUX) +#include "base/nix/xdg_util.h" +#endif + using atom::Browser; namespace atom { @@ -60,6 +67,22 @@ void App::OnFinishLaunching() { Emit("ready"); } +std::string App::GetDataPath() { + base::FilePath path; +#if defined(OS_LINUX) + scoped_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), + base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); +#else + CHECK(PathService::Get(base::DIR_APP_DATA, &path)); +#endif + + base::FilePath dataPath = path.Append(base::FilePath::FromUTF8Unsafe(Browser::Get()->GetName())); + + return dataPath.value(); +} + mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( v8::Isolate* isolate) { Browser* browser = Browser::Get(); @@ -75,7 +98,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( .SetMethod("getName", base::Bind(&Browser::GetName, base::Unretained(browser))) .SetMethod("setName", base::Bind(&Browser::SetName, - base::Unretained(browser))); + base::Unretained(browser))) + .SetMethod("getDataPath", &App::GetDataPath); } // static diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 6a5a58edb791..ae11123eb6d7 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -34,6 +34,7 @@ class App : public mate::EventEmitter, virtual void OnActivateWithNoOpenWindows() OVERRIDE; virtual void OnWillFinishLaunching() OVERRIDE; virtual void OnFinishLaunching() OVERRIDE; + virtual std::string GetDataPath(); // mate::Wrappable implementations: virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(