From ea1f81aa5260fe2d4a844f18e0251278fbadc093 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Aug 2013 16:39:31 +0800 Subject: [PATCH] [Mac] Add app.dock.getBadge() API. --- browser/api/atom_api_app.cc | 7 +++++++ browser/api/atom_api_app.h | 1 + browser/api/lib/app.coffee | 1 + browser/browser.h | 3 ++- browser/browser_mac.mm | 5 +++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/browser/api/atom_api_app.cc b/browser/api/atom_api_app.cc index 62ccc22a8875..51a1362b4b69 100644 --- a/browser/api/atom_api_app.cc +++ b/browser/api/atom_api_app.cc @@ -169,6 +169,12 @@ v8::Handle App::DockSetBadgeText(const v8::Arguments& args) { return v8::Undefined(); } +// static +v8::Handle App::DockGetBadgeText(const v8::Arguments& args) { + std::string text(Browser::Get()->DockGetBadgeText()); + return v8::String::New(text.data(), text.size()); +} + #endif // defined(OS_MACOSX) // static @@ -194,6 +200,7 @@ void App::Initialize(v8::Handle target) { NODE_SET_METHOD(target, "dockBounce", DockBounce); NODE_SET_METHOD(target, "dockCancelBounce", DockCancelBounce); NODE_SET_METHOD(target, "dockSetBadgeText", DockSetBadgeText); + NODE_SET_METHOD(target, "dockGetBadgeText", DockGetBadgeText); #endif // defined(OS_MACOSX) } diff --git a/browser/api/atom_api_app.h b/browser/api/atom_api_app.h index 674b229d36cf..04b70eb78f91 100644 --- a/browser/api/atom_api_app.h +++ b/browser/api/atom_api_app.h @@ -47,6 +47,7 @@ class App : public EventEmitter, static v8::Handle DockBounce(const v8::Arguments& args); static v8::Handle DockCancelBounce(const v8::Arguments& args); static v8::Handle DockSetBadgeText(const v8::Arguments& args); + static v8::Handle DockGetBadgeText(const v8::Arguments& args); #endif // defined(OS_MACOSX) DISALLOW_COPY_AND_ASSIGN(App); diff --git a/browser/api/lib/app.coffee b/browser/api/lib/app.coffee index a1c418ed37bc..0960db29e3b7 100644 --- a/browser/api/lib/app.coffee +++ b/browser/api/lib/app.coffee @@ -18,6 +18,7 @@ if process.platform is 'darwin' bounce: (type = 'informational') -> bindings.dockBounce type cancelBounce: bindings.dockCancelBounce setBadge: bindings.dockSetBadgeText + getBadge: bindings.dockGetBadgeText # Only one App object pemitted. module.exports = app diff --git a/browser/browser.h b/browser/browser.h index 15ab9ce7fbbc..c715dfe1c618 100644 --- a/browser/browser.h +++ b/browser/browser.h @@ -42,8 +42,9 @@ class Browser : public WindowListObserver { int DockBounce(BounceType type); void DockCancelBounce(int request_id); - // Set dock's badge text. + // Set/Get dock's badge text. void DockSetBadgeText(const std::string& label); + std::string DockGetBadgeText(); #endif // defined(OS_MACOSX) // Tell the application to open a file. diff --git a/browser/browser_mac.mm b/browser/browser_mac.mm index c9072657ca02..95ce57e1d1bd 100644 --- a/browser/browser_mac.mm +++ b/browser/browser_mac.mm @@ -42,4 +42,9 @@ void Browser::DockSetBadgeText(const std::string& label) { [tile setBadgeLabel:base::SysUTF8ToNSString(label)]; } +std::string Browser::DockGetBadgeText() { + NSDockTile *tile = [[AtomApplication sharedApplication] dockTile]; + return base::SysNSStringToUTF8([tile badgeLabel]); +} + } // namespace atom