atom_main_delegate_mac.mm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "base/files/file_path.h"
  6. #include "base/files/file_util.h"
  7. #include "base/mac/bundle_locations.h"
  8. #include "base/mac/foundation_util.h"
  9. #include "base/mac/scoped_nsautorelease_pool.h"
  10. #include "base/path_service.h"
  11. #include "base/strings/sys_string_conversions.h"
  12. #include "brightray/common/application_info.h"
  13. #include "brightray/common/mac/main_application_bundle.h"
  14. #include "content/public/common/content_paths.h"
  15. namespace atom {
  16. namespace {
  17. base::FilePath GetFrameworksPath() {
  18. return brightray::MainApplicationBundlePath()
  19. .Append("Contents")
  20. .Append("Frameworks");
  21. }
  22. base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
  23. const std::string& name) {
  24. return frameworks_path.Append(name + " Helper.app")
  25. .Append("Contents")
  26. .Append("MacOS")
  27. .Append(name + " Helper");
  28. }
  29. } // namespace
  30. void AtomMainDelegate::OverrideFrameworkBundlePath() {
  31. base::mac::SetOverrideFrameworkBundlePath(
  32. GetFrameworksPath().Append(ATOM_PRODUCT_NAME " Framework.framework"));
  33. }
  34. void AtomMainDelegate::OverrideChildProcessPath() {
  35. base::FilePath frameworks_path = GetFrameworksPath();
  36. base::FilePath helper_path =
  37. GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME);
  38. if (!base::PathExists(helper_path))
  39. helper_path =
  40. GetHelperAppPath(frameworks_path, brightray::GetApplicationName());
  41. if (!base::PathExists(helper_path))
  42. LOG(FATAL) << "Unable to find helper app";
  43. PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
  44. }
  45. void AtomMainDelegate::SetUpBundleOverrides() {
  46. base::mac::ScopedNSAutoreleasePool pool;
  47. NSBundle* bundle = brightray::MainApplicationBundle();
  48. std::string base_bundle_id =
  49. base::SysNSStringToUTF8([bundle bundleIdentifier]);
  50. NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
  51. if (team_id)
  52. base_bundle_id = base::SysNSStringToUTF8(team_id) + "." + base_bundle_id;
  53. base::mac::SetBaseBundleID(base_bundle_id.c_str());
  54. }
  55. } // namespace atom