]> khamidou — GitHub mirrors - electron.git/commitdiff
Set process.resourcesPath in C++
authorCheng Zhao <zcbenz@gmail.com>
Fri, 13 Feb 2015 05:32:58 +0000 (13:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 13 Feb 2015 05:32:58 +0000 (13:32 +0800)
atom/browser/lib/init.coffee
atom/common/node_bindings.cc
atom/renderer/lib/init.coffee

index fcdc1b11d9d54dc60a1ff00d4610516f97287ad4..a606c888f0b2294665ab482bb0e6c897f61b6968 100644 (file)
@@ -3,10 +3,6 @@ path   = require 'path'
 module = require 'module'
 util   = require 'util'
 
-# Expose information of current process.
-process.type = 'browser'
-process.resourcesPath = path.resolve process.argv[1], '..', '..', '..', '..'
-
 # We modified the original process.argv to let node.js load the atom.js,
 # we need to restore it here.
 process.argv.splice 1, 1
index cd13a65516751321f81543d045ace2aaadf6d92c..f98aaad81281bf532e7ea13f615dd79355645bd7 100644 (file)
@@ -7,6 +7,7 @@
 #include <string>
 #include <vector>
 
+#include "atom/common/native_mate_converters/file_path_converter.h"
 #include "base/command_line.h"
 #include "base/base_paths.h"
 #include "base/files/file_path.h"
@@ -14,6 +15,7 @@
 #include "base/path_service.h"
 #include "content/public/browser/browser_thread.h"
 #include "native_mate/locker.h"
+#include "native_mate/dictionary.h"
 
 #if defined(OS_WIN)
 #include "base/strings/utf_string_conversions.h"
@@ -110,6 +112,20 @@ std::vector<std::string> String16VectorToStringVector(
 }
 #endif
 
+base::FilePath GetResourcesPath(CommandLine* command_line, bool is_browser) {
+  base::FilePath exec_path(command_line->argv()[0]);
+  PathService::Get(base::FILE_EXE, &exec_path);
+  base::FilePath resources_path =
+#if defined(OS_MACOSX)
+      is_browser ? exec_path.DirName().DirName().Append("Resources") :
+                   exec_path.DirName().DirName().DirName().DirName().DirName()
+                            .Append("Resources");
+#else
+      exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
+#endif
+  return resources_path;
+}
+
 }  // namespace
 
 node::Environment* global_env = nullptr;
@@ -158,31 +174,25 @@ node::Environment* NodeBindings::CreateEnvironment(
 #endif
 
   // Feed node the path to initialization script.
-  base::FilePath exec_path(command_line->argv()[0]);
-  PathService::Get(base::FILE_EXE, &exec_path);
-  base::FilePath resources_path =
-#if defined(OS_MACOSX)
-      is_browser_ ? exec_path.DirName().DirName().Append("Resources") :
-                    exec_path.DirName().DirName().DirName().DirName().DirName()
-                             .Append("Resources");
-#else
-      exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
-#endif
+  const char* process_type = is_browser_ ? "browser" : "renderer";
+  base::FilePath resources_path = GetResourcesPath(command_line, is_browser_);
   base::FilePath script_path =
       resources_path.Append(FILE_PATH_LITERAL("atom.asar"))
-                    .Append(is_browser_ ? FILE_PATH_LITERAL("browser") :
-                                          FILE_PATH_LITERAL("renderer"))
+                    .Append(FILE_PATH_LITERAL(process_type))
                     .Append(FILE_PATH_LITERAL("lib"))
                     .Append(FILE_PATH_LITERAL("init.js"));
   std::string script_path_str = script_path.AsUTF8Unsafe();
   args.insert(args.begin() + 1, script_path_str.c_str());
 
   scoped_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
-  return node::CreateEnvironment(context->GetIsolate(),
-                                 uv_default_loop(),
-                                 context,
-                                 args.size(), c_argv.get(),
-                                 0, nullptr);
+  node::Environment* env =  node::CreateEnvironment(
+      context->GetIsolate(), uv_default_loop(), context,
+      args.size(), c_argv.get(), 0, nullptr);
+
+  mate::Dictionary process(context->GetIsolate(), env->process_object());
+  process.Set("type", process_type);
+  process.Set("resourcesPath", resources_path);
+  return env;
 }
 
 void NodeBindings::LoadEnvironment(node::Environment* env) {
index a11037ffc0ee757a0f5f403e03a1a13131ac7822..43d0fa9cfa069f1cc1600cc405a34ef9f7080fa0 100644 (file)
@@ -4,10 +4,6 @@ path    = require 'path'
 url     = require 'url'
 Module  = require 'module'
 
-# Expose information of current process.
-process.type = 'renderer'
-process.resourcesPath = path.resolve process.argv[1], '..', '..', '..', '..'
-
 # We modified the original process.argv to let node.js load the
 # atom-renderer.js, we need to restore it here.
 process.argv.splice 1, 1