atom_main_delegate_mac.mm 2.3 KB

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