(mainWindow)
| 33 | } |
| 34 | |
| 35 | function init (mainWindow) { |
| 36 | windowCount++ |
| 37 | |
| 38 | // Listen for auth response from renderer if not already listening |
| 39 | if (ipcMain.listenerCount('webview-auth-response') === 0) { |
| 40 | ipcMain.on('webview-auth-response', onAuthResponse) |
| 41 | } |
| 42 | |
| 43 | // Handle new webviews |
| 44 | mainWindow.webContents.on('did-attach-webview', (event, viewWebContents) => { |
| 45 | setupWebview(viewWebContents, mainWindow) |
| 46 | |
| 47 | // Clean up when webview is destroyed |
| 48 | viewWebContents.once('destroyed', () => { |
| 49 | credentialsMap.delete(viewWebContents.id) |
| 50 | // Remove any pending requests for this webview |
| 51 | for (const [reqId, entry] of authRequestMap.entries()) { |
| 52 | if (entry.webContentsId === viewWebContents.id) { |
| 53 | authRequestMap.delete(reqId) |
| 54 | } |
| 55 | } |
| 56 | }) |
| 57 | }) |
| 58 | |
| 59 | mainWindow.on('closed', () => { |
| 60 | windowCount-- |
| 61 | if (windowCount <= 0) { |
| 62 | ipcMain.removeListener('webview-auth-response', onAuthResponse) |
| 63 | credentialsMap.clear() |
| 64 | authRequestMap.clear() |
| 65 | initializedSessions.clear() |
| 66 | windowCount = 0 |
| 67 | } |
| 68 | }) |
| 69 | } |
| 70 | |
| 71 | function setupWebview (viewWebContents, mainWindow) { |
| 72 | const session = viewWebContents.session |
nothing calls this directly
no test coverage detected