()
| 175 | } |
| 176 | |
| 177 | export function createPluginWindow() { |
| 178 | if (pluginWindow && !pluginWindow.isDestroyed()) { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | ensureIpcListeners(); |
| 183 | |
| 184 | pluginWindow = new BrowserWindow({ |
| 185 | show: false, |
| 186 | title: 'PluginWindow', |
| 187 | webPreferences: { |
| 188 | contextIsolation: false, |
| 189 | nodeIntegration: true, |
| 190 | preload: path.join(__dirname, 'entry.plugin-window-preload.min.js'), |
| 191 | backgroundThrottling: false, |
| 192 | devTools: process.env.NODE_ENV === 'development', |
| 193 | }, |
| 194 | }); |
| 195 | |
| 196 | pluginWindow.on('closed', () => { |
| 197 | pluginWindow = null; |
| 198 | windowReady = false; |
| 199 | for (const [id, { reject }] of pendingRequests) { |
| 200 | pendingRequests.delete(id); |
| 201 | reject(new Error('[plugin-window] window closed')); |
| 202 | } |
| 203 | }); |
| 204 | |
| 205 | pluginWindow.webContents.on('render-process-gone', (_event, details) => { |
| 206 | bridgeMetrics.windowCrashes += 1; |
| 207 | console.log(`[plugin-bridge] window_crash reason=${details.reason} exit_code=${details.exitCode}`); |
| 208 | }); |
| 209 | |
| 210 | bridgeMetrics.windowStartups += 1; |
| 211 | bridgeMetrics.lastStartupAt = Date.now(); |
| 212 | const pluginWindowPath = path.resolve(__dirname, 'plugin-window.html'); |
| 213 | pluginWindow.loadFile(pluginWindowPath); |
| 214 | console.log(`[plugin-bridge] window_loading path=${pluginWindowPath} startups_total=${bridgeMetrics.windowStartups}`); |
| 215 | } |
| 216 | |
| 217 | function waitForReady(timeoutMs = 10_000): Promise<void> { |
| 218 | if (windowReady) { |
no test coverage detected