From 6a949ca481072f0fa29485ded83ec137de49dcd5 Mon Sep 17 00:00:00 2001 From: Tristan Koch <73974+trkoch@users.noreply.github.com> Date: Mon, 11 Apr 2022 19:18:06 +0200 Subject: [PATCH] --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 --- app/src/helpers/helpers.test.ts | 5 +++++ app/src/helpers/helpers.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/helpers/helpers.test.ts b/app/src/helpers/helpers.test.ts index edade5d..454729f 100644 --- a/app/src/helpers/helpers.test.ts +++ b/app/src/helpers/helpers.test.ts @@ -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'; diff --git a/app/src/helpers/helpers.ts b/app/src/helpers/helpers.ts index 618ab0d..d36e31d 100644 --- a/app/src/helpers/helpers.ts +++ b/app/src/helpers/helpers.ts @@ -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; }