From 38c3c56f2527de319319a46e6f00f9c3bfbf9817 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Sat, 6 Jul 2019 19:34:51 +0200 Subject: [PATCH] refactor: implement GetResourcesPath using MainApplicationBundlePath on Mac --- shell/common/mac/main_application_bundle.h | 4 ++++ shell/common/node_bindings.cc | 23 +++++++--------------- shell/common/node_bindings.h | 1 - 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/shell/common/mac/main_application_bundle.h b/shell/common/mac/main_application_bundle.h index a54f712d19ee1..ec9f97bd3f6d0 100644 --- a/shell/common/mac/main_application_bundle.h +++ b/shell/common/mac/main_application_bundle.h @@ -6,7 +6,11 @@ #ifndef SHELL_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ #define SHELL_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ +#ifdef __OBJC__ @class NSBundle; +#else +struct NSBundle; +#endif namespace base { class FilePath; diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 68d54efdc8757..c0fd84152241b 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -26,6 +26,7 @@ #include "shell/common/api/event_emitter_caller.h" #include "shell/common/api/locker.h" #include "shell/common/atom_command_line.h" +#include "shell/common/mac/main_application_bundle.h" #include "shell/common/native_mate_converters/file_path_converter.h" #include "shell/common/node_includes.h" @@ -136,21 +137,16 @@ std::unique_ptr StringVectorToArgArray( return array; } -base::FilePath GetResourcesPath(bool is_browser) { +base::FilePath GetResourcesPath() { +#if defined(OS_MACOSX) + return MainApplicationBundlePath().Append("Contents").Append("Resources"); +#else auto* command_line = base::CommandLine::ForCurrentProcess(); base::FilePath exec_path(command_line->GetProgram()); base::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")); + return exec_path.DirName().Append(FILE_PATH_LITERAL("resources")); #endif - return resources_path; } } // namespace @@ -199,10 +195,6 @@ bool NodeBindings::IsInitialized() { return g_is_initialized; } -base::FilePath::StringType NodeBindings::GetHelperResourcesPath() { - return GetResourcesPath(false).value(); -} - void NodeBindings::Initialize() { TRACE_EVENT0("electron", "NodeBindings::Initialize"); // Open node's error reporting system for browser process. @@ -318,8 +310,7 @@ node::Environment* NodeBindings::CreateEnvironment( process_type = "worker"; break; } - base::FilePath resources_path = - GetResourcesPath(browser_env_ == BrowserEnvironment::BROWSER); + base::FilePath resources_path = GetResourcesPath(); std::string init_script = "electron/js2c/" + process_type + "_init"; args.insert(args.begin() + 1, init_script); diff --git a/shell/common/node_bindings.h b/shell/common/node_bindings.h index 6ac18fc9f0835..c648f1e80beac 100644 --- a/shell/common/node_bindings.h +++ b/shell/common/node_bindings.h @@ -34,7 +34,6 @@ class NodeBindings { static NodeBindings* Create(BrowserEnvironment browser_env); static void RegisterBuiltinModules(); static bool IsInitialized(); - static base::FilePath::StringType GetHelperResourcesPath(); virtual ~NodeBindings();