MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / connect_port

Function connect_port

extension/src/panel.tsx:54–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52
53 let connecting = false
54 function connect_port() {
55 if (connecting) return
56
57 connecting = true
58 place_log(Place_Name.Panel, 'Attempting to connect port...')
59
60 try {
61 let new_port = chrome.runtime.connect({name: Connection_Name.Panel})
62 setPort(new_port)
63 place_log(Place_Name.Panel, 'Port connected successfully')
64
65 // Flush queued messages
66 for (let m of message_queue.splice(0, message_queue.length)) {
67 port_post_message_obj(new_port, m)
68 }
69
70 port_on_message(new_port, e => {
71 // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
72 switch (e.kind) {
73 case 'Versions':
74 setVersions(e.data ?? empty_versions)
75 break
76 default:
77 /* Client -> Devtools */
78 devtools.input.emit(
79 // @ts-expect-error - type mismatch between debug types and actual message
80 e,
81 )
82 }
83 })
84
85 new_port.onDisconnect.addListener(() => {
86 if (port() === new_port) {
87 setPort(null)
88 setTimeout(connect_port, 100)
89 }
90 })
91 } catch (err) {
92 place_error(Place_Name.Panel, 'Failed to connect port:', err)
93 }
94
95 connecting = false
96 }
97
98 connect_port()
99

Callers 1

AppFunction · 0.70

Calls 4

place_logFunction · 0.90
port_post_message_objFunction · 0.90
port_on_messageFunction · 0.90
place_errorFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…