electron 如何控制雙屏的顯示內(nèi)容?

位置:首頁(yè) / 新聞中心 / 知識(shí)教程

知識(shí)教程 Admin 2024-02-22 17:54:34 757
function createOtherWin(){
    const newURL = './src/otherWin/otherWin.html';
    let displays = electron.screen.getAllDisplays();
    console.log(displays);  let externalDisplay = displays.find((display) => {
      return display.bounds.x !== 0 || display.bounds.y !== 0  })
    console.log(externalDisplay)  if (externalDisplay) {
      newWindow = new BrowserWindow({
          fullscreen:true,
          x: externalDisplay.bounds.x,
          y: externalDisplay.bounds.y,
            webPreferences: {
              nodeIntegration: true,
          }
      })
      newWindow.loadFile(newURL);
        newWindow.on('closed', () => {   //這一段放外面的話,如果你電腦沒(méi)雙屏?xí)?bào)錯(cuò)。
         newWindow = null
        })
        //主進(jìn)程監(jiān)聽(tīng)事件
       ipcMain.on('send-card', (event, obj) => {
           newWindow.webContents.send('sendWebsock', obj);
        })
        ipcMain.on('sendError', (event, res) => {
           newWindow.webContents.send('sendErrorData', res);
        })  }
  }app.on('ready', ()=>{
  createWindow();
  createOtherWin();})

屏幕之間的通信的話用主進(jìn)程與渲染進(jìn)程通信的方式很好解決(main.js/ipcMain),
渲染進(jìn)程
ipcRenderer.send('send-card', obj)  觸發(fā)主進(jìn)程的send-card事件.
newWindow.webContents.send('sendWebsock', obj); 把數(shù)據(jù)傳遞給副屏幕窗口
副屏幕窗口接收

const { ipcRenderer } = require('electron');ipcRenderer.on('sendWebsock', (event, obj) => {
    console.log(obj)})



以上就是“electron 如何控制雙屏的顯示內(nèi)容?”的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注木子天禾科技其它相關(guān)文章!

以上就是“electron 如何控制雙屏的顯示內(nèi)容?”的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注木子天禾科技其它相關(guān)文章!

15934152105 掃描微信