electron/shell/app/atom_main_delegate_mac.mm

72 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 "shell/app/atom_main_delegate.h"
2014-12-29 17:35:08 +00:00
#include <string>
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"
2014-12-29 17:35:08 +00:00
#include "content/public/common/content_paths.h"
#include "shell/browser/mac/atom_application.h"
#include "shell/common/application_info.h"
#include "shell/common/mac/main_application_bundle.h"
2014-12-29 17:35:08 +00:00
namespace atom {
namespace {
base::FilePath GetFrameworksPath() {
2018-10-24 10:49:10 +00:00
return 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(
GetFrameworksPath().Append(ELECTRON_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, ELECTRON_PRODUCT_NAME);
2015-04-14 05:51:08 +00:00
if (!base::PathExists(helper_path))
2018-10-24 10:49:10 +00:00
helper_path = GetHelperAppPath(frameworks_path, 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;
2018-10-24 10:49:10 +00:00
NSBundle* bundle = MainApplicationBundle();
2016-05-19 01:57:57 +00:00
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