Merge pull request #578 from cornedor/appdata
Fixed #442 added app.getDataPath()
This commit is contained in:
commit
f96c6e4bd7
3 changed files with 38 additions and 1 deletions
|
@ -5,15 +5,23 @@
|
||||||
#include "atom/browser/api/atom_api_app.h"
|
#include "atom/browser/api/atom_api_app.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "base/command_line.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 "atom/browser/browser.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"
|
||||||
|
|
||||||
#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 atom {
|
namespace atom {
|
||||||
|
@ -60,6 +68,23 @@ void App::OnFinishLaunching() {
|
||||||
Emit("ready");
|
Emit("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base::FilePath App::GetDataPath() {
|
||||||
|
base::FilePath path;
|
||||||
|
#if defined(OS_LINUX)
|
||||||
|
scoped_ptr<base::Environment> 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 data_path = path.Append(
|
||||||
|
base::FilePath::FromUTF8Unsafe(Browser::Get()->GetName()));
|
||||||
|
|
||||||
|
return data_path;
|
||||||
|
}
|
||||||
|
|
||||||
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||||
v8::Isolate* isolate) {
|
v8::Isolate* isolate) {
|
||||||
Browser* browser = Browser::Get();
|
Browser* browser = Browser::Get();
|
||||||
|
@ -75,7 +100,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||||
.SetMethod("getName", base::Bind(&Browser::GetName,
|
.SetMethod("getName", base::Bind(&Browser::GetName,
|
||||||
base::Unretained(browser)))
|
base::Unretained(browser)))
|
||||||
.SetMethod("setName", base::Bind(&Browser::SetName,
|
.SetMethod("setName", base::Bind(&Browser::SetName,
|
||||||
base::Unretained(browser)));
|
base::Unretained(browser)))
|
||||||
|
.SetMethod("getDataPath", &App::GetDataPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "atom/browser/api/event_emitter.h"
|
#include "atom/browser/api/event_emitter.h"
|
||||||
#include "atom/browser/browser_observer.h"
|
#include "atom/browser/browser_observer.h"
|
||||||
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -34,6 +35,7 @@ class App : public mate::EventEmitter,
|
||||||
virtual void OnActivateWithNoOpenWindows() OVERRIDE;
|
virtual void OnActivateWithNoOpenWindows() OVERRIDE;
|
||||||
virtual void OnWillFinishLaunching() OVERRIDE;
|
virtual void OnWillFinishLaunching() OVERRIDE;
|
||||||
virtual void OnFinishLaunching() OVERRIDE;
|
virtual void OnFinishLaunching() OVERRIDE;
|
||||||
|
virtual base::FilePath GetDataPath();
|
||||||
|
|
||||||
// mate::Wrappable implementations:
|
// mate::Wrappable implementations:
|
||||||
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
|
|
@ -87,6 +87,15 @@ executed. It is possible that a window cancels the quitting by returning
|
||||||
Quit the application directly, it will not try to close all windows so cleanup
|
Quit the application directly, it will not try to close all windows so cleanup
|
||||||
code will not run.
|
code will not run.
|
||||||
|
|
||||||
|
## app.getDataPath()
|
||||||
|
|
||||||
|
Returns the right data path for the OS appended with the app name.
|
||||||
|
|
||||||
|
* `%APPDATA%\My App Name` (`C:\Users\[username]\AppData\Roaming\My App Name`)
|
||||||
|
in Windows
|
||||||
|
* `~/.config/My App Name` in Linux
|
||||||
|
* `/Users/[username]/Library/Application Support/My App Name` in OS X
|
||||||
|
|
||||||
## app.getVersion()
|
## app.getVersion()
|
||||||
|
|
||||||
Returns the version of loaded application, if no version is found in
|
Returns the version of loaded application, if no version is found in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue