@@ -5,6 +5,7 @@ import { TabAndTabsetId } from 'src/tabsets/models/TabAndTabsetId'
55import { Tabset , TabsetStatus } from 'src/tabsets/models/Tabset'
66import { LocalStorageTabsetsPersistence } from 'src/tabsets/persistence/LocalStorageTabsetsPersistence'
77import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore'
8+ import { useTabsStore2 } from 'src/tabsets/stores/tabsStore2'
89import { ref } from 'vue'
910
1011export const useTabsetsUiStore = defineStore ( 'tabsetsUi' , ( ) => {
@@ -79,6 +80,32 @@ export const useTabsetsUiStore = defineStore('tabsetsUi', () => {
7980 lastUsedTabsets . value = _ . union ( lastUsedTabsets . value , favorites . value )
8081 }
8182
83+ function updateExtensionIcon ( ) {
84+ const currentBrowserTab = useTabsStore2 ( ) . currentChromeTab
85+ const currentUrl = currentBrowserTab ?. url
86+ if ( currentUrl ) {
87+ console . log ( 'updating extension icon' , currentUrl )
88+ chrome . action . setBadgeText ( { text : '' } )
89+ chrome . action . setTitle ( { title : 'Tabsets' } )
90+ setMatchingTabsFor ( currentUrl )
91+ if ( matchingTabs . value . length > 0 ) {
92+ chrome . action . setBadgeText ( { text : '' + matchingTabs . value . length } )
93+ chrome . action . setBadgeBackgroundColor ( { color : 'orange' } )
94+ chrome . action . setTitle ( { title : `The current tab is contained in ${ matchingTabs . value . length } tabsets` } )
95+ if (
96+ matchingTabs . value
97+ . map ( ( ts : TabAndTabsetId ) => ts . tabsetId )
98+ . indexOf ( useTabsetsStore ( ) . currentTabsetId || '' ) >= 0
99+ ) {
100+ chrome . action . setBadgeBackgroundColor ( { color : 'green' } )
101+ chrome . action . setTitle ( {
102+ title : `The current tab is contained in ${ matchingTabs . value . length } tabsets, including the current one (${ useTabsetsStore ( ) . currentTabsetName } ).` ,
103+ } )
104+ }
105+ }
106+ }
107+ }
108+
82109 return {
83110 initialize,
84111 setMatchingTabsFor,
@@ -88,5 +115,6 @@ export const useTabsetsUiStore = defineStore('tabsetsUi', () => {
88115 lastUpdate,
89116 clearFromLastUsedTabsets,
90117 load,
118+ updateExtensionIcon,
91119 }
92120} )
0 commit comments