electron/atom/browser/atom_browser_main_parts_mac.mm

64 lines
2.1 KiB
Text
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
2014-03-16 00:30:26 +00:00
#include "atom/browser/atom_browser_main_parts.h"
2018-10-24 10:49:10 +00:00
#include "atom/browser/atom_paths.h"
#include "atom/browser/mac/atom_application_delegate.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
2014-05-29 07:54:25 +00:00
#include "ui/base/l10n/l10n_util_mac.h"
namespace atom {
void AtomBrowserMainParts::PreMainMessageLoopStart() {
// Set our own application delegate.
2014-11-16 15:04:31 +00:00
AtomApplicationDelegate* delegate = [[AtomApplicationDelegate alloc] init];
2016-08-05 20:57:33 +00:00
[NSApp setDelegate:delegate];
PreMainMessageLoopStartCommon();
// Prevent Cocoa from turning command-line arguments into
// |-application:openFiles:|, since we already handle them directly.
[[NSUserDefaults standardUserDefaults]
2018-04-20 18:47:04 +00:00
setObject:@"NO"
forKey:@"NSTreatUnknownArgumentsAsOpen"];
}
void AtomBrowserMainParts::FreeAppDelegate() {
[[NSApp delegate] release];
[NSApp setDelegate:nil];
}
void AtomBrowserMainParts::OverrideAppLogsPath() {
base::FilePath path;
NSString* bundleName =
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString* logsPath =
[NSString stringWithFormat:@"Library/Logs/%@", bundleName];
NSString* libraryPath =
[NSHomeDirectory() stringByAppendingPathComponent:logsPath];
2018-10-24 10:49:10 +00:00
base::PathService::Override(DIR_APP_LOGS,
base::FilePath([libraryPath UTF8String]));
}
// Replicates NSApplicationMain, but doesn't start a run loop.
void AtomBrowserMainParts::InitializeMainNib() {
auto infoDictionary = base::mac::OuterBundle().infoDictionary;
auto principalClass =
NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]);
auto application = [principalClass sharedApplication];
NSString* mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"];
auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName
bundle:base::mac::FrameworkBundle()];
[mainNib instantiateWithOwner:application topLevelObjects:nil];
[mainNib release];
}
} // namespace atom