browser_main_parts_mac.mm 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #import "brightray/browser/browser_main_parts.h"
  2. #import <AppKit/AppKit.h>
  3. #import "base/logging.h"
  4. #import "base/mac/bundle_locations.h"
  5. namespace brightray {
  6. void BrowserMainParts::OverrideAppLogsPath() {
  7. base::FilePath path;
  8. NSString* bundleName =
  9. [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
  10. NSString* logsPath =
  11. [NSString stringWithFormat:@"Library/Logs/%@", bundleName];
  12. NSString* libraryPath =
  13. [NSHomeDirectory() stringByAppendingPathComponent:logsPath];
  14. PathService::Override(DIR_APP_LOGS, base::FilePath([libraryPath UTF8String]));
  15. }
  16. // Replicates NSApplicationMain, but doesn't start a run loop.
  17. void BrowserMainParts::InitializeMainNib() {
  18. auto infoDictionary = base::mac::OuterBundle().infoDictionary;
  19. auto principalClass =
  20. NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]);
  21. auto application = [principalClass sharedApplication];
  22. NSString* mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"];
  23. auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName
  24. bundle:base::mac::FrameworkBundle()];
  25. [mainNib instantiateWithOwner:application topLevelObjects:nil];
  26. [mainNib release];
  27. }
  28. } // namespace brightray