2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 20:09:19 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
2013-05-02 20:09:19 +08:00
|
|
|
|
2022-09-23 11:50:46 -07:00
|
|
|
#include <string>
|
|
|
|
|
2019-10-21 14:11:09 -07:00
|
|
|
#include "base/mac/bundle_locations.h"
|
|
|
|
#include "base/mac/foundation_util.h"
|
|
|
|
#include "base/path_service.h"
|
2021-06-28 20:26:57 -07:00
|
|
|
#include "services/device/public/cpp/geolocation/geolocation_manager_impl_mac.h"
|
2019-10-10 17:54:03 +02:00
|
|
|
#import "shell/browser/mac/electron_application.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/mac/electron_application_delegate.h"
|
2020-05-07 13:31:26 -07:00
|
|
|
#include "shell/common/electron_paths.h"
|
2019-10-21 14:11:09 -07:00
|
|
|
#include "ui/base/l10n/l10n_util_mac.h"
|
2013-05-02 20:09:19 +08:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2021-05-19 16:15:47 -07:00
|
|
|
void ElectronBrowserMainParts::PreCreateMainMessageLoop() {
|
2016-01-08 12:06:06 +08:00
|
|
|
// Set our own application delegate.
|
2014-11-16 23:04:31 +08:00
|
|
|
ElectronApplicationDelegate* delegate =
|
|
|
|
[[ElectronApplicationDelegate alloc] init];
|
2016-08-05 22:57:33 +02:00
|
|
|
[NSApp setDelegate:delegate];
|
2013-05-02 20:09:19 +08:00
|
|
|
|
2021-05-19 16:15:47 -07:00
|
|
|
PreCreateMainMessageLoopCommon();
|
2013-05-31 10:17:40 +08:00
|
|
|
|
|
|
|
// Prevent Cocoa from turning command-line arguments into
|
|
|
|
// |-application:openFiles:|, since we already handle them directly.
|
|
|
|
[[NSUserDefaults standardUserDefaults]
|
2018-04-20 14:47:04 -04:00
|
|
|
setObject:@"NO"
|
|
|
|
forKey:@"NSTreatUnknownArgumentsAsOpen"];
|
2021-06-28 20:26:57 -07:00
|
|
|
|
|
|
|
geolocation_manager_ = device::GeolocationManagerImpl::Create();
|
2013-05-02 20:09:19 +08:00
|
|
|
}
|
|
|
|
|
2015-11-04 17:23:27 +08:00
|
|
|
void ElectronBrowserMainParts::FreeAppDelegate() {
|
2014-11-17 09:52:24 +08:00
|
|
|
[[NSApp delegate] release];
|
|
|
|
[NSApp setDelegate:nil];
|
2013-05-30 16:03:10 +08:00
|
|
|
}
|
|
|
|
|
2019-10-10 17:54:03 +02:00
|
|
|
void ElectronBrowserMainParts::RegisterURLHandler() {
|
2020-02-21 11:05:03 -08:00
|
|
|
[[AtomApplication sharedApplication] registerURLHandler];
|
2019-10-10 17:54:03 +02:00
|
|
|
}
|
|
|
|
|
2019-10-21 14:11:09 -07:00
|
|
|
// Replicates NSApplicationMain, but doesn't start a run loop.
|
|
|
|
void ElectronBrowserMainParts::InitializeMainNib() {
|
|
|
|
auto infoDictionary = base::mac::OuterBundle().infoDictionary;
|
|
|
|
|
|
|
|
auto principalClass =
|
|
|
|
NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]);
|
|
|
|
auto application = [principalClass sharedApplication];
|
|
|
|
|
|
|
|
NSString* mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"];
|
|
|
|
|
|
|
|
NSNib* mainNib;
|
|
|
|
|
|
|
|
@try {
|
|
|
|
mainNib = [[NSNib alloc] initWithNibNamed:mainNibName
|
|
|
|
bundle:base::mac::FrameworkBundle()];
|
|
|
|
// Handle failure of initWithNibNamed on SMB shares
|
|
|
|
// TODO(codebytere): Remove when
|
|
|
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=932935 is fixed
|
|
|
|
} @catch (NSException* exception) {
|
|
|
|
NSString* nibPath =
|
|
|
|
[NSString stringWithFormat:@"Resources/%@.nib", mainNibName];
|
|
|
|
nibPath = [base::mac::FrameworkBundle().bundlePath
|
|
|
|
stringByAppendingPathComponent:nibPath];
|
|
|
|
|
|
|
|
NSData* data = [NSData dataWithContentsOfFile:nibPath];
|
|
|
|
mainNib = [[NSNib alloc] initWithNibData:data
|
|
|
|
bundle:base::mac::FrameworkBundle()];
|
|
|
|
}
|
|
|
|
|
|
|
|
[mainNib instantiateWithOwner:application topLevelObjects:nil];
|
|
|
|
[mainNib release];
|
2018-10-23 22:15:55 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 11:50:46 -07:00
|
|
|
std::string ElectronBrowserMainParts::GetCurrentSystemLocale() {
|
|
|
|
NSString* systemLocaleIdentifier =
|
|
|
|
[[NSLocale currentLocale] localeIdentifier];
|
|
|
|
|
|
|
|
// Mac OS X uses "_" instead of "-", so swap to get a real locale value.
|
|
|
|
std::string locale_value = [[systemLocaleIdentifier
|
|
|
|
stringByReplacingOccurrencesOfString:@"_"
|
|
|
|
withString:@"-"] UTF8String];
|
|
|
|
|
|
|
|
return locale_value;
|
|
|
|
}
|
|
|
|
|
2013-05-02 20:09:19 +08:00
|
|
|
} // namespace electron
|