electron/atom/app/atom_main_delegate_mac.mm

73 lines
2.3 KiB
Text
Raw Normal View History

2014-12-29 17:35:08 +00:00
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/app/atom_main_delegate.h"
#include "atom/browser/mac/atom_application.h"
2014-12-29 17:35:08 +00:00
#include "base/files/file_path.h"
2015-04-14 05:51:08 +00:00
#include "base/files/file_util.h"
2018-04-20 18:47:04 +00:00
#include "base/mac/bundle_locations.h"
2016-05-18 07:42:26 +00:00
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsautorelease_pool.h"
2014-12-29 17:35:08 +00:00
#include "base/path_service.h"
2016-05-19 01:57:57 +00:00
#include "base/strings/sys_string_conversions.h"
2015-04-14 05:51:08 +00:00
#include "brightray/common/application_info.h"
2014-12-29 17:35:08 +00:00
#include "brightray/common/mac/main_application_bundle.h"
#include "content/public/common/content_paths.h"
namespace atom {
namespace {
base::FilePath GetFrameworksPath() {
2018-04-20 18:47:04 +00:00
return brightray::MainApplicationBundlePath()
.Append("Contents")
.Append("Frameworks");
2014-12-29 17:35:08 +00:00
}
2015-04-17 07:10:48 +00:00
base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
2015-04-14 05:51:08 +00:00
const std::string& name) {
return frameworks_path.Append(name + " Helper.app")
2018-04-20 18:47:04 +00:00
.Append("Contents")
.Append("MacOS")
.Append(name + " Helper");
2015-04-14 05:51:08 +00:00
}
2014-12-29 17:35:08 +00:00
} // namespace
void AtomMainDelegate::OverrideFrameworkBundlePath() {
base::mac::SetOverrideFrameworkBundlePath(
2015-04-14 06:13:03 +00:00
GetFrameworksPath().Append(ATOM_PRODUCT_NAME " Framework.framework"));
2014-12-29 17:35:08 +00:00
}
void AtomMainDelegate::OverrideChildProcessPath() {
2015-04-14 05:51:08 +00:00
base::FilePath frameworks_path = GetFrameworksPath();
2018-04-20 18:47:04 +00:00
base::FilePath helper_path =
GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME);
2015-04-14 05:51:08 +00:00
if (!base::PathExists(helper_path))
2018-04-20 18:47:04 +00:00
helper_path =
GetHelperAppPath(frameworks_path, brightray::GetApplicationName());
2015-04-14 05:51:08 +00:00
if (!base::PathExists(helper_path))
LOG(FATAL) << "Unable to find helper app";
2018-09-15 00:09:42 +00:00
base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
2014-12-29 17:35:08 +00:00
}
2016-05-18 07:42:26 +00:00
void AtomMainDelegate::SetUpBundleOverrides() {
base::mac::ScopedNSAutoreleasePool pool;
2016-05-19 01:57:57 +00:00
NSBundle* bundle = brightray::MainApplicationBundle();
std::string base_bundle_id =
base::SysNSStringToUTF8([bundle bundleIdentifier]);
NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
if (team_id)
base_bundle_id = base::SysNSStringToUTF8(team_id) + "." + base_bundle_id;
base::mac::SetBaseBundleID(base_bundle_id.c_str());
2016-05-18 07:42:26 +00:00
}
void RegisterAtomCrApp() {
// Force the NSApplication subclass to be used.
[AtomApplication sharedApplication];
}
2014-12-29 17:35:08 +00:00
} // namespace atom