refactor: implement GetResourcesPath using MainApplicationBundlePath on Mac (#19135)

This commit is contained in:
Milan Burda 2019-07-09 11:56:40 +02:00 committed by Alexey Kuzmin
parent 436d5c9ac1
commit b32bee5d84
3 changed files with 11 additions and 17 deletions

View file

@ -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;

View file

@ -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"
@ -137,21 +138,16 @@ std::unique_ptr<const char* []> 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
@ -200,10 +196,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.
@ -319,8 +311,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);

View file

@ -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();