refactor: implement GetResourcesPath using MainApplicationBundlePath on Mac (#19135)
This commit is contained in:
parent
436d5c9ac1
commit
b32bee5d84
3 changed files with 11 additions and 17 deletions
|
@ -6,7 +6,11 @@
|
||||||
#ifndef SHELL_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_
|
#ifndef SHELL_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_
|
||||||
#define SHELL_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_
|
#define SHELL_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
@class NSBundle;
|
@class NSBundle;
|
||||||
|
#else
|
||||||
|
struct NSBundle;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
class FilePath;
|
class FilePath;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "shell/common/api/event_emitter_caller.h"
|
#include "shell/common/api/event_emitter_caller.h"
|
||||||
#include "shell/common/api/locker.h"
|
#include "shell/common/api/locker.h"
|
||||||
#include "shell/common/atom_command_line.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/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
@ -137,21 +138,16 @@ std::unique_ptr<const char* []> StringVectorToArgArray(
|
||||||
return array;
|
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();
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
base::FilePath exec_path(command_line->GetProgram());
|
base::FilePath exec_path(command_line->GetProgram());
|
||||||
base::PathService::Get(base::FILE_EXE, &exec_path);
|
base::PathService::Get(base::FILE_EXE, &exec_path);
|
||||||
|
|
||||||
base::FilePath resources_path =
|
return exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
|
||||||
#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
|
#endif
|
||||||
return resources_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -200,10 +196,6 @@ bool NodeBindings::IsInitialized() {
|
||||||
return g_is_initialized;
|
return g_is_initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
base::FilePath::StringType NodeBindings::GetHelperResourcesPath() {
|
|
||||||
return GetResourcesPath(false).value();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NodeBindings::Initialize() {
|
void NodeBindings::Initialize() {
|
||||||
TRACE_EVENT0("electron", "NodeBindings::Initialize");
|
TRACE_EVENT0("electron", "NodeBindings::Initialize");
|
||||||
// Open node's error reporting system for browser process.
|
// Open node's error reporting system for browser process.
|
||||||
|
@ -319,8 +311,7 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
process_type = "worker";
|
process_type = "worker";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
base::FilePath resources_path =
|
base::FilePath resources_path = GetResourcesPath();
|
||||||
GetResourcesPath(browser_env_ == BrowserEnvironment::BROWSER);
|
|
||||||
std::string init_script = "electron/js2c/" + process_type + "_init";
|
std::string init_script = "electron/js2c/" + process_type + "_init";
|
||||||
|
|
||||||
args.insert(args.begin() + 1, init_script);
|
args.insert(args.begin() + 1, init_script);
|
||||||
|
|
|
@ -34,7 +34,6 @@ class NodeBindings {
|
||||||
static NodeBindings* Create(BrowserEnvironment browser_env);
|
static NodeBindings* Create(BrowserEnvironment browser_env);
|
||||||
static void RegisterBuiltinModules();
|
static void RegisterBuiltinModules();
|
||||||
static bool IsInitialized();
|
static bool IsInitialized();
|
||||||
static base::FilePath::StringType GetHelperResourcesPath();
|
|
||||||
|
|
||||||
virtual ~NodeBindings();
|
virtual ~NodeBindings();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue