Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: implement GetResourcesPath using MainApplicationBundlePath on Mac #19135

Merged
merged 1 commit into from Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions shell/common/mac/main_application_bundle.h
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super weird, why do we need to define NSBundle in non-objc code?

#endif

namespace base {
class FilePath;
Expand Down
23 changes: 7 additions & 16 deletions shell/common/node_bindings.cc
Expand Up @@ -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"

Expand Down Expand Up @@ -136,21 +137,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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion shell/common/node_bindings.h
Expand Up @@ -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();

Expand Down