ElectronJS:Windows系统上的子窗口不会与父窗口一起移动

时间:2019-06-22 06:19:23

标签: electron

我创建了一个电子应用程序,其中有一个父窗口和该父窗口的子窗口。在Mac上,它工作正常,父窗口移动时,子窗口也随之移动。但是,将相同的代码打包到.exe文件中并在Windows计算机上进行测试时,子窗口不会随父窗口一起移动。

下面是代码:

const {app, BrowserWindow} = require('electron');
const url = require('url');
const path = require('path');  
let win , childWin; 

    function createWindow() { 
      win = new BrowserWindow({ height:300,width:600,show: false,   
        webPreferences: {
            nodeIntegration: true
        },resizable: false
     });
     win.loadURL(url.format ({ 
        pathname: path.join(__dirname, 'index.html'), 
        protocol: 'file:', 
        slashes: true 
    }));

    win.once('ready-to-show', () => {
        win.show();
        var pos = win.getPosition();
        childWin.show();
        childWin.setPosition((pos[0]+300),(pos[1]+22));
    });
    win.on('closed',()=>{
        win =null;
    });
    childWin = new BrowserWindow({ height:275,width:300,    
        webPreferences: {
            nodeIntegration: true
        },parent: win, frame:false,resizable: false
    });
    childWin.loadURL(url.format ({ 
        pathname: path.join(__dirname, 'index_child.html'), 
        protocol: 'file:', 
        slashes: true 
    }));

    childWin.once('ready-to-show', () => {
        childWin.show()
    });

    childWin.on('closed',()=>{
        childWin =null;
    });
   }  

   app.on('ready', createWindow);
   app.on('window-all-closed',()=>{
     if(process.platform!=='darwin'){
        app.quit();
     } 
   });

0 个答案:

没有答案
相关问题