export const portalViews = new Map() mainWindow.webContents.setWindowOpenHandler((details) => { const { frameName } = details if (frameName && frameName.startsWith('portal:')) { const portalId = frameName.slice('portal:'.length) if (portalViews.has(portalId)) { return { action: 'deny' } } return { action: 'allow', createWindow: (options) => { const wc = (options as any).webContents as Electron.WebContents const view = new WebContentsView({ webContents: wc }) view.setBackgroundColor('#00000000') view.setBounds({ x: 0, y: 0, width: 1, height: 1 }) mainWindow!.contentView.addChildView(view) portalViews.set(portalId, view) wc.once('destroyed', () => { try { mainWindow?.contentView.removeChildView(view) } catch {} portalViews.delete(portalId) }) return wc } } } // todo: good impl if (details.url) shell.openExternal(details.url) return { action: 'deny' } }) ipcMain.on( 'portal:update-bounds', ( _e, payload: { id: string; bounds: { x: number; y: number; width: number; height: number } } ) => { const view = portalViews.get(payload.id) if (!view) return view.setBounds(payload.bounds) try { mainWindow!.contentView.addChildView(view) } catch {} } )