--counter: accept colon character; useful for time-tracking apps with hour:min in title (PR #1378)

Modify regexp to track hour counters such as `(1:23)`.

This is supported by macOS' dock and displays in the red badge:
https://user-images.githubusercontent.com/73974/162786478-609a90e1-5efb-44ba-9aa5-7a3038f0689b.png
This commit is contained in:
Tristan Koch 2022-04-11 19:18:06 +02:00 committed by GitHub
parent 567fede701
commit 6a949ca481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -233,6 +233,7 @@ test.each(testNonLoginPages)(
const smallCounterTitle = 'Inbox (11) - nobody@example.com - Gmail';
const largeCounterTitle = 'Inbox (8,756) - nobody@example.com - Gmail';
const hourCounterTitle = 'Today (1:23) - nobody@example.com - TimeTracker';
const noCounterTitle = 'Inbox - nobody@example.com - Gmail';
test('getCounterValue should return undefined for titles without counter numbers', () => {
@ -247,6 +248,10 @@ test('getCounterValue should return a string for large counter numbers in the ti
expect(getCounterValue(largeCounterTitle)).toEqual('8,756');
});
test('getCounterValue should return a string for hour counter numbers in the title', () => {
expect(getCounterValue(hourCounterTitle)).toEqual('1:23');
});
describe('removeUserAgentSpecifics', () => {
const userAgentFallback =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) app-nativefier-804458/1.0.0 Chrome/89.0.4389.128 Electron/12.0.7 Safari/537.36';

View File

@ -56,7 +56,7 @@ export function getAppIcon(): string | undefined {
}
export function getCounterValue(title: string): string | undefined {
const itemCountRegex = /[([{]([\d.,]*)\+?[}\])]/;
const itemCountRegex = /[([{]([\d.,:]*)\+?[}\])]/;
const match = itemCountRegex.exec(title);
return match ? match[1] : undefined;
}