@@ -43,7 +43,7 @@ function mill2Str(milliseconds: number) {
4343
4444function setBadgeTextOfMills ( milliseconds : number | undefined , tabId : number | undefined ) {
4545 const text = milliseconds === undefined ? '' : mill2Str ( milliseconds )
46- setBadgeText ( text )
46+ setBadgeText ( text , tabId )
4747}
4848
4949async function findActiveTab ( ) : Promise < BadgeLocation > {
@@ -61,6 +61,14 @@ async function findActiveTab(): Promise<BadgeLocation> {
6161 return { tabId : tab . id , url : tab . url }
6262}
6363
64+ async function clearAllBadge ( ) : Promise < void > {
65+ const tabs = await listTabs ( )
66+ if ( ! tabs ?. length ) return
67+ for ( const tab of tabs ) {
68+ await setBadgeText ( '' , tab ?. id )
69+ }
70+ }
71+
6472type BadgeState = 'HIDDEN' | 'NOT_SUPPORTED' | 'PAUSED' | 'TIME' | 'WHITELIST'
6573
6674class BadgeManager {
@@ -106,8 +114,9 @@ class BadgeManager {
106114
107115 private processOption ( option : timer . option . AppearanceOption ) {
108116 const { displayBadgeText, badgeBgColor } = option || { }
117+ const before = this . visible
109118 this . visible = ! ! displayBadgeText
110- this . render ( )
119+ ! this . visible && before && clearAllBadge ( )
111120 setBadgeBgColor ( badgeBgColor )
112121 }
113122
@@ -118,20 +127,20 @@ class BadgeManager {
118127 private async processState ( ) : Promise < BadgeState > {
119128 const { url, tabId, focus } = this . current || { }
120129 if ( ! this . visible || ! url ) {
121- this . state !== 'HIDDEN' && setBadgeText ( '' )
130+ this . state !== 'HIDDEN' && setBadgeText ( '' , tabId )
122131 return 'HIDDEN'
123132 }
124133 if ( isBrowserUrl ( url ) ) {
125- this . state !== 'NOT_SUPPORTED' && setBadgeText ( '∅' )
134+ this . state !== 'NOT_SUPPORTED' && setBadgeText ( '∅' , tabId )
126135 return 'NOT_SUPPORTED'
127136 }
128137 const host = extractHostname ( url ) ?. host
129138 if ( whitelistHolder . contains ( host , url ) ) {
130- this . state !== 'WHITELIST' && setBadgeText ( 'W' )
139+ this . state !== 'WHITELIST' && setBadgeText ( 'W' , tabId )
131140 return 'WHITELIST'
132141 }
133142 if ( this . pausedTabId === tabId ) {
134- this . state !== 'PAUSED' && setBadgeText ( 'P' )
143+ this . state !== 'PAUSED' && setBadgeText ( 'P' , tabId )
135144 return 'PAUSED'
136145 }
137146 const milliseconds = focus || ( host ? ( await statDatabase . get ( host , new Date ( ) ) ) . focus : undefined )
0 commit comments