mac: Add app.dock.hide()/show() APIs, closes #422.

This commit is contained in:
Cheng Zhao 2014-06-25 11:55:33 +08:00
parent 3eecd664b4
commit 8ecc4061a8
5 changed files with 39 additions and 1 deletions

View file

@ -131,6 +131,10 @@ void Initialize(v8::Handle<v8::Object> exports) {
dict.SetMethod("dockGetBadgeText",
base::Bind(&Browser::DockGetBadgeText,
base::Unretained(browser)));
dict.SetMethod("dockHide",
base::Bind(&Browser::DockHide, base::Unretained(browser)));
dict.SetMethod("dockShow",
base::Bind(&Browser::DockShow, base::Unretained(browser)));
#endif
}

View file

@ -24,6 +24,8 @@ if process.platform is 'darwin'
cancelBounce: bindings.dockCancelBounce
setBadge: bindings.dockSetBadgeText
getBadge: bindings.dockGetBadgeText
hide: bindings.hide
show: bindings.show
# Be compatible with old API.
app.once 'ready', -> app.emit 'finish-launching'

View file

@ -56,6 +56,10 @@ class Browser : public WindowListObserver {
// Set/Get dock's badge text.
void DockSetBadgeText(const std::string& label);
std::string DockGetBadgeText();
// Hide/Show dock.
void DockHide();
void DockShow();
#endif // defined(OS_MACOSX)
// Tell the application to open a file.

View file

@ -4,9 +4,11 @@
#include "atom/browser/browser.h"
#import "atom/browser/mac/atom_application.h"
#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#import "base/mac/bundle_locations.h"
#include "base/strings/sys_string_conversions.h"
#import "atom/browser/mac/atom_application.h"
namespace atom {
@ -44,4 +46,18 @@ std::string Browser::DockGetBadgeText() {
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() {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
} // namespace atom

View file

@ -153,3 +153,15 @@ Sets the string to be displayed in the docks badging area.
Returns the badge string of the dock.
**Note:** This API is only available on Mac.
## app.dock.hide()
Hides the dock icon.
**Note:** This API is only available on Mac.
## app.dock.show()
Shows the dock icon.
**Note:** This API is only available on Mac.