Add app.setPath and app.getPath APIs
They can be used to set/get any path defined in PathService
This commit is contained in:
parent
2d1afbf51b
commit
06da5f254a
4 changed files with 33 additions and 9 deletions
|
@ -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,14 +149,18 @@ void App::OnFinishLaunching() {
|
|||
Emit("ready");
|
||||
}
|
||||
|
||||
void App::SetDataPath(const base::FilePath& path) {
|
||||
PathService::Override(brightray::DIR_USER_DATA, path);
|
||||
base::FilePath App::GetPath(const std::string& name) {
|
||||
base::FilePath path;
|
||||
int key = GetPathConstant(name);
|
||||
if (key >= 0)
|
||||
PathService::Get(key, &path);
|
||||
return path;
|
||||
}
|
||||
|
||||
base::FilePath App::GetDataPath() {
|
||||
base::FilePath path;
|
||||
PathService::Get(brightray::DIR_USER_DATA, &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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 395b3359cb5e8209fa740b9c678fd60709789106
|
||||
Subproject commit 8eb714dac77e3d3fd43fba76c835d29b838cc8be
|
Loading…
Reference in a new issue