Skip to content

Commit 5e250b0

Browse files
committed
Display place connection status in popup
1 parent dc59213 commit 5e250b0

File tree

5 files changed

+88
-10
lines changed

5 files changed

+88
-10
lines changed

.changeset/fresh-camels-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solid-devtools/extension": patch
3+
---
4+
5+
Display place connection status in popup

extension/src/background.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

6565
let 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+
100106
function 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
}

extension/src/popup.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ a:hover {
4040
p {
4141
margin: 0;
4242
}
43-
p[data-detected]::before {
43+
p[data-status]::before {
4444
content: '';
4545
display: inline-block;
4646
width: 0.5rem;
@@ -49,10 +49,10 @@ p[data-detected]::before {
4949
margin-right: 0.3rem;
5050
background-color: var(--disabled);
5151
}
52-
p[data-detected='false'] {
52+
p[data-status='false'] {
5353
color: var(--lighter-dark);
5454
}
55-
p[data-detected='true']::before {
55+
p[data-status='true']::before {
5656
background-color: var(--blue);
5757
}
5858

extension/src/popup.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ const empty_detection_state: Detection_State = {
2424
}
2525
const [detectionState, setDetectionState] = s.createSignal(empty_detection_state)
2626

27+
type Connection_Status = {
28+
[Place_Name.Content]: boolean
29+
[Place_Name.Devtools]: boolean
30+
[Place_Name.Panel]: boolean
31+
}
32+
const empty_connection_status: Connection_Status = {
33+
[Place_Name.Content]: false,
34+
[Place_Name.Devtools]: false,
35+
[Place_Name.Panel]: false,
36+
}
37+
const [connectionStatus, setConnectionStatus] = s.createSignal(empty_connection_status)
38+
2739
port_on_message(port, e => {
2840
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
2941
switch (e.kind) {
@@ -33,24 +45,34 @@ port_on_message(port, e => {
3345
case 'Versions':
3446
setVersions(e.data)
3547
break
48+
case 'Port_Connection_Status':
49+
setConnectionStatus(prev => ({
50+
...prev,
51+
[e.data.place]: e.data.state
52+
}))
53+
break
3654
}
3755
})
3856

57+
function not_str(value: boolean): string {
58+
return value ? '' : 'not'
59+
}
60+
3961
const App: s.Component = () => {
4062
return <>
4163
<div>
42-
<p data-detected={detectionState().solid}>
43-
Solid {detectionState().solid ? 'detected' : 'not detected'}
64+
<p data-status={detectionState().solid}>
65+
Solid {not_str(detectionState().solid)} detected
4466
</p>
4567
</div>
4668
<div>
47-
<p data-detected={detectionState().solid_dev}>
48-
Solid Dev Mode {detectionState().solid_dev ? 'detected' : 'not detected'}
69+
<p data-status={detectionState().solid_dev}>
70+
Solid Dev Mode {not_str(detectionState().solid_dev)} detected
4971
</p>
5072
</div>
5173
<div>
52-
<p data-detected={detectionState().setup}>
53-
Debugger {detectionState().setup ? 'detected' : 'not detected'}
74+
<p data-status={detectionState().setup}>
75+
Debugger {not_str(detectionState().setup)} detected
5476
</p>
5577
<s.Show when={detectionState().solid_dev && !detectionState().setup}>
5678
<div class="details">
@@ -69,6 +91,21 @@ const App: s.Component = () => {
6991
</div>
7092
</s.Show>
7193
</div>
94+
<div>
95+
<p data-status={connectionStatus()[Place_Name.Content]}>
96+
Content Script {not_str(connectionStatus()[Place_Name.Content])} connected
97+
</p>
98+
</div>
99+
<div>
100+
<p data-status={connectionStatus()[Place_Name.Devtools]}>
101+
Devtools {not_str(connectionStatus()[Place_Name.Devtools])} connected
102+
</p>
103+
</div>
104+
<div>
105+
<p data-status={connectionStatus()[Place_Name.Panel]}>
106+
Panel {not_str(connectionStatus()[Place_Name.Panel])} connected
107+
</p>
108+
</div>
72109
<s.Show when={versions()} keyed>
73110
{v => (
74111
<div class="versions">

extension/src/shared.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export interface General_Channels {
8080
DevtoolsOpened: boolean
8181

8282
ResetPanel: void
83+
84+
/** background -> popup: connection status for different places */
85+
Port_Connection_Status: {
86+
place: Place_Name
87+
state: boolean
88+
}
8389
}
8490

8591
export type Channels = debug.InputChannels

0 commit comments

Comments
 (0)