Last active
September 10, 2025 11:17
-
-
Save RobPruzan/1c6bb4ad5bd24d34eb244e1e55af9100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const portalViews = new Map<string, WebContentsView>() | |
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 {} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment