electron/atom/browser/browser_mac.mm

115 lines
3.7 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/browser.h"
#include "atom/browser/mac/atom_application.h"
#include "atom/browser/mac/atom_application_delegate.h"
#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "brightray/common/application_info.h"
namespace atom {
2013-05-30 11:24:47 +00:00
void Browser::Focus() {
[[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
2013-05-30 11:24:47 +00:00
}
void Browser::Hide() {
[[AtomApplication sharedApplication] hide:nil];
}
2014-11-17 05:05:06 +00:00
void Browser::AddRecentDocument(const base::FilePath& path) {
NSString* path_string = base::mac::FilePathToNSString(path);
if (!path_string)
return;
NSURL* u = [NSURL fileURLWithPath:path_string];
if (!u)
return;
2014-11-17 05:05:06 +00:00
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:u];
}
2014-11-17 08:13:47 +00:00
void Browser::ClearRecentDocuments() {
[[NSDocumentController sharedDocumentController] clearRecentDocuments:nil];
2014-11-17 08:13:47 +00:00
}
void Browser::SetAppUserModelID(const base::string16& name) {
}
2013-12-05 02:26:01 +00:00
std::string Browser::GetExecutableFileVersion() const {
return brightray::GetApplicationVersion();
}
std::string Browser::GetExecutableFileProductName() const {
return brightray::GetApplicationName();
}
2013-08-06 08:19:56 +00:00
int Browser::DockBounce(BounceType type) {
2015-12-21 02:52:49 +00:00
return [[AtomApplication sharedApplication]
requestUserAttention:(NSRequestUserAttentionType)type];
2013-08-06 08:19:56 +00:00
}
void Browser::DockCancelBounce(int request_id) {
[[AtomApplication sharedApplication] cancelUserAttentionRequest:request_id];
2013-08-06 08:19:56 +00:00
}
void Browser::DockSetBadgeText(const std::string& label) {
NSDockTile *tile = [[AtomApplication sharedApplication] dockTile];
[tile setBadgeLabel:base::SysUTF8ToNSString(label)];
}
2013-08-06 08:39:31 +00:00
std::string Browser::DockGetBadgeText() {
NSDockTile *tile = [[AtomApplication sharedApplication] dockTile];
return base::SysNSStringToUTF8([tile badgeLabel]);
}
void Browser::DockHide() {
WindowList* list = WindowList::GetInstance();
for (WindowList::iterator it = list->begin(); it != list->end(); ++it)
[(*it)->GetNativeWindow() setCanHide:NO];
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}
void Browser::DockShow() {
BOOL active = [[NSRunningApplication currentApplication] isActive];
ProcessSerialNumber psn = { 0, kCurrentProcess };
if (active) {
2015-12-21 02:52:49 +00:00
// Workaround buggy behavior of TransformProcessType.
// http://stackoverflow.com/questions/7596643/
NSArray* runningApps = [NSRunningApplication
runningApplicationsWithBundleIdentifier:@"com.apple.dock"];
for (NSRunningApplication* app in runningApps) {
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
break;
}
2015-12-21 02:52:49 +00:00
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
2015-12-21 02:52:49 +00: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];
});
});
} else {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
}
2014-11-16 15:04:31 +00:00
void Browser::DockSetMenu(ui::MenuModel* model) {
2014-11-23 21:52:59 +00:00
AtomApplicationDelegate* delegate = (AtomApplicationDelegate*)[NSApp delegate];
2014-11-16 15:04:31 +00:00
[delegate setApplicationDockMenu:model];
}
void Browser::DockSetIcon(const gfx::Image& image) {
[[NSApplication sharedApplication]
setApplicationIconImage:image.AsNSImage()];
}
} // namespace atom