Skip to content

Commit 1a8131a

Browse files
committed
Add 'node-main', fix nwjs#36.
1 parent 64c5ebb commit 1a8131a

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/common/shell_switches.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ const char kNoToolbar[] = "no-toolbar";
3434
// Open specified url
3535
const char kUrl[] = "url";
3636

37-
// Set current working directory
37+
// Set current working directory.
3838
const char kWorkingDirectory[] = "working-directory";
3939

40+
// Pass the main script to node.
41+
const char kNodeMain[] = "node-main";
42+
4043
const char kmMain[] = "main";
4144
const char kmName[] = "name";
4245
const char kmWebkit[] = "webkit";

src/common/shell_switches.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern const char kDeveloper[];
1414
extern const char kNoToolbar[];
1515
extern const char kUrl[];
1616
extern const char kWorkingDirectory[];
17+
extern const char kNodeMain[];
1718

1819
// Manifest settings
1920
extern const char kmMain[];

src/renderer/shell_content_renderer_client.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,19 @@ void ShellContentRendererClient::RenderThreadStarted() {
5454
command_line->GetSwitchValuePath(switches::kWorkingDirectory));
5555
}
5656

57+
int argc = 1;
58+
char* argv[] = { const_cast<char*>("node"), NULL, NULL };
59+
std::string node_main;
60+
61+
// Check if there is a 'node-main'.
62+
if (command_line->HasSwitch(switches::kNodeMain)) {
63+
argc++;
64+
node_main = command_line->GetSwitchValueASCII(switches::kNodeMain);
65+
argv[1] = const_cast<char*>(node_main.c_str());
66+
}
67+
5768
// Initialize uv.
58-
char* argv[] = { (char*)"node", NULL };
59-
node::SetupUv(1, argv);
69+
node::SetupUv(argc, argv);
6070

6171
// Initialize node after render thread is started.
6272
v8::V8::Initialize();
@@ -66,7 +76,7 @@ void ShellContentRendererClient::RenderThreadStarted() {
6676
node::g_context->Enter();
6777

6878
// Setup node.js.
69-
node::SetupContext(1, argv, node::g_context->Global());
79+
node::SetupContext(argc, argv, node::g_context->Global());
7080

7181
// Start observers.
7282
shell_observer_.reset(new ShellRenderProcessObserver());

src/shell_content_browser_client.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "base/file_path.h"
2525
#include "base/file_util.h"
2626
#include "base/threading/thread_restrictions.h"
27+
#include "base/values.h"
2728
#include "content/public/browser/browser_url_handler.h"
2829
#include "content/public/browser/resource_dispatcher_host.h"
2930
#include "content/nw/src/api/dispatcher_host.h"
@@ -75,6 +76,11 @@ void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
7576
// Set cwd
7677
command_line->AppendSwitchPath(switches::kWorkingDirectory,
7778
package->path());
79+
80+
// Check if we have 'node-main'.
81+
std::string node_main;
82+
if (package->root()->GetString(switches::kNodeMain, &node_main))
83+
command_line->AppendSwitchASCII(switches::kNodeMain, node_main);
7884
}
7985
}
8086

0 commit comments

Comments
 (0)