app.setBadgeCount should return boolean

This commit is contained in:
Cheng Zhao 2016-07-01 22:18:39 +09:00
Родитель f8ec377123
Коммит 1da2a1c2ae
6 изменённых файлов: 24 добавлений и 11 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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,

Просмотреть файл

@ -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() {

Просмотреть файл

@ -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,

Просмотреть файл

@ -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)
})
})
})