diff options
Diffstat (limited to 'src/webview/badge.js')
-rw-r--r-- | src/webview/badge.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/webview/badge.js b/src/webview/badge.js index 1e02fb56a..6be4cf609 100644 --- a/src/webview/badge.js +++ b/src/webview/badge.js | |||
@@ -10,19 +10,22 @@ export class BadgeHandler { | |||
10 | }; | 10 | }; |
11 | } | 11 | } |
12 | 12 | ||
13 | setBadge(direct, indirect) { | 13 | _normalizeNumber(count) { |
14 | if (this.countCache.direct === direct | ||
15 | && this.countCache.indirect === indirect) return; | ||
16 | |||
17 | // Parse number to integer | 14 | // Parse number to integer |
18 | // This will correct errors that recipes may introduce, e.g. | 15 | // This will correct errors that recipes may introduce, e.g. |
19 | // by sending a String instead of an integer | 16 | // by sending a String instead of an integer |
20 | const directInt = parseInt(direct, 10); | 17 | const parsedNumber = parseInt(count, 10); |
21 | const indirectInt = parseInt(indirect, 10); | 18 | const adjustedNumber = Number.isNaN(parsedNumber) ? 0 : parsedNumber; |
19 | return Math.max(adjustedNumber, 0); | ||
20 | } | ||
21 | |||
22 | setBadge(direct, indirect) { | ||
23 | if (this.countCache.direct === direct | ||
24 | && this.countCache.indirect === indirect) return; | ||
22 | 25 | ||
23 | const count = { | 26 | const count = { |
24 | direct: Math.max(directInt, 0), | 27 | direct: this._normalizeNumber(direct), |
25 | indirect: Math.max(indirectInt, 0), | 28 | indirect: this._normalizeNumber(indirect), |
26 | }; | 29 | }; |
27 | 30 | ||
28 | ipcRenderer.sendToHost('message-counts', count); | 31 | ipcRenderer.sendToHost('message-counts', count); |