atom_main_delegate_mac.mm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "shell/app/atom_main_delegate.h"
  5. #include <string>
  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 "content/common/mac_helpers.h"
  14. #include "content/public/common/content_paths.h"
  15. #include "shell/browser/mac/atom_application.h"
  16. #include "shell/common/application_info.h"
  17. #include "shell/common/mac/main_application_bundle.h"
  18. namespace electron {
  19. namespace {
  20. base::FilePath GetFrameworksPath() {
  21. return MainApplicationBundlePath().Append("Contents").Append("Frameworks");
  22. }
  23. base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
  24. const std::string& name) {
  25. // Figure out what helper we are running
  26. base::FilePath path;
  27. base::PathService::Get(base::FILE_EXE, &path);
  28. std::string helper_name = "Helper";
  29. if (base::EndsWith(path.value(), content::kMacHelperSuffix_renderer,
  30. base::CompareCase::SENSITIVE)) {
  31. helper_name += content::kMacHelperSuffix_renderer;
  32. } else if (base::EndsWith(path.value(), content::kMacHelperSuffix_gpu,
  33. base::CompareCase::SENSITIVE)) {
  34. helper_name += content::kMacHelperSuffix_gpu;
  35. } else if (base::EndsWith(path.value(), content::kMacHelperSuffix_plugin,
  36. base::CompareCase::SENSITIVE)) {
  37. helper_name += content::kMacHelperSuffix_plugin;
  38. }
  39. return frameworks_path.Append(name + " " + helper_name + ".app")
  40. .Append("Contents")
  41. .Append("MacOS")
  42. .Append(name + " " + helper_name);
  43. }
  44. } // namespace
  45. void AtomMainDelegate::OverrideFrameworkBundlePath() {
  46. base::mac::SetOverrideFrameworkBundlePath(
  47. GetFrameworksPath().Append(ELECTRON_PRODUCT_NAME " Framework.framework"));
  48. }
  49. void AtomMainDelegate::OverrideChildProcessPath() {
  50. base::FilePath frameworks_path = GetFrameworksPath();
  51. base::FilePath helper_path =
  52. GetHelperAppPath(frameworks_path, ELECTRON_PRODUCT_NAME);
  53. if (!base::PathExists(helper_path))
  54. helper_path = GetHelperAppPath(frameworks_path, GetApplicationName());
  55. if (!base::PathExists(helper_path))
  56. LOG(FATAL) << "Unable to find helper app";
  57. base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
  58. }
  59. void AtomMainDelegate::SetUpBundleOverrides() {
  60. base::mac::ScopedNSAutoreleasePool pool;
  61. NSBundle* bundle = MainApplicationBundle();
  62. std::string base_bundle_id =
  63. base::SysNSStringToUTF8([bundle bundleIdentifier]);
  64. NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
  65. if (team_id)
  66. base_bundle_id = base::SysNSStringToUTF8(team_id) + "." + base_bundle_id;
  67. base::mac::SetBaseBundleID(base_bundle_id.c_str());
  68. }
  69. void RegisterAtomCrApp() {
  70. // Force the NSApplication subclass to be used.
  71. [AtomApplication sharedApplication];
  72. }
  73. } // namespace electron