MCPcopy
hub / github.com/electerm/electerm / init

Function init

src/app/lib/webview-handler.js:35–69  ·  view source on GitHub ↗
(mainWindow)

Source from the content-addressed store, hash-verified

33}
34
35function 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
71function setupWebview (viewWebContents, mainWindow) {
72 const session = viewWebContents.session

Callers

nothing calls this directly

Calls 4

setupWebviewFunction · 0.85
onceMethod · 0.80
clearMethod · 0.80
onMethod · 0.45

Tested by

no test coverage detected