()
| 146 | ws.removeEventListener('open', onOpen); |
| 147 | } |
| 148 | fn(); |
| 149 | } |
| 150 | function onOpen() { |
| 151 | finish(resolve); |
| 152 | } |
| 153 | function attachToCurrentSocket() { |
| 154 | if (settled) return; |
| 155 | if (ws && ws.readyState === WebSocket.OPEN) { |
| 156 | finish(resolve); |
| 157 | return; |
| 158 | } |
| 159 | if (ws) { |
| 160 | ws.removeEventListener('open', onOpen); |
| 161 | ws.addEventListener('open', onOpen); |
| 162 | } |
| 163 | } |
| 164 | function poll() { |
| 165 | if (settled) return; |
| 166 | if (ws && ws.readyState === WebSocket.OPEN) { |
| 167 | finish(resolve); |
| 168 | return; |
| 169 | } |
| 170 | if (Date.now() >= deadline) { |
| 171 | finish(function() { |
| 172 | reject(new Error('WebSocket connection failed')); |
| 173 | }); |
| 174 | return; |
| 175 | } |
| 176 | if (reconnectAttempts >= maxReconnectAttempts && (!ws || ws.readyState === WebSocket.CLOSED)) { |
| 177 | finish(function() { |
| 178 | reject(new Error('WebSocket connection unavailable')); |
| 179 | }); |
| 180 | return; |
| 181 | } |
| 182 | // Keep trying connect while waiting (no-ops if already connecting/open) |
| 183 | connect(); |
| 184 | attachToCurrentSocket(); |
| 185 | pollTimer = setTimeout(poll, 250); |
| 186 | } |
| 187 | |
| 188 | attachToCurrentSocket(); |
| 189 | pollTimer = setTimeout(poll, 250); |
| 190 | }); |
| 191 | } |
| 192 | |
| 193 | // Define send() method - will be enhanced when WebSocket connects |
| 194 | let sendFunction = function(channel, ...args) { |
| 195 | // Will be enhanced when WebSocket connects |
| 196 | console.warn('window.electron.send called before WebSocket connected:', channel); |
| 197 | }; |
| 198 | window.electron.send = sendFunction; |
| 199 | |
| 200 | function showBrowserMessage(title, message, buttons = ['OK']) { |
| 201 | return new Promise((resolve) => { |
| 202 | const dialog = document.createElement('dialog'); |
| 203 | const dialogId = `browser-message-${Date.now()}-${Math.floor(Math.random() * 1000)}`; |
| 204 | dialog.id = dialogId; |
| 205 | dialog.style.cssText = ` |
no test coverage detected