Skip to content

Commit

Permalink
Fix #648: provide nw.App.startPath
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed May 22, 2018
1 parent 78db7c4 commit a8197eb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api/nw_app.idl
Expand Up @@ -25,6 +25,7 @@ namespace nw.App {
[nocompile] static void removeOriginAccessWhitelistEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
static DOMString[] getArgvSync();
static DOMString getDataPath();
[nocompile] static DOMString getStartPath();
static void crashBrowser();
};
interface Events {
Expand Down
22 changes: 22 additions & 0 deletions src/nw_custom_bindings.cc
Expand Up @@ -94,6 +94,14 @@ using namespace blink;
#include "V8HTMLIFrameElement.h"
#include "extensions/renderer/script_context_set.h"

namespace content {
#if defined(COMPONENT_BUILD) && defined(WIN32)
CONTENT_EXPORT base::FilePath g_nw_temp_dir, g_nw_old_cwd;
#else
extern base::FilePath g_nw_temp_dir, g_nw_old_cwd;
#endif
}

using blink::WebFrame;

namespace extensions {
Expand Down Expand Up @@ -133,6 +141,9 @@ void NWCustomBindings::AddRoutes() {
RouteHandlerFunction("crashRenderer",
base::Bind(&NWCustomBindings::CrashRenderer,
base::Unretained(this)));
RouteHandlerFunction("getOldCwd",
base::Bind(&NWCustomBindings::GetOldCwd,
base::Unretained(this)));
RouteHandlerFunction("evalScript",
base::Bind(&NWCustomBindings::EvalScript,
base::Unretained(this)));
Expand Down Expand Up @@ -317,6 +328,17 @@ void NWCustomBindings::GetAbsolutePath(
#endif
}

void NWCustomBindings::GetOldCwd(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
base::FilePath path = content::g_nw_old_cwd;
#if defined(OS_POSIX)
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, path.value().c_str()));
#else
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, path.AsUTF8Unsafe().c_str()));
#endif
}

void NWCustomBindings::AddOriginAccessWhitelistEntry(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();

Expand Down
1 change: 1 addition & 0 deletions src/nw_custom_bindings.h
Expand Up @@ -22,6 +22,7 @@ class NWCustomBindings : public ObjectBackedNativeHandler {
void EvalScript(const v8::FunctionCallbackInfo<v8::Value>& args);
void EvalNWBin(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetAbsolutePath(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetOldCwd(const v8::FunctionCallbackInfo<v8::Value>& args);
void AddOriginAccessWhitelistEntry(const v8::FunctionCallbackInfo<v8::Value>& args);
void RemoveOriginAccessWhitelistEntry(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetProxyForURL(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
6 changes: 6 additions & 0 deletions src/resources/api_nw_app.js
Expand Up @@ -108,11 +108,17 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
apiFunctions.setHandleRequest('getDataPath', function() {
return sendRequest.sendRequestSync('nw.App.getDataPath', [], this.definition.parameters, {})[0];
});
apiFunctions.setHandleRequest('getStartPath', function() {
return nwNatives.getOldCwd();
});
bindingsAPI.compiledApi.__defineGetter__('dataPath', function() {
if (!dataPath)
dataPath = nw.App.getDataPath();
return dataPath;
});
bindingsAPI.compiledApi.__defineGetter__('startPath', function() {
return nw.App.getStartPath();
});
bindingsAPI.compiledApi.registerGlobalHotKey = function() {
return nw.Shortcut.registerGlobalHotKey.apply(nw.Shortcut, arguments);
};
Expand Down

0 comments on commit a8197eb

Please sign in to comment.