@@ -59,7 +59,7 @@ type Script_Content = {
5959 tab_id : Tab_Id
6060 port : Port
6161 detection : Detection_State | null
62- versions : Versions | null
62+ versions : Versions | null
6363}
6464
6565let popup : Script_Popup | undefined
@@ -97,6 +97,12 @@ function toggle_action_icon(tab_id: Tab_Id) {
9797 }
9898}
9999
100+ function send_connection_status_to_popup ( place : Place_Name , state : boolean ) {
101+ if ( popup ) {
102+ port_post_message ( popup . port , 'Port_Connection_Status' , { place, state} )
103+ }
104+ }
105+
100106function on_connected ( port : Port ) {
101107
102108 place_log ( Place_Name . Background , 'Port connected' , port )
@@ -111,6 +117,14 @@ function on_connected(port: Port) {
111117 port_post_message ( popup . port , 'Versions' , content . versions )
112118 }
113119
120+ send_connection_status_to_popup ( Place_Name . Content , content != null )
121+
122+ let devtools = script_devtools_map . get ( active_tab_id )
123+ send_connection_status_to_popup ( Place_Name . Devtools , devtools != null )
124+
125+ let panel = script_panel_map . get ( active_tab_id )
126+ send_connection_status_to_popup ( Place_Name . Panel , panel != null )
127+
114128 break
115129 }
116130 case Connection_Name . Content : {
@@ -130,6 +144,10 @@ function on_connected(port: Port) {
130144 port_post_message ( content . port , 'ResetState' , undefined )
131145 }
132146
147+ if ( tab_id === active_tab_id ) {
148+ send_connection_status_to_popup ( Place_Name . Content , true )
149+ }
150+
133151 break
134152 }
135153 case Connection_Name . Devtools : {
@@ -142,6 +160,8 @@ function on_connected(port: Port) {
142160 port_post_message ( port , 'Versions' , content . versions )
143161 }
144162
163+ send_connection_status_to_popup ( Place_Name . Devtools , true )
164+
145165 break
146166 }
147167 case Connection_Name . Panel : {
@@ -157,6 +177,8 @@ function on_connected(port: Port) {
157177 port_post_message ( content . port , 'ResetState' , undefined )
158178 }
159179
180+ send_connection_status_to_popup ( Place_Name . Panel , true )
181+
160182 break
161183 }
162184 }
@@ -200,6 +222,10 @@ function on_disconnected(port: Port) {
200222
201223 toggle_action_icon ( tab_id )
202224
225+ if ( tab_id === active_tab_id ) {
226+ send_connection_status_to_popup ( Place_Name . Content , false )
227+ }
228+
203229 break
204230 }
205231 case Connection_Name . Devtools : {
@@ -210,6 +236,8 @@ function on_disconnected(port: Port) {
210236 port_post_message ( content . port , 'DevtoolsOpened' , false )
211237 }
212238
239+ send_connection_status_to_popup ( Place_Name . Devtools , false )
240+
213241 break
214242 }
215243 case Connection_Name . Panel : {
@@ -220,6 +248,8 @@ function on_disconnected(port: Port) {
220248 port_post_message ( content . port , 'DevtoolsOpened' , false )
221249 }
222250
251+ send_connection_status_to_popup ( Place_Name . Panel , false )
252+
223253 break
224254 }
225255 }
0 commit comments