atom_main_delegate_mac.mm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/app/atom_main_delegate.h"
  5. #include "atom/browser/mac/atom_application.h"
  6. #include "base/files/file_path.h"
  7. #include "base/files/file_util.h"
  8. #include "base/mac/bundle_locations.h"
  9. #include "base/mac/foundation_util.h"
  10. #include "base/mac/scoped_nsautorelease_pool.h"
  11. #include "base/path_service.h"
  12. #include "base/strings/sys_string_conversions.h"
  13. #include "brightray/common/application_info.h"
  14. #include "brightray/common/mac/main_application_bundle.h"
  15. #include "content/public/common/content_paths.h"
  16. namespace atom {
  17. namespace {
  18. base::FilePath GetFrameworksPath() {
  19. return brightray::MainApplicationBundlePath()
  20. .Append("Contents")
  21. .Append("Frameworks");
  22. }
  23. base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
  24. const std::string& name) {
  25. return frameworks_path.Append(name + " Helper.app")
  26. .Append("Contents")
  27. .Append("MacOS")
  28. .Append(name + " Helper");
  29. }
  30. } // namespace
  31. void AtomMainDelegate::OverrideFrameworkBundlePath() {
  32. base::mac::SetOverrideFrameworkBundlePath(
  33. GetFrameworksPath().Append(ATOM_PRODUCT_NAME " Framework.framework"));
  34. }
  35. void AtomMainDelegate::OverrideChildProcessPath() {
  36. base::FilePath frameworks_path = GetFrameworksPath();
  37. base::FilePath helper_path =
  38. GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME);
  39. if (!base::PathExists(helper_path))
  40. helper_path =
  41. GetHelperAppPath(frameworks_path, brightray::GetApplicationName());
  42. if (!base::PathExists(helper_path))
  43. LOG(FATAL) << "Unable to find helper app";
  44. base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
  45. }
  46. void AtomMainDelegate::SetUpBundleOverrides() {
  47. base::mac::ScopedNSAutoreleasePool pool;
  48. NSBundle* bundle = brightray::MainApplicationBundle();
  49. std::string base_bundle_id =
  50. base::SysNSStringToUTF8([bundle bundleIdentifier]);
  51. NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
  52. if (team_id)
  53. base_bundle_id = base::SysNSStringToUTF8(team_id) + "." + base_bundle_id;
  54. base::mac::SetBaseBundleID(base_bundle_id.c_str());
  55. }
  56. void RegisterAtomCrApp() {
  57. // Force the NSApplication subclass to be used.
  58. [AtomApplication sharedApplication];
  59. }
  60. } // namespace atom