зеркало из https://github.com/electron/electron.git
app.setBadgeCount should return boolean
This commit is contained in:
Родитель
f8ec377123
Коммит
1da2a1c2ae
|
@ -88,7 +88,7 @@ class Browser : public WindowListObserver {
|
||||||
bool IsDefaultProtocolClient(const std::string& protocol);
|
bool IsDefaultProtocolClient(const std::string& protocol);
|
||||||
|
|
||||||
// Set/Get the badge count.
|
// Set/Get the badge count.
|
||||||
void SetBadgeCount(int count);
|
bool SetBadgeCount(int count);
|
||||||
int GetBadgeCount();
|
int GetBadgeCount();
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
|
|
@ -47,9 +47,14 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetBadgeCount(int count) {
|
bool Browser::SetBadgeCount(int count) {
|
||||||
current_badge_count_ = count;
|
if (IsUnityRunning()) {
|
||||||
unity::SetDownloadCount(count);
|
unity::SetDownloadCount(count);
|
||||||
|
current_badge_count_ = count;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Browser::GetExecutableFileVersion() const {
|
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::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;
|
current_badge_count_ = count;
|
||||||
DockSetBadgeText(count == 0 ? base::IntToString(count) : "");
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetUserActivity(const std::string& type,
|
void Browser::SetUserActivity(const std::string& type,
|
||||||
|
|
|
@ -269,8 +269,8 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetBadgeCount(int count) {
|
bool Browser::SetBadgeCount(int count) {
|
||||||
current_badge_count_ = count;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PCWSTR Browser::GetAppUserModelID() {
|
PCWSTR Browser::GetAppUserModelID() {
|
||||||
|
|
|
@ -582,7 +582,7 @@ This method can only be called before app is ready.
|
||||||
* `count` Integer
|
* `count` Integer
|
||||||
|
|
||||||
Sets the counter badge for current app. Setting the count to `0` will hide the
|
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,
|
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 () {
|
it('should set a badge count', function () {
|
||||||
app.setBadgeCount(42)
|
app.setBadgeCount(42)
|
||||||
assert.equal(app.getBadgeCount(), 42)
|
assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Загрузка…
Ссылка в новой задаче