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 23:43:23 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/browser/browser.h"
|
2013-05-02 23:43:23 +08:00
|
|
|
|
2015-04-14 15:55:41 +08:00
|
|
|
#include "atom/browser/mac/atom_application.h"
|
|
|
|
#include "atom/browser/mac/atom_application_delegate.h"
|
2014-06-25 11:55:33 +08:00
|
|
|
#include "atom/browser/native_window.h"
|
|
|
|
#include "atom/browser/window_list.h"
|
2015-04-14 15:55:41 +08:00
|
|
|
#include "base/mac/foundation_util.h"
|
2013-06-19 13:41:54 +08:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2015-04-14 15:55:41 +08:00
|
|
|
#include "brightray/common/application_info.h"
|
2013-05-02 23:43:23 +08:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2013-05-30 19:24:47 +08:00
|
|
|
void Browser::Focus() {
|
2013-06-26 17:22:24 +08:00
|
|
|
[[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
|
2013-05-30 19:24:47 +08:00
|
|
|
}
|
|
|
|
|
2014-11-17 13:05:06 +08:00
|
|
|
void Browser::AddRecentDocument(const base::FilePath& path) {
|
2015-12-15 17:17:24 +08:00
|
|
|
NSString* path_string = base::mac::FilePathToNSString(path);
|
|
|
|
if (!path_string)
|
|
|
|
return;
|
|
|
|
NSURL* u = [NSURL fileURLWithPath:path_string];
|
|
|
|
if (!u)
|
|
|
|
return;
|
2014-11-17 13:05:06 +08:00
|
|
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:u];
|
|
|
|
}
|
|
|
|
|
2014-11-17 16:13:47 +08:00
|
|
|
void Browser::ClearRecentDocuments() {
|
2015-12-29 18:35:54 -06:00
|
|
|
[[NSDocumentController sharedDocumentController] clearRecentDocuments:nil];
|
2014-11-17 16:13:47 +08:00
|
|
|
}
|
|
|
|
|
2015-11-03 15:09:31 +08:00
|
|
|
void Browser::SetAppUserModelID(const base::string16& name) {
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:26:01 +08:00
|
|
|
std::string Browser::GetExecutableFileVersion() const {
|
2015-04-14 15:55:41 +08:00
|
|
|
return brightray::GetApplicationVersion();
|
2013-06-19 13:41:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:42:04 +08:00
|
|
|
std::string Browser::GetExecutableFileProductName() const {
|
2015-04-14 15:55:41 +08:00
|
|
|
return brightray::GetApplicationName();
|
2013-12-05 10:42:04 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 16:19:56 +08:00
|
|
|
int Browser::DockBounce(BounceType type) {
|
2015-12-21 10:52:49 +08:00
|
|
|
return [[AtomApplication sharedApplication]
|
|
|
|
requestUserAttention:(NSRequestUserAttentionType)type];
|
2013-08-06 16:19:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::DockCancelBounce(int rid) {
|
|
|
|
[[AtomApplication sharedApplication] cancelUserAttentionRequest:rid];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::DockSetBadgeText(const std::string& label) {
|
|
|
|
NSDockTile *tile = [[AtomApplication sharedApplication] dockTile];
|
|
|
|
[tile setBadgeLabel:base::SysUTF8ToNSString(label)];
|
|
|
|
}
|
|
|
|
|
2013-08-06 16:39:31 +08:00
|
|
|
std::string Browser::DockGetBadgeText() {
|
|
|
|
NSDockTile *tile = [[AtomApplication sharedApplication] dockTile];
|
|
|
|
return base::SysNSStringToUTF8([tile badgeLabel]);
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:55:33 +08:00
|
|
|
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() {
|
2015-12-17 14:00:04 -06:00
|
|
|
BOOL active = [[NSRunningApplication currentApplication] isActive];
|
2014-06-25 11:55:33 +08:00
|
|
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
2015-12-17 14:00:04 -06:00
|
|
|
if (active) {
|
2015-12-21 10:52:49 +08: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 14:00:04 -06:00
|
|
|
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
|
|
|
break;
|
|
|
|
}
|
2015-12-21 10:52:49 +08: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 14:00:04 -06:00
|
|
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
2015-12-21 10:52:49 +08: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];
|
|
|
|
});
|
2015-12-17 14:00:04 -06:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
|
|
|
}
|
2014-06-25 11:55:33 +08:00
|
|
|
}
|
|
|
|
|
2014-11-16 23:04:31 +08:00
|
|
|
void Browser::DockSetMenu(ui::MenuModel* model) {
|
2014-11-23 13:52:59 -08:00
|
|
|
AtomApplicationDelegate* delegate = (AtomApplicationDelegate*)[NSApp delegate];
|
2014-11-16 23:04:31 +08:00
|
|
|
[delegate setApplicationDockMenu:model];
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
} // namespace atom
|