1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| const {app,BrowserWindow,ipcMain,WebContentsView} = require('electron') const path = require('node:path') const minWindow = function(){ let win = new BrowserWindow({ width:800, height:600, webPreferences:{ preload:path.join(__dirname,'./preload.js'), } }) win.loadFile('./page/search.html') win.setMenu(null) let [width,height] = win.getContentSize(); let webview = null; ipcMain.on('create-webview',()=>{ if(webview === null){ webview = new WebContentsView(); webview.setBounds({ x:0, y:40, width:width, height:height - 40, }) win.contentView.addChildView(webview) } }) ipcMain.on('search-loadurl',(event,url)=>{ webview.webContents.loadURL(url); }) win.on('resize',()=>{ let [width,height] = win.getContentSize(); if(webview !== null){ webview.setBounds({ x:0, y:40, width:width, height:height - 40, }) } }) } app.whenReady().then(() => { minWindow() })
|