Load atom.js on startup.

This commit is contained in:
Cheng Zhao 2013-04-13 21:10:41 +08:00
parent f853fc3df5
commit 40307126d7
8 changed files with 24 additions and 9 deletions

View file

@ -71,6 +71,12 @@
'<(PRODUCT_DIR)/<(product_name).framework',
],
},
{
'destination': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources',
'files': [
'browser/atom',
],
},
],
'postbuilds': [
{

1
browser/atom/atom.js Normal file
View file

@ -0,0 +1 @@
console.log(process.argv);

View file

0
browser/atom/index.html Normal file
View file

View file

@ -15,7 +15,7 @@
namespace atom {
AtomBrowserMainParts::AtomBrowserMainParts()
: node_bindings_(new NodeBindings) {
: node_bindings_(new NodeBindings(true)) {
}
AtomBrowserMainParts::~AtomBrowserMainParts() {

View file

@ -5,6 +5,7 @@
#include "common/node_bindings.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "v8/include/v8.h"
#include "vendor/node/src/node.h"
@ -12,7 +13,8 @@
namespace atom {
NodeBindings::NodeBindings() {
NodeBindings::NodeBindings(bool is_browser)
: is_browser_(is_browser) {
}
NodeBindings::~NodeBindings() {
@ -23,10 +25,8 @@ void NodeBindings::Initialize() {
// Convert string vector to char* array.
std::vector<char*> argv(str_argv.size(), NULL);
for (size_t i = 0; i < str_argv.size(); ++i) {
LOG(ERROR) << str_argv[i];
for (size_t i = 0; i < str_argv.size(); ++i)
argv[i] = const_cast<char*>(str_argv[i].c_str());
}
// Init node.
node::Init(argv.size(), &argv[0]);
@ -39,8 +39,14 @@ void NodeBindings::Initialize() {
v8::Context::Scope context_scope(node::g_context);
v8::Handle<v8::Object> process = node::SetupProcessObject(
argv.size(), &argv[0]);
// Tell node.js we are in browser or renderer.
v8::Handle<v8::String> type =
is_browser_ ? v8::String::New("browser") : v8::String::New("renderer");
process->Set(v8::String::New("__atom_type"), type);
node::Load(process);
}
}
} // namespace at
} // namespace atom

View file

@ -11,13 +11,15 @@ namespace atom {
class NodeBindings {
public:
NodeBindings();
NodeBindings(bool is_browser);
virtual ~NodeBindings();
// Setup everything including V8, libuv and node.js main script.
void Initialize();
private:
bool is_browser_;
DISALLOW_COPY_AND_ASSIGN(NodeBindings);
};

2
vendor/node vendored

@ -1 +1 @@
Subproject commit 4ca67139123acff24c884377ebfd6f31eb4efa01
Subproject commit 6dadfdb1f5fbaf0d7132fa2b4e4ed084bddead8a