From 77f7cfc938d481fec022bc33c0bf227656aa7de9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Nov 2015 18:52:07 +0800 Subject: [PATCH 1/2] Change how we detect Helper process --- brightray/common/mac/main_application_bundle.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm index 730eb36207b6..bfdf8f748185 100644 --- a/brightray/common/mac/main_application_bundle.mm +++ b/brightray/common/mac/main_application_bundle.mm @@ -5,10 +5,10 @@ #import "common/mac/main_application_bundle.h" -#import "common/mac/foundation_util.h" - -#import "base/files/file_path.h" -#import "base/path_service.h" +#include "base/files/file_path.h" +#include "base/mac/foundation_util.h" +#include "base/path_service.h" +#include "base/strings/string_util.h" namespace brightray { @@ -18,7 +18,7 @@ base::FilePath MainApplicationBundlePath() { PathService::Get(base::FILE_EXE, &path); // Up to Contents. - if (base::mac::IsBackgroundOnlyProcess()) { + if (base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE)) { // The running executable is the helper. Go up five steps: // Contents/Frameworks/Helper.app/Contents/MacOS/Helper // ^ to here ^ from here From b81876775e245dbdd917fbaed36cef1d4c07d86a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Nov 2015 19:07:03 +0800 Subject: [PATCH 2/2] Check ElectronMainProcess key in Info.plist --- brightray/common/mac/main_application_bundle.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm index bfdf8f748185..3e386b40dc58 100644 --- a/brightray/common/mac/main_application_bundle.mm +++ b/brightray/common/mac/main_application_bundle.mm @@ -6,19 +6,30 @@ #import "common/mac/main_application_bundle.h" #include "base/files/file_path.h" +#include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" #include "base/path_service.h" #include "base/strings/string_util.h" namespace brightray { +namespace { + +bool HasMainProcessKey() { + NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary]; + return [[info_dictionary objectForKey:@"ElectronMainProcess"] boolValue] != NO; +} + +} // namespace + base::FilePath MainApplicationBundlePath() { // Start out with the path to the running executable. base::FilePath path; PathService::Get(base::FILE_EXE, &path); // Up to Contents. - if (base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE)) { + if (!HasMainProcessKey() && + base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE)) { // The running executable is the helper. Go up five steps: // Contents/Frameworks/Helper.app/Contents/MacOS/Helper // ^ to here ^ from here @@ -40,4 +51,4 @@ NSBundle* MainApplicationBundle() { return [NSBundle bundleWithPath:base::mac::FilePathToNSString(MainApplicationBundlePath())]; } -} +} // namespace brightray