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 {
|
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 {
|
class ResolveProxyHelper {
|
||||||
public:
|
public:
|
||||||
ResolveProxyHelper(const GURL& url, App::ResolveProxyCallback callback)
|
ResolveProxyHelper(const GURL& url, App::ResolveProxyCallback callback)
|
||||||
|
@ -139,14 +149,18 @@ void App::OnFinishLaunching() {
|
||||||
Emit("ready");
|
Emit("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::SetDataPath(const base::FilePath& path) {
|
base::FilePath App::GetPath(const std::string& name) {
|
||||||
PathService::Override(brightray::DIR_USER_DATA, path);
|
base::FilePath path;
|
||||||
|
int key = GetPathConstant(name);
|
||||||
|
if (key >= 0)
|
||||||
|
PathService::Get(key, &path);
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
base::FilePath App::GetDataPath() {
|
void App::SetPath(const std::string& name, const base::FilePath& path) {
|
||||||
base::FilePath path;
|
int key = GetPathConstant(name);
|
||||||
PathService::Get(brightray::DIR_USER_DATA, &path);
|
if (key >= 0)
|
||||||
return path;
|
PathService::Override(key, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
|
void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
|
||||||
|
@ -179,8 +193,8 @@ 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("setPath", &App::SetPath)
|
||||||
.SetMethod("getDataPath", &App::GetDataPath)
|
.SetMethod("getPath", &App::GetPath)
|
||||||
.SetMethod("resolveProxy", &App::ResolveProxy)
|
.SetMethod("resolveProxy", &App::ResolveProxy)
|
||||||
.SetMethod("setDesktopName", &App::SetDesktopName);
|
.SetMethod("setDesktopName", &App::SetDesktopName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,10 @@ class App : public mate::EventEmitter,
|
||||||
v8::Isolate* isolate) override;
|
v8::Isolate* isolate) override;
|
||||||
|
|
||||||
private:
|
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);
|
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);
|
||||||
|
|
|
@ -8,6 +8,12 @@ app.__proto__ = EventEmitter.prototype
|
||||||
app.getHomeDir = ->
|
app.getHomeDir = ->
|
||||||
process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME']
|
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) ->
|
app.setApplicationMenu = (menu) ->
|
||||||
require('menu').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