Skip to content

Commit a8197eb

Browse files
committed
Fix nwjs#648: provide nw.App.startPath
1 parent 78db7c4 commit a8197eb

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/api/nw_app.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace nw.App {
2525
[nocompile] static void removeOriginAccessWhitelistEntry(DOMString sourceOrigin, DOMString destinationProtocol, DOMString destinationHost, boolean allowDestinationSubdomains);
2626
static DOMString[] getArgvSync();
2727
static DOMString getDataPath();
28+
[nocompile] static DOMString getStartPath();
2829
static void crashBrowser();
2930
};
3031
interface Events {

src/nw_custom_bindings.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ using namespace blink;
9494
#include "V8HTMLIFrameElement.h"
9595
#include "extensions/renderer/script_context_set.h"
9696

97+
namespace content {
98+
#if defined(COMPONENT_BUILD) && defined(WIN32)
99+
CONTENT_EXPORT base::FilePath g_nw_temp_dir, g_nw_old_cwd;
100+
#else
101+
extern base::FilePath g_nw_temp_dir, g_nw_old_cwd;
102+
#endif
103+
}
104+
97105
using blink::WebFrame;
98106

99107
namespace extensions {
@@ -133,6 +141,9 @@ void NWCustomBindings::AddRoutes() {
133141
RouteHandlerFunction("crashRenderer",
134142
base::Bind(&NWCustomBindings::CrashRenderer,
135143
base::Unretained(this)));
144+
RouteHandlerFunction("getOldCwd",
145+
base::Bind(&NWCustomBindings::GetOldCwd,
146+
base::Unretained(this)));
136147
RouteHandlerFunction("evalScript",
137148
base::Bind(&NWCustomBindings::EvalScript,
138149
base::Unretained(this)));
@@ -317,6 +328,17 @@ void NWCustomBindings::GetAbsolutePath(
317328
#endif
318329
}
319330

331+
void NWCustomBindings::GetOldCwd(
332+
const v8::FunctionCallbackInfo<v8::Value>& args) {
333+
v8::Isolate* isolate = args.GetIsolate();
334+
base::FilePath path = content::g_nw_old_cwd;
335+
#if defined(OS_POSIX)
336+
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, path.value().c_str()));
337+
#else
338+
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, path.AsUTF8Unsafe().c_str()));
339+
#endif
340+
}
341+
320342
void NWCustomBindings::AddOriginAccessWhitelistEntry(const v8::FunctionCallbackInfo<v8::Value>& args) {
321343
v8::Isolate* isolate = args.GetIsolate();
322344

src/nw_custom_bindings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class NWCustomBindings : public ObjectBackedNativeHandler {
2222
void EvalScript(const v8::FunctionCallbackInfo<v8::Value>& args);
2323
void EvalNWBin(const v8::FunctionCallbackInfo<v8::Value>& args);
2424
void GetAbsolutePath(const v8::FunctionCallbackInfo<v8::Value>& args);
25+
void GetOldCwd(const v8::FunctionCallbackInfo<v8::Value>& args);
2526
void AddOriginAccessWhitelistEntry(const v8::FunctionCallbackInfo<v8::Value>& args);
2627
void RemoveOriginAccessWhitelistEntry(const v8::FunctionCallbackInfo<v8::Value>& args);
2728
void GetProxyForURL(const v8::FunctionCallbackInfo<v8::Value>& args);

src/resources/api_nw_app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
108108
apiFunctions.setHandleRequest('getDataPath', function() {
109109
return sendRequest.sendRequestSync('nw.App.getDataPath', [], this.definition.parameters, {})[0];
110110
});
111+
apiFunctions.setHandleRequest('getStartPath', function() {
112+
return nwNatives.getOldCwd();
113+
});
111114
bindingsAPI.compiledApi.__defineGetter__('dataPath', function() {
112115
if (!dataPath)
113116
dataPath = nw.App.getDataPath();
114117
return dataPath;
115118
});
119+
bindingsAPI.compiledApi.__defineGetter__('startPath', function() {
120+
return nw.App.getStartPath();
121+
});
116122
bindingsAPI.compiledApi.registerGlobalHotKey = function() {
117123
return nw.Shortcut.registerGlobalHotKey.apply(nw.Shortcut, arguments);
118124
};

0 commit comments

Comments
 (0)