diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 5f496b89ee..bdaed5be0f 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -88,7 +88,7 @@ class Browser : public WindowListObserver { bool IsDefaultProtocolClient(const std::string& protocol); // Set/Get the badge count. - void SetBadgeCount(int count); + bool SetBadgeCount(int count); int GetBadgeCount(); #if defined(OS_MACOSX) diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index ff48e5bed0..e2f968613b 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -47,9 +47,14 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) { return false; } -void Browser::SetBadgeCount(int count) { - current_badge_count_ = count; - unity::SetDownloadCount(count); +bool Browser::SetBadgeCount(int count) { + if (IsUnityRunning()) { + unity::SetDownloadCount(count); + current_badge_count_ = count; + return true; + } else { + return false; + } } std::string Browser::GetExecutableFileVersion() const { diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index ebd225c599..a02034097a 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -115,9 +115,10 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) { void Browser::SetAppUserModelID(const base::string16& name) { } -void Browser::SetBadgeCount(int count) { +bool Browser::SetBadgeCount(int count) { + DockSetBadgeText(count != 0 ? base::IntToString(count) : ""); current_badge_count_ = count; - DockSetBadgeText(count == 0 ? base::IntToString(count) : ""); + return true; } void Browser::SetUserActivity(const std::string& type, diff --git a/atom/browser/browser_win.cc b/atom/browser/browser_win.cc index e49e3b4cee..5eb9275dcf 100644 --- a/atom/browser/browser_win.cc +++ b/atom/browser/browser_win.cc @@ -269,8 +269,8 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) { } } -void Browser::SetBadgeCount(int count) { - current_badge_count_ = count; +bool Browser::SetBadgeCount(int count) { + return false; } PCWSTR Browser::GetAppUserModelID() { diff --git a/docs/api/app.md b/docs/api/app.md index 128300f53a..2a640de75e 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -582,7 +582,7 @@ This method can only be called before app is ready. * `count` Integer Sets the counter badge for current app. Setting the count to `0` will hide the -badge. +badge. Returns `true` when the call succeeded, otherwise returns `false`. On macOS it shows on the dock icon. On Linux it only works for Unity launcher, diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 4d27755d27..44d4ddd019 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -285,10 +285,17 @@ describe('app module', function () { }) }) - describe('app.getBadgeCount API', function () { + describe('app.setBadgeCount API', function () { + const shouldFail = process.platform === 'win32' || + (process.platform === 'linux' && app.isUnityRunning()) + + it('returns false when failed', function () { + assert.equal(app.setBadgeCount(42), !shouldFail) + }) + it('should set a badge count', function () { app.setBadgeCount(42) - assert.equal(app.getBadgeCount(), 42) + assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42) }) }) })