2014-10-31 21:17:05 +03:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 13:49:37 +04:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 19:43:23 +04:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 23:46:59 +03:00
|
|
|
#include "shell/browser/browser.h"
|
2013-05-02 19:43:23 +04:00
|
|
|
|
2019-05-02 15:05:37 +03:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
2016-03-21 21:24:25 +03:00
|
|
|
#include "base/mac/bundle_locations.h"
|
2015-04-14 10:55:41 +03:00
|
|
|
#include "base/mac/foundation_util.h"
|
2016-07-06 21:43:44 +03:00
|
|
|
#include "base/mac/mac_util.h"
|
2019-02-21 20:13:43 +03:00
|
|
|
#include "base/mac/scoped_cftyperef.h"
|
2016-07-01 11:39:01 +03:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2016-07-02 04:36:11 +03:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2016-05-23 18:49:46 +03:00
|
|
|
#include "net/base/mac/url_conversions.h"
|
2019-06-19 23:46:59 +03:00
|
|
|
#include "shell/browser/mac/atom_application.h"
|
|
|
|
#include "shell/browser/mac/atom_application_delegate.h"
|
|
|
|
#include "shell/browser/mac/dict_util.h"
|
|
|
|
#include "shell/browser/native_window.h"
|
|
|
|
#include "shell/browser/window_list.h"
|
|
|
|
#include "shell/common/application_info.h"
|
|
|
|
#include "shell/common/platform_util.h"
|
|
|
|
#include "shell/common/promise_util.h"
|
2018-03-06 10:12:10 +03:00
|
|
|
#include "ui/gfx/image/image.h"
|
2016-05-23 18:49:46 +03:00
|
|
|
#include "url/gurl.h"
|
2013-05-02 19:43:23 +04:00
|
|
|
|
2019-06-20 00:23:04 +03:00
|
|
|
namespace electron {
|
2013-05-02 19:43:23 +04:00
|
|
|
|
2018-02-05 10:13:35 +03:00
|
|
|
void Browser::SetShutdownHandler(base::Callback<bool()> handler) {
|
|
|
|
[[AtomApplication sharedApplication] setShutdownHandler:std::move(handler)];
|
|
|
|
}
|
|
|
|
|
2013-05-30 15:24:47 +04:00
|
|
|
void Browser::Focus() {
|
2019-02-26 04:44:38 +03:00
|
|
|
[[AtomApplication sharedApplication] activateIgnoringOtherApps:NO];
|
2013-05-30 15:24:47 +04:00
|
|
|
}
|
|
|
|
|
2016-01-29 14:30:19 +03:00
|
|
|
void Browser::Hide() {
|
|
|
|
[[AtomApplication sharedApplication] hide:nil];
|
|
|
|
}
|
|
|
|
|
2016-01-30 23:40:32 +03:00
|
|
|
void Browser::Show() {
|
|
|
|
[[AtomApplication sharedApplication] unhide:nil];
|
|
|
|
}
|
|
|
|
|
2014-11-17 08:05:06 +03:00
|
|
|
void Browser::AddRecentDocument(const base::FilePath& path) {
|
2015-12-15 12:17:24 +03:00
|
|
|
NSString* path_string = base::mac::FilePathToNSString(path);
|
|
|
|
if (!path_string)
|
|
|
|
return;
|
|
|
|
NSURL* u = [NSURL fileURLWithPath:path_string];
|
|
|
|
if (!u)
|
|
|
|
return;
|
2014-11-17 08:05:06 +03:00
|
|
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:u];
|
|
|
|
}
|
|
|
|
|
2014-11-17 11:13:47 +03:00
|
|
|
void Browser::ClearRecentDocuments() {
|
2015-12-30 03:35:54 +03:00
|
|
|
[[NSDocumentController sharedDocumentController] clearRecentDocuments:nil];
|
2014-11-17 11:13:47 +03:00
|
|
|
}
|
|
|
|
|
2016-08-16 08:54:30 +03:00
|
|
|
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|
|
|
mate::Arguments* args) {
|
2016-05-07 21:07:58 +03:00
|
|
|
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
|
|
|
|
if (!identifier)
|
|
|
|
return false;
|
|
|
|
|
2016-08-16 10:40:44 +03:00
|
|
|
if (!Browser::IsDefaultProtocolClient(protocol, args))
|
2016-05-08 20:50:17 +03:00
|
|
|
return false;
|
|
|
|
|
2016-05-07 21:07:58 +03:00
|
|
|
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
|
|
|
|
CFStringRef protocol_cf = base::mac::NSToCFCast(protocol_ns);
|
|
|
|
CFArrayRef bundleList = LSCopyAllHandlersForURLScheme(protocol_cf);
|
|
|
|
if (!bundleList) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-18 16:26:26 +03:00
|
|
|
// On macOS, we can't query the default, but the handlers list seems to put
|
2016-05-07 21:07:58 +03:00
|
|
|
// Apple's defaults first, so we'll use the first option that isn't our bundle
|
|
|
|
CFStringRef other = nil;
|
2017-03-30 23:56:21 +03:00
|
|
|
for (CFIndex i = 0; i < CFArrayGetCount(bundleList); ++i) {
|
2018-04-20 21:47:04 +03:00
|
|
|
other =
|
|
|
|
base::mac::CFCast<CFStringRef>(CFArrayGetValueAtIndex(bundleList, i));
|
|
|
|
if (![identifier isEqualToString:(__bridge NSString*)other]) {
|
2016-05-07 21:07:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 06:16:37 +03:00
|
|
|
// No other app was found set it to none instead of setting it back to itself.
|
|
|
|
if ([identifier isEqualToString:(__bridge NSString*)other]) {
|
|
|
|
other = base::mac::NSToCFCast(@"None");
|
|
|
|
}
|
|
|
|
|
2016-05-07 21:07:58 +03:00
|
|
|
OSStatus return_code = LSSetDefaultHandlerForURLScheme(protocol_cf, other);
|
|
|
|
return return_code == noErr;
|
2016-03-24 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2016-08-16 08:54:30 +03:00
|
|
|
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
|
2016-08-22 03:50:58 +03:00
|
|
|
mate::Arguments* args) {
|
2016-03-21 21:24:25 +03:00
|
|
|
if (protocol.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
|
|
|
|
if (!identifier)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
|
2018-04-20 21:47:04 +03:00
|
|
|
OSStatus return_code = LSSetDefaultHandlerForURLScheme(
|
|
|
|
base::mac::NSToCFCast(protocol_ns), base::mac::NSToCFCast(identifier));
|
2016-03-21 21:24:25 +03:00
|
|
|
return return_code == noErr;
|
|
|
|
}
|
|
|
|
|
2016-08-16 08:54:30 +03:00
|
|
|
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
|
|
|
mate::Arguments* args) {
|
2016-04-25 08:17:01 +03:00
|
|
|
if (protocol.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
|
|
|
|
if (!identifier)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
|
2016-04-30 21:17:29 +03:00
|
|
|
|
2019-02-21 20:13:43 +03:00
|
|
|
base::ScopedCFTypeRef<CFStringRef> bundleId(
|
|
|
|
LSCopyDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns)));
|
|
|
|
|
2016-04-25 08:17:01 +03:00
|
|
|
if (!bundleId)
|
|
|
|
return false;
|
|
|
|
|
2016-04-30 21:17:29 +03:00
|
|
|
// Ensure the comparison is case-insensitive
|
2016-04-25 08:17:01 +03:00
|
|
|
// as LS does not persist the case of the bundle id.
|
2019-02-21 20:13:43 +03:00
|
|
|
NSComparisonResult result =
|
|
|
|
[base::mac::CFToNSCast(bundleId) caseInsensitiveCompare:identifier];
|
2016-04-25 08:17:01 +03:00
|
|
|
return result == NSOrderedSame;
|
|
|
|
}
|
|
|
|
|
2018-04-20 21:47:04 +03:00
|
|
|
void Browser::SetAppUserModelID(const base::string16& name) {}
|
2015-11-03 10:09:31 +03:00
|
|
|
|
2016-07-01 16:18:39 +03:00
|
|
|
bool Browser::SetBadgeCount(int count) {
|
2019-04-20 20:20:37 +03:00
|
|
|
DockSetBadgeText(count != 0 ? base::NumberToString(count) : "");
|
2016-07-02 04:36:11 +03:00
|
|
|
badge_count_ = count;
|
2016-07-01 16:18:39 +03:00
|
|
|
return true;
|
2016-07-01 11:39:01 +03:00
|
|
|
}
|
|
|
|
|
2016-05-23 18:49:46 +03:00
|
|
|
void Browser::SetUserActivity(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info,
|
|
|
|
mate::Arguments* args) {
|
|
|
|
std::string url_string;
|
|
|
|
args->GetNext(&url_string);
|
|
|
|
|
2016-05-05 10:38:47 +03:00
|
|
|
[[AtomApplication sharedApplication]
|
|
|
|
setCurrentActivity:base::SysUTF8ToNSString(type)
|
2016-05-23 18:49:46 +03:00
|
|
|
withUserInfo:DictionaryValueToNSDictionary(user_info)
|
|
|
|
withWebpageURL:net::NSURLWithGURL(GURL(url_string))];
|
2016-05-04 01:51:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Browser::GetCurrentActivityType() {
|
2019-02-25 20:21:57 +03:00
|
|
|
NSUserActivity* userActivity =
|
|
|
|
[[AtomApplication sharedApplication] getCurrentActivity];
|
|
|
|
return base::SysNSStringToUTF8(userActivity.activityType);
|
2016-04-30 03:35:07 +03:00
|
|
|
}
|
|
|
|
|
2017-06-26 22:14:44 +03:00
|
|
|
void Browser::InvalidateCurrentActivity() {
|
|
|
|
[[AtomApplication sharedApplication] invalidateCurrentActivity];
|
|
|
|
}
|
|
|
|
|
2019-06-07 08:16:03 +03:00
|
|
|
void Browser::ResignCurrentActivity() {
|
|
|
|
[[AtomApplication sharedApplication] resignCurrentActivity];
|
|
|
|
}
|
|
|
|
|
2017-06-26 22:14:44 +03:00
|
|
|
void Browser::UpdateCurrentActivity(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) {
|
2017-09-14 10:12:34 +03:00
|
|
|
[[AtomApplication sharedApplication]
|
2017-06-26 22:14:44 +03:00
|
|
|
updateCurrentActivity:base::SysUTF8ToNSString(type)
|
|
|
|
withUserInfo:DictionaryValueToNSDictionary(user_info)];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Browser::WillContinueUserActivity(const std::string& type) {
|
|
|
|
bool prevent_default = false;
|
2017-09-14 10:12:34 +03:00
|
|
|
for (BrowserObserver& observer : observers_)
|
|
|
|
observer.OnWillContinueUserActivity(&prevent_default, type);
|
2017-06-26 22:14:44 +03:00
|
|
|
return prevent_default;
|
|
|
|
}
|
2017-09-14 10:12:34 +03:00
|
|
|
|
2017-06-26 22:14:44 +03:00
|
|
|
void Browser::DidFailToContinueUserActivity(const std::string& type,
|
|
|
|
const std::string& error) {
|
|
|
|
for (BrowserObserver& observer : observers_)
|
|
|
|
observer.OnDidFailToContinueUserActivity(type, error);
|
|
|
|
}
|
|
|
|
|
2016-05-23 18:49:46 +03:00
|
|
|
bool Browser::ContinueUserActivity(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) {
|
2016-05-05 10:26:44 +03:00
|
|
|
bool prevent_default = false;
|
2017-01-24 06:34:39 +03:00
|
|
|
for (BrowserObserver& observer : observers_)
|
|
|
|
observer.OnContinueUserActivity(&prevent_default, type, user_info);
|
2016-05-05 10:26:44 +03:00
|
|
|
return prevent_default;
|
|
|
|
}
|
2017-09-14 10:12:34 +03:00
|
|
|
|
2017-06-26 22:14:44 +03:00
|
|
|
void Browser::UserActivityWasContinued(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info) {
|
|
|
|
for (BrowserObserver& observer : observers_)
|
|
|
|
observer.OnUserActivityWasContinued(type, user_info);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:47 +03:00
|
|
|
bool Browser::UpdateUserActivityState(const std::string& type,
|
2017-06-26 22:14:44 +03:00
|
|
|
const base::DictionaryValue& user_info) {
|
2017-08-09 18:09:47 +03:00
|
|
|
bool prevent_default = false;
|
2017-06-26 22:14:44 +03:00
|
|
|
for (BrowserObserver& observer : observers_)
|
2017-08-09 18:09:47 +03:00
|
|
|
observer.OnUpdateUserActivityState(&prevent_default, type, user_info);
|
|
|
|
return prevent_default;
|
2017-06-26 22:14:44 +03:00
|
|
|
}
|
2016-05-05 10:26:44 +03:00
|
|
|
|
2017-01-31 01:01:40 +03:00
|
|
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
2017-03-29 22:29:52 +03:00
|
|
|
const LoginItemSettings& options) {
|
2016-07-08 02:29:09 +03:00
|
|
|
LoginItemSettings settings;
|
2017-10-17 10:28:29 +03:00
|
|
|
#if defined(MAS_BUILD)
|
|
|
|
settings.open_at_login = platform_util::GetLoginItemEnabled();
|
|
|
|
#else
|
2018-04-20 21:47:04 +03:00
|
|
|
settings.open_at_login =
|
|
|
|
base::mac::CheckLoginItemStatus(&settings.open_as_hidden);
|
2016-07-08 02:29:09 +03:00
|
|
|
settings.restore_state = base::mac::WasLaunchedAsLoginItemRestoreState();
|
|
|
|
settings.opened_at_login = base::mac::WasLaunchedAsLoginOrResumeItem();
|
|
|
|
settings.opened_as_hidden = base::mac::WasLaunchedAsHiddenLoginItem();
|
2017-10-17 10:28:29 +03:00
|
|
|
#endif
|
2016-07-08 02:29:09 +03:00
|
|
|
return settings;
|
2016-07-06 23:26:16 +03:00
|
|
|
}
|
|
|
|
|
2018-10-13 01:19:27 +03:00
|
|
|
// copied from GetLoginItemForApp in base/mac/mac_util.mm
|
|
|
|
LSSharedFileListItemRef GetLoginItemForApp() {
|
|
|
|
base::ScopedCFTypeRef<LSSharedFileListRef> login_items(
|
|
|
|
LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL));
|
|
|
|
if (!login_items.get()) {
|
|
|
|
LOG(ERROR) << "Couldn't get a Login Items list.";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
base::scoped_nsobject<NSArray> login_items_array(
|
|
|
|
base::mac::CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL)));
|
|
|
|
NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]];
|
|
|
|
for (NSUInteger i = 0; i < [login_items_array count]; ++i) {
|
|
|
|
LSSharedFileListItemRef item =
|
|
|
|
reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]);
|
2019-02-04 20:07:51 +03:00
|
|
|
base::ScopedCFTypeRef<CFErrorRef> error;
|
|
|
|
CFURLRef item_url_ref =
|
|
|
|
LSSharedFileListItemCopyResolvedURL(item, 0, error.InitializeInto());
|
|
|
|
if (!error && item_url_ref) {
|
2018-10-13 01:19:27 +03:00
|
|
|
base::ScopedCFTypeRef<CFURLRef> item_url(item_url_ref);
|
|
|
|
if (CFEqual(item_url, url)) {
|
|
|
|
CFRetain(item);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveFromLoginItems() {
|
|
|
|
base::ScopedCFTypeRef<LSSharedFileListRef> list(
|
|
|
|
LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL));
|
|
|
|
if (!list) {
|
|
|
|
LOG(ERROR) << "Unable to access shared file list";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetLoginItemForApp() != NULL) {
|
|
|
|
base::scoped_nsobject<NSArray> login_items_array(
|
|
|
|
base::mac::CFToNSCast(LSSharedFileListCopySnapshot(list, NULL)));
|
|
|
|
|
|
|
|
if (!login_items_array) {
|
|
|
|
LOG(ERROR) << "No items in list of auto-loaded apps";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSUInteger i = 0; i < [login_items_array count]; ++i) {
|
|
|
|
LSSharedFileListItemRef item =
|
|
|
|
reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]);
|
2019-02-04 20:07:51 +03:00
|
|
|
base::ScopedCFTypeRef<CFErrorRef> error;
|
|
|
|
CFURLRef url_ref =
|
|
|
|
LSSharedFileListItemCopyResolvedURL(item, 0, error.InitializeInto());
|
|
|
|
if (!error && url_ref) {
|
2018-10-13 01:19:27 +03:00
|
|
|
base::ScopedCFTypeRef<CFURLRef> url(url_ref);
|
|
|
|
if ([[base::mac::CFToNSCast(url.get()) path]
|
|
|
|
hasPrefix:[[NSBundle mainBundle] bundlePath]])
|
|
|
|
LSSharedFileListItemRemove(list, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-31 01:01:40 +03:00
|
|
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
2017-10-17 10:28:29 +03:00
|
|
|
#if defined(MAS_BUILD)
|
2018-11-28 07:16:53 +03:00
|
|
|
if (!platform_util::SetLoginItemEnabled(settings.open_at_login)) {
|
|
|
|
LOG(ERROR) << "Unable to set login item enabled on sandboxed app.";
|
|
|
|
}
|
2017-10-17 10:28:29 +03:00
|
|
|
#else
|
2019-05-02 15:05:37 +03:00
|
|
|
if (settings.open_at_login) {
|
2016-07-08 02:29:09 +03:00
|
|
|
base::mac::AddToLoginItems(settings.open_as_hidden);
|
2019-05-02 15:05:37 +03:00
|
|
|
} else {
|
2018-10-13 01:19:27 +03:00
|
|
|
RemoveFromLoginItems();
|
|
|
|
}
|
2017-10-17 10:28:29 +03:00
|
|
|
#endif
|
2016-07-06 23:26:16 +03:00
|
|
|
}
|
|
|
|
|
2013-12-05 06:26:01 +04:00
|
|
|
std::string Browser::GetExecutableFileVersion() const {
|
2018-10-24 13:49:10 +03:00
|
|
|
return GetApplicationVersion();
|
2013-06-19 09:41:54 +04:00
|
|
|
}
|
|
|
|
|
2013-12-05 06:42:04 +04:00
|
|
|
std::string Browser::GetExecutableFileProductName() const {
|
2018-10-24 13:49:10 +03:00
|
|
|
return GetApplicationName();
|
2013-12-05 06:42:04 +04:00
|
|
|
}
|
|
|
|
|
2013-08-06 12:19:56 +04:00
|
|
|
int Browser::DockBounce(BounceType type) {
|
2015-12-21 05:52:49 +03:00
|
|
|
return [[AtomApplication sharedApplication]
|
2017-03-31 00:05:47 +03:00
|
|
|
requestUserAttention:static_cast<NSRequestUserAttentionType>(type)];
|
2013-08-06 12:19:56 +04:00
|
|
|
}
|
|
|
|
|
2016-01-23 16:59:05 +03:00
|
|
|
void Browser::DockCancelBounce(int request_id) {
|
|
|
|
[[AtomApplication sharedApplication] cancelUserAttentionRequest:request_id];
|
2013-08-06 12:19:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::DockSetBadgeText(const std::string& label) {
|
2018-04-20 21:47:04 +03:00
|
|
|
NSDockTile* tile = [[AtomApplication sharedApplication] dockTile];
|
2013-08-06 12:19:56 +04:00
|
|
|
[tile setBadgeLabel:base::SysUTF8ToNSString(label)];
|
|
|
|
}
|
|
|
|
|
2016-05-10 22:02:56 +03:00
|
|
|
void Browser::DockDownloadFinished(const std::string& filePath) {
|
|
|
|
[[NSDistributedNotificationCenter defaultCenter]
|
2018-04-20 21:47:04 +03:00
|
|
|
postNotificationName:@"com.apple.DownloadFileFinished"
|
|
|
|
object:base::SysUTF8ToNSString(filePath)];
|
2016-05-10 22:02:56 +03:00
|
|
|
}
|
|
|
|
|
2013-08-06 12:39:31 +04:00
|
|
|
std::string Browser::DockGetBadgeText() {
|
2018-04-20 21:47:04 +03:00
|
|
|
NSDockTile* tile = [[AtomApplication sharedApplication] dockTile];
|
2013-08-06 12:39:31 +04:00
|
|
|
return base::SysNSStringToUTF8([tile badgeLabel]);
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:55:33 +04:00
|
|
|
void Browser::DockHide() {
|
2018-04-18 01:41:47 +03:00
|
|
|
for (auto* const& window : WindowList::GetWindows())
|
2019-01-09 23:25:19 +03:00
|
|
|
[window->GetNativeWindow().GetNativeNSWindow() setCanHide:NO];
|
2014-06-25 07:55:33 +04:00
|
|
|
|
2018-04-20 21:47:04 +03:00
|
|
|
ProcessSerialNumber psn = {0, kCurrentProcess};
|
2014-06-25 07:55:33 +04:00
|
|
|
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
|
|
|
|
}
|
|
|
|
|
2016-08-02 01:22:37 +03:00
|
|
|
bool Browser::DockIsVisible() {
|
|
|
|
// Because DockShow has a slight delay this may not be true immediately
|
|
|
|
// after that call.
|
2018-04-20 21:47:04 +03:00
|
|
|
return ([[NSRunningApplication currentApplication] activationPolicy] ==
|
|
|
|
NSApplicationActivationPolicyRegular);
|
2016-08-02 01:22:37 +03:00
|
|
|
}
|
|
|
|
|
2019-02-13 08:06:33 +03:00
|
|
|
v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
|
2019-02-21 15:32:44 +03:00
|
|
|
util::Promise promise(isolate);
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
2015-12-17 23:00:04 +03:00
|
|
|
BOOL active = [[NSRunningApplication currentApplication] isActive];
|
2018-04-20 21:47:04 +03:00
|
|
|
ProcessSerialNumber psn = {0, kCurrentProcess};
|
2015-12-17 23:00:04 +03:00
|
|
|
if (active) {
|
2015-12-21 05:52:49 +03:00
|
|
|
// Workaround buggy behavior of TransformProcessType.
|
|
|
|
// http://stackoverflow.com/questions/7596643/
|
|
|
|
NSArray* runningApps = [NSRunningApplication
|
|
|
|
runningApplicationsWithBundleIdentifier:@"com.apple.dock"];
|
|
|
|
for (NSRunningApplication* app in runningApps) {
|
2015-12-17 23:00:04 +03:00
|
|
|
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
|
|
|
break;
|
|
|
|
}
|
2019-02-21 15:32:44 +03:00
|
|
|
__block util::Promise p = std::move(promise);
|
2015-12-21 05:52:49 +03:00
|
|
|
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
|
|
|
|
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
|
2015-12-17 23:00:04 +03:00
|
|
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
2015-12-21 05:52:49 +03:00
|
|
|
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
|
|
|
|
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
|
|
|
|
[[NSRunningApplication currentApplication]
|
|
|
|
activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
2019-02-21 15:32:44 +03:00
|
|
|
p.Resolve();
|
2015-12-21 05:52:49 +03:00
|
|
|
});
|
2015-12-17 23:00:04 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
2019-02-21 15:32:44 +03:00
|
|
|
promise.Resolve();
|
2015-12-17 23:00:04 +03:00
|
|
|
}
|
2019-02-21 15:32:44 +03:00
|
|
|
return handle;
|
2014-06-25 07:55:33 +04:00
|
|
|
}
|
|
|
|
|
2016-07-02 05:47:40 +03:00
|
|
|
void Browser::DockSetMenu(AtomMenuModel* model) {
|
2018-04-20 21:47:04 +03:00
|
|
|
AtomApplicationDelegate* delegate =
|
|
|
|
(AtomApplicationDelegate*)[NSApp delegate];
|
2014-11-16 18:04:31 +03:00
|
|
|
[delegate setApplicationDockMenu:model];
|
|
|
|
}
|
|
|
|
|
2016-01-24 02:30:14 +03:00
|
|
|
void Browser::DockSetIcon(const gfx::Image& image) {
|
2016-02-01 11:06:09 +03:00
|
|
|
[[AtomApplication sharedApplication]
|
2016-01-24 02:30:14 +03:00
|
|
|
setApplicationIconImage:image.AsNSImage()];
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:30:58 +03:00
|
|
|
void Browser::ShowAboutPanel() {
|
|
|
|
NSDictionary* options = DictionaryValueToNSDictionary(about_panel_options_);
|
2016-11-15 20:36:23 +03:00
|
|
|
|
|
|
|
// Credits must be a NSAttributedString instead of NSString
|
|
|
|
id credits = options[@"Credits"];
|
|
|
|
if (credits != nil) {
|
|
|
|
NSMutableDictionary* mutable_options = [options mutableCopy];
|
|
|
|
mutable_options[@"Credits"] = [[[NSAttributedString alloc]
|
|
|
|
initWithString:(NSString*)credits] autorelease];
|
|
|
|
options = [NSDictionary dictionaryWithDictionary:mutable_options];
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:30:58 +03:00
|
|
|
[[AtomApplication sharedApplication]
|
|
|
|
orderFrontStandardAboutPanelWithOptions:options];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
|
|
|
|
about_panel_options_.Clear();
|
2016-10-12 20:52:59 +03:00
|
|
|
|
2018-11-14 01:12:24 +03:00
|
|
|
for (const auto& pair : options) {
|
|
|
|
std::string key = pair.first;
|
|
|
|
const auto& val = pair.second;
|
|
|
|
if (!key.empty() && val->is_string()) {
|
2016-10-12 20:52:59 +03:00
|
|
|
key[0] = base::ToUpperASCII(key[0]);
|
2018-11-14 01:12:24 +03:00
|
|
|
about_panel_options_.SetString(key, val->GetString());
|
2016-10-12 20:52:59 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-10 23:30:58 +03:00
|
|
|
}
|
|
|
|
|
2019-03-14 23:39:52 +03:00
|
|
|
void Browser::ShowEmojiPanel() {
|
|
|
|
[[AtomApplication sharedApplication] orderFrontCharacterPalette:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Browser::IsEmojiPanelSupported() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-20 00:23:04 +03:00
|
|
|
} // namespace electron
|