Last active
September 10, 2025 11:17
-
-
Save RobPruzan/1c6bb4ad5bd24d34eb244e1e55af9100 to your computer and use it in GitHub Desktop.
Revisions
-
RobPruzan revised this gist
Sep 10, 2025 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ 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) -
RobPruzan created this gist
Sep 10, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ 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 {} } )