Set unread count badge when background page is refreshed
Refreshing the background page unsets the badge.
This commit is contained in:
parent
bfe23d86aa
commit
d3dbf2328f
1 changed files with 10 additions and 6 deletions
|
@ -34,12 +34,7 @@
|
||||||
var prev = model.previous('unreadCount') || 0;
|
var prev = model.previous('unreadCount') || 0;
|
||||||
if (count < prev) { // decreased
|
if (count < prev) { // decreased
|
||||||
var newUnreadCount = textsecure.storage.get("unreadCount", 0) - (prev - count);
|
var newUnreadCount = textsecure.storage.get("unreadCount", 0) - (prev - count);
|
||||||
if (newUnreadCount <= 0) {
|
setUnreadCount(newUnreadCount);
|
||||||
newUnreadCount = 0;
|
|
||||||
extension.navigator.setBadgeText("");
|
|
||||||
} else {
|
|
||||||
extension.navigator.setBadgeText(newUnreadCount);
|
|
||||||
}
|
|
||||||
textsecure.storage.put("unreadCount", newUnreadCount);
|
textsecure.storage.put("unreadCount", newUnreadCount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -57,4 +52,13 @@
|
||||||
|
|
||||||
extension.on('message', fetch);
|
extension.on('message', fetch);
|
||||||
fetch();
|
fetch();
|
||||||
|
setUnreadCount(textsecure.storage.get("unreadCount", 0));
|
||||||
|
|
||||||
|
function setUnreadCount(count) {
|
||||||
|
if (count > 0) {
|
||||||
|
extension.navigator.setBadgeText(count);
|
||||||
|
} else {
|
||||||
|
extension.navigator.setBadgeText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue