From: Cheng Zhao Date: Mon, 19 Jan 2015 01:52:15 +0000 (-0800) Subject: Add app.setPath and app.getPath APIs X-Git-Tag: v0.20.7~8^2~8 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=06da5f254a05ec5c1eb32b738f3ed441815e2c1a;p=electron.git Add app.setPath and app.getPath APIs They can be used to set/get any path defined in PathService --- diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 9a9ce028..d5c68835 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -61,6 +61,16 @@ namespace api { namespace { +// Return the path constant from string. +int GetPathConstant(const std::string& name) { + if (name == "appData") + return brightray::DIR_APP_DATA; + else if (name == "userData") + return brightray::DIR_USER_DATA; + else + return -1; +} + class ResolveProxyHelper { public: ResolveProxyHelper(const GURL& url, App::ResolveProxyCallback callback) @@ -139,16 +149,20 @@ void App::OnFinishLaunching() { Emit("ready"); } -void App::SetDataPath(const base::FilePath& path) { - PathService::Override(brightray::DIR_USER_DATA, path); -} - -base::FilePath App::GetDataPath() { +base::FilePath App::GetPath(const std::string& name) { base::FilePath path; - PathService::Get(brightray::DIR_USER_DATA, &path); + int key = GetPathConstant(name); + if (key >= 0) + PathService::Get(key, &path); return path; } +void App::SetPath(const std::string& name, const base::FilePath& path) { + int key = GetPathConstant(name); + if (key >= 0) + PathService::Override(key, path); +} + void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) { new ResolveProxyHelper(url, callback); } @@ -179,8 +193,8 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( .SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser)) #endif - .SetMethod("setDataPath", &App::SetDataPath) - .SetMethod("getDataPath", &App::GetDataPath) + .SetMethod("setPath", &App::SetPath) + .SetMethod("getPath", &App::GetPath) .SetMethod("resolveProxy", &App::ResolveProxy) .SetMethod("setDesktopName", &App::SetDesktopName); } diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 61d06156..9b67cb5b 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -48,6 +48,10 @@ class App : public mate::EventEmitter, v8::Isolate* isolate) override; private: + // Get/Set the pre-defined path in PathService. + base::FilePath GetPath(const std::string& name); + void SetPath(const std::string& name, const base::FilePath& path); + void SetDataPath(const base::FilePath& path); base::FilePath GetDataPath(); void ResolveProxy(const GURL& url, ResolveProxyCallback callback); diff --git a/atom/browser/api/lib/app.coffee b/atom/browser/api/lib/app.coffee index 51fd6609..5ac0d719 100644 --- a/atom/browser/api/lib/app.coffee +++ b/atom/browser/api/lib/app.coffee @@ -8,6 +8,12 @@ app.__proto__ = EventEmitter.prototype app.getHomeDir = -> process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME'] +app.getDataPath = -> + app.getPath 'userData' + +app.setDataPath = (path) -> + app.setPath 'userData', path + app.setApplicationMenu = (menu) -> require('menu').setApplicationMenu menu diff --git a/vendor/brightray b/vendor/brightray index 395b3359..8eb714da 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 395b3359cb5e8209fa740b9c678fd60709789106 +Subproject commit 8eb714dac77e3d3fd43fba76c835d29b838cc8be