]> khamidou — GitHub mirrors - electron.git/commitdiff
[Win] Override node's console and output stream with chromium's logging.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Jul 2013 12:06:23 +0000 (20:06 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 25 Jul 2013 12:06:23 +0000 (20:06 +0800)
On Window node doesn't outputing as GUI program, so we have to switch to
chromium's implementation. Hacking into node (like what we did before
this commit) would sometimes make the outputing blocked.

browser/atom/atom.coffee
common/api/atom_bindings.cc
common/api/atom_bindings.h

index bbc6c617883d6b22fcf4521b3483047fe39e3ebc..6385a01f95502a024f6dc422f4c909245891282f 100644 (file)
@@ -1,6 +1,12 @@
 fs = require 'fs'
 path = require 'path'
 
+# Redirect node's console to use our own implementations, since node can not
+# handle output when running as GUI program.
+if process.platform is 'win32'
+  console.log = console.error = console.warn = process.log
+  process.stdout.write = process.stderr.write = process.log
+
 # Enable idle gc.
 process.atomBinding('idle_gc').start()
 
index ca9f09f63834bbf4c73d7ef795926daf6f491c22..1f478c127de02a26b837de2b669eae47cf65f5c2 100644 (file)
@@ -35,6 +35,7 @@ void AtomBindings::BindTo(v8::Handle<v8::Object> process) {
   node::SetMethod(process, "atomBinding", Binding);
   node::SetMethod(process, "crash", Crash);
   node::SetMethod(process, "activateUvLoop", ActivateUVLoop);
+  node::SetMethod(process, "log", Log);
 }
 
 // static
@@ -96,4 +97,14 @@ v8::Handle<v8::Value> AtomBindings::ActivateUVLoop(const v8::Arguments& args) {
   return v8::Undefined();
 }
 
+// static
+v8::Handle<v8::Value> AtomBindings::Log(const v8::Arguments& args) {
+  std::string message;
+  for (int i = 0; i < args.Length(); ++i)
+    message += *v8::String::Utf8Value(args[i]);
+
+  logging::LogMessage("CONSOLE", 0, 0).stream() << message;
+  return v8::Undefined();
+}
+
 }  // namespace atom
index 8280b7760945cb1389a4c70a648cddd264cf4e2d..31b0152f047a3a1de8f3e036b436b369b89c8936 100644 (file)
@@ -23,6 +23,7 @@ class AtomBindings {
   static v8::Handle<v8::Value> Binding(const v8::Arguments& args);
   static v8::Handle<v8::Value> Crash(const v8::Arguments& args);
   static v8::Handle<v8::Value> ActivateUVLoop(const v8::Arguments& args);
+  static v8::Handle<v8::Value> Log(const v8::Arguments& args);
 
   DISALLOW_COPY_AND_ASSIGN(AtomBindings);
 };