()
| 72 | |
| 73 | let connecting = false |
| 74 | function connect_port() { |
| 75 | if (connecting) return |
| 76 | |
| 77 | connecting = true |
| 78 | DEV: {place_log(Place_Name.Content, 'Attempting to connect port...')} |
| 79 | |
| 80 | try { |
| 81 | let new_port = chrome.runtime.connect({name: Connection_Name.Content}) |
| 82 | bg_port = new_port |
| 83 | DEV: {place_log(Place_Name.Content, 'Port connected successfully')} |
| 84 | |
| 85 | // Post detection state to each background port |
| 86 | if (detection) { |
| 87 | port_post_message(new_port, 'Detected', detection) |
| 88 | } |
| 89 | |
| 90 | // Post versions to each background port |
| 91 | port_post_message(new_port, 'Versions', versions) |
| 92 | |
| 93 | // Flush queued messages |
| 94 | for (let m of message_queue.splice(0, message_queue.length)) { |
| 95 | port_post_message_obj(new_port, m) |
| 96 | } |
| 97 | |
| 98 | /* From Background */ |
| 99 | port_on_message(new_port, e => { |
| 100 | // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check |
| 101 | switch (e.kind) { |
| 102 | case 'DevtoolsOpened': |
| 103 | devtools_opened = e.data |
| 104 | window_post_message_obj(e) |
| 105 | break |
| 106 | default: |
| 107 | /* Background -> Client */ |
| 108 | window_post_message_obj(e) |
| 109 | } |
| 110 | }) |
| 111 | |
| 112 | new_port.onDisconnect.addListener(() => { |
| 113 | DEV: {place_log(Place_Name.Content, 'Port disconnected...')} |
| 114 | |
| 115 | if (bg_port === new_port) { |
| 116 | bg_port = null |
| 117 | devtools_opened = false |
| 118 | setTimeout(connect_port, 100) |
| 119 | } |
| 120 | }) |
| 121 | } catch (err) { |
| 122 | place_error(Place_Name.Content, 'Failed to connect port:', err) |
| 123 | } |
| 124 | |
| 125 | connecting = false |
| 126 | } |
| 127 | |
| 128 | connect_port() |
| 129 |
no test coverage detected
searching dependent graphs…